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

is there a simple way to recode levels of a factor variable so that levels occuring below a given frequency are recoded to "other"

theshold <- c(0.001, 0.5, 0.1) df$a df$b df$c - Recode levels based on level frequency of less than first threshold df$x df$y df$x - Recode levels based on level frequency of less than second threshold df$d df$e df$f - Recode levels based on level…
2
votes
1 answer

Recode a variable within the mids object of the mice library in R

The following dataset is available data <- structure(list(asdas_6month = c(23.1222666868239, 25.4056847196073, 25.9886630231065, NA, 26.9450864282904, 15.1832953552198, 22.1618055512694, NA, 24.1387146612986, 25.598233740795, 22.6844495409994,…
Pashtun
  • 123
  • 7
2
votes
2 answers

How do I generate a new column using a conditional which evaluates values against a vector?

Let's say I have this column. dataframe$column<-c(1, 2, 2, 2, 3, 4, 4, 5, 5, 5, 6, 7, 8, 9, NA, NA, 0) and I got this vector vector<- c(1, 5, 9) I need to create a new column in my data frame that would return 0 when the value in any given row is…
esteban
  • 102
  • 8
2
votes
1 answer

Convert all french accents into HTML character format

I have for example a bunch of HTML pages like this : Table des matières
user1773603
2
votes
1 answer

How to recode a range of values in a variable and coerce it to a factor?

I am looking for a way to (cleanly) recode a variable with a range of values into an ordered factor in R tidyverse way. This is an example of what I have: set.seed(1505) n <- 100 df <- data.frame(id=1:n, education=sample(1:5, n,…
Helena
  • 23
  • 3
2
votes
2 answers

Recode character IDs into numeric IDs

I need to modify an id variable values. Here is how a sample data looks like: df <- data.frame(id = c(11,21,22,"33_AS_A","33_AS_B","33_AS_X", "35_Part1","35_Part2","35_Part4","35_Part7"), Grade= c(3,3,3, 4,4,4,5,5,5,5)) > df …
amisos55
  • 1,913
  • 1
  • 10
  • 21
2
votes
2 answers

recode character to numeric for specific conditions in r

I had an original dataset that looks like this.: > df.1 id score 1 13_B 1 2 13_C 4 3 133_D 5 4 141 2 5 145 3 6 143 4 7 12_B 6 8 12_C 7 9 12_D 9 I needed to do some process that needs all the ids…
amisos55
  • 1,913
  • 1
  • 10
  • 21
2
votes
2 answers

R - Fuzzy find and recode

I am cleaning demographic data that has been submitted by 10+ school districts and the submissions are not standardized/uniform. I would like to find patterns and recode them so that the data is clean and simple. Let's say I have a variable called…
missgwolf
  • 356
  • 1
  • 11
2
votes
5 answers

How can I apply a simple function to multiple columns?

I have the following data frame: df <- data.frame("A" = c("y", "y", "n", "n"), "B" = c("n", NA, "y", "y"), "C" = c("n", "y", "y", "n")) I would like to apply the following code to columns A and B: df$A <- df$A %>% …
Takanashi
  • 37
  • 7
2
votes
1 answer

How can I recode multiple variables with the same mapping at once in R?

I am struggling to find a cleaner way to recode (numeric to numeric) multiple variables at once in a leaner way. Is there an alternative an easier way than this piece of code below? mhomes_min <- mhomes %>% mutate(contrib_private_3rd_party =…
2
votes
1 answer

tidyverse solution for recoding several columnsinto new ones where column name suffixes increase by one

This is only pseudo code, but let's assume I have 22 columns named from Q46x47_1 to Q46x47_22. I now want to apply the following recode logic: if Q46x47_1=0 Q46x47_2=0. if Q46x47_3=0 Q46x47_4=0. if Q46x47_5=0 Q46x47_6=0. if Q46x47_7=0 Q46x47_8=0.…
deschen
  • 10,012
  • 3
  • 27
  • 50
2
votes
1 answer

Recode values based on look up table with dplyr (R)

A relatively trivial question that has been bothering me for a while, but to which I have not yet found an answer - perhaps because I have trouble verbalizing the problem for search engines. Here is a column of a data frame that contains…
MaVe
  • 169
  • 2
  • 8
2
votes
1 answer

Recode a numeric variable with many values including NAs

How to recode a numeric variable with many values including missing values, to have numbers 0:n-1 where n is the number of unique values including NA, in a tidy way? Example: df <- tibble(x = c(1000, 1000, NA, 1001, 1002, 1003, NA, 1003)) Required…
Giora Simchoni
  • 3,487
  • 3
  • 34
  • 72
2
votes
0 answers

Error: Problem with `mutate()` input `relig2`. x unused arguments

I am relatively new to R and currently doing an assignment where I have to run some models. I have some variables that I need to recode, but when running the code I get an error (see R code and error below). I use library(dplyr) to execute the…
Asiya Ahmed
  • 21
  • 1
  • 3
2
votes
0 answers

dyld: lazy symbol binding failed: Symbol not found

I have install recode via homebrew and when I executing the commands the error occurred $ recode TIS620..u8 LOTUS/Supplement/*.txt dyld: lazy symbol binding failed: Symbol not found: _rpl_malloc Referenced from:…