[R] Loop Help
bdossman
bdossman at gmail.com
Sat May 19 01:14:08 CEST 2012
Hi all,
I am a beginner R user and need some help with a simple loop function.
Currently, I have seven datasets (TOWER1,TOWER2...TOWER7) that are all in
the same format (same # of col and headers). I am trying to add a new column
(factor) to each dataset that simply identifies the dataset. Ultimately, I
would like to merge all 7 datasets and need that column to identify what
rows came from what dataset.
Using the code below, I get the error message "Error in rep(i,
nrow(TOWER.i)) : invalid 'times' argument" but it doesn't make sense to me
since nrow should give an integer value. Any help will be really
appreciated.
TOWERS<-c("TOWER1","TOWER2","TOWER3","TOWER4","TOWER5","TOWER6","TOWER7")
for(i in 1:7){
TOWER.i<-TOWERS[i]
TOWER<-rep(i,nrow(TOWER.i))
TOWER.i<-cbind(TOWER.i[1:2],TOWER, TOWER.i[2:length(TOWER.i)])
}
--
View this message in context: http://r.789695.n4.nabble.com/Loop-Help-tp4630555.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list