1

I have a data frame like the image. why when I use df[,test] it outputed the first column value while when I try test=="Yield (%)" is true?

I did test on

Browse[2]> test=="Yield (%)" 
[1] TRUE 
Browse[2]> df[,"Yield (%)"]  
 [1] 67.283951 67.283951 67.283951
> 
> Browse[2]> df[,test]   [1] Lot_726.1 Lot_726.1 Lot_726.1 Lot_726.1
> Lot_726.1 Lot_726.1 Lot_726.1 Lot_726.1 Lot_726.1*

Mindy
  • 7
  • 3
  • So you do mean data.table rather than data.frame, right? A data.table has different indexing properties. Maybe try `df[,test, with=FALSE]` and then maybe read a basic introduction to data.tables. In the future, please post [reproducible examples](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) rather than images of data. – MrFlick Dec 01 '15 at 02:31
  • Hi, I actually imported df as data frame. here is how i imported it df<-read.delim("zonedata.txt",check.names=FALSE) – Mindy Dec 01 '15 at 02:35
  • Well, you said data table which is a very different type of object. You really need to prepare a self contained, minimal reproducible example so we can see what's going in. The link i provided before has many tips on how to do that. – MrFlick Dec 01 '15 at 02:36
  • I figured out the issue, when I imported the data frame it auto changed the string to factor. so when I do df[,test] it actually returned the df[,1] – Mindy Dec 01 '15 at 23:47

0 Answers0