将列的值分隔或分组为 R 中的不同类别 [英] Separating or grouping Values of a column into different categories in R

查看:35
本文介绍了将列的值分隔或分组为 R 中的不同类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家早上好.拜托,我确实有一个问题,我已经有一段时间无法解决了.(请查看图片链接以查看我的数据集的屏幕截图) https://i.stack.imgur.com/g2eTM.jpg

Good morning everyone. Please I do have a problem that I have not been able to solve for quite some time now.(please take a look at the image link to see a screen shot of my data set) https://i.stack.imgur.com/g2eTM.jpg

我有一列数据 (status) 包含两组值(1 和 2).这些是代表回归所需的两类(或状态)因变量(例如 Pp 和 Pt)的虚拟变量. 它们的实际值包含在最后一列 Pp.Pt (Pp.Pt) 中.Pt 只是一个名字而已).

I have a column of data (status) containing two set of values (1 and 2). These are dummies representing two categories (or status) of dependent Variables (say Pp and Pt) that I need for a regression. their actual values are contained the last column Pp.Pt (Pp.Pt is just a name nothing more).

我需要分别使用 Pp 或 Pt 运行两个单独的回归(意思是在 Pp.Pt 列中使用它们各自的值(最后一列中的每个值都是状态 1 或状态 2) . **我的问题是如何将它们分开或将它们分为两类 1= Pp 和 2 = Pt,以便我可以清楚地识别它们并将它们分组.

I need to run two separate regressions each using either Pp or Pt (meaning using their respective values in the Pp.Pt column (each value in the last column is either of status 1 or of status 2) . **My question is How do I separte them or group them into these two categories 1= Pp and 2 = Pt so that i could clearly identitify and group them.

https://i.stack.imgur.com/g2eTM.jpg

非常感谢您的热心帮助.最好的卢多维奇

Thank you very much for your kind help. Best Ludovic

推荐答案

这种方法可以解决您的问题

this approach can fix your issue

yourdata %>%
mutate(classofyourcolumn=ifelse(columntosplit<quantile(columntosplit,0.5),1,0))  

这篇关于将列的值分隔或分组为 R 中的不同类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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