tidyverse / dplyr

dplyr: A grammar of data manipulation
https://dplyr.tidyverse.org/
Other
4.78k stars 2.12k forks source link

[ and [[ behavior #920

Closed zhenglei-gao closed 9 years ago

zhenglei-gao commented 9 years ago

I am not sure if this is an issue or it was actually the intention.

require(dplyr)
ttt <- data.frame(a=1:6,b=11:16)
ttt2 <- group_by(ttt,factor(ttt$a))
identical(ttt[[1]],ttt[,1])
identical(ttt2[[1]],ttt2[,1])

So in Base R, when subsetting one column, a vector is returned, but with dplyr, it is always a data frame. This made some of my old codes break. Is dplyr always working like this or this is because of an updated version of dplyr?

hadley commented 9 years ago

Yes, it's by design.