Force mapply to return a list?

拈花ヽ惹草 提交于 2019-11-27 08:53:45

To get a list of data.frames as the return value, set mapply's SIMPLIFY argument to FALSE. (Its default value is TRUE, which directs the function to "attempt to reduce the result to a vector, matrix or higher dimensional array" -- just what you experienced).

res <- mapply("CreateDataFrame", type=toupper(letters[1:5]), n=10, n.true=8:4, 
              SIMPLIFY = FALSE)

identical(class(res), "list")
[1] TRUE

Alternative you can use the Map function. It is basically mapply with SIMPLIFY set to FALSE.

Map("CreateDataFrame", type=toupper(letters[1:5]), n=10, n.true=8:4)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!