Re: [R] Delete Block of Rows

From: milton ruser <milton.ruser_at_gmail.com>
Date: Sun, 15 Jun 2008 12:35:01 -0300

Hi there,

I donīt know if you are trying to solve the delete job or to test how functions work.

If you really want to delete lines from a data.frame, try something like this.

rowcount<-1:100
x<-runif(100)
y<-runif(100)

df<-data.frame(cbind(rowcount,x,y))

df.subset<-subset(df, !(rownames(df) %in% 1:25))

     # ! (a condition) is the negation of the condition

     # so the output will be those lines that are not on interval 1:25

By the way, it is not a good idea to use "data" as a input argument on a function because "data" is a pre-defined function. Kind regards,

miltinho

On 6/15/08, nmarti <nate318i_at_yahoo.com> wrote:
>
>
> I am trying to delete a section of rows from a data frame (based on no
> condition). Lets say my data frame has 200 rows and I want to delete rows
> 1
> through 25. How would I do this?
>
> I know x[ -1, ] deletes the first row (or any desired row). I tried using
> different variations of this, like x[ -c(1:25), ] but that didn't work. I
> also tried writting a few functions, for example:
>
> deleteRows <- function( data, s, e, ) {
> for( i in s:e )
> data[ -i, ]
> }
> deleteRows( ds, 1, 25 )
>
> But that didn't work either, it only deleted row 25 (i'm new to writing
> functions).
> Any thoughts on how to solve my problem would be appreciated.
> --
> View this message in context:
> http://www.nabble.com/Delete-Block-of-Rows-tp17849775p17849775.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>

        [[alternative HTML version deleted]]



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 Sun 15 Jun 2008 - 16:16:16 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 Mon 16 Jun 2008 - 15:00:42 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