织梦CMS - 轻松建站从此开始!

abg欧博官网|登陆|游戏|

Recoding continuous variable into categorical with

时间:2025-09-13 01:59来源: 作者:admin 点击: 5 次
I found this helpful answer to almost the same question, but it doesn't quite do what I need. I have respondents' age, a continuous variable, and I

I found this helpful answer to almost the same question, but it doesn't quite do what I need.

I have respondents' age, a continuous variable, and I'd like to recode it to categorical using tidyverse. The link above includes explanations of the functions cut_number(), cut_interval(), and cut_width(), but the reason those don't work for me is because I'd like to recode into categories that I've already determined ahead of time, namely, the ranges 18-34, 35-54, and 55+. None of those cut functions allow me to do this (or at least I didn't see how).

I was able to get my code to run without tidyverse, using:

data$age[data$"Age(Self-report)"<35] <- "18-34" data$age[data$"Age(Self-report)">34 & data$"Age(Self-report)"<55] <- "35-54" data$age[data$"Age(Self-report)">55] <- "55+"

but I'm trying to be consistent in my coding style and would like to learn how to do this in Tidyverse. Thanks for any and all help!

(责任编辑:)
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:
发布者资料
查看详细资料 发送留言 加为好友 用户等级: 注册时间:2025-09-18 17:09 最后登录:2025-09-18 17:09
栏目列表
推荐内容