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

Recoding one hevan_labelled variable

I tried to recode one variable of a dataset of a complex survey. I have tried dplyr::recode function. occup<-recode(sv$v717, c(0 )='0'; c(1, 2, 3 )='1'; c(4 )='2'; c(8, 9 )='3'; c(96, 98)='98'") Earlier I did same way successfully. However, this…
2
votes
1 answer

Recode continuous variable in R based on conditions

I want to "translate" a syntax written in SPSS into R code but am a total beginner in R and struggling to get it to work. The SPSS syntax is DO IF (Geschlecht = 0). RECODE hang0 (SYSMIS=SYSMIS) (Lowest thru 22.99=0) (23 thru 55=1) (55.01 thru…
Fabienne
  • 25
  • 4
2
votes
1 answer

Recode observation in column for a specific ID

I have a dataset, called 'survey'. In this I have rows of individual IDs, and columns with many questions. I need to recode the value in 1 column as NA and move the observation to the other column. For example: ID Fruit Vegetable aaa NA …
Gabriella
  • 421
  • 3
  • 11
2
votes
2 answers

recoding variables in a loop in R

I want to recode several variables together. All these variables will undergo same recoding change. For this, I followed the thread below. The thread below describes two ways of doing it. 1). Using column number 2). using variable names I tried…
2
votes
1 answer

Function to convert set of categorical variables to single vector

There are many posts about creating dummy variables, but in my case I have a set of columns similar to dummy variables which need recoding back into one column. Given as set of categorical/string variables (counties in the…
Ben
  • 1,113
  • 10
  • 26
2
votes
2 answers

How to recode factor levels from a vector in tidyverse?

Consider the data set below, there is a factor No with 34 levels, I want to recode these levels according to newLvl MWE structure(list(No = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L,…
doctorate
  • 1,381
  • 1
  • 19
  • 43
2
votes
1 answer

Dplyr: Recode numeric and character vectors

I have a screen of death in my mind. How do I use recode in dplyr? data = data.frame(id=rep(1:10, each=1), time=seq(1:5), char = strrep("a", 3)) library(dplyr) # everything throws an error data %>% recode(time, `1` = 0) data %>% recode(time, `1` =…
Marco
  • 2,368
  • 6
  • 22
  • 48
2
votes
2 answers

What is the shortest and cleanest way to recode multiple variables in a dataframe using R?

So I'm working in the field of social science and what I often have to do is to manipulate multiple variables to change values. More often than not this means to reverse a scale. I've been working with SPSS for a long time and the syntax there is…
2freet
  • 57
  • 1
  • 5
2
votes
2 answers

Recode multiple columns in dataframe R

I am trying to convert a Y into a 1 for a number of columns that could change (e.g. it could go up to x20). An example of the data is below as well as an expected output. Data <- tibble(Date = seq.Date(as.Date('2019-01-01'),as.Date('2019-01-08'), by…
Scott
  • 285
  • 2
  • 11
2
votes
3 answers

R: Replacing Strings with their Most Common Variant

I'm looking to standardise a set of manually inputted strings, so that: index fruit 1 Apple Pie 2 Apple Pie. 3 Apple. Pie 4 Apple Pie 5 Pear should look like: index fruit 1 Apple Pie 2 Apple Pie 3 Apple Pie 4 Apple Pie 5 …
rsylatian
  • 429
  • 2
  • 14
2
votes
2 answers

recode values in a character variable based on another character variable's value in sas

jrnlfile is a dataset with journal names and identifiers. Here are the first 6 obs: id journal issn 56201 ACTA HAEMATOLOGICA 0001-5792 94365 ACTA PHARMACOLOGICA SINICA 10334 ACTA PHARMACOLOGICA…
J.Q
  • 971
  • 1
  • 14
  • 29
2
votes
2 answers

How can I use a sub function in R to change a factor level that has a plus (+ ) symbol?

I ran into a hiccup using the sub() and gsub() functions in R to rename/change a factor level in R. But I'm not sure why it is not working. Scenario: I have some survey data that several factors with levels that truncate the high value. For…
Shawn Janzen
  • 369
  • 3
  • 15
2
votes
3 answers

How to add a - to a date in r?

I have dates in my data set that are formatted in the following way: "4252001" "5092001" "4242001" "5092001" "5192001" "6292001" "10242001" I want to add a dash (-) in between them, so they look like this: "4-25-2001" "5-09-2001" "4-24-2001"…
Sharif Amlani
  • 1,138
  • 1
  • 11
  • 25
2
votes
2 answers

Recode dates to study day within subject

I have data in which subjects completed multiple ratings per day over 6-7 days. The number of ratings per day varies. The data set includes subject ID, date, and the ratings. I would like to create a new variable that recodes the dates for each…
2
votes
1 answer

Recoding with missingness in R

I am trying to recode and create a variable based on the four variables. Recoding should be like this. If any of the four columns have the value of 1, then the recoded value should be 1, even though any 0 exists. If that row of values has only 0s…
amisos55
  • 1,913
  • 1
  • 10
  • 21