I got an error when trying to extract a 1-column subset of a data frame (called "my.output") created by dplyr/summarize. The ncol() function says that my.output has 4 columns, but "my.output[4]" fails. Note that converting my.output using as.data.frame() makes for a happy ending.
Is this the intended behavior of dplyr?
Tx,
John
library(dplyr)
# set up data frame
rows = 100
repcnt = 50
sexes = c("Female", "Male")
heights = c("Med", "Short", "Tall")
Your code in creating 'frm' is not working for me and it is complicated enough that I don't want to work it out. See ?dput for a better way to supply data. Also see:
https://github.com/hadley/devtools/wiki/Reproducibilityhttp://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
That said, I don't see why 'my.output[4]' is not working. Try something like str(frm) to see what you have there and/or resubmit the data in dput format
See simple example below:
dat1 <- data.frame(aa = sample(1:20, 100, replace = TRUE), bb = 1:100 )
dat1[2]
John Kane
Kingston ON Canada
-----Original Message-----
From: john.posner at mjbiostat.com
Sent: Fri, 21 Nov 2014 17:10:16 +0000
To: r-help at r-project.org
Subject: [R] dplyr/summarize does not create a true data frame
I got an error when trying to extract a 1-column subset of a data frame
(called "my.output") created by dplyr/summarize. The ncol() function says
that my.output has 4 columns, but "my.output[4]" fails. Note that
converting my.output using as.data.frame() makes for a happy ending.
Is this the intended behavior of dplyr?
Tx,
John
library(dplyr)
# set up data frame
rows = 100
repcnt = 50
sexes = c("Female", "Male")
heights = c("Med", "Short", "Tall")
____________________________________________________________
FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family!
Visit http://www.inbox.com/photosharing to find out more!
Thanks to John Kane for an off-list consultation. As the following annotated transcript shows, it's the group_by() function that transforms a data frame into something else: a "grouped_df" object that *looks* identical to the original data frame (e.g. the rows are in the original order -- *not* grouped, as arrange() would do), but does not always act like a data frame.
library(dplyr)
# set up data frame, and show its structure [ see below for clean copy of dput() code ]
frm = structure(list(Id = structure(1:10, .Label = c("P01", "P02",
-----Original Message-----
From: John Kane [mailto:jrkrideau at inbox.com]
Sent: Friday, November 21, 2014 12:33 PM
To: John Posner; 'r-help at r-project.org'
Subject: RE: [R] dplyr/summarize does not create a true data frame
Your code in creating 'frm' is not working for me and it is complicated enough
that I don't want to work it out. See ?dput for a better way to supply data.
Also see:
https://github.com/hadley/devtools/wiki/Reproducibilityhttp://stackoverflow.com/questions/5963269/how-to-make-a-great-r-
reproducible-example
That said, I don't see why 'my.output[4]' is not working. Try something like
str(frm) to see what you have there and/or resubmit the data in dput format
See simple example below:
dat1 <- data.frame(aa = sample(1:20, 100, replace = TRUE), bb = 1:100 )
dat1[2]
John Kane
Kingston ON Canada
-----Original Message-----
From: john.posner at mjbiostat.com
Sent: Fri, 21 Nov 2014 17:10:16 +0000
To: r-help at r-project.org
Subject: [R] dplyr/summarize does not create a true data frame
I got an error when trying to extract a 1-column subset of a data
frame (called "my.output") created by dplyr/summarize. The ncol()
function says that my.output has 4 columns, but "my.output[4]" fails.
Note that converting my.output using as.data.frame() makes for a happy
ending.
Is this the intended behavior of dplyr?
Tx,
John
library(dplyr)
# set up data frame
rows = 100
repcnt = 50
sexes = c("Female", "Male")
heights = c("Med", "Short", "Tall")
__________________________________________________________
__
FREE ONLINE PHOTOSHARING - Share your photos online with your friends
and family!
Visit http://www.inbox.com/photosharing to find out more!
On Sunday, November 23, 2014, John Posner <john.posner at mjbiostat.com> wrote:
Thanks to John Kane for an off-list consultation. As the following
annotated transcript shows, it's the group_by() function that transforms a
data frame into something else: a "grouped_df" object that *looks*
identical to the original data frame (e.g. the rows are in the original
order -- *not* grouped, as arrange() would do), but does not always act
like a data frame.
library(dplyr)
# set up data frame, and show its structure [ see below for clean copy
-----Original Message-----
From: John Kane [mailto:jrkrideau at inbox.com <javascript:;>]
Sent: Friday, November 21, 2014 12:33 PM
To: John Posner; 'r-help at r-project.org <javascript:;>'
Subject: RE: [R] dplyr/summarize does not create a true data frame
Your code in creating 'frm' is not working for me and it is complicated
enough
that I don't want to work it out. See ?dput for a better way to supply
str(frm) to see what you have there and/or resubmit the data in dput
format
See simple example below:
dat1 <- data.frame(aa = sample(1:20, 100, replace = TRUE), bb = 1:100 )
dat1[2]
John Kane
Kingston ON Canada
-----Original Message-----
From: john.posner at mjbiostat.com <javascript:;>
Sent: Fri, 21 Nov 2014 17:10:16 +0000
To: r-help at r-project.org <javascript:;>
Subject: [R] dplyr/summarize does not create a true data frame
I got an error when trying to extract a 1-column subset of a data
frame (called "my.output") created by dplyr/summarize. The ncol()
function says that my.output has 4 columns, but "my.output[4]" fails.
Note that converting my.output using as.data.frame() makes for a happy
ending.
Is this the intended behavior of dplyr?
Tx,
John
library(dplyr)
# set up data frame
rows = 100
repcnt = 50
sexes = c("Female", "Male")
heights = c("Med", "Short", "Tall")
__________________________________________________________
__
FREE ONLINE PHOTOSHARING - Share your photos online with your friends
and family!
Visit http://www.inbox.com/photosharing to find out more!