[R] deleteing all but some observations in data.frame

Erik Iverson eriki at ccbr.umn.edu
Wed Nov 3 20:51:27 CET 2010


It depends on which 20 you want.

If you have a data.frame called 'test.df', you can do:

#first 20
test.df[20, ]

-or-

head(test.df, 20)

#random 20
test.df[sample(nrow(test.df), 20), ]

None of this was tested, but it should be a start.

--Erik

Matevž Pavlič wrote:
> Hi, 
> 
>  
> 
> I am sure that can be done in R....
> 
> How would i delete all but let say 20 observations in data.frame?
> 
>  
> 
> Thank you, M
> 
>  
> 
>  
> 
> 
> 	[[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.



More information about the R-help mailing list