为什么我会看到“错误:length(rows)== 1不是TRUE";与ddply? [英] Why am I seeing "Error: length(rows) == 1 is not TRUE" with ddply?
本文介绍了为什么我会看到“错误:length(rows)== 1不是TRUE";与ddply?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数据框,例如工资单,例如:
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)
"NumRate"实际上是数字:
The "NumRate" is actually numeric:
payroll$NumRate <- as.numeric(payroll$NumRate)
我想了解PayBasis的最高,最低和平均工资.我希望这能奏效:
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)
但是我收到一个错误消息:Error: length(rows) == 1 is not TRUE
But instead I'm getting an error: Error: length(rows) == 1 is not TRUE
我在这里想念什么?
推荐答案
可能是因为您将summarize
误认为summary
(在这种情况下无法正常工作).您可能想要:
Probably because you've mistaken summarize
for summary
(which won't work like you expect in this context). You probably wanted:
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
并确保更仔细地查看?summarize
和?ddply
中的示例.
And be sure to look more carefully at the examples in ?summarize
and ?ddply
.
这篇关于为什么我会看到“错误:length(rows)== 1不是TRUE";与ddply?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文