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

Select columns by pattern and replace factor at once

I have a data frame with several columns. Some of the columns have fixed patterns at the beginning for example q1a, q1a_30, q1a_60, q1a_90. I want to call the columns with the same begging pattern and replace their factors. Process I can do it…
Meli
  • 33
  • 6
1
vote
1 answer

Alternative function for recode() that applies for "Date" class objects

track type shortcut player system_played date time_period time record_duration 1 Luigi Racew~ Three ~ No Salam NTSC …
NganKD
  • 71
  • 6
1
vote
3 answers

How to mutate conditionally, while keeping original values intact in dplyr?

I'm working on my first dataset in R, so please forgive if this is a silly question but I have been struggling with it for days now. My data looks something like this: library(tidyverse) tb1 <- tibble(ID = c(1,2,3,4,5), Quest_MF_1_1 =…
Anneke
  • 53
  • 7
1
vote
2 answers

Recoding levels of categorical variable in Stata without ruining data

I have this variable which takes on these values: tab expenditure Q11 | Freq. Percent Cum. --------------------------------+----------------------------------- Afs 2500-5000 | …
Joanna
  • 27
  • 4
1
vote
2 answers

Recode levels of a factor to specific numbers in R

I am trying to recode some psychometric scales for scoring in R. Often the scales will come in the form of a factor that will need to be converted to a number to calculate the score; for example ("Never" = 0, "Sometimes" = 1, "Always" = 2). I am…
Aaron
  • 15
  • 4
1
vote
3 answers

Is there any way to replace values of df in R using sum of rows?

I have an issue which looks like easy to solve, but I'm stuck. I have a dataframe composed of columns (significant pathways retrieved from GSEA) and rows (entrez gene ids). In this data frame there are 1 if a gene is present in a pathway or 0 when…
necrosnake
  • 41
  • 6
1
vote
3 answers

function declaring column names

I have a function written in R. Basically I am applying a function to data frame column based on its values. Can anyone help me?................................. asd <- data.frame(a = c("High Impact", "High Impact", "Medium Impact"), …
user11740857
  • 502
  • 3
  • 10
1
vote
1 answer

Converting some values in a variable from minutes to hours while keeping the rest the same

In a questionnaire I asked people for how long they ususally sleep a night. Now replys were supposed to be in a h.mm format but were accidently set to h only. This is why some participants gave their sleep duration in minutes or simply wrote "830"…
Ninke
  • 247
  • 1
  • 12
1
vote
0 answers

Recode values by function()

I have one quest (pretty short). I shoud recode variebles with function(). I tried some, but it doesn't work still. It should work with this: recode.numeric(x = c(5, 3, -5, 4, 3, 97),lb = 0, ub = 10) And turn this call to c(5, 3, NA, 4, 3, NA) My…
Anys
  • 21
  • 7
1
vote
5 answers

Replace values in one vector with values from other vector(s)

I have a dataframe something this: id <- c(1, 2, 3, 4, 5, 6, 7) var1 <- c(1, NA, 2, NA, 1, 1, 2) var2 <- c(1, 1, 2, 2, NA, 2, 2) However, how do I manage to create a new vector, which takes the values from var2, and replace it with NAs in var1 and…
R9413
  • 53
  • 4
1
vote
7 answers

Recoding several variables in for loop

I am working with some survey data where some of the responses have been coded inconsistently. For instance' "I don't know" may be coded as 4, 5, 97, or 777. I want to standardize all of these responses as "77" as efficiently as possible. I would…
Quinterpret
  • 133
  • 6
1
vote
1 answer

Recode using three dataframes in python

I have three separate DataFrames: import pandas as pd df1 = pd.DataFrame({ "Log": ["1114","1115","1116","1117","1118","1119","120"], "Gender": ["2","2","2","1","1","1","2"] }) df2 = pd.DataFrame({"NAME": ["Gender"],"SOURCE":…
t.neil89
  • 13
  • 4
1
vote
2 answers

Apply recode pattern to many columns

I have a dataframe with the following columns: Name, Year, V1, V2, V5, V10, V12... This Table contains about 40 Vx Variables. The values of these variables can be 1-5. I want to recode them so 1-3 = 0 and 4-5 = 1 I know how to replace data for one…
ruedi
  • 5,365
  • 15
  • 52
  • 88
1
vote
2 answers

Creating New Variables in R- issues with missing data

I keep encountering a problem in my R code with generating a new variable based upon another variable. Every participant has entries for multiple different variables. Not all of these variables matter for each participant. I have a dummy coded…
1
vote
4 answers

Vectorized recoding of rows in R data frame based on value in another column

I have a dataset of binary responses (0, 1) to a number of questions like below. Each row indicates an individual and each column is a response to a question. "completed" indicates how many questions were reached. For example, if completed = 2 only…
Kate N
  • 423
  • 3
  • 14