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

Search through range of 'education' variables and assign a number based on the highest qualification contained within these variables

I'm currently an R novice and have come across an issue while recoding variables in my dataset. I would really appreciate any advice you may have on this issue. I have several different "education_code" variables that contain information about a…
M_Oxford
  • 361
  • 4
  • 11
0
votes
1 answer

Recode NA with values from similar ID with data.table

I'm in a learning process to use data.table and trying to recode NA to the non-missing values by b. library(data.table) dt <- data.table(a = rep(1:3, 2), b = c(rep(1,3), rep(2, 3)), c = c(NA, 4, NA, 6, NA, NA)) >…
yuskam
  • 310
  • 3
  • 8
0
votes
1 answer

How to place dates on the same scale using a reference point

I have a set of dates for multiple years and I am wondering how to place them on the same scale using a reference point. For example, I have the following dates: "2018-04-15" "2018-04-30" "2018-05-06" "2018-05-12" "2018-05-13" I want to create a…
Sharif Amlani
  • 1,138
  • 1
  • 11
  • 25
0
votes
0 answers

How to quickly recode column values based on a list?

Consider this matrix Y. > (Y <- matrix(c(rep(1:4, each=2), rnorm(8)), 8)) [,1] [,2] [1,] 1 -0.2452812 [2,] 1 1.3988440 [3,] 2 0.1558103 [4,] 2 0.2677039 [5,] 3 0.4716238 [6,] 3 -0.4442094 [7,] 4 1.9262647 [8,] …
jay.sf
  • 60,139
  • 8
  • 53
  • 110
0
votes
1 answer

Recode month factor

I have a dataset with like this: age month 5 apr 6 jun 7 dec When i write : str(data$month) I have, Factor w/ 10 levels "apr","aug","dec",..: 7 7 7 7 7 7 7 7 7 7 ... And levels(data$month) [1] "apr" "aug" "dec" "jul" "jun" "mar" "may"…
liguang
  • 161
  • 1
  • 9
0
votes
1 answer

How to recode several values for a specific row tidyverse

I would like to find a way to change values in several columns for a specific row using tidyverse. For example, with base R and the iris dataset: iris[iris$Sepal.Length == 5.1, c("Petal.Length", "Petal.Width")] <-…
Mleinss
  • 37
  • 5
0
votes
0 answers

How do I recode an XML document in XMLSpy to use entities

I have a rather large XSLT template which contains bilingual text (national characters in UTF-8). I am looking for a function that will recode all CDATA elements inside to use XML # entities, allowing me to store the XSLT as plain US-ASCII encoding.…
Stavr00
  • 3,219
  • 1
  • 16
  • 28
0
votes
1 answer

Odd gsub error for a recode function in R when I didn't use the gsub function

I regularly use the recode() function in R from the car library. It works great. However, now I'm getting an odd gsub error message and I've got no clue why since I haven't called the gsub() function in my commands. I used the gsub() function the…
Shawn Janzen
  • 369
  • 3
  • 15
0
votes
1 answer

Keep first record when event occurrs

I have the following data in Stata: clear * Input data input grade id exit time 1 1 . 10 2 1 . 20 3 1 2 30 4 1 0 40 5 1 . 50 1 2 0 10 2 2 0 20 3 2 0 30 4 2 0 40 5 2 0 50 1 3 1 10 2 …
bvowe
  • 3,004
  • 3
  • 16
  • 33
0
votes
1 answer

Combining data from two variables into a new variable

I am trying to recode a new variable out of two variables in my dataset. I don't see how I could create a MWE for SPSS, so I will just describe my data and hope that you are still able to follow me. If you let me know how to create a MWE for SPSS,…
Tea Tree
  • 882
  • 11
  • 26
0
votes
2 answers

Create new variable for many columns in R

Say I have some data and I want to do a loop for multiple variables where I subtract '1' from oldvariable and create a new variable that adds 'p' to the original variable name. Here is some data. So say I have var1 and var2 and want to create var1p…
bvowe
  • 3,004
  • 3
  • 16
  • 33
0
votes
2 answers

Recode variables

I'm trying recode some variables using ppar$denr <- recode(ppar$q3c, 0 =c("1"), 1 =c("2"), 2 =c("5"), 3 = c("4", "11"), 4 = c("3","6", "7", "10", "12", "77")) It return this error Error: unexpected '=' in "ppar$denr <- recode(ppar$q3c, 0 =" I try…
Mariane Campos
  • 121
  • 1
  • 7
0
votes
0 answers

Recoding multiple columns at once

I wonder how to recode an array of columns in R - none of the answers in Stackoverflow have worked for me so far. I have education level (ed_level_yy) from 2005-2015, however, as the data frame is structured at the moment the columns are not exactly…
rica
  • 67
  • 1
  • 9
0
votes
1 answer

Efficient and generic recoding of categorical variables in R

Imagine a data.table like this library(data.table) DT = data.table(values=c('call', NA, 'letter', 'call', 'e-mail', 'phone')) print(DT) values 1: call 2: 3: letter 4: call 5: e-mail 6: phone I wish to recode the values by the…
mr.bjerre
  • 2,384
  • 2
  • 24
  • 37
0
votes
2 answers

R: Assign Rank 1 to Predifined Largest Value

I have dataset like this: Value 5 4 2 1 I want the largest value to have the smallest rank while the lowest value to have the highest rank. In this dataset, Value=1 will recode to 5 while Value=5 will recode to 1. However, due to…
CHONG
  • 373
  • 1
  • 5
  • 13