Dear list,

I have two lists: one with data and one with TRUE/FALSE values for data I want to further analyze (see example below). I have been able to use a for loop to extract the data that I want to keep, but think that there probably exists a way to do it without a loop. Any ideas?

#sample data
set.seed(100)
example = list(letters[1:10], letters[1:10], letters[1:10])
ind = list(as.logical(sample(0:1, 10, rep=TRUE)), as.logical(sample(0:1, 10, rep=TRUE)), as.logical(sample(0:1, 10, rep=TRUE)), as.logical(sample(0:1, 10, rep=TRUE)))

#loop method
for (i in 1:length(example)) print(example[[i]][ind[[i]]])

#result
[1] "c" "g" "i"
[1] "a" "b" "e" "f" "j"
[1] "a" "b" "c" "d" "g" "h" "i"


Thank you for the help.

Greg

--
Greg Hirson
ghir...@ucdavis.edu

Graduate Student
Agricultural and Environmental Chemistry

1106 Robert Mondavi Institute North
One Shields Avenue
Davis, CA 95616

______________________________________________
R-help@r-project.org mailing list
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.

Reply via email to