[R] re place column names

R Help rhelp.stats at gmail.com
Fri Feb 22 16:42:19 CET 2008


names(dat) will return the column names for a dataset called dat, and
they can also be set this way.

names(dat) <- c("firstName","secondName","thirdName",...)

I would suggest reading the column names into a vector, and then
assigning them as demonstrated above.

On Fri, Feb 22, 2008 at 9:42 AM, hochoi <evilonegirl2006 at yahoo.com> wrote:
>
>  Hi,
>
>  When I tried to replace column names in a data set with label names read
>  from a separated file,
>  I got the following message:
>
>  Error in `[.data.frame` (dataset, , classlabel): undefined columns selected
>
>  I am new in R programming languague. Could someone please tell me what do I
>  need to consider in the dataset dataframe.
>  There are no column names in the dataset dataframe,
>  When I entered
>  dimnames(dataset)[[2]]
>  [1] "X1"  "X2"  "X3"  "X4"  "X5"  "X6"  "X7"  "X8"  "X9"  "X10" "X11" "X12"
>
>  [13] "X13" "X14" "X15" "X16" "X17" "X18" "X19" "X20" "X21" "X22" "X23" "X24"
>
>  [25] "X25" "X26" "X27" "X34" "X35" "X36" "X37" "X38" "X28" "X29" "X30" "X31"
>
>  [37] "X32" "X33"
>
>  Thanks
>  --
>  View this message in context: http://www.nabble.com/replace-column-names-tp15633387p15633387.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.
>



More information about the R-help mailing list