Skip to main content
Filter by
Sorted by
Tagged with
1 vote
1 answer
76 views

Main Problem Suppose I have the following Pandas DataFrame (code shared below): Suppose further that I want to create a new column called NewVal according to the following rule (process often called &...
Felipe D.'s user avatar
  • 1,301
1 vote
1 answer
39 views

I have a series of variables of the form NAMEx to which I want to apply the same recoding scheme. (In stata I would do this using "recode NAME* (recode specifications)" My inclination was to ...
Bert Kritzer's user avatar
0 votes
1 answer
63 views

I´m a uni student who recently started learning to use statistical analysis code with R. Unfortunately I´m not the best yet, and my prof. isn´t really willing to help. Which is why I´m hoping that ...
Alina Dzaferovic's user avatar
0 votes
1 answer
56 views

I just have what seems like a simple list of numbers, that I'd like to recategorize. The numbers are: 1, 2, 3, 4, 5, 6, 7 I'd like to recode such that 1,2 = 1, 5=2 and 3,4,6,7 = 3. I've tried the ...
Archie34's user avatar
0 votes
1 answer
28 views

I am working my way through the data engineer salary data set on Kaggle. The salary_currency column has the following value counts. salary_currency USD 13695 GBP 558 EUR 406 INR 51 CAD 49 ....
Englishman Bob's user avatar
2 votes
1 answer
102 views

I have the following dataframe in: a 1 3 2 2 3 Nan 4 3 5 Nan I need to recode this column so it looks like this: df_miss_a 1 0 2 0 3 1 4 0 5 1 I've tried: df_miss_a = np.where(df['a'] == 'Nan', ...
Englishman Bob's user avatar
4 votes
2 answers
641 views

In the dplyr package, recode() has been superseded in favor of case_match(). Is there a way to use labels stored in, for example, char array to recode values using case_match()? For example, with ...
teppo's user avatar
  • 716
0 votes
1 answer
138 views

This is my code:* data %>% mutate(r_stemster_3 = recode(stemster_3, `1` = 7, `2` = 6, `3` = 5, ...
Shay's user avatar
  • 1
1 vote
3 answers
521 views

I have a column with almost a 100 string categories that I would like to group/recode into fewer categories. I am trying to figure out the easiest way to do so, I thought about turning it into factor ...
Victor Shin's user avatar
2 votes
2 answers
85 views

I'm creating a new variable that uses conditional "ifelse" statements based on the values of several source variables. The source variables are a survey question that changed names over ...
David Crow's user avatar
1 vote
3 answers
220 views

I have columns with different ratings from 1-5 with descriptors next to the number. The format is "number dash descriptor", ex. "1 - very happy" or "5 - hungry". I want ...
Sophia L's user avatar
1 vote
2 answers
86 views

Here is my dataframe: dt <- data.frame( session_id = c("17472631", "17472632", "17472633", "17472635", "17472636", "17472638"), ...
Yahel's user avatar
  • 15
0 votes
1 answer
55 views

I'd like to count the numbers of TRUE of a variable for each category of another variable. Or more precisely the average number of TRUE for each category. Afterward, I'd like to create a vector. The ...
Linus's user avatar
  • 353
0 votes
1 answer
52 views

This is my dataframe df <- data.frame(Var=c("Var1", "Var1","Var1","Var1","Var1","Var1"), measure=c("M1","M1&...
Hazem's user avatar
  • 57
0 votes
4 answers
93 views

I have a df containing values for several ids and multiple variables. There is a reserve code, "no", the same code for all variables, that I would like to recode to different values based on ...
Gabrielle S's user avatar
0 votes
1 answer
55 views

I have data frame with 18 columns. Columns 2 to 13 include numeric values such as 0, 1, 2, 4 ... I want to recode them based on range into three categories: if columns 2:13 are 0 -> 0 if columns 2:...
abenol's user avatar
  • 91
0 votes
3 answers
39 views

I currently have a dataframe in R with a variable for names ("Name") and one that notes whether an individual is female ("Female") (1, NA). A given individual likely has multiple ...
user21027866's user avatar
0 votes
1 answer
63 views

I am using the replace command to recode a string variable countrycode to a numeric variable ccode. But the replace command has no effect. Stata gives no error messages, bt just says "0 changes ...
DBart2022's user avatar
0 votes
2 answers
108 views

I perform lots of data transformation and one of them makes me some troubles. Let's assume that I have a dataset with variavles from v1 to v100, every one with numbers from 1 to 5. I want to recode/...
Maciej B.'s user avatar
  • 393
1 vote
1 answer
64 views

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 ...
Cloft X's user avatar
  • 458
1 vote
2 answers
295 views

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....
theChemist's user avatar
1 vote
2 answers
154 views

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 ...
La180923's user avatar
0 votes
1 answer
86 views

Whereas the direction of main effects can be interpreted from the sign of the estimate, the interpretation of interaction effects often requires plots. This task is facilitated by the R package sjPlot....
Pablo Bernabeu's user avatar
3 votes
2 answers
141 views

I have data from a survey, where several questions are in the format "Do you think that [xxxxxxx]" The possible answers to the questions are in the format "I am certain that [xxxxxxx]&...
nico's user avatar
  • 51.9k
0 votes
2 answers
103 views

I made up this example df to make an example. set.seed(357) # Generate binary variables var1 <- sample(c(0, 1, NA), 200, replace = TRUE, prob = c(0.4, 0.4, 0.2)) var2 <- sample(c(0, 1, NA), 200, ...
esteban's user avatar
  • 112
0 votes
2 answers
124 views

I have a data set that has over 260 columns that have character values that need to be recoded as numerical factors. For example, N=0, Y=1, S=1, O=2, F=99. However, apply this to only some columns, ...
wisamb's user avatar
  • 502
-1 votes
1 answer
172 views

I have a variable in Stata which consists of letters such as A, B, AB, AC, etc. I want to change to numeric, with values numbers instead of letters, such as 1 instead of A. I tried to encode the ...
Suha Ahmed 's user avatar
0 votes
0 answers
50 views

Apologies, pretty new to R and I'm struggling with releveling multiple variables that have a common element/word. What I want to do is mutate all variables that have a common word in the same way. All ...
scroopynoopers's user avatar
0 votes
1 answer
933 views

I'm sure that this answer exists somewhere but I've been trying to get this code to work and I just can't seem to be able to for my purpose. I have 7 different dataframes which each contains an ID, ...
user21027866's user avatar
1 vote
3 answers
128 views

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 (...
user21027866's user avatar
0 votes
1 answer
183 views

I am trying to make the table below show a "Y" if the cell is populated. And if the cell is empty it is recoded as an "N" Below I have provided a image along with the code I am ...
Cole's user avatar
  • 23
1 vote
4 answers
1k views

Let's say I have this data frame. df <- data.frame(record = c("1", "2", "3", "4", "5", "6"), fruit = c("apple",...
BDuff's user avatar
  • 29
2 votes
3 answers
1k views

I want to recode a variable that has values from 1 to 10 (numeric) into a factor variable of 5 values. I'm using the command dplyr::recode, but it is not working. I know how to do it with the cut ...
Renato's user avatar
  • 23
1 vote
3 answers
196 views

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 ...
DuesserBaest's user avatar
  • 3,215
0 votes
1 answer
218 views

I want to create a simplified way of recoding the same variable (the same way) across multiple data frames. For example, right now I'm re-coding an age variable from state datasets FL and GA. I'm ...
Still learning's user avatar
1 vote
2 answers
121 views

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 ...
Linus's user avatar
  • 353
5 votes
2 answers
249 views

I have a dataframe with questionnaire response labels. I always like to make a tibble with item-answer definitions and then use dplyr::recode() to replace all item labels with their corresponding ...
Claudiu Papasteri's user avatar
1 vote
4 answers
150 views

I have a continuous variable. Entries 1-60 need to stay the same. NAs and 0s are coded as a number above 60. I tried using mutate in a few different ways, but none worked. Most of the outcomes were ...
exumablue's user avatar
1 vote
1 answer
62 views

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 (...
user21027866's user avatar
2 votes
3 answers
97 views

I have data in R that looks like this: T1 <- c(0,0,0,0,0) T2 <- c(1,0,0,0,0) T3 <- c(0,1,0,0,0) T4 <- c(1,1,0,NA,1) T5 <- c(0,1,0,NA,0) df <- data.frame(T1,T2,T3,T4,T5) T1 T2 T3 ...
user21027866's user avatar
1 vote
1 answer
63 views

I am trying to create a new set of variables based on observations at 5 different time points. However, there is not an observation for each row at each time point. Assuming it looks something like ...
user21027866's user avatar
1 vote
2 answers
112 views

I have the following data frame df: Index col_a col_b col_c col_d 1 4 c v g j 2 1 x <NA> z s 3 1, 3 k j n y 4 2 q t o i ...
benson23's user avatar
  • 19.6k
0 votes
1 answer
51 views

I feel like this may be a very easy fix but I can't seem to get it to work correctly, I'm sorry. Essentially, I am trying to create a variable that dichotomizes whether 'NA' appears across multiple ...
user21027866's user avatar
1 vote
0 answers
2k views

I am trying to recode multiple columns, using a code that has previously worked: test <- tibble ( a_test = c(7,6,5,4), b_test = c(7,7,5,3), c_test = c(7,3,7,5), d_test = c(7,7,7,7) ) test %...
joh_anna's user avatar
0 votes
1 answer
307 views

I'm trying to recode the values in my column but I keep getting errors. My code looks like this: dataTable1 %>% mutate(income = recode(income, "1" = "Under $20,000", "2&...
12345qwert6y's user avatar
3 votes
2 answers
741 views

I want to create a variable with the number of the day a participant took a survey (first day, second day, thirds day, etc.) The issue is that there are participants that took the survey after ...
MAIMAU's user avatar
  • 41
3 votes
4 answers
2k views

I'm sure this is a really easy fix but I can't seem to find the answer... I am trying to create a column at the end of my dataframe that is a sum of the number of times a specific value (say "1&...
user21027866's user avatar
0 votes
2 answers
544 views

I have a lot of columns in 1 dataframe that identify different timepoints of the same variable. Basically, within my data, if there's no response at timepoint X-1, there will be no response at time ...
user21027866's user avatar
1 vote
1 answer
69 views

I'm new here so apologies if I make a couple mistakes here but essentially, I am trying to recode a lot of columns that have to do with the same content but at different time points. Therefore, I'm ...
user21027866's user avatar
0 votes
1 answer
704 views

I've searched several help-pages and already answered questions but still get an error message when I try to recode multiple columns. Example dataset: test <- tibble ( a_test = c(7,6,5,4), ...
joh_anna's user avatar

1
2 3 4 5
13