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
votes
1 answer

Selecting multiple columns in R wide data to pipe an operation

I have a data in wide format.e.g. dt <- (age, gender, income, EDU1990, EDU1991, EDU1992, EDU1993, EDU1994, EDU1995 ..... EDU2021) I am trying to select all the column with EDU and recode the variables in all of them at once. I tried to use the grep…
rais
  • 81
  • 6
-1
votes
1 answer

Recoding a factor into a binary numeric variable

I have a condition with the levels positive and negative. I want to create numeric variables (contrast coding), so the positive = 0.5 and negative = -0.5. I tried a lot, but I don't know how to achieve this. I am happy for help!
Nini
  • 1
-1
votes
2 answers

Automating the process of recoding numeric variables to meaningful factor variables

I have a large data frame (hundreds of variables wide) in which all values of categorical variables are saved as numerics, for example, 1, 2, 8, representing no, yes, and unknown. However, this is not always consistent. There are variables that have…
Klaus Peter
  • 125
  • 7
-1
votes
1 answer

Recoding items for questionnaire

I would like to recode items for a questionnaire. I have a scale from 1 to 5, currently the best value is 5, but I want the best value to be 1. # loading…
Kitty123
  • 171
  • 2
  • 12
-1
votes
1 answer

R Data.Table Recode Many Columns

DATA=data.table(X1=c("Yes", "Maybe", "No", "Yes"), X7a=c("Yes", "Maybe", "No", "Yes"), X1_A = c("Yes", NA, "No", "Yes"), X1_B = c(1,NA,0,1)) FIX=c('X1','X7') I have 'DATA' which contains ~100 columns such as 'X1' and 'X7a' I first wish to create a…
bvowe
  • 3,004
  • 3
  • 16
  • 33
-1
votes
1 answer

How to retrieve label and value information for data in dataframe A from dataframe B

Edited (in order to be more precise): I have a csv file in which the label and value information is stored for each variable in dataframe A. In the original dataframe A there are 250 variables. For demonstration purposes I have: Reduced dataframe A…
TarJae
  • 72,363
  • 6
  • 19
  • 66
-1
votes
3 answers

Recode continuous variable_summary

enter image description here After recode from continuous variables into categorical. The summary for the new categorical variable doens't show how it summarize for categorical in levels we often see. Please help!
Will N
  • 1
  • 1
-1
votes
1 answer

creating factor out of dummy variables and counting

I would like to count certain things in my dataset. I have panel data and ideally would like to count the number of activities per zip. zip <- c(1,1,1,2,2,3,3,4,4,5,5) activity <- c(1,1,1,2,2,3,4,5,5,6,6) completion <-…
Lisam
  • 31
  • 7
-1
votes
2 answers

R - How to recode multiple columns

I am trying to change the 6s to NAs across multiple columns. I have tried using the mutate_at command in dplyr, but can't seem to make it work. Any ideas? library(dplyr) ID <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) #Create vector of IDs for ID…
aspark2020
  • 341
  • 2
  • 17
-1
votes
2 answers

Recoding a discrete variable

I have a discrete variable with scores from 1-3. I would like to change it so 1=2, 2=1, 3=3. I have tried recode(Data$GEB43, "c(1=2; 2=1; 3=3") But that doesn't work. I know this is an overly stupid question that can be solved in excel within…
A Soutter
  • 61
  • 1
  • 1
  • 7
-1
votes
1 answer

How to recode values based on duplicate values in another dataset

I am working with the following data. We can call it x New_Name_List Old_Name_List 1 bumiputera bumiputera (muslims) 2 bumiputera bumiputera (other) 3 non bumiputera non bumiputera (indigenous) 4 …
Sharif Amlani
  • 1,138
  • 1
  • 11
  • 25
-1
votes
1 answer

Recoding binomial variables in R

I need to clean/modify the data, but I am interested in data where var1=0 only. Can I 'permanently' remove the data where var1=0 or is missing, so that I can simplify my codes. For example,for summary statistics i have mytable <- xtabs(~var1+…
Beata
  • 7
  • 5
-1
votes
3 answers

R: gsub in a loop to replace names

I have a large dataset (60.000+rows) that contains names. However, the format of writing the names down differs and to enhance data quality I need to recode the names in a single format. Instead of copy pasting the recode-command I would like to do…
Hannie
  • 417
  • 5
  • 17
-1
votes
2 answers

Create new variable in R with assumptions from SPSS file

I've read in my SPSS file in R and want to recode a new variable if such and such assumptions are made. To be specific: I want to turn my spssdata_sub$gest variable into a new variable if the following the conditions are met: spssdata_sub$indusert…
Gunn-Helen Moen
  • 115
  • 2
  • 10
-1
votes
2 answers

R. Conditional replace of characters in data frame if two columns match

I have a data frame with columns c1 to c11, which looks like this: c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 G A G 1 1 0 1 1 0 0 1 T C T 0 0 1 1 0 1 0 1 C C T 0 1 1 1 1 1 1 0 I would like to do the following: if the character in c1 is the same as c3,…
Lucas
  • 1,139
  • 3
  • 11
  • 23