Re: [R] nested looping functions and dataframes

2010-03-16 Thread Lanna Jin
Thanks Phil, That worked wonders! Best, Lanna 2010/3/16 Phil Spector > Lanna - > Here's one way: > > makeframe = function(x){ > b = as.data.frame(as.matrix(table(x$Species,x$Species))) > b = b[!(b$Var1 == b$Var2),-3] > data.frame(Year=x$Year[1],Location=x$Location[1],b) > } > > result

Re: [R] nested looping functions and dataframes

2010-03-16 Thread Phil Spector
Lanna - Here's one way: makeframe = function(x){ b = as.data.frame(as.matrix(table(x$Species,x$Species))) b = b[!(b$Var1 == b$Var2),-3] data.frame(Year=x$Year[1],Location=x$Location[1],b) } result = lapply(split(x,list(x$Year,x$Location)),makeframe) result will be a list of data fra

[R] nested looping functions and dataframes

2010-03-16 Thread Lanna Jin
Hey All, So, I am confused how exactly to use nesting loop functions in R to spit out data frames. I've managed to create a working function for my data set that generates a data frame for a given set of Year i and Location j; but how would I do it for all Years and Locations? Here is my workin