[R] Repeating a series of commands
KoopaTrooper
ncooper1 at tulane.edu
Thu Oct 11 20:09:46 CEST 2012
I'm trying to figure out how to repeat a series of commands in R and have the
outputs added to a dataframe after each iteration.
My code starts this way...
a<-read.csv("File1.csv")
b<-read.csv("File2.csv")
a$Z<-ifelse(a$Z=="L",sample(1:4,length(a$Z),replace=TRUE),ifelse(a$Z=="M",sample(5:8,length(a$Z),replace=TRUE),ifelse(a$Z=="U",sample(9:10,length(a$Z),replace=TRUE),"")))
a$Z<-as.numeric(a$Z)
b$Z<-ifelse(b$Z=="L",sample(1:4,length(b$Z),replace=TRUE),ifelse(b$Z=="M",sample(5:8,length(b$Z),replace=TRUE),ifelse(b$Z=="U",sample(9:10,length(b$Z),replace=TRUE),"")))
b$Z<-as.numeric(b$Z)
This is basically just starting off with a new and partially random data set
every time that then goes through a bunch of other commands (not shown) and
ends with the following outputs saved.
Output1, Output2, Output3, Output4
where each of these is just a single number. My questions is:
1. How do I repeat the entire series of commands x number of times and save
each of the outputs into a structure like this:
Output1 Output2 Output3 Output4
Iteration 1
Iteration 2
Iteration 3
etc.
Not even sure where to start. Are loops the answer? Thanks,
--
View this message in context: http://r.789695.n4.nabble.com/Repeating-a-series-of-commands-tp4645881.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list