Search code examples
rdollar-sign

Can drop=FALSE be passed to $?


I tried `$`(mtcars,cyl,drop=FALSE), but this threw an error. I know that in practice you would use [ or [[ instead, but I'm curious, can drop=FALSE be passed to $?


Solution

  • The $ function doesn't have a drop= parameter. While they are used for similar things, the $ function is distinct from the [ function which does have a drop= parameter.

    I'm assuming that you are only interested in the case for using $ with data.frames, but there's actually no special data.frame method for $, it just treats the data.frame like a list. And drop= wouldn't make as much sense in the case of a generic list.