Re: [R] ask a question about list in R project

2010-06-28 Thread Joshua Wiley
Hello, It looks to me like you want all the values of 'mylist' returned in a list except for a[i] for each element of a. In this case, length(a) = 4, so you want 4 lists. If this is not what you were trying to do, perhaps you could explain the pattern between your data and your desired output.

Re: [R] ask a question about list in R project

2010-06-28 Thread song song
I found this loop can do this. is there any simple method? rm(list=ls()) a=c(2,3,5,7) mylist=list(c(2,3),5,7) newlist=list() for (i in 1:4){ for (j in 1:length(mylist)){ newlist[[j]]=mylist[[j]] if (a[i] %in% mylist[[j]]){ newlist[[j]]=mylist[[j]][mylist[[j]]!=a[i]] if

Re: [R] ask a question about list in R project

2010-06-28 Thread David Winsemius
There was a recent fortune suggestion along the lines of any simple English sentence can probably be satisfied with a simple set of R functions without loops. In this case you appear to be forgetting the "simple English sentence" part of that formulation. -- David. On Jun 28, 2010, at 7:3

[R] ask a question about list in R project

2010-06-28 Thread song song
my list al is as below: mylist=list(c(2,3),5,7) > mylist [[1]] [1] 2 3 [[2]] [1] 5 [[3]] [1] 7 How could I get the following FOUR lists: First one [[1]] [1] 3 [[2]] [1] 5 [[3]] [1] 7 Second one [[1]] [1] 2 [[2]] [1] 5 [[3]] [1] 7 Third One [[1]] [1] 2 3 [[2]] [1] 7 Last one [[1]] [1] 2

Re: [R] ask a question about list in R

2010-06-25 Thread David Winsemius
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) [

Re: [R] ask a question about list in R

2010-06-24 Thread Phil Spector
Song - Set the element to NULL: al=list(c(2,3),5,7) al[[2]] = NULL al [[1]] [1] 2 3 [[2]] [1] 7 - Phil Spector Statistical Computing Facility Department of Statistics

[R] ask a question about list in R

2010-06-24 Thread song song
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 li