R数据帧提取非顺序列并创建新的子数据帧 [英] R data frame extracting non-sequential columns and creating new sub data frames

查看:106
本文介绍了R数据帧提取非顺序列并创建新的子数据帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由25列和30,000行组成的数据框。我想要创建包含所有行的子数据框,但是仅创建非顺序的某些列。例如,包含列1,12,15和25的子数据框架。



我已经用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.frames 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆