venkata kirankumar
2010-Apr-20 11:32 UTC
[R] problem with retreaving column from a data.frame
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 can any one help me how to get column values from dataframe like these cases thanks in advance kiran [[alternative HTML version deleted]]
Maybe you want something like this. temp<-data.frame(id=rbinom(10,5,.5),grp=rbinom(10,3,.3),stdid=rnorm(10)) kk<-"stdid" temp[,kk] -tgs On Tue, Apr 20, 2010 at 7:32 AM, venkata kirankumar <kiran4u2all@gmail.com>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 > > 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@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. >[[alternative HTML version deleted]]
David Winsemius
2010-Apr-20 13:56 UTC
[R] problem with retreaving column from a data.frame
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 tableDon'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