I am trying to incrementally add rows to an empty data frame. The data has 7 columns, the last 6 are numeric.
For the first columns I would like to include a text identifier, called ‘Case’ like Andrew, Burt, Charlie etc. that is also output to a data frame – this is where I am having the problem The identifiers are being input from file which automatically assigns them to a data frame Code: Inp_dat<- read.csv("/File/Input data.csv") out_put<-data.frame(Case=character(), StdL=numeric(), StdPP=numeric(), StdSE=numeric(), L=numeric(), MRPP=numeric(), MRSE=numeric(), stringsAsFactors=FALSE) for(i in 1:4) { if (i==1) b<-Andrew if (i==2) b<-Burt if (i==3) b<-Charlie if (i==4) b<-Dave pr <- Inp_dat$p[i] SE_pr <- Inp_dat$SE[i] r<- Inp_dat$r[i] n<- Inp_dat$n[i] Case<- levels(Inp_dat$Case)[i]) … out_put[i,]<-data.frame(Case, stdL, stdPP, stdSE, L, PP, PP_SE) } out_put Case StdL StdPP StdSE L MRPP MRSE 1 1 19.466823 0.16432300 0.03137456 26.002294 0.2080145 0.03804692 2 1 2.334130 0.22566939 0.08962662 5.095703 0.3888451 0.08399101 3 1 2.588678 0.05502765 0.00454159 42.058326 0.4861511 0.02128030 4 1 7.857898 0.18457822 0.04372297 4.705487 0.1193687 0.01921609 Unfortunately the Case column loses the labels Andrew, Burt … I’ve tried always to keep these, but are clearly doing something wrong. Can anyone help? -- View this message in context: http://r.789695.n4.nabble.com/Dataframes-and-text-identifier-columns-tp4693184.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.