Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
349 views
in Technique[技术] by (71.8m points)

r - 将列表转换为数据框(Convert a list to a data frame)

I have a nested list of data.

(我有一个嵌套的数据列表。)

Its length is 132 and each item is a list of length 20. Is there a quick way to convert this structure into a data frame that has 132 rows and 20 columns of data?

(它的长度是132,每个项目都是一个长度为20的列表。是否有一种快速的方法将这种结构转换为具有132行和20列数据的数据帧?)

Here is some sample data to work with:

(以下是一些示例数据:)

l <- replicate(
  132,
  list(sample(letters, 20)),
  simplify = FALSE
)
  ask by Btibert3 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

With rbind

(与rbind)

do.call(rbind.data.frame, your_list)

Edit: Previous version return data.frame of list 's instead of vectors (as @IanSudbery pointed out in comments).

(编辑:以前版本的回报data.framelist的替代载体(如@IanSudbery在评论中指出)。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...