Re: [R] combining/deleting rows

From: David Winsemius <dwinsemius_at_comcast.net>
Date: Tue, 11 Mar 2008 03:01:43 +0000 (UTC)

"Suran, Luciana @ Torto Wheaton Research" <Luciana.Suran_at_tortowheatonresearch.com> wrote in news:09EBE0E1A7DEA24CAD5EA6827A7EB16D0C620EF5_at_usidcxmb02.us.cbre.net:

> I'm new to R and have some question on combining (and deleting)
> rows.

You posted your email in response to a question that had nothing to do with this question. If you have new question, you should not send a reply to someone else's question.  

> I have a dataset that looks like this:
>

      <snipped single element per line listing with 47 elements>

The lines you posted had no organization that would suggest they had ever been part of a data.frame. The first 5 elements looked to be variable names. But the number of elements was not evenly divisible by 5. Can you post a new message with complete data and the code (or method) that you used to bring this data into the R environment?

>
> How can I add row 1 to row 24?

If this is arranged as only one column, and you wanted the value in row 24, then the code might be:

df[24] <- df[24] + df[1]

> Also, how can I delete rows from the dataframe?

You could assign another object the values in the first object rows that you wanted kept:

df2 <- df[c(1:3, 5:10), ]

Or you could exclude the rows you wanted dropped using a minus-sign:

df2 <- df[-4,]

df2 <- df[-c(2,5,8), ]

-- 
David Winsemius

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Tue 11 Mar 2008 - 03:04:45 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 11 Mar 2008 - 03:30:21 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive