Relative noob here, I have a data.frame and simply want to add an explicit column of names in column 1 of the form "trial_number01" for row 1, "trial_number02" for row 2 .... etc. It is simply for visual purposes and to explain data to others. I've tried Using row.names and other but still no luck, am sure it has been covered but I can't find it, can you please point me in the right direction? Thanks Jim ==============================Dr. Jim Maas University of East Anglia Norwich, UK [[alternative HTML version deleted]]
Jim Is this what you need? #create data Lines <- "Drug1 Drug2 Drug3 Drug4 153 133 145 111 189 177 200 170 221 241 187 243 215 228 201 178 302 283 292 248 223 255 220 202 201 238 233 163 173 164 172 139 121 128 119 120 100 200 300 400" # read in data d <- read.table(textConnection(Lines), header = TRUE) #add row.names row.names(d)=paste("trial_number",sprintf("%02d",as.numeric(row.names(d))),sep="") # view output print(d) HTH Pete -- View this message in context: http://r.789695.n4.nabble.com/adding-a-row-of-names-to-data-frame-tp2278278p2278345.html Sent from the R help mailing list archive at Nabble.com.
Thanks Pete, It works fine. I should have explained, already had the data.frame with data in it, just wanted to add a string vector into the first column of the data.frame, could not figure out how to do that. Jim -- View this message in context: http://r.789695.n4.nabble.com/adding-a-row-of-names-to-data-frame-tp2278278p2279421.html Sent from the R help mailing list archive at Nabble.com.
On Jul 6, 2010, at 8:00 AM, jamaas wrote:> > Thanks Pete, > > It works fine. I should have explained, already had the data.frame > with > data in it, just wanted to add a string vector into the first column > of the > data.frame, could not figure out how to do that.?cbind # generic, has a data.frame method> > Jim > -- > View this message in context: http://r.789695.n4.nabble.com/adding-a-row-of-names-to-data-frame-tp2278278p2279421.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at 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.David Winsemius, MD West Hartford, CT