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
3
votes
2 answers

Group individuals based on direct and indirect relationships

I want to group individuals into different households on the basis of their address and their ownership of parcels. People belong to the same household if they live at the same address and if they are linked by ownership, directly or indirectly, of…
3
votes
4 answers

Is there a faster way to recode character data when it's actually a factor?

I often deal with character data that need some recoding. One common scenario is that a character vector that's being recorded is a factor in essence, but not necessarily in class. Consider for example, a chr vector such as the following…
Emman
  • 3,695
  • 2
  • 20
  • 44
3
votes
3 answers

Create a categorical variable

I want to categorized one variable with the next conditionals: 0 - 4: "fail" 5 - 7: "good" 8 - 10: "excellent" None of the above: NA I tried using the recode function The values of variable is numeric segur <- data$segur Created a new variable…
Raq
  • 75
  • 1
  • 6
3
votes
2 answers

Is there a function in R to change several similar factor levels at once?

My second question at stack overflow so all tips are welcome :) For clinical research I have to recode many dichotomous baseline characteristics that have several variations of "yes" and "no" in it. Currently i am recoding these variables one by one…
3
votes
1 answer

Recoding a Variable in Python similar to R ifelse

I am just new in Python, and I am trying to do an analysis. But before that, I want to recode some of the variables. I am wondering if this R code has an equivalent in Python. df$col1 <- ifelse(df$col1 == "yes", 1, 0) Here df is a pandas.DataFrame…
ambmil
  • 115
  • 3
  • 9
3
votes
4 answers

How to recode multiple variables for a subset of a dataframe?

I'm lost, so any directions would be helpful. Let's say I have a dataframe: df <- data.frame( id = 1:12, v1 = rep(c(1:4), 3), v2 = rep(c(1:3), 4), v3 = rep(c(1:6), 2), v4 = rep(c(1:2), 6)) My goal would be to recode 2=4 and 4=2 for…
2freet
  • 57
  • 1
  • 5
3
votes
3 answers

R recode multiple variables following same rules

data=data.frame("x1"=c(1:10), "x2"=c(1:4,4,6:10), "x3"=c(1:3,2:5,5:7), "x4"=c(21:30), "x5"=c(35:44)) recode=c("x1","x2","x3") data <- data[recode %in% c(4,5)] <- NA I want to store…
bvowe
  • 3,004
  • 3
  • 16
  • 33
3
votes
5 answers

Replace strings with values across multiple columns at once

I need to replace strings with numbers across multiple columns. Below is a sample data set: x <- c("Low Outlier", "High Outlier", "Novice", "Novice", "Emerging", NA, "Proficient", "Approaching") y <- c("Novice", "Approaching", "Proficient",…
asokol
  • 119
  • 1
  • 16
3
votes
3 answers

how to `replace` (or equivalent function) in R for long lists

I'd like to be able to replace a subset of element values in a vector within my data.frame object in R. Toy examples I've found thus far are simple (and small) enough to manually type and replace the few elements you want to target with those you…
Devon O'Rourke
  • 237
  • 2
  • 11
3
votes
2 answers

Conditional recoding of factor to factor

I have a tibble, df, with a factor, A, I wish to: 1) copy of,C, and 2) recode based on a second variable, B. At the moment I'm doing it in this roundabout way. I'm quite confused by the conditional recoding of factor. I also looked at dplyr's…
Eric Fail
  • 8,191
  • 8
  • 72
  • 128
3
votes
1 answer

H.264 fast recoding

I'm working on a (sort of a) VOIP application for mobile with video support. Most of modern smartphones are equipped with hardware H.264 encoder/decoder. However most of those support only a limited number of encoding profiles. In particular I'm…
valdo
  • 12,632
  • 2
  • 37
  • 67
3
votes
1 answer

recode in dplyr from character to numeric in factors

I am getting familiar with recode from dplyr V0.5. Am I missing something? Seems like Recode from car is way more efficent. Unless I am doing something wrong: This works: x <- c("a", "b", "c") y <- dplyr::recode(x, a = 1, b = 2, c= 3) y But not…
Bonfil
  • 31
  • 1
  • 4
3
votes
3 answers

SPSS recoding variables data from multiple variables into boolean variables

I have 26 variables and each of them contain numbers ranging from 1 to 61. I want for each case of 1, each case of 2 etc. the number 1 in a new variable. If there is no 1, the variable should contain 2. So 26 variables with data like: 1 15 28 39 46…
Larissa
  • 83
  • 5
3
votes
1 answer

Syntax to loop variable recode in SPSS

I'm new to using syntax and need help recoding a long series of variables into new variables. Essentially the bit of code I am trying to loop is: RECODE cqC2_1_11 (9 thru Highest=10) (ELSE=COPY) INTO cqC2_1_11_T3. VARIABLE LABELS cqC2_1_11_T3…
Chad
  • 31
  • 2
3
votes
1 answer

Recode the same value pattern for all variables in Stata

In my dataset, I have a bunch of Yes/No type variables. For some reason, "Yes" is coded as 1 and "No" is coded as 2 instead of 0. Now I want to recode 2 to 0 based on the value label "No". How can I do it without having to check and recode every…
Elise
  • 87
  • 2
  • 10