Re: [R] count and sum simultaneously in R pivot table

2014-02-18 Thread Crombie, Burnette N
The script works nicely, Arun. You were right, I pasted code from email instead of Rhelp and didn't reformat properly in R. I appreciate your time with this! -Original Message- It seems like part of the next line is also being run (in the end 'colnames'). For e.g. res2 <- within(as.dat

Re: [R] count and sum simultaneously in R pivot table

2014-02-18 Thread Crombie, Burnette N
r-help@r-project.org Cc: Crombie, Burnette N Subject: Re: [R] count and sum simultaneously in R pivot table Hi, Check if this works: library(reshape2) res1 <- acast(FLSAdata_melt, ViolationDesc + ReasonDesc ~ variable, sum, margins=TRUE)[,-4] res2 <- within(as.data.frame(res1),`Count

Re: [R] count and sum simultaneously in R pivot table

2014-02-17 Thread arun
Hi, Check if this works: library(reshape2) res1 <- acast(FLSAdata_melt, ViolationDesc + ReasonDesc ~ variable, sum, margins=TRUE)[,-4] res2 <- within(as.data.frame(res1),`Count of Case ID` <- dcast(FLSAdata_melt, ViolationDesc + ReasonDesc ~ variable, length, margins=TRUE)[,3])[,c(4,1:3)] colna

[R] count and sum simultaneously in R pivot table

2014-02-06 Thread bcrombie
Based on the following code, how can I add a column to this pivot table output that will count CaseID's for each variable sum? CaseID is a factor. # library(reshape) # FLSA_Violation_Reason_melt <- melt(FLSA_ViolRsnfixed, #id=c("CaseID", "ViolationDesc", "Reas