0

How can create a subset from the data ToothGrowth

    len supp dose
1   4.2   VC  0.5
2  11.5   VC  0.5
3   7.3   VC  0.5
    ...
29 23.3   VC  2.0
30 29.5   VC  2.0
31 15.2   OJ  0.5
32 21.5   OJ  0.5
    . . .
58 27.3   OJ  2.0
59 29.4   OJ  2.0
60 23.0   OJ  2.0

by choosing all records where dose supplement type (supp )is OJ and assign them to variable ans?

I tried this:

ans <- ToothGrowth[ToothGrowth$supp=="OJ"]

and this:

ans <- ToothGrowth[ToothGrowth$supp=="OJ",]

but apparently neither of those are correct.

I would be really grateful for advice.

  • Sorry, I meant that I need ones with supp=OJ. – Tapio Ahonen Dec 03 '17 at 22:08
  • So I tried "ans <- ToothGrowth[ToothGrowth$supp=="OJ",]" but it didn't do the job. – Tapio Ahonen Dec 03 '17 at 22:13
  • @TapioAhonen please share `str()` of `ToothGrowth`. – MKR Dec 03 '17 at 22:20
  • @MKR `str()` is `'data.frame': 60 obs. of 3 variables: $ len : num 4.2 11.5 7.3 5.8 6.4 10 11.2 11.2 5.2 7 ... $ supp: Factor w/ 2 levels "OJ","VC": 2 2 2 2 2 2 2 2 2 2 ... $ dose: num 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 ...` – Tapio Ahonen Dec 03 '17 at 22:32
  • The assignment as explained by you is expected result. e.g: ans<- ToothGrowth[TootheGrowth$supp == "OJ",]. Now print ans to revew the results. – MKR Dec 04 '17 at 22:48

0 Answers0