• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home » Resolved: How to recode a range of values (numeric) into a factor variable?

Resolved: How to recode a range of values (numeric) into a factor variable?

0
By Isaac Tonny on 16/03/2023 Issue
Share
Facebook Twitter LinkedIn

In this post, we will see how to resolve How to recode a range of values (numeric) into a factor variable?

Question:

I want to recode a variable that has values from 1 to 10 (numeric) into a factor variable of 5 values. I’m using the command dplyr::recode, but it is not working. I know how to do it with the cut function or case_when, but i want to know if there is a way to do it with the recode function.
I’m trying this code but is showing an error:
The output shows this:
I tried to use drop_na(), but is not working. I also tried to use the argument “.default = NA” and “.missing = NA” but it says that is an unused argument. If someone can help me it would be great. Thanks a lot.

Best Answer:

recode() will only help you if your input is a factor variable already. Use cut() to convert numerical values into factor levels.
Created on 2023-03-09 with reprex v2.0.2

If you have better answer, please add a comment about this, thank you!

Source: Stackoverflow.com

dplyr r recode
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How to make statement case insensitive when uploading a dta file with specified columns?

27/03/2023

Resolved: Sort dataframe columns value by close it to another column

27/03/2023

Resolved: PostgreSQL resample 1 minute OHLCV candle data into 5 minute OHLCV candle data

27/03/2023

Comments are closed.

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.