本文介绍了如何使用循环从巨大的数据框架创建多个数据帧?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常大的数据框架:

I have a very large data frame:

ID    A   B   C   D   E ...
1     34  56  67  98  23 ...
2     23  67  99  45  73 ...
3     3   15  56  100 29 ...
...   ... ... ... ... ...

我已经创建了几个函数来处理两列数据帧。我想使用(一个列表)来编写一个循环,通过总是包含ID列来生成大数据帧。例如:

I have created several functions to process a two-column data frame. I would like to write a loop using (a list?) to generate such data frames from the large one by always incorporating the ID column. For example:

ID    A    ID   B   ID  C

然后很容易将临时数据框传递给函数。

Then it would be easy to pass the temporary data frames to the functions.

谢谢!

 解决方案 

推荐答案

c> lapply(colnames(veryVeryVERYLargeDF)[2:ncol(veryVeryVERYLargeDF)],function(nameOFColumnInveryVeryVERYLargeDF)cbind(veryVeryVERYLargeDF $ ID,veryVeryVERYLargeDF [,nameOFColumnInveryVeryVERYLargeDF]))

lapply(colnames(veryVeryVERYLargeDF)[2:ncol(veryVeryVERYLargeDF)], function(nameOFColumnInveryVeryVERYLargeDF) cbind(veryVeryVERYLargeDF$ID, veryVeryVERYLargeDF[,nameOFColumnInveryVeryVERYLargeDF]))

,这将给你一些someMallerDF的列表,其中someSmallerDF只是来自veryVeryVERYLargeDF的ID列,而来自veryVeryVERYLargeDF的其他列之一

that will give you a list of somewhatSmallerDFs, where each somewhatSmallerDF is simply the ID column from veryVeryVERYLargeDF and one of the other columns from veryVeryVERYLargeDF

这篇关于如何使用循环从巨大的数据框架创建多个数据帧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 10:55