在r中的数据框中创建组
hello i have the following dataframe
n<-c(2,8,9,3,7,5,7,6,3,8,2,9,10,1)
tab<-data.frame("note"=n)
I need to add a new column that classifies if the number is less than 3 it will be group 1 if it is greater than 5 it will be group 2 from 5 to 7 it will be group 3 and from 7 to 10 group 4 as shown below
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一个选项是使用
case_when
定义组:或使用
cut
的其他选项:output
One option is to use
case_when
to define the groups:Or another option using
cut
:Output
基本r(从Latemail和Andrewgb借用可重复使用的功能):
Base R (borrowing heavily from the latemail and AndrewGB) with a reusable function: