循环之do.call() 接上次apply家族的学习,R语言基础包中也有这样一个循环处理list中每一项的小函数,用起来也是很方便,do.call(what, args, quote = FALSE, envir = parent.frame()). 第一部分: 函数介绍 作为基础函数,do.call的作用可以简单总结为:对**列表**中的每一项进行...
###2. lapply读入6个文件,并使用do.call来调用rbind去合并6个文件### library(magrittr) # 读入数据 file_list <- list.files("test", full.names = T)%>%lapply(function(x){ read.table(x, header = T) }) # 使用rbind合并 do.call(rbind, file_list) #结果如下: # a b c #1 1 1 1 ...
do.callconstructs and executes a function call from a name or a function and a list of arguments to be passed to it. Usage do.call(what,args,quote=FALSE,envir=parent.frame()) Arguments 最常用的就是,使用do.call将一个list 中n个数据框,通过rbind或者cbind 的方式合并成一个数据框。即起到了...
do.callconstructs and executes a function call from a name or a function and a list of arguments to be passed to it. Usage do.call(what, args, quote = FALSE, envir = parent.frame()) Arguments Details IfquoteisFALSE, the default, then the arguments are evaluated (in the calling environ...
对于最后的结果,我使用do.call(rbind,result )的组合,它生成如下所示的输出:由于我使用的是rbind,所以第一列没有标题。 代码语言:javascript 代码运行次数:0 运行 AI代码解释 Count Sum File1.Blue 5 10 File1.Red 2 6 File2.Blue 1 3 File2.Red 1 1 File3.Blue 4 File3.Red 7 2 名单很长。我想...
do.call給出一個錯誤,正如意味著參數“trim”為1。 另一方面, rbind綁定所有參數。 所以綁定X行,你做: > do.call(rbind,X) [,1] [,2] [,3] [1,] 1 2 3 [2,] 4 5 6 [3,] 7 8 9 如果你使用lapply ,R會將rbind應用於列表中的每一個元素,給你這個廢話: ...
do.call {base}R Documentation Execute a Function Call Description do.call constructs and executes a function call from a name or a function and a list of arguments to be passed to it.Usage do.call(what, args, quote = FALSE, envir = parent.frame())Arguments what either a function or a...
do.call给出一个错误,因为平均值要求参数"trim"为1. 另一方面,以行方式rbind绑定所有参数.所以要按行绑定X,你可以: >do.call(rbind,X)[,1][,2][,3][ 1,]1 2 3[ 2,]4 5 6[ 3,]7 8 9 Run Code Online (Sandbox Code Playgroud)
r = do.call("data.frame", l) print(r) 仍然有替代方案: (1)我就用read.table()+t(),大不了事后再按列转换类型! (2)仍然是上述循环,我不要每次都把值押入list中,我直接创建data.frame,之后再用cbind()逐列添加,这样就用不着do.call了 ...
r = do.call("data.frame", l)print(r)仍然有替代⽅案:(1)我就⽤read.table()+t(),⼤不了事后再按列转换类型!(2)仍然是上述循环,我不要每次都把值押⼊list中,我直接创建data.frame,之后再⽤cbind()逐列添加,这样就⽤不着do.call了 那么现在再次提⾼难度:取消转置函数t()的使...