如何在r中使用特定条件的数据包数据
我有一个数据集,该数据集要求我对数据进行分类以考虑随着时间的推移而考虑更改。我想创建一个编码数据范围的新列。例如,我想在以下名为“类别”的数据集中添加列,其中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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论