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

R: counting and recoding consecutive values in a matrix

I am working with a matrix containing a large number of NA. I would like to record the length of each sequence of NA in a new matrix. The following example should be more plain. #Generating a random 5x5 population matrix with 15…
goclem
  • 904
  • 1
  • 10
  • 21
2
votes
3 answers

Recoding variables with NAs in R

I am trying to code a new variable based on the values of three other variables. Specifically, if all of the variables are NA, I would like the new variable to take NA and if any of them are 1, it should take a 1, otherwise it should take a 0.…
coding_heart
  • 1,245
  • 3
  • 25
  • 46
2
votes
1 answer

Recode a table in R

Suppose I have a table of ages: ages <- array(round(runif(min=10,max=200,n=100)),dim=100,dimnames=list(age=0:99)) Suppose now I want to collapse my ages table in 5-year wide age groups. This could be done quite easily by summarizing over different…
mzuba
  • 1,226
  • 1
  • 16
  • 33
2
votes
1 answer

Translating a C++ (dealing with corona) function into C#

i had a C++ .exe i was using as a standalone image cleaner. But i now want to use its fonction into my own c# app, so i started to translate it. But i REALLY TOTALLY know nothing about C++ and its logic. So i come here for some help. First, does…
user3916429
  • 562
  • 6
  • 25
2
votes
1 answer

Recoding variables in a list

I guess I am writing in the spirit of "no question is too easy", I am just an average Stata-user social scientist approaching R for the first time and having endless nights facing it... Please have mercy! I am working with a comparative dataset from…
000andy8484
  • 563
  • 3
  • 16
2
votes
1 answer

Recode in Car package returns unexpected symbol when recoding strings

I have run into a recurring issue when using the car package recode function. If I recreate a publicly used example (http://susanejohnston.wordpress.com/2012/07/18/find-and-replace-in-r-part-1-recode-in-the-library-car/) and do: y <-…
MattT
  • 99
  • 4
2
votes
2 answers

Recoding single variable spread across several in R

I am working with survey data that has a question about race. Each race category is its own variable. Here is what I want to do: Create a new variable, p.race. Assign p.race the value of one of the eight variables for race/ethnicity…
oatmilkyway
  • 429
  • 1
  • 6
  • 17
2
votes
2 answers

Recode categorical variable to binary (0/1)

Could someone help me regarding the use of ifelse. I have a data.frame (dat) with a categorical variable/factor called Q1 (dat$Q1). dat$Q1 was coded as 1,2,3 or 4. I need to create a new column data$new1 based on the following rule: if dat$Q1 == 3…
user2284663
  • 21
  • 1
  • 2
1
vote
1 answer

How to recode values in a column in R?

I have the following data, where I have calculated the tercile for each value in x: dc <- data.frame(x = c(1, 2, 5, 6, 8, 9)) dc$tercile <- fabricatr::split_quantile(dc$x, 3) x tercile 1 1 2 1 5 2 6 2 8 3 9 3 I…
Cloft X
  • 141
  • 7
1
vote
2 answers

SPSS: How to access values of variables, where the names of the variables I want are the values of another variable

In SPSS, I have a variable, CumulLast, which takes on values between 1 and 20. I have another family of variables, of the form Status.X, where X takes on values between 1 and 20 (e.g. Status.1, Status.2, Status.3, are all variables in my dataset).…
theChemist
  • 21
  • 3
1
vote
3 answers

Is there a Python code in SPSS to RECODE a specific value in all numeric questions?

I am working in SPSS and I need to create syntax to recode all numeric variables but only in case of a specific value of another value. For all numeric variables I need to recode the value 50 to missing only in case that the variable status=0. I…
La180923
  • 11
  • 1
1
vote
3 answers

How to make all responses in a column into their own unique column in R

I currently have a dataset in R that is in long format and I'm trying to make it wide with a couple of specifications. So my dataset has a respondent ID and their gender along with one other column (let's say "fruits") that I'm interested in. id <-…
user21027866
  • 129
  • 5
1
vote
3 answers

Renaming columns systematically

Consider the two dataframe df1, df2 that have different column names. I need to systematically change the column naming scheme to obtain the same as in df_target df1 <- data.frame( a = 0, b = 0 ) df2 <- data.frame( A = 0, B = 0 ) df_target…
1
vote
2 answers

Using vector for recoding variables in a dataframe

In a recent project, I have quite a big data frame. And I'd like to reprogram certain variables using a vector that I defined earlier. I know there are many other ways to recode the data, but I was wondering if I could use the vector because it…
Linus
  • 41
  • 5
1
vote
1 answer

How to change the value in specific rows based on a given condition in R?

I hope I can explain this properly but essentially, I am trying to organize some data that I have that is censored. Say, for example I have people who are still alive ("."), people who died (1), people who stopped responding to the study (0). I…
user21027866
  • 129
  • 5