Re: [R] dplyr and function length()

2015-08-04 Thread Karl Schilling

Dear Jeff:

No, the effect I described has nothing to do wit USING dplyr. It occurs 
with any (preexisting) data.frame once dplyr is LOADED (require(dplyr). 
It is this silent, sort of backward acting effect that disturbs me.


Best,

Karl Schilling

On 04.08.2015 12:20, Jeff Newmiller wrote:

I can confirm that the drop default is different, but keep in mind that it is 
only changed for a tbl_df so just convert back to data.frame at the end of your 
dplr operations to get back to your familiar data.frame behavior.
---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.us Basics: ##.#.   ##.#.  Live Go...
   Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
---
Sent from my phone. Please excuse my brevity.

On August 4, 2015 5:06:44 AM EDT, peter dalgaardpda...@gmail.com  wrote:


On 04 Aug 2015, at 10:50 , Karl Schillingkarl.schill...@uni-bonn.de
wrote:


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.


Presumably, dplyr changes how [.data.frame works (by altering the
default for drop=, I expect) so that df[,1] is a data frame with 1
variable and not a vector. And yes, that_is_  somewhat disturbing.

-pd



Thank you so much,

Karl


--
Karl Schilling



--
Karl Schilling

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] dplyr and function length()

2015-08-04 Thread Hadley Wickham
 No, the effect I described has nothing to do wit USING dplyr. It occurs with
 any (preexisting) data.frame once dplyr is LOADED (require(dplyr). It is
 this silent, sort of backward acting effect that disturbs me.

You're going to need to provide some evidence for that charge: dplyr
does not affect the behaviour of data.frames (only tbl_dfs)

Hadley

-- 
http://had.co.nz/

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] dplyr and function length()

2015-08-04 Thread Hadley Wickham
 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.

 Presumably, dplyr changes how [.data.frame works (by altering the default for 
 drop=, I expect) so that df[,1] is a data frame with 1 variable and not a 
 vector. And yes, that _is_ somewhat disturbing.

It changes the behaviour for [.tbl_df (tbl_df is a very minor
extension of data frame with custom [ and print methods).  This is
partly an experiment to see what happens when you make [ more
consistent - [.tbl_df always returns a data frame, so if you want a
vector you have to use [[.

Hadley

-- 
http://had.co.nz/

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] dplyr and function length() and some apologies

2015-08-04 Thread Karl Schilling

Dear Hadley:

your request for evidence for my observation seems to have paved the way 
to solve this issue. As it turns out, the effect I described only occurs 
with data.frames read in with readxl. Clearly, I missed that these are 
tbl_df. And that explains the differential behavior depending on whether 
dplyr is loaded or not. Also, I realize that this latter effect can be 
avoided by explicitly converting objects read in with readxl to a 
data.frame.


Well, I should have known that if i had carefully read the README stuff 
for readxl. But then, readxl is so much of an every-day tool for me that 
I didn't even think of its involvement in my problem, all the more as 
the reference manual does not mention the format/class of objects read 
in with readxl.


So my apologies for any confusion I may have caused - and I certainly 
did not mean my observation as a charge against dplyr or its authors. 
Quite to the contrary, i appreciate thees tools, and as you may see, 
tray to understand and use them.


Thank you so much again

Karl

On 04.08.2015 13:14, Hadley Wickham wrote:

No, the effect I described has nothing to do wit USING dplyr. It occurs with
any (preexisting) data.frame once dplyr is LOADED (require(dplyr). It is
this silent, sort of backward acting effect that disturbs me.

You're going to need to provide some evidence for that charge: dplyr
does not affect the behaviour of data.frames (only tbl_dfs)

Hadley


--
Karl Schilling

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] dplyr and function length()

2015-08-04 Thread Karl Schilling

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

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] dplyr and function length()

2015-08-04 Thread peter dalgaard

On 04 Aug 2015, at 10:50 , Karl Schilling karl.schill...@uni-bonn.de wrote:

 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.

Presumably, dplyr changes how [.data.frame works (by altering the default for 
drop=, I expect) so that df[,1] is a data frame with 1 variable and not a 
vector. And yes, that _is_ somewhat disturbing.

-pd 

 
 Thank you so much,
 
 Karl
 
 
 -- 
 Karl Schilling
 
 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] dplyr and function length()

2015-08-04 Thread Jeff Newmiller
I can confirm that the drop default is different, but keep in mind that it is 
only changed for a tbl_df so just convert back to data.frame at the end of your 
dplr operations to get back to your familiar data.frame behavior.
---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

On August 4, 2015 5:06:44 AM EDT, peter dalgaard pda...@gmail.com wrote:

On 04 Aug 2015, at 10:50 , Karl Schilling karl.schill...@uni-bonn.de
wrote:

 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.

Presumably, dplyr changes how [.data.frame works (by altering the
default for drop=, I expect) so that df[,1] is a data frame with 1
variable and not a vector. And yes, that _is_ somewhat disturbing.

-pd 

 
 Thank you so much,
 
 Karl
 
 
 -- 
 Karl Schilling
 
 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.