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] == 1 ) x[2] <- 0 ) $A [1] 0 $B [1] 0 $C NULL > lapply(foo, function(x) if(x[1] == 1 ) x ) $A [1] 1 3 $B [1] 1 2 $C NULL how to do it correctly ? thanks ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.