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
3 answers

Recode the value of a variable given the value of another one

I am using a dataset in which there is a mistake in the way the answers for a given country are coded. Let's call my first variable my.data$country_year and the second one my.data$attitude. A table of the two gives the following…
saladin1991
  • 142
  • 9
0
votes
1 answer

Renaming Categorical/Integer Cells into Binary Variables

Renaming is a big factor in the analysis. I have a dataset like the following: dat1 <- read.table(header=TRUE, text=" ID Age Align Weat 8645 15-24 A 1 6228 15-24 B 1 …
S Das
  • 3,291
  • 6
  • 26
  • 41
0
votes
2 answers

creating a new variable that combines several others using if else

I am using a large data.frame of health conditions and outcomes, I wish to combine 10 health conditions into a single condition, If the patient has either a, or b, c, or d, etc. then the condition would be condition one. I am trying to code it…
0
votes
1 answer

Recoding in R for items with missing data

I just started working with R and this is one of problems: I want to recode text variables from one item (column) in numeric variables. Since I had missing values, I tried to recode like this: install.packages("dplyr") library("dplyr") zdf_all <-…
Papea
  • 15
  • 1
  • 1
  • 7
0
votes
0 answers

Recoding categorical variables into binary variables in the same way on multiple data sets

I built a model using binary variables to represent categorical variables. I am trying to us the same binning and recodes I used in my research environment on production data. I use pyodc to query and pull realtime data that has the same elements as…
mitch
  • 379
  • 1
  • 3
  • 14
0
votes
0 answers

Group variables into vectors by grouping variable

I have a dataset containing the access logs of a website. Every step within the website is a line in the data. Now I want the pages visited by the user, grouped by session id into a vector (and these pages as character variables). This is necessary…
ItK
  • 63
  • 1
  • 7
0
votes
1 answer

Recode variable conditioning using dplyr

I am trying to recode one value in my dataframe conditioning on a second variable: recode age2 from 4 to 1 when age is 0 adm_id sex age counts age2 year rate1 rate2 1 1 0 547 1 2009 0.02387617 1.632533 1 1…
Ale
  • 303
  • 1
  • 9
0
votes
1 answer

Recoding Number to String R

I am new to R and I am trying to recode a numeric variable which is 1,2,3 to string. I have seen how to do it but I do not know why mine is not working, maybe it is because it should be from string to number? This is what I got, and thanks in…
Borja_042
  • 1,071
  • 1
  • 14
  • 26
0
votes
1 answer

recode related values in an efficient way

I have a dataframe df with only one variable var with some related values. df <- data.frame(var = c(rep('AUS',12), rep('NZ',12), rep('ENG',7), rep('SOC',12), rep('PAK',11), rep('SRI',17), rep('IND',15))) df %>%…
Prradep
  • 5,506
  • 5
  • 43
  • 84
0
votes
1 answer

Creating Multiple Covariates from Partial Matches of a Character Variable in R

I have a large data frame that contains an alphanumeric character variable, specifically it contains information on breed composition, from which I need to create covariates of breed fraction. The breed composition column contains over 7000…
Erin M
  • 3
  • 3
0
votes
1 answer

applying a loop to iteratively recode variables based on a macro variable (call symput/symget)

I have a dataset that looks like this, I am going to call it data1: data1 I want to recode the values for the ss, out1 and out2 variables when dv=1 to the values within each "var" group when dv=0. The outcome dataset I want looks like this, let's…
0
votes
3 answers

How to recode many data frame columns with same function

I have a data frame like this: CriterionVar Var1 Var2 Var3 3 0 0 0 1 0 0 0 2 0 0 0 5 0 0 0 I want to recode the values of Var1, Var2, and Var3 based on the value of CriterionVar.…
user1757436
  • 151
  • 4
0
votes
2 answers

Using if, else within recode

I am trying to replicate some code, but am running into trouble: data$var1 has values from 1-7 which I am trying to reduce to just 2 value in a new variable called data$var2. The code looks like this: data$var2 <- recode(data$var1, "1:3=1;…
user8394142
  • 3
  • 1
  • 1
  • 2
0
votes
1 answer

Conditional recoding in R

Here is an excerpt from an R data.frame which consist of indicators. It can be seen that for some rows the indictors switch to 1 until the end of the row while others switch back to zero. [,18] [,19] [,20] [,21] [,22] [,23] [,24] [1,] …
tomka
  • 2,516
  • 7
  • 31
  • 45
0
votes
0 answers

R: Using "otherwise" in RECODE function

I would like to recode numeric values to ordinal variable using 'car' library. However, it seems that I'm unable to use "otherwise" in my recode function. Can I know how to fix the code if I want to code any other values that are not within (0.0 to…
CHONG
  • 373
  • 1
  • 5
  • 13