[R] for loop using index values

arun smartpink111 at yahoo.com
Thu May 15 13:26:53 CEST 2014


Hi,

Not sure I understand correctly.  May be this helps:
##If the blocks are created as a list
set.seed(475)
 lst1 <- setNames(lapply(1:10, function(i) {rowN <- sample(20,1)*15; matrix(sample(40,10*rowN, replace=TRUE), nrow=rowN)}),1:10) 

sapply(lst1,nrow)>100
 #   1     2     3     4     5     6     7     8     9    10 
 #TRUE  TRUE  TRUE  TRUE  TRUE FALSE  TRUE FALSE  TRUE  TRUE 
sapply(lst1[sapply(lst1,nrow)>100],mean)
##
lapply(lst1[sapply(lst1,nrow)>100],summary)

A.K.





On Thursday, May 15, 2014 12:26 AM, David Gwenzi <dgwenzi at gmail.com> wrote:
Hi all

I have point data along a transect and I want to divide the transect into
small blocks of 10m length each. I have named the blocks as a list i.e
subset[[i]]. Now the issue is I want to process only those blocks that have
at least 100 data points and keep the original index values of those
subsets. How do I set the for loop. I have tried the following but it is
still processing everything

select<-which(nrow(subset[[i]])>=100
for (i in c(select)){
..............
}
Thank you in advance,

David Gwenzi
Graduate Degree Program in Ecology
Natural Resources Ecology Lab
Colorado State University

    [[alternative HTML version deleted]]

______________________________________________
R-help at 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.




More information about the R-help mailing list