Questions tagged [mutated]
77 questions
1
vote
1 answer
Summation over multiple rows based on a condition in R
I have a dataset like the following
name
city
number
A
M
2
A
N
3
A
O
5
A
P
7
B
M
7
B
N
8
B
0
9
B
P
2
For each of of the name category, I want to sum the number of M and N value and put it in a new variable. The same goes…

Abdullah Al Mamun
- 65
- 7
1
vote
2 answers
How do you modify numerical values from a column when using tidyverse pivot_longer (ie. multiplied by 10)
I need to plot the following with B variable values multiplied by 10, in order to be adjusted to the secondary axis. How do you do this in tidyverse? I am using mutate within the %>% but does not work
data<- data.frame(
Date=(1:13),
…

Ecg
- 908
- 1
- 10
- 28
1
vote
1 answer
Repeat row and mutate multiple observations on conditional statement
I'm trying write a conditional statement that duplicates the row where df$food=1. Then changes the value "df$weight" of initial row to the value of df$prior_w and not the duplicate. Also i need to change the df$food value to 0 on the duplicate and…

Em Manuel
- 93
- 6
1
vote
1 answer
Mutate across, if: if column name occurs in first column, replace by value from different dataframe with same name
I have two dataframes: one in which I would like to replace values (df_1), the other one from which I would like to obtain the values for replacement (df_2). Please consider the example data below:
Data
df_1 <- data.frame(
var=c("xAp", "xBp",…

samarehuls
- 13
- 3
1
vote
0 answers
Losing all variable labels when mutating a column
I uploaded an .sav file using haven.
df <- read_sav("file.sav", user_na = FALSE)
This makes sure that all the metadata including the labels are imported into r.
However, after running all my code (mutations etc.), I notice that all variables that…

Victor Nielsen
- 443
- 2
- 14
1
vote
0 answers
Error: Problem with `mutate()` column `nested.col`. i `nested.col = purrr::map(...)`. x no applicable method for 'tk_make_future_timeseries'
I tried to execute the code below and I'm getting error message
Here is the code:
full_data_tbl <- merger %>%
select(outcome, date.y, crime_numbers, sentiment) %>%
# Apply Group-wise Time Series Manipulations
group_by(outcome) %>%
…

Oladosu Oladimeji
- 19
- 3
1
vote
1 answer
How do you apply a function that has multiple inputs across multiple columns?
I have a function that takes in two arguments (columns). The function changes the value of one column (x) based on what the value in another column is (y).
fun <- function(x, y) {
x = coalesce(case_when(y %in% c("hello", "hi") ~ '1',
y…

Victor Nielsen
- 443
- 2
- 14
1
vote
2 answers
How to use a match function with a mutate function?
I'm trying to embed a match (or equivalent --- I just migrated from Excel where there is liberal use of Match) function inside a mutate(). Suppose we start with a data frame df1 that looks like this, generated by the code below it:
ID Status
1 1 …

Curious Jorge - user9788072
- 2,548
- 1
- 9
- 22
1
vote
3 answers
Turning to variables into one based on logical criteria
I have this dataframe that consists of three variables: id, wwb and ub_bene
id wwb ub_bene
1 800009 0 0
2 800009 0 1
3 800009 1 0
4 800009 1 0
5 800009 0 0
…

RH1994
- 37
- 3
1
vote
2 answers
R: Mutate across multiple variables with quantcut
I'd like to transform multiple variables into a discrete form using quantcut.
library(gtools)
library(dplyr)
quantcut(df$var3, q=4, na.rm = TRUE)
Works.
Now I'd like to apply this formula to multiple variables. What I have is something like…

PierreRoubaix
- 167
- 1
- 1
- 7
1
vote
2 answers
Creating a new column with conditions in addition to the row value of the new column
Any ideas on how to create a new column B using the values of column A,
while using the value of the row above of the new created colum B?
The value of B should be corresponding to:
A0 = value of the row above.
A1 = 1.
A2 = value of the row above +…

Gebruiker10
- 13
- 3
1
vote
1 answer
How mutate data in method computed?
I'm on Vue 3. I have an onclick method which is supposed to modify the value of my props which is a boolean, I have tried several ways, I manage to enter the computed method, but the value of my props does not change
I register my data
data() {
…

Péah
- 131
- 1
- 3
- 11
1
vote
1 answer
Mutate variable if certain columns contain string in R
I have been struggling for hours with this dataset. I have searched for hours and tried many things, but I failed (I am a novice in R). So I really hope you guys can help me.
I have this dataset:
df <- data.frame(ID = c(1,2,3,4,5), a.1 =…

R90
- 13
- 4
1
vote
2 answers
Changing key name in OrderedDict in a loop cause RuntimeError: OrderedDict mutated during iteration
Consider the following problem, I have an OrderedDict, and only want to change the name of the keys. We can do it line by line with the following command:
od[new_key] = od.pop(old_key)
However, if I try to do it in a loop I get a RuntimeError:…

jmamath
- 190
- 2
- 13
1
vote
2 answers
R dplyr basic percentage
I just can't seem to figure out this basic percentage by totals
Here is my simple data.frame
A=data.frame(sex=c('f', 'f', 'm'))
library(dplyr)
A%>%
mutate(sex_totals=count(sex=='f')/count(a) # ????
Basically a new column should say
sex …

Peter Hui
- 119
- 2
- 9