r - 调用具有可变数量参数的函数
问题描述
library(plyr)
stack_dataframes <- function(...){
dataframes <- list(...)
for (i in dataframes){
colnames(i) <- "b"
}
plyr::rbind.fill(...)
# Still has the colnames "a", but I want to stack
# all the changed dataframes with colname "b"
}
一些样本数据和三个参数调用函数
df1 <- data.frame(a=c(1,2))
df2 <- data.frame(a=c(1,2))
df3 <- data.frame(a=c(1,2))
stack_dataframes(df1, df2, df3)
但是如何更改stack_dataframes()
-function 以便它plyr::rbind.fill()
根据 data.frames 的数量自动调整参数?例如,如果我stack_dataframes(df1, df2)
用两个 data.frames 调用它也应该是plyr::rbind.fill(df1, df2)
等。
解决方案
推荐阅读
- python - 回文分区
- python - 我不明白为什么多线程代码无法获取 lineedit.text()
- c++ - C ++如何“重载”模板以同时用于值和类型?
- activemq-artemis - 如何查找多播队列?
- linux - Cypress文件路径需要支持windows和linux
- python - 如何修复 Python 中 statsmodels 的 Holt 和 Holt-Winters 函数中的“TypeError”
- scala - 尝试执行 spark-shell 时出现错误“没有这样的文件或目录”
- node.js - 建议我最好的 NodeJs API 验证包
- node.js - mongoose find() 返回模型的属性
- javascript - 以优化方式处理 JSON