如何根据 R 中一列的值对该表进行子集/拆分? [英] How do I subset/split this table bases on the values of one column in R?

查看:27
本文介绍了如何根据 R 中一列的值对该表进行子集/拆分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

数据可以在这里找到:https://www.dropbox.com/s/l7pc11hhiwr8zzn/data.csv?dl=0 ,或者在图书馆 MASS 中作为 nlschools .

The data can be found here: https://www.dropbox.com/s/l7pc11hhiwr8zzn/data.csv?dl=0 , or else as nlschools in the library MASS.

我想根据 nlschools$SES 的值拆分此表,将表拆分为 nlschools$SES<=30 的表,<代码>30 >40,并保留所有列.

I'd like to split this table based on the value of nlschools$SES, having the table divide into tables where nlschools$SES is <=30, 30 < SES <= 40 and > 40, and with all the columns remaining.

我尝试过使用带有 0:30 之类的间隔的 cut,但结果非常混乱,并且没有剩余的完整列集.

I have tried using cut with intervals like 0:30, but the result is very confusing and does not have the complete set of columns remaining.

我希望我要实现的目标描述得足够清楚.

I hope what I'm trying to achieve is described clear enough.

推荐答案

尝试:

one<-subset(nlschools, nlschools$SES <=30)
two<-subset(nlschools, nlschools$SES >30 &  nlschools$SES<=40)
three<-subset(nlschools, nlschools$SES >40)

这篇关于如何根据 R 中一列的值对该表进行子集/拆分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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