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

Recode several similar variables in R

I am working with a medium size dataset and I am interested in recoding several variables at once. There are 15 variables coded as factors with three levels. YES=3, NO=2, N/A=1. I would like to recode all 15 variables as numeric. YES=1, NO=0,…
-1
votes
5 answers

recode and add prefix to sas variables

Lets's say I have a bunch of variables named the same way and I'd like to recode them and add a prefix to each (the variables are all numeric). In Stata I would do something like (let's say the variables start with eq) foreach var of varlist eq* { …
vashts85
  • 1,069
  • 3
  • 14
  • 28
-1
votes
2 answers

R Create a variable with the levels of grouped data

I have a data frame such as data data = data.frame(ID = as.factor(c("A", "A", "B","B","C","C")), var.color= as.factor(c("red", "blue", "green", "red", "green", "yellow"))) I wonder whether it is possible to get the levels of each…
Edu
  • 903
  • 6
  • 17
-1
votes
1 answer

If else with conditional recoding

I have a variable "dif2" in data2, and I'm going to add a new variable to the dataset named "L" with the condition that ( if -0.1 <= dif2 <= 0.1, L == "B", while if dif2 > 0.1, then L == "S", and if dif2 <-0.1 then L == "E") I tried different ways.…
LeoNiu
  • 13
  • 1
  • 3
-1
votes
1 answer

Recoding multiple variables based on logical rules in external table.

Objective Given data ds, compute a new variable ds$h1 from ds$raw1 and ds$raw2 according to the harmonization rule specified in the object hrule. The reproducible example contains response of 10 individuals on 2 measures, raw1 and raw2: >ds id…
andrey
  • 2,029
  • 2
  • 18
  • 23
-1
votes
1 answer

How to recode a byte variable to a string variable in Stata

I'm trying to recode a byte variable in my Stata file to a string variable. But it is showing me an error (stating that it doesn't recognize the element). Stringing it isn't working either. Can I do this in Stata? The data file I have includes the…
dexter
  • 143
  • 1
  • 2
  • 5
-1
votes
2 answers

Recent development in recoding repeated variables in R?

So I have a long dataset of sequence. Every column (from t1 to t...n) has the same levels or categories. There are more than 200 categories or levels and 144 column (variables) in total. id t1 t2 t3 t...n "1" …
giac
  • 4,261
  • 5
  • 30
  • 59
-1
votes
2 answers

Recoding of Gender in Stata

In my dataset I currently have the labels Male and Female within my gender variable. As I am going to be running a regression model I would like to change this so Male and Female are recoded to appear as 0 and 1. However, I am not sure how to do…
SouthernSoul
  • 11
  • 1
  • 1
-2
votes
1 answer

trying to rename the groups of the variable named "age" to the actual age groups they represent (eg 17-21). rather than 1, 2, 3, 4 (and so on)

I am rather new to R and am struggling to recode/rename the variable answer groupings. The values within the groups are correct, it's just that the names of them are not. I changed the variable from 'factor' to 'numeric' The dataset is called 'nes',…
cl1791
  • 1
-2
votes
1 answer

How to use multiple condition to generate a new variable in Stata?

I want to generate 3 NEW variables using these variables in my data set: Ucod 19 variables in series by this name: Record_2, Record_3......Record_20 Both of them have values in alphanumerical format in it, basically ICD codes i.e, I150 I want to…
Pkbti
  • 9
  • 3
-2
votes
1 answer

Search for multiple strings, print different values if present

I'd like to be able to search a column (say A) cell-by-cell and, if the cell contains certain strings (say "apple" or "pear"), print a certain value (say "A" or "P") in the corresponding cell of another column (say B). So, if A1 has "pear", then B1…
j400nb
  • 17
  • 5
-2
votes
3 answers

is there a way to use lambda or quicker way than a dictionary to recode pandas df column of unique categories into integer buckets like 0, 1, 2, etc?

Is there a quicker way via lambda or otherwise to recode the every unique value in a pandas df? I am trying to recode this without a dictionary or for loop: df['Genres'].unique() array(['Art & Design', 'Art & Design;Pretend Play', 'Art &…
-2
votes
1 answer

Using R to recode numeric variables

I am working with a data set where I have to recode variables so that Never and Rarely =0, Sometimes and Always as 1, and Not Applicable as NA. For reference, the numbering scheme for the code is that 1=Never, 2=Rarely, 3=Sometimes, 4=Always, and 5=…
-2
votes
1 answer

Is there an R function to "spread" a variable?

Data set has question: What country have you visited? Subject can pick multiple countries. So... country 1. 1, 2, 3 2 1, 3 2 Would like item to look like: country_1 country_2 country_3 1. 1 2 3 2 1 3 2 What…
Nick
  • 21
  • 6
-2
votes
1 answer

Recode continuous data into categorical data using is.na() and if_else() in R

I have a data frame and one of the columns contain both continuous data and NA. I want to recode all continuous data as one level of categorical data and the NA as another using if_else() and is.na(). How can I do it? Example data…
P Z
  • 3
  • 2
1 2 3
41
42