R数据帧提取非顺序列并创建新的子数据帧 [英] R data frame extracting non-sequential columns and creating new sub data frames
问题描述
我已经用lapply玩了,但我不知道如何创建子具有非顺序列的数据帧。
谢谢。
可以通过使用 data.frame
一个 data.frame
的行,列或两者的索引。
一般形式是: / p>
数据集[rows_wanted,cols_wanted]
省略其中一个返回的所有内容。例如, dataset [c(1,2,3),]
将返回一行到三行,并列出所有列。
因此,对于您的问题,您可以简单地执行以下操作:
数据集[,c(1,2,12 ,25)]
I have a data frame consisting of 25 columns and 30,000 rows. I want to create sub-data frames that contain all rows but only certain columns that are in non-sequential order. As an example, a sub data frame containing columns 1, 12, 15, and 25.
I have been playing around with lapply but I dont know how to create the sub data frames with columns that are in non-sequential order.
Thanks.
Information from data.frame
s can be extracted by using the indices of a data.frame
's rows, columns, or both.
The general form is of:
dataset[rows_wanted, cols_wanted]
Omitting one of those returns all of what was omitted. For example, dataset[c(1, 2, 3), ]
would return rows one through three, and all the columns.
Thus, for your problem, you can simply do:
dataset[, c(1, 2, 12, 25)]
这篇关于R数据帧提取非顺序列并创建新的子数据帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!