Skip to content
Prev 260670 / 398502 Next

Looping through values in a data frame that are >zero

Thank you very much, everyone! Extremely helpful!

I really liked these two solutions:

# reshape is really cool + it gives me the value I need!
library(reshape2)
solution1<-subset(melt(x, id = c('y', 'z')), value > 0)

# This one is also very good, just need one additional loop - to
include variable names:
mylist<-lapply(x[,c("a","b","c")], function(zz)x[zz>0, c("y","z")])
for(i in 1:length(mylist)){
	mylist[[i]]["varname"]<-names(mylist[i])
}

Dimitri
On Sat, May 21, 2011 at 5:28 PM, Dennis Murphy <djmuser at gmail.com> wrote: