[R] dplyr and function length()
Karl Schilling
karl.schilling at uni-bonn.de
Tue Aug 4 10:50:07 CEST 2015
Dear All,
I have an observation / question about how the function length() works
once package dplyr is loaded.
Say we have a data.frame df with n rows and m columns. Then a way to
get the number of rows is to use
length(df$m1) (m1 here stand is as the header of the first column)
or, alternatively
length(df[,1]).
Both commands will return n.
However, once dplyr is loaded,
length(df[,1]) will return a value of 1.
length(df$m1) and also length(df[[1]]) will correctly return n.
I know that using length() may not be the most elegant or efficient way
to get the value of n. However, what puzzles (and somewhat disturbs) me
is that loading of dplyr affects how length() works, without there being
a warning or masking message upon loading it.
Any clarification or comment would be welcome.
Thank you so much,
Karl
--
Karl Schilling
More information about the R-help
mailing list