Hi All! Please find code and the respective lists below. My problem: I specify the case that lilwin[[p]] is not an NA and want the code found in iwish to be returned ONLY for that case. Why do I get a list of length 2 (and why is NULL the first element)? I understand that the code below is quite senseless. I have run into a problem while working on a large project and wanted to simplify it in order for it to be more understandable and accessible. If I should not be using the if function, please let me know what I should be doing instead. I know that I must use the for function for my project. The thing I most want to understand is how, after specifying a certain condition, one may save certain data that occurs when that condition is met. I hope I have been clear enough!
Thank you very much for your help! Anna biglist<-list(a=1:4,b=2:6) lilwin<-list(x=NA,y=2) lilloss<-list(m=1,n=3) > biglist$a [1] 1 2 3 4 $b [1] 2 3 4 5 6 > lilwin$x [1] NA $y [1] 2 > lilloss$m [1] 1 $n [1] 3 iwish<-list() for(p in 1:length(biglist)){ if(is.na(lilwin[[p]])==F) iwish[p]<-list(biglist[[p]][lilwin[[p]]]) } > iwish[[1]] NULL [[2]] [1] 3 [[alternative HTML version deleted]] ______________________________________________ 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.