Why do I see "Error: length (string) == 1 not TRUE" with ddply?

I have a data frame like payroll, like this:

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) 

"NumRate" is actually numeric:

 payroll$NumRate <- as.numeric(payroll$NumRate) 

And I would like to know the maximum, minimum and average salary of PayBasis. I expect this to work:

 ddply(payroll, "PayBasis", summarize) 

But instead, I get an error: Error: length(rows) == 1 is not TRUE

What am I missing here?

+6
source share
1 answer

Perhaps because you are wrong to summarize for summary (which will not work as you expect in this context). You probably wanted to:

 ddply(payroll, "PayBasis", summarize,mx = max(NumRate),mn = min(NumRate),avg = mean(NumRate)) PayBasis mx mn avg 1 Annual 26843.0 26843.0 26843.0 2 Hourly 13.5 13.5 13.5 3 ProratedAnnual 14970.0 14970.0 14970.0 

And don't forget to look carefully at the examples in ?summarize and ?ddply .

+3
source

Source: https://habr.com/ru/post/947055/


All Articles