[R] combining/deleting rows

David Winsemius dwinsemius at comcast.net
Tue Mar 11 04:01:43 CET 2008


"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



More information about the R-help mailing list