0

how do i runt this command hist(dataset$V3) by using a variable? I have tried doing something like this but no joy paste("dataset$",q,sep=""). Can anyone advise?

> dataset
  Rec.Open.Date V3 V4  V5
1    2014-12-03  1 11 111
2    2014-12-04  2 12 112
3    2014-12-05  3 13 113
4    2014-12-06  4 14 114
5    2014-12-07  5 15 115
> 
> hist(dataset$V3)
>
> q<-"V3"
> q
[1] "V3"
> 
> paste("dataset$",q,sep="")
[1] "dataset$V3"
> 
> hist(paste("dataset$",q,sep=""))
Error in hist.default(paste("dataset$", q, sep = "")) : 
  'x' must be numeric
HattrickNZ
  • 4,373
  • 15
  • 54
  • 98
  • Is there a reason you don't just set a variable to the desired data? e.g. `var=dataset$V3` and then `hist(var)`. – Minnow Feb 17 '15 at 02:47
  • Also: [this question answers it](http://stackoverflow.com/questions/12391950/variably-selecting-assigning-to-fields-in-a-data-table.) – Minnow Feb 17 '15 at 02:53

1 Answers1

0

You want to use something like hist(dataset["row","column"]). In this way you can access certain rows that you want to filter for as well.

hist(dataset[,"V3"])
Jason
  • 1,559
  • 1
  • 9
  • 14