Re: [R] colnames from read.table

From: Erik Iverson <iverson_at_biostat.wisc.edu>
Date: Wed, 30 Jul 2008 21:56:38 -0500

Chua Siang Li wrote:
> Hi. May I know why the colnames is NULL when reading only 1 column from a
> csv file?

You are not "reading only 1 column from a csv file", you are subsetting one column of a data.frame. See ?Extract and the "drop" argument specifically.

How do I get the colname then?

?names in this case. Always know the class of the object you are dealing with, and which methods are defined for that class.

?class, ?methods

See
  Thanks.
> > xy = read.table("dataFile.csv",header=T, sep=",")
> > y <- xy[,1]
> > xDate <- xy[,2]
> > x <- xy[,3:8]
> > colnames(y)
> NULL
> > colnames(xDate)
> NULL
> > colnames(x)
> [1] "Market.Price" "Quantity" "Country" "Incoterm"
> "Channel"
> [6] "PaymentTerm"
> ----
> Chua Siang Li
> Consultant - Operations Research
> Acceval Pte Ltd
> Tel: 6297 8740
> Email: siang.li.chua_at_acceval-intl.com
> Website: www.acceval-intl.com
> This message and any attachments (the "message"...{{dropped:12}}
> ______________________________________________
> 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.



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. Received on Thu 31 Jul 2008 - 02:59:08 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 31 Jul 2008 - 03:33:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive