循环之do.call() 接上次apply家族的学习,R语言基础包中也有这样一个循环处理list中每一项的小函数,用起来也是很方便,do.call(what, args, quote = FALSE, envir = parent.frame()). 第一部分: 函数介绍 作为基础函数,do.call的作用可以简单总结为:对**列表**中的每一项进行...
data.frame的do.call(rbind,)为什么这么慢 do.call(rbind, ) 换成 dplyr::bind_rows( ) 竟然提速千倍,R让人如此无语。 个人理解: R给人的感觉是一切操作赋值都是“传值”。 list 是R的基本数据类型,本身是 C struct, 定义操作等使用了指针,传地址操作,list的函数,很多也是primitive函数,这些应该也是C 代...
###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.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應用於列表中的每一個元素,給你這個廢話: ...
up down number1A a12B b23C c34D d45E e5[[3]] up down number1A a12B b23C c34D d45E e5>do.call("rbind",list1) up down number1A a12B b23C c34D d45E e56A a17B b28C c39D d410E e511A a112B b213C c314D d415E e5
对于效率并不完全确定,但是使用purrr和tibble的一个紧凑的选项可以是:
up down number1A a12B b23C c34D d45E e5[[3]] up down number1A a12B b23C c34D d45E e5>do.call("rbind",list1) up down number1A a12B b23C c34D d45E e56A a17B b28C c39D d410E e511A a112B b213C c314D d415E e5
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)
X <-list(1:3,4:6,7:9) AI代码助手复制代码 用lapply你可以得到列表中每个元素的意思: > lapply(X,mean)[[1]][1]2[[2]][1]5[[3]][1]8 AI代码助手复制代码 do.call给出一个错误,正如意味着参数“trim”为1。 另一方面, rbind绑定所有参数。 所以绑定X行,你做: ...