[R] Problem looping a function to create/add to new dataframe
Mike Treglia
mlt35 at tamu.edu
Thu Sep 15 19:50:57 CEST 2011
Dear List Members,
I have created a function to run a simulation based on a given set of
values within a vector, such that I run the function like this:
new.data<-sapply(vector, function)
In which I run 'function' on every value within a vector that I created.
The result is a matrix of 1000 rows, and as many columns as the length
of the vector.
I modified the function to utilize two given values, such that it is:
function(x,y), and I want to run this function for not only a range of
values of 'x', but a range of values of 'y' as well, such that for each
value of 'y', I'd create another 1000 rows in the matrix. I was trying
to loop this, but in doing so, it looks like I just keep creating
datasets and replacing them with datasets for subsequent 'y' values,
rather than adding new rows. The structure of my current loop is below.
Any suggestions on what to change to accomplish what I want? Would it be
good to create a dataframe first and then somehow add these new rows to
the dataframe? Also, is it appropriate to have the 'i' in the sapply
statement?
for (i in c(seq(10,100,10))){
new.data<-sapply(vector, function, i)
}
Please let me know if more detail on my code would be helpful- I was
just trying to keep it simple and focus on what I saw as the problem at
hand for now.
Thank you for your help.
Sincerely,
Mike Treglia
--
Michael Treglia
Applied Biodiversity Sciences NSF-IGERT Program
Wildlife and Fisheries Sciences
Texas A&M University
Lab: (979)862-7245
mlt35 at tamu.edu
http://people.tamu.edu/~mlt35
More information about the R-help
mailing list