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. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.