[R] How can i select a set of element in a list ?
djnordlund at frontier.com
Wed Dec 8 23:46:17 CET 2010
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> On Behalf Of Julian TszKin Chan
> Sent: Wednesday, December 08, 2010 2:39 PM
> To: r-help at r-project.org
> Subject: [R] How can i select a set of element in a list ?
> How can i select a set of element in a list ?
> How can I create a new list which only have the last 4 elements of x.
> I can do it with a loop, but I want to avoid that. Thanks!
> example :
> for ( i in 1:length(y) )
> y[[i]] <- x[[ i + length(x) - length(y) ]]
> > y
>  2
>  3
>  4
>  5
You use standard indexing to do that.
y <- x[-1]
Hope this is helpful,
Bothell, WA USA
More information about the R-help