将函数应用于数据框的相应元素?

dla*_*ser 3 r list

我在R中有一个数据帧列表.列表中的所有数据帧都具有相同的大小.但是,元素可以是不同类型的.例如,

在此输入图像描述

我想将一个函数应用于数据框的相应元素.例如,我想使用粘贴函数来生成数据框,例如

"1a" "2b" "3c"

"4d" "5e" "6f"
Run Code Online (Sandbox Code Playgroud)

有没有一种直接的方法在R中执行此操作.我知道可以使用Reduce函数在列表中的数据帧的相应元素上应用函数.但在这种情况下使用Reduce功能似乎没有达到预期的效果.

Reduce(paste,l)
Run Code Online (Sandbox Code Playgroud)

生产:

"c(1, 4) c(\"a\", \"d\")" "c(2, 5) c(\"b\", \"e\")" "c(3, 6) c(\"c\", \"f\")"
Run Code Online (Sandbox Code Playgroud)

想知道我是否可以这样做而不用乱写for循环.任何帮助表示赞赏!

mne*_*nel 6

而不是Reduce,使用Map.

 # not quite the same as your data
 l <- list(data.frame(matrix(1:6,ncol=3)),
           data.frame(matrix(letters[1:6],ncol=3), stringsAsFactors=FALSE))
 # this returns a list
 LL <- do.call(Map, c(list(f=paste0),l))
 #
 as.data.frame(LL)
 #  X1 X2 X3
 # 1 1a 3c 5e
 # 2 2b 4d 6f
Run Code Online (Sandbox Code Playgroud)