如何在r中使用特定条件的数据包数据

发布于 2025-01-23 22:35:38 字数 430 浏览 3 评论 0原文

我有一个数据集,该数据集要求我对数据进行分类以考虑随着时间的推移而考虑更改。我想创建一个编码数据范围的新列。例如,我想在以下名为“类别”的数据集中添加列,其中V1在10-13之间为1; 2当V1在14-16之间; 3当V1在17-20之间。

Data<-data.frame(
X = factor(c("SU", "Staff")),
V1 = c(10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20))

我以前使用以下代码创建5个相等的垃圾箱,但是我现在想指定上述范围:

binning <- Data %>% mutate(Category=ntile(Data$'V1', 5))

任何帮助都将不胜感激,我对R的新手将受到欢迎。

非常感谢 劳拉

I have a data set that requires me to categorise data to consider changes over time. I want to create a new column that codes a data range. For example, I would want to add a column to the following data set called 'category' where category is 1 when V1 is between 10-13; 2 when V1 is between 14-16; and 3 when V1 is between 17-20.

Data<-data.frame(
X = factor(c("SU", "Staff")),
V1 = c(10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20))

I previously used the following code to create 5 equal bins, but I now want to specify the range as above:

binning <- Data %>% mutate(Category=ntile(Data

Any help would be appreciated and I am new to r so simple language would be welcomed.

Many thanks,
Laura

V1', 5))

Any help would be appreciated and I am new to r so simple language would be welcomed.

Many thanks,
Laura

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文