I have a data frame, say payroll, like:
payroll <- read.table(text="
AgencyName Rate PayBasis Status NumRate
HousingAuthority $26,843.00 Annual Full-Time 26843.00
HousingAuthority $14,970.00 ProratedAnnual Part-Time 14970.00
HousingAuthority $26,843.00 Annual Full-Time 26843.00
HousingAuthority $14,970.00 ProratedAnnual Part-Time 14970.00
HousingAuthority $13.50 Hourly Part-Time 13.50
HousingAuthority $14,970.00 ProratedAnnual Part-Time 14970.00
HousingAuthority $26,843.00 Annual Full-Time 26843.00", header = TRUE)
The "NumRate" is actually numeric:
payroll$NumRate <- as.numeric(payroll$NumRate)
And I'd like to get a know the max, min and mean salaries by PayBasis. I expect this to work:
ddply(payroll, "PayBasis", summarize)
But instead I'm getting an error: Error: length(rows) == 1 is not TRUE
What am I missing here?
Probably because you've mistaken
summarize
forsummary
(which won't work like you expect in this context). You probably wanted:And be sure to look more carefully at the examples in
?summarize
and?ddply
.It could also be the
plyr
library. Try either not to load it, or, if you need it be careful whether you load it before or after other libraries such asdplyr
, ortidyverse
which automatically fires up thedplyr