[英]R code: How can I extract a column from a list of tibbles and use it as a parameter for functions?
I have a list of 9 tibbles called CCLF_Details. 我有一个9个小标题CCLF_Details的列表。 Each Tibble is named CCLF1_Details-CCLF9_Details.
每个Tibble都命名为CCLF1_Details-CCLF9_Details。 I have columns "COLUMN_LABEL" and "COLUMN_WIDTH" in each tibble.
我在每个小标题中都有“ COLUMN_LABEL”和“ COLUMN_WIDTH”列。 I want to use those columns as parameters for read_fwf.
我想将这些列用作read_fwf的参数。
So far I've done 到目前为止,我已经完成了
width <- lapply(CCLF_details, "[","COLUMN_WIDTH", drop = FALSE)
label <- lapply(CCLF_details, "[","COLUMN_WIDTH", drop = FALSE)
but when I run it through read_fwf, I get 但是当我通过read_fwf运行它时,我得到了
"Error in fwf_widths(width) : (list) object cannot be coerced to type 'double'"
“ fwf_widths(width)中的错误:(列表)对象无法强制输入“ double”类型”
When inspecting "width", it states it is a list of tibbles with one column (and that column is numeric) instead of a list of numeric vectors. 当检查“宽度”时,它指出它是一个带有一列(并且该列是数字)的小标题列表,而不是数字矢量列表。
How can I get the columns in a format that I can run the list as a parameter for a Map function? 如何以一种格式将列用作Map函数的参数来获取列?
Was a simple fix. 是一个简单的修复。 Needed to use sapply instead
需要使用sapply代替
width <- sapply(CCLF_details, "[","COLUMN_WIDTH", drop = FALSE)
label <- sapply(CCLF_details, "[","COLUMN_WIDTH", drop = FALSE)
Then could use it as arguments for read_fwf by using 然后可以通过使用它作为read_fwf的参数
fwf_widths(widths = as.vector(width), col_names = as.vector(label))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.