[R] Setting the names of a data.frame
Santosh Srinivas
santosh.srinivas at gmail.com
Tue Nov 2 14:58:17 CET 2010
I have tData as below. I need to set the names with the headers from the
first row in sHeaders
Sorry .. forgot how to set the names from row in another data frame .. pls
advise.
names(tData) = sHeaders[1,] does not work correctly
Also, why doesn't drop.levels(sHeaders) not work?
dput(tData)
structure(list(V1 = structure(c(3L, 1L, 1L, 2L), .Label = c("P H Ravi
Kumar",
"Rahul Kumar Singh", "Ramu GSV"), class = "factor"), V2 = structure(c(1L,
3L, 3L, 2L), .Label = c("05/10/2010", "09/09/2010", "30/09/2010"
), class = "factor"), V3 = structure(c(2L, 1L, 1L, 2L), .Label = c("B",
"S"), class = "factor"), V4 = structure(c(2L, 3L, 3L, 1L), .Label =
c("2120",
"4000", "11000"), class = "factor"), V5 = structure(c(1L, 2L,
2L, 1L), .Label = c("", "0.01"), class = "factor"), V6 = structure(c(2L,
3L, 3L, 1L), .Label = c("765", "1000", "11000"), class = "factor"),
V7 = structure(c(1L, 2L, 2L, 1L), .Label = c("", "0.01"), class =
"factor")), .Names = c("V1",
"V2", "V3", "V4", "V5", "V6", "V7"), row.names = 5:8, class = "data.frame")
dput(sHeaders)
structure(list(V1 = structure(1L, .Label = c("Name of Acquirer / Seller",
"Qty", "Ramu GSV"), class = "factor"), V2 = structure(3L, .Label =
c("05/10/2010",
"%", "Transaction Date"), class = "factor"), V3 = structure(1L, .Label =
c("Buy /Sale",
"Qty", "S"), class = "factor"), V4 = structure(3L, .Label = c("4000",
"%", "No.of Shares Transacted"), class = "factor"), V5 = structure(2L,
.Label = c("",
"Holding after Transaction"), class = "factor"), V6 = structure(NA_integer_,
.Label = "1000", class = "factor"),
V7 = structure(NA_integer_, .Label = "", class = "factor")), .Names =
c("V1",
"V2", "V3", "V4", "V5", "V6", "V7"), row.names = 3L, class = "data.frame")
Thanks very much.
More information about the R-help
mailing list