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

recode ifelse or statement

i am trying to generate a new variable as follows: if value for testA is 1 and value for testB is 1 ==> code testAB as 1 if value for testA is 1 and value for testB is missing or 0 ==> code testAB as 1 if value for testA is missing or 0 and value…
victoria
  • 43
  • 1
  • 7
0
votes
3 answers

remove/replace specific words or phrases from character strings - R

I looked around both here and elsewhere, I found many similar questions but none which exactly answer mine. I need to clean up naming conventions, specifically replace/remove certain words and phrases from a specific column/variable, not the entire…
Adam_S
  • 687
  • 2
  • 12
  • 24
0
votes
1 answer

How to recode a variable into another variable

I am trying to recode the following variable: str(dades$Edat) num [1:30000] 24 26 34 37 57 37 29 23 28 35 ... Into this: agrupar.edat<-function(x){ for (i in 1:length(x)){ if (x[i]>=21 & x[i]<30) {x[i]<-'1'} else if (x[i]>=30 &…
Gotey
  • 449
  • 4
  • 15
  • 41
0
votes
1 answer

Not understanding the ifelse statement

I'm trying to recode a variable based on two other variables and I think I'm misunderstanding how the ifelse statement works. I have one column that is a string and then other is an integer. I want the new column to be the same as the string c1…
Yolo_chicken
  • 1,221
  • 2
  • 12
  • 24
0
votes
1 answer

"Unreplaced values treated as NA as .x is not compatible": Recoding numeric variables

I have a numeric variable (V110) that takes on values between 1-4. As the numbers stand for higher (1) and lower (4) trust in the govt, I want to recode them, so that the highest value signifies the highest and the lowest value the lowest trust. Now…
ureuss
  • 1
  • 1
  • 1
  • 1
0
votes
1 answer

recode specific dates in R

I want to change all of the dates 2006-04-11 in my dataset to 2006-04-01. I converted the date variable to a factor, recoded 2006-04-11 to 2006-04-01, and re-converted the variable back to class = date. The recode works while the variable is a…
nusbaume
  • 27
  • 1
  • 1
  • 6
0
votes
1 answer

read_excel recode number as na value

While importing data from an excel file using the read_excel function in the readxl package, I have tried specifying a number for the na argument but it does not recode the missing values. The data was entered with a numeric value as the missing…
Andrew Jackson
  • 823
  • 1
  • 11
  • 23
0
votes
3 answers

Conditional recode and sum in R

My (sample) data look as follows: mydata <- structure(list(x1 = c(0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), x2 = c(1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 4L, 4L), x3 = c(1L, 3L, 5L, 1L, 3L, 5L, 1L, 4L, 5L, 2L, 1L, 5L, 6L,…
research111
  • 347
  • 5
  • 18
0
votes
1 answer

Recoding multiple variables into one variable with many and/or statements

I am attempting to convert from SPSS to R; I wanted to translate my cleaning syntax as a good way to learn R, but I am having a great deal of trouble with what is a simple command in SPSS. The following code works in SPSS: IF (n_race = 1 &…
KCP
  • 1
0
votes
3 answers

matching if string values are equal, creating a new string value in new column in R

I am trying to do a kind of 'if' statement in R where I want to find if two values (string) are the same in two different columns. For example, if my Origin and my Destination country are the same, I want to create a new column with Domestic as a…
0
votes
2 answers

Conditional recoding of factor

I need to recode a couple of factor variables, but I just keep on failing. Suppose my data looks like this: df <- data.frame(a = c("1","2","","Other"), b = c("3","","Other","Other"), v1 =…
chamaoskurumi
  • 2,271
  • 2
  • 23
  • 30
0
votes
1 answer

R: Apostrophes in recode()

I am using the recode() function in the car package to recode an integer class variable in a data frame. I am trying to recode one of the values of the variable to a string that contains a single apostrophe ('). However, this does not work. I…
socialscientist
  • 3,759
  • 5
  • 23
  • 58
0
votes
0 answers

Recode, categorical variables with massive amount of categories based on the mean of another variable

I have a database with variables which are categorical and have a massive amount of categories. I would love to recategorise it in less amount of categories in this case 2, and base the decision to place a category in one of the new based on the…
Tim
  • 3
  • 1
0
votes
1 answer

R: recoding 2 variables into 1 inside function

I've run into two problems writing functions for data frames. I often get a data frames with 2 variables, and I want to recode them into one variable. If V1>0 and V2 <0 then new_variable = "V1>0, V2<0. In all of dataframes I've got V1 and V2…
M. Siwik
  • 486
  • 7
  • 17
0
votes
1 answer

More efficient method of recoding one column in a data.frame conditional on other column entries

I am looking for a more efficient method of re-coding column entries in a dataframe, where the recoding is conditional on the entries in other columns. Take this simple example, which demonstrates my current procedure of creating a new column for…
user3237820
  • 211
  • 1
  • 8