Re: [R] how to update a value in a list with lapply

2015-05-11 Thread Henric Winell
On 2015-05-10 21:14, David Winsemius wrote: On May 10, 2015, at 6:11 AM, ce wrote: yes indeed : foo <- lapply(foo, function(x) if(x[1] == 1 ) {x[2] <- 0; x }else{x} ) would work. But if the list is too long, would it be time consuming rather than just updating elements that meet the if cond

Re: [R] how to update a value in a list with lapply

2015-05-11 Thread ce
5 06:00 PM To: "ce" CC: "David Winsemius" , r-help@r-project.org Subject: Re: [R] how to update a value in a list with lapply You can do the timing yourself on a dataset which you feel is typical of your usage.E.g., define a function the implements each algorithm  > f1 <-

Re: [R] how to update a value in a list with lapply

2015-05-10 Thread William Dunlap
e{x} ) > > would work. But if the list is too long, would it be time consuming > rather than just updating elements that meet the if condition? > > thx > ce > > > -Original Message- > From: "David Winsemius" [dwinsem...@comcast.net] > Date:

Re: [R] how to update a value in a list with lapply

2015-05-10 Thread David Winsemius
The data.table package was invented in large part to get around that design concern. -- David. > > thx > ce > > > -Original Message- > From: "David Winsemius" [dwinsem...@comcast.net] > Date: 05/09/2015 08:00 PM > To: "ce" > CC: r-help

Re: [R] how to update a value in a list with lapply

2015-05-10 Thread ce
s" [dwinsem...@comcast.net] Date: 05/09/2015 08:00 PM To: "ce" CC: r-help@r-project.org Subject: Re: [R] how to update a value in a list with lapply On May 9, 2015, at 4:35 PM, ce wrote: > Dear All, > > I have a list, using lapply I find some elements of the list, and then I

Re: [R] how to update a value in a list with lapply

2015-05-09 Thread David Winsemius
On May 9, 2015, at 4:35 PM, ce wrote: > Dear All, > > I have a list, using lapply I find some elements of the list, and then I want > to change the values I find. but it doesn't work: > > foo<-list(A = c(1,3), B =c(1, 2), C = c(3, 1)) > lapply(foo, function(x) if(x[1] == 1 ) x ) > $A > [1] 1 3

[R] how to update a value in a list with lapply

2015-05-09 Thread ce
Dear All, I have a list, using lapply I find some elements of the list, and then I want to change the values I find. but it doesn't work: foo<-list(A = c(1,3), B =c(1, 2), C = c(3, 1)) lapply(foo, function(x) if(x[1] == 1 ) x ) $A [1] 1 3 $B [1] 1 2 $C NULL lapply(foo, function(x) if(x[1]