[R] ask a question about list in R
David Winsemius
dwinsemius at comcast.net
Fri Jun 25 13:25:31 CEST 2010
On Jun 25, 2010, at 1:00 AM, song song wrote:
> my list al is as below:
> al=list(c(2,3),5,7)
>> al
> [[1]]
> [1] 2 3
>
> [[2]]
> [1] 5
>
> [[3]]
> [1] 7
>
> and I check the second component, its element is 5, then I remove
> this, now
> my al is:
>
> al[[2]][al[[2]]!=5]->al[[2]]
>> al
> [[1]]
> [1] 2 3
>
> [[2]]
> numeric(0)
>
> [[3]]
> [1] 7
>
> The Question is, how I can get the new list without the second
> component,
> that is :
>
>> alwanted
> [[1]]
> [1] 2 3
>
> [[2]]
> [1] 7
Another way:
> al=list(c(2,3),5,7)
> al[-2]
[[1]]
[1] 2 3
[[2]]
[1] 7
> alwanted <- al[-2]
Negative indexing with the "[" operator.
--
David.
More information about the R-help
mailing list