Questions tagged [mutate]
426 questions
0
votes
1 answer
How do I resolve dplyr::mutate error "Unexpected '='"?
I'm having issues with dplyr::mutate(). It works fine when I use it regularly, but it throws an error when I use it in a function and then try to define that function.
My goal is to create a function that lets you calculate the quartiles of a…

berntgl
- 5
- 3
0
votes
5 answers
Converting wide table to long programmatically
My example dataset is wide and contains these values:
olddata_wide <- read.table(header=TRUE, text='
subject sex a b c a1 b1 c1 a2 b2 c2
1 M 7.9 12.3 10.7 7.5 12.1 10.3 8.1 12.5 10.9
2 F 6.3 10.6 11.1 6.0 …

Nneka
- 1,764
- 2
- 15
- 39
0
votes
1 answer
Mutate with multiple conditionals
I'm trying to create a mutate a new column called category with each of the product name classifications. And also I would like to mutate a column wherein caffeine_mg>0 has caffeine, but caffeine_mg=0 has no caffeine.
sbucks <-…

Clairine
- 23
- 5
0
votes
2 answers
Create new column using grouped column and numeric column from different data frame - R
I have two data frames (regionSum and areaSum) shown below.
Area
Region
void_pts
0
010
0.125
1
110
1.566
1
111
1.350
3
310
2.004
3
312
1.652
Area
void_pts
0
0.455
1
1.436
2
1.396
3
1.981
I'm trying to create a…

JanLawlee
- 31
- 5
0
votes
2 answers
How to add new column conditional to NA in one column of data
I have been trying to make a new column in data set, lets say jk. I want in this column the values from column a6 if value in column a6b is NA, otherwise I need the value from column a6b. I have written the following line of code for this…

Ali Inayat
- 41
- 5
0
votes
1 answer
R tidyverse: function(df, colName) to apply some dplyr::mutate transformation to given col
# 0. Some data frame
df <- tibble::tibble( A = c('12 Z 34', 'N56\t709') )
df
# 1. Desired result (with pipes and mutate())
df %>%
# Removes all of the white space characters
dplyr::mutate(A = gsub("\\s", "", A))
# 2. !!! Define a function…

Didier
- 15
- 2
0
votes
0 answers
grouping_by_condition_and_mutate in R
I need your help:
The general idea is to create 1 new column,
Group the data by a column (DEP) then count the number of Total lines per group using the column (id).
Then filter the data with another column (dely): (only dely>=60) and count the…

Sony
- 19
- 3
0
votes
0 answers
R: Retrieve the date when a sum is reached
and thanks in advance!!
I have a climatic dataframe with julian days (DOY), also a start value (TR_EM). For each start date there is a temperature sum (DC55) to be reached by adding the value of each daily value (TMED). I want to iterate over each…

Mariana Jardon
- 1
- 1
0
votes
1 answer
Determine subgroups with mutate, a for loop and ifelse
I have a middle sized dataset (> 20 million observations) and I want to use a shiny app to filter the desired information about specific subgroups in the dataset.
Right now, I want to assign for each observation a subgroup number (1 = subgroup1, 2…

SG_95
- 13
- 4
0
votes
2 answers
Fill in NAs using mutate
I have the following data frame:
library(tidyverse)
v1 = c(1 , NA, 3, 5, NA, NA, 2, 12, NA, 5, NA, 0, 1, 2, 6, 8)
alt = rnorm(length(v1), 0, 1)
tb = tibble(v1, alt)
print(tb)
A tibble: 16 × 2
v1 alt
1 1 0.495
2 …

Alien
- 116
- 8
0
votes
2 answers
Creating a new data frame based on the range of numeric values of a specific column in R
I am working with a dataset that looks like this...
group col_2 col_3 col_4
A TT 12 21
A RR 11 21
A LL 13 22
A QQ 11 24
A PP 14 25
A RR 15 26
A TT …

Ajrhjnd
- 330
- 1
- 9
0
votes
0 answers
Error caused in mutate function (mask$eval_all_mutate())
Don't know if I'm getting the syntax wrong or not. I've already downloaded the dplyr package and tidyverse package.
The code below is what I wrote:
Watch_time_hour <- mutate(twitchdata,Watch_time_hours == Watchtime(Minutes)/60)
Below is the error…

Sakouna
- 1
- 1
0
votes
2 answers
Loop through dataframe to create new variable
I am trying to come up with a way to loop through a data frame and recognise points shared between 2 columns and work iteratively to assign a unique factor to these. Specifically, I have a data frame indicating points along a river and which points…

James White
- 705
- 2
- 7
- 20
0
votes
4 answers
Mutate, case_when, paste in R
apple
banana
orange
fruits_name
1
0
1
apple orange
1
0
0
apple
1
0
1
apple orange
1
1
1
apple banana orange
I want to create and mutate the column "frutis_name" if the rest of the columns get 1.
As an example, apple and orange got…

Glen P Janson
- 13
- 2
0
votes
1 answer
The fileInput() cause error in process with mutate() in a shiny app
I have a dataset in a csv file.I also display it here. When I run it without uploading it via fileInput() it is processed normally. If I load it via fileInput() I get: Warning: Error in mutate: object 'prοcess' not…

firmo23
- 7,490
- 2
- 38
- 114