[英]R: Error Running Example Code for reduce() from purrr package
I'm looking to use reduce() to concatenate a variable number of columns from a data frame pairwise.我正在寻找使用 reduce() 将数据帧中的可变数量的列成对连接起来。 It looked like reduce() would do the job, so I tried some of the example code and got this error.
看起来 reduce() 可以完成这项工作,所以我尝试了一些示例代码并得到了这个错误。 I'm using RStudio, Version 1.0.136
我正在使用 RStudio,版本 1.0.136
> require(tidyverse)
> x <- list(c(0, 1), c(2, 3), c(4, 5))
> x %>% reduce(c)
# Error: `x` must be a vector (not a NULL)
> sessionInfo()
# R version 3.3.2 (2016-10-31)
# Platform: x86_64-apple-darwin13.4.0 (64-bit)
# Running under: OS X El Capitan 10.11.6
# locale:
# [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
# attached base packages:
# [1] stats graphics grDevices utils datasets methods base
# other attached packages:
# [1] dplyr_0.5.0 purrr_0.2.2 readr_1.0.0 tidyr_0.6.1 tibble_1.2 ggplot2_2.2.1
# [7] tidyverse_1.1.1
# loaded via a namespace (and not attached):
# [1] Rcpp_0.12.9 xml2_1.1.1 magrittr_1.5 hms_0.3 rvest_0.3.2 mnormt_1.5-5
# [7] munsell_0.4.3 colorspace_1.3-2 lattice_0.20-34 R6_2.2.0 httr_1.2.1 stringr_1.1.0
# [13] plyr_1.8.4 tools_3.3.2 parallel_3.3.2 grid_3.3.2 broom_0.4.1 nlme_3.1-130
# [19] gtable_0.2.0 psych_1.6.12 DBI_0.5-1 modelr_0.1.0 readxl_0.1.1 lazyeval_0.2.0
# [25] assertthat_0.1 reshape2_1.4.2 haven_1.0.0 stringi_1.1.2 forcats_0.2.0 scales_0.4.1
# [31] lubridate_1.6.0 jsonlite_1.2 foreign_0.8-67
PS This is my first question, so I tried to err on the side of too much info. PS这是我的第一个问题,所以我试图在太多信息方面犯错。 Let me know if I need to provide different/more/less information.
如果我需要提供不同/更多/更少的信息,请告诉我。
As said in comments there was a variable named c
that masked the function c
.正如评论中所说,有一个名为
c
的变量掩盖了函数c
。
Don't ever name anything c
, except maybe list elements or column names.永远不要命名任何
c
,除了列表元素或列名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.