Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用dplyr mutate_根据向量估计每个值的分位数_R_Dplyr_Mutate_Quantile - Fatal编程技术网

使用dplyr mutate_根据向量估计每个值的分位数

使用dplyr mutate_根据向量估计每个值的分位数,r,dplyr,mutate,quantile,R,Dplyr,Mutate,Quantile,我试图用与其值相关联的分位数修改data.frame中的数值变量。这个问题被反复回答了两次。但是,我有一个包含多个变量的大的data.frame,我想通过mutate\u at调用来完成它们 我通过一个简单的mutate调用成功地做到了这一点: library(dplyr) dd <- data.frame(id = letters[1:10], v1 = runif(10), v2 = runif(10)) dd %>% mutate(v1_quantile = ec

我试图用与其值相关联的分位数修改
data.frame
中的数值变量。这个问题被反复回答了两次。但是,我有一个包含多个变量的大的
data.frame
,我想通过
mutate\u at
调用来完成它们

我通过一个简单的
mutate
调用成功地做到了这一点:

library(dplyr)    
dd <- data.frame(id = letters[1:10], v1 = runif(10), v2 = runif(10))
dd %>% 
  mutate(v1_quantile = ecdf(v1)(v1))
但是,如果我尝试在调用的
mutate_中执行此操作,我会得到一个错误:

dd %>% 
   mutate_at(vars(one_of("v1", "v2")), list(quantile = ~ecdf(.)(.)))
Error in `[.data.frame`(x, order(x, na.last = na.last, decreasing = decreasing)) : 
  undefined columns selected
你知道我做错了什么以及如何修复吗

我的
会话信息

R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server x64 (build 14393)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] dplyr_0.8.0.1

loaded via a namespace (and not attached):
 [1] tidyselect_0.2.5      compiler_3.5.1        magrittr_1.5
 [4] assertthat_0.2.1      R6_2.4.0              pillar_1.4.2
 [7] glue_1.3.1            rstudioapi_0.8.0.9000 tibble_2.1.3
[10] crayon_1.3.4          Rcpp_1.0.2            pkgconfig_2.0.3
[13] rlang_0.4.0           purrr_0.3.0

dd%>%mutate\u at(vars(v1,v2中的一个)),list(分位数=~ecdf(.))
适用于您发布的示例。另外,您得到的错误通常是由于向
ecdf
函数传递了数据帧而不是数字向量/列。可能是版本问题吗?我已经发布了我的
sessionInfo
。对于错误,如果我将函数从
ecdf
改为
sum
,我没有得到错误,这意味着这可能不是
numeric
vs
other
的问题。似乎是,只是更新了
dplyr
,它工作了。。。抱歉打扰你了。。。
R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server x64 (build 14393)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] dplyr_0.8.0.1

loaded via a namespace (and not attached):
 [1] tidyselect_0.2.5      compiler_3.5.1        magrittr_1.5
 [4] assertthat_0.2.1      R6_2.4.0              pillar_1.4.2
 [7] glue_1.3.1            rstudioapi_0.8.0.9000 tibble_2.1.3
[10] crayon_1.3.4          Rcpp_1.0.2            pkgconfig_2.0.3
[13] rlang_0.4.0           purrr_0.3.0