0

These two produce the same outcome, but is there an advantage of using one over the other.

  1. Are they the same thing across all boards?
  2. Is one inherently better than the other?
  3. Do they have different applications and are good at different things?

mtcars[mtcars$mpg > 20, c("mpg", "cyl")]

subset(mtcars, mpg > 20, select=c("mpg", "cyl"))

ant
  • 565
  • 1
  • 6
  • 12

2 Answers2

1

from the help for subset (?subset):

This is a convenience function intended for use interactively. For programming it is better to use the standard subsetting functions like [, and in particular the non-standard evaluation of argument subset can have unanticipated consequences.

Adrian
  • 684
  • 3
  • 20
0

from ?subset

Warning

This is a convenience function intended for use interactively. For programming it is better to use the standard subsetting functions like [, and in particular the non-standard evaluation of argument subset can have unanticipated consequences.

Community
  • 1
  • 1
Ricardo Saporta
  • 54,400
  • 17
  • 144
  • 178