R - 使用ddply时找不到对象错误
R - Object not found error when using ddply
我正在将 ddply 应用于以下数据框。重点是将 ecdf 函数应用于 yearly_test_count 具有相同国家/地区的行的值。
> head(test)
country yearly_test_count download_speed
1 AU 1 2.736704
2 AU 6 3.249486
3 AU 6 2.287267
4 AU 6 2.677241
5 AU 6 1.138213
6 AU 6 3.205364
这是我使用的脚本:
house_total_year_ecdf <- ddply(test, c("country"), mutate,
ecdf_val = ecdf(yearly_test_count)(yearly_test_count)*length(yearly_test_count))
但我收到以下错误:
Error in eval(substitute(expr), envir, enclos) :
object 'yearly_test_count' not found
============================================= =====================
我尝试将函数 ecdf 单独与 yearly_test_count 列一起使用,它有效:
ecdf(test$yearly_test_count)(test$yearly_test_count)*length(test$yearly_test_count)
有人知道为什么这在使用 ddply 时不起作用吗?
这很奇怪,因为脚本之前可以运行,现在我再次 运行 脚本并遇到上述错误。我不确定这个问题是否与 R 版本或包版本不同有关?
非常感谢任何帮助! :)
一个选项是使用 base R
中的 ave
test$ecdf_val <- with(test, ave(yearly_test_count, country,
FUN = function(x) ecdf(x)(x)*length(x)))
我正在将 ddply 应用于以下数据框。重点是将 ecdf 函数应用于 yearly_test_count 具有相同国家/地区的行的值。
> head(test)
country yearly_test_count download_speed
1 AU 1 2.736704
2 AU 6 3.249486
3 AU 6 2.287267
4 AU 6 2.677241
5 AU 6 1.138213
6 AU 6 3.205364
这是我使用的脚本:
house_total_year_ecdf <- ddply(test, c("country"), mutate,
ecdf_val = ecdf(yearly_test_count)(yearly_test_count)*length(yearly_test_count))
但我收到以下错误:
Error in eval(substitute(expr), envir, enclos) :
object 'yearly_test_count' not found
============================================= =====================
我尝试将函数 ecdf 单独与 yearly_test_count 列一起使用,它有效:
ecdf(test$yearly_test_count)(test$yearly_test_count)*length(test$yearly_test_count)
有人知道为什么这在使用 ddply 时不起作用吗?
这很奇怪,因为脚本之前可以运行,现在我再次 运行 脚本并遇到上述错误。我不确定这个问题是否与 R 版本或包版本不同有关?
非常感谢任何帮助! :)
一个选项是使用 base R
ave
test$ecdf_val <- with(test, ave(yearly_test_count, country,
FUN = function(x) ecdf(x)(x)*length(x)))