Hi, With this data.frame:> class(rwl)[1] "data.frame">rwl0028002F 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" Thanks in advance, Alfredo
Try names(rwl[1]) 2008/6/19, Alfredo Alessandrini <alfreale74 at gmail.com>:> 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" > > > > Thanks in advance, > > Alfredo > > ______________________________________________ > 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. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
Alfredo> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of Alfredo > Alessandrini > Sent: Friday, 20 June 2008 10:56 a.m. > To: r-help at r-project.org > Subject: [R] colnames of a column > > 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"Because rwl[,1] is a numeric vector and not a dataframe: is.data.frame(rwl[,1]) [1] FALSE You probably want names(rwl)[1] HTH .... Peter Alspach The contents of this e-mail are privileged and/or confidential to the named recipient and are not to be used by any other person and/or organisation. If you have received this e-mail in error, please notify the sender and delete all material pertaining to this e-mail.
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