[R] problem with retreaving column from a data.frame

David Winsemius dwinsemius at comcast.net
Tue Apr 20 15:56:53 CEST 2010


On Apr 20, 2010, at 7:32 AM, venkata kirankumar wrote:

> Hi all,
> I have a problem with retreaving column from a data.frame that is
>
> I have a data.frame named  "temp"
> in that dataframe some column  are there whose names are
>
> "IDENTIFIER"    "UNIQUEID"      "TRIALGROUPSID" "GRPNUMBER"
> "GRPDESC"       "SEXDID"        "STDID"         "STUDYTYPE"
> "SDID"          "DOSDID"        "SOPDID"        "SPECIES"
>
> i can retreave any column with using  command like  "temp$STDID"
>
> but my problem is  the column name i have to get from another xml its
> comming like  "STDID"
> that one i assigned to a variable named    "kk"  like  kk<-"STDID"
>
> but now while i am trying to retreave this column from dataframe  temp
> like  temp$kk   or
> with using command paste like
>
> paste("temp",kk,sep"$")
> both the times its giving null result
> but its having values in table

Don't use the "$" operator for such tasks. Instead use the indexing  
operator "[":

temp[ , kk]


 > testdf <- data.frame(aa=letters[1:10], bb=LETTERS[1:10], cc=1:10)
 > colname <- "aa"
 > testdf[ , colname]
  [1] a b c d e f g h i j
Levels: a b c d e f g h i j

-- David.
>
> can any one help me how to get column values from dataframe like  
> these cases
>
> thanks in advance
> kiran
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> 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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list