[R] Probably a good use for apply

LCOG1 jroll at lcog.org
Thu May 31 02:50:07 CEST 2012


Hi all, 
  I Have a data frame test.. that I would like to convert into a list below
test_ but am unsure how to efficiently do this.  I can do it in a for loop
but my data set is huge and it takes forever.  Wondering how I can do this
more efficiently.  So again how to I go from test.. to test_ below?  
#Data frame
test.. <- data.frame(Apples = c(1,3,0,0,1), Pears = c(0,0,1,0,2), Beans =
c(1,2,1,0,0))

#list - my desired outcome
test_ <- list("1" = c("Apples","Beans"),
			  "2" = c("Apples","Apples","Apples","Beans","Beans"),
			  "3" = c("Pears","Beans"),
			  "4" = c(NULL),
			  "5" = c("Apples","Pears","Pears"))

Thanks

Josh

--
View this message in context: http://r.789695.n4.nabble.com/Probably-a-good-use-for-apply-tp4631883.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list