r - R闪亮部署 - 替换rowr cbind.fill
问题描述
我正在 Heroku 上部署一个闪亮的应用程序。
但是 buildpack 不支持 rowr,因为 R 的版本与此包不兼容。
如何用基本 R 或 dplyr 函数替换 rowr::cbind.fill ?
我试图查看函数中的内容,但我不清楚:
function (..., fill = NULL)
{
inputs <- list(...)
inputs <- lapply(inputs, vert)
maxlength <- max(unlist(lapply(inputs, len)))
bufferedInputs <- lapply(inputs, buffer, length.out = maxlength,
fill, preserveClass = FALSE)
return(Reduce(cbind.data.frame, bufferedInputs))
}
问这个问题的另一种方法是在 dplyr 中是否有以下问题的解决方案,我需要 fill = NA ?
解决方案
这是一种检测每列中缺失元素数量的解决方案,将其附加NA
s 并将其绑定在一起。我假设这些列存储在一个列表中:
# test data
test_data <- list(c1 = rep(1, 5),
c2 = rep(2, 7),
c3 = rep(3, 4))
# find the longest column
longest_column <- max(unlist(lapply(test_data, length)))
# calculate how many NAs need to be added
number_append <- lapply(test_data, function(x) longest_column - length(x))
# append the columns
data_appended <- lapply(seq_len(length(test_data)), function(i) {
c(test_data[[i]], rep(NA, number_append[[i]]))
})
# combine the columns
data_combined <- do.call("cbind", data_appended)
推荐阅读
- c++ - 数据类型浮点数
- jquery - 使用来自 HTML 服务的数据填充 Google 表格
- hadoop - Hadoop不使用配置文件?
- performance-testing - 在 gatling 中连接异常 - 这是什么意思?
- angular - 电子邮件的Angular 4 Formarray唯一值验证
- ios - objective-c,如何将文件作为参数发送
- android - Android TalkBack EditText - 提示与 contentDescription
- php - ORDER BY 子句在实时服务器中无法正常工作
- c++ - 用 stl 矩阵初始化 boost 矩阵
- objective-c - 多页文件可可打印