[R] adding a row of names to data.frame

Pete B Peter.Brecknock at bp.com
Mon Jul 5 15:06:28 CEST 2010


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.



More information about the R-help mailing list