Questions tagged [recode]

Recoding refers to the process of modifying the values of dataset, matrix, or vector according to a set of rules by which input values are changed to replacement values.

Recoding refers to the process of modifying the values of dataset, matrix, or vector according to a set of rules by which input values are changed to replacement values.

624 questions
1
vote
3 answers

Creating new variable based on conditions of different columns in R

can someone please help me with creating a new variable in R? I need to tell R something like this: data <- data %>% mutate(c = if_else(x == y, x, ifelse(x != y, y, ifelse(is.na(x), y, ifelse(is.na(y), x, NA)))) of course, in this form, it…
1
vote
1 answer

Recode or bin multiple numeric columns as categorical values and summing the counts

I want to recode or bin multiple numeric columns as categorical values and summing the counts. The columns are ages by individual year from 18yrs to 90+ yrs with the cells containing summed totals by age. I want to create categories to reflect age…
db2020
  • 69
  • 8
1
vote
2 answers

Convert value to 1 if it is max or min in a row

I have the following dataframe: final_odds <- structure(list(player_prop = c("Aaron Jones: Rush + Rec Yards", "Aaron Jones: Rush + Rec Yards", "Aaron Rodgers: Interceptions", "Aaron Rodgers: Interceptions", "Aaron Rodgers: Pass TDs", "Aaron…
Sam Hoppen
  • 355
  • 2
  • 9
1
vote
1 answer

How Recode values in R from SPSS .sav file which contain NA?

enter code hereI have a SPSS data, loaded using haven package, which I need to change values 0-4 to 4-0 in several columns called here as "tss" in the data psychophobia (psychophobia$tss1, psychophobia$tss2...), creating a new column as recodtss...…
Jontexas
  • 121
  • 8
1
vote
2 answers

How to create categorical column condition on values rows in R?

My dataframe is the following: df <- data.frame (RR_Code = c("848140", "848180", "848190", "848310", "848360", "848410", "848490", "850131", "850132", "850133"), Model = c("X1", "FG", "FD", "XR", "RT", "FG", "CV", "GH", "ER",…
user18948933
1
vote
2 answers

Recode monetary string values into new variable as numeric

First off - newbie with R so bear with me. I'm trying to recode string values as numeric. My problem is I have two different string patterns present in my values: "M" and "B" for 'million' and 'billion', respectively. df <- (funds = c($1.76M, $2B,…
Ariel
  • 21
  • 4
1
vote
1 answer

Recoding misspelled entries in a string variable in SPSS

I am fairly new to SPSS and not very familiar with string variables. I have a large data set that contains multiple string variables. I know how to convert them into numeric, however, the issue is with data entry. The data was entered by a number of…
Meg90
  • 11
  • 1
1
vote
1 answer

How do I change a value within a variable based on the value of another variable in R?

I am trying to recode demographic variables. If the variable Q36 equals Other and the variable Q35 equals Yes, I want Other (from Q36) to be changed to Hispanic. If the variable Q36 equals Other and the variable Q35 equals No, I want Other (from…
1
vote
1 answer

Recoding with and/or condition across multiple columns

I want to create a new variable (new_var) and condition it off of multiple columns: class == "yes" & score1:score5 >80. I have code that works below but is there a cleaner way to do this? I do it by embedding multiple ifelse columns, but is there a…
SaraFormula
  • 61
  • 1
  • 6
1
vote
1 answer

How to recode a new date variable and select the lowest date out of four date columns in R

Sample data stack_dat <- structure(list(bio_drug_stop_date = structure(c(15376, NA, 15602, NA, 15550, NA, 15350, 15363, 15418, 16157), class = "Date"), follow_up_2_years = structure(c(16047, 14318, 16038, 14352, 16044, 16582, 16054,…
Pashtun
  • 123
  • 7
1
vote
2 answers

How can I recode likert scale survey responses so that I am consolidating like responses within the vector?

I have likert scale responses ranging from 1:7 where 8 is "don't know". I'd like to recode 1:3, 4, 5:7 as a new variable where instead of a vector with 8 different responses, I have a new variable that consolidates 1:3, 4, and 5:7 and ignores "don't…
1
vote
1 answer

new variable based on value range of other column R

I know there are a lot of similiar questions like this but I couldn't get an answer. What i need to do is to group a numerical variable into three levels. What I tried next to some other things is the following: data_long$average_success_grouped <-…
1
vote
1 answer

Changing value of a variable based on condition in R

I am trying to change a value for a variable depending on other variables. So if value of one variable equals that of second variable then value of third variable should be multiplied by -1. My code looks like this: df <- df %>% mutate (C =…
craby111
  • 15
  • 3
1
vote
1 answer

Loop to create new variable based on answers to other variables

I would like to create a new variable based on the answers to three other variables (A,B and C) in my data set. Basically my variables have three modalities : "often", "sometime" and "never". I would like to have a new variable in which each…
1
vote
1 answer

How to recode data using dplyr::recode when variables have a space

I have myColors <- c("red", "purple", "blue", "blue", "orange", "red", "orange") library(dplyr) recode(myColors, red="rot", blue="blau", purple="violett") However if my data have spaces in them this method does not work myColors <- c("Color red",…
ECII
  • 10,297
  • 18
  • 80
  • 121