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

Recode variable in R based on first characters of vector

I have a data frame which looks like this: codes <- c('TFAA1', 'TFAA2', 'TFAA3', 'TFAA4', 'TFAB1', 'TFAB2', 'TFAB3', 'TFAB4') scores <- c(4,3,2,2,4,5,1,2) example <- data.frame(codes, scores) I want to create a new column called code_group whereby…
stixmcvix
  • 313
  • 1
  • 2
  • 10
2
votes
2 answers

Recode a dataframe variable based on matches in a list

I am trying to recode a variable in a data frame based on matches to elements in a separate list. For example: df <- data.frame(stringsAsFactors = FALSE, var1 = c("116", "117", "118", "SL1", "SL2", "234")) matchList <- list(c("116, 117, and 118",…
Marcos
  • 444
  • 4
  • 9
2
votes
4 answers

Look up and replace values from a separate table in SAS

Dataset HAVE includes two variables with misspelled names in them: names and friends. Name Age Friend Jon 11 Ann Jon 11 Tom Jimb 12 Egg Joe 11 Egg Joe 11 Anne Joe 11 Tom Jed 10 Ann I have a small dataset…
J.Q
  • 971
  • 1
  • 14
  • 29
2
votes
1 answer

Recode empty string with dplyr::recode

Consider these factor objects: x <- factor(c(1,2,2,4,5), 1:5, labels = c('Ja', 'Nein', '', 'Weiß nicht', 'Keine Antwort')) y <- factor(c(1:5), 1:5, labels = c('Ja', 'Nein', '', 'Weiß nicht', 'Keine Antwort')) > table(x) x Ja …
LAP
  • 6,605
  • 2
  • 15
  • 28
2
votes
2 answers

Reverse coding in matlab

I have a survey data in matlab and I have some reverse coded items. All I need is to do reverse coding in certain questions.I was using this code reversecoding = myStruct.mysurvey(:,4) == 5 ; mySturct.mysurvey(reversecoding,4) = 3 ; but I…
2
votes
4 answers

Matching and replacing factor values using id

I have two dataframes both of which contain the same variable and a unique id for each observation. df.1 is a large dataset which contains missing values denoted by an NA. The values for those missing entries are contained within df.2 and I would…
dayleymart
  • 23
  • 8
2
votes
2 answers

What is the most efficient & pythonic way to recode a pandas column?

I'd like to 'anonymize' or 'recode' a column in a pandas DataFrame. What's the most efficient way to do so? I wrote the following, but it seems likely there's a built-in function or better way. dataset =…
user1318135
  • 717
  • 2
  • 12
  • 36
2
votes
1 answer

A better way to do over 150 country recodes?

I'm trying to recode a variable consisting of the recognised countries into regions that I am specifying. I've tried to do multiple if_else statements using dplyr to recode country variable into regions, but it is getting ridiculously long. I would…
elliot
  • 1,844
  • 16
  • 45
2
votes
1 answer

create a dummy variable (using mutate) based on a pattern in a character string

I'm trying to figure out how to create a dummy variable based on a pattern in a character string. The point is to end up with a simple way to make certain aspects of my ggplot (color, linetype, etc.) the same for samples that have something in…
phosphorelated
  • 635
  • 2
  • 7
  • 22
2
votes
1 answer

Recode variable with car - unexpectedly variable (.x value) treated as NA

My aim is to recode my variable into another variable with an inverted value: f1_1_recAktuell <- recode(Dat_MonatAktuell$f1_1, "1=10; 2=9; 3=8; 4=7; 5=6; 6=5; 7=4; 8=3; 9=2; 10=1") This code has served me know for more than a year, yet out of a…
Rieke
  • 99
  • 5
2
votes
2 answers

Summing up multiple variable scores depending on their score

tl;dr: I need to first dichotomize a set of variables to 0/1, then sum up these values. I need to do this for 14x8 variables, so I am looking for a way to to this in a loop. Hi guys, I have a very specific problem I need your help with: Description…
Dekay
  • 147
  • 1
  • 9
2
votes
1 answer

Recoding non-mutually exclusive variables into mutually exclusive variables

Any help with this would be much appreciated. I have four overlapping race variables that I would like to make mutually exclusive and code the remainder into a new variable mixed race variable. I've been trying to use if and ifelse and failing…
swhusky
  • 305
  • 3
  • 12
2
votes
3 answers

Efficiently recoding multiple variables from character to numeric values in R

I am using R (version 3.2.3) to recode multiple variables (in the same dataframe) from character values ("High", "Medium", "Low" and "No Concerns") to numeric values (4,3,2 and 1). I know there are several ways to recode a variable and in my example…
2
votes
2 answers

Pandas/Python: Replace multiple values in multiple columns

All, I have an analytical csv file with 190 columns and 902 rows. I need to recode values in several columns (18 to be exact) from it's current 1-5 Likert scaling to 0-4 Likert scaling. I've tried using replace: df.replace({'Job_Performance1':…
R_Queery
  • 497
  • 1
  • 9
  • 19
2
votes
2 answers

Recode Multiple Columns into Single Variable

I have six columns: age01 ... age06 They contain a 1 or 0 depending on whether a respondent fits into that age category. The data is as follows: The age categories are mutually exclusive, respondent cannot answer 1 to more than 1, and at least 1…
Steve
  • 2,764
  • 4
  • 27
  • 32