Re: [R] colnames of a column

From: Wacek Kusnierczyk <Waclaw.Marcin.Kusnierczyk_at_idi.ntnu.no>
Date: Fri, 20 Jun 2008 06:12:54 +0200

Alfredo Alessandrini wrote:
> Hi,
>
> With this data.frame:
>
>
>> class(rwl)
>>
> [1] "data.frame"
>
>
>> rwl
>>
> 0028002F 0028013F 0028032F
> 1833 3.39 NA NA
> 1834 3.09 NA NA
> 1835 3.05 NA NA
> 1836 3.31 NA NA
> 1837 2.26 NA NA
>
>
>> colnames(rwl)
>>
> [1] "0028002F" "0028013F" "0028032F"
>
> Ok....
>
>
>> colnames(rwl[,1])
>>
> NULL
>
> why?? I expect: "0028002F"
>
>
have you read the docs? start with ?`[`

you're yet another user confused by r's policy to drop dimensions as soon as possible.
when you select one column from a data frame, you get a vector, not a one-column data frame.
if you're always expecting a data frame while indexing, be sure to include 'drop=FALSE':

> colnames(rwl[,1,drop=FALSE])
>

[1] "0028002F"

vQ



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 Fri 20 Jun 2008 - 06:15:31 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 Fri 20 Jun 2008 - 11:30:51 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