Questions tagged [mutate]

mutate is a verb to create a new column in a data frame using dplyr package in R programming language.

When using dplyr for data wrangling, mutate is commonly used to add a new column to a data frame. With a data frame df, mutate(df, a = 3) adds a constant column 3 to the data frame. For more information on related verbs in dplyr and more examples on how to use mutate check the official help page.

Note that as of dplyr version 1.0.0, the scoped helpers (including mutate_if, mutate_at and mutate_all) have been superseded by across() (see the official change-log).

1668 questions
0
votes
0 answers

Why doesn't filter_at work within ifelse?

I'm working with a dataset of family relationships, with a row for each person and columns describing potential relationships (there is a father column, a mother column, a spouse column, etc.). The columns that I am having problems with are those…
Clara R.
  • 1
  • 3
0
votes
1 answer

Calculating days since and days until next event

I had written some code months ago to find the days until the next visit and the days since the last visit to track patient progress and identify missed appointments. This code worked beautifully and gave the correct number of days (I verified a…
regents
  • 365
  • 3
  • 13
0
votes
2 answers

Categorising Time in different slots using R

Working on Time differences and want to create time slots based on different times in my dataframe. For example I do have separate column in my data frame which contains seconds. What I want to do is by checking these seconds whether it is falling…
Sharmi
  • 43
  • 9
0
votes
1 answer

Select a group with dplyr, only for the operation, without saving the selection

I would like to select a part of the data with dplyr to carry out an operation on, but without it saving the selection on which the operation has been carried out. My database looks as follows: country country-year year a b 1 France …
Tom
  • 1,237
  • 8
  • 29
0
votes
1 answer

Using shift with mutate and case_when in dplyr in R: not working as expected

My data shows changes in pupil size. When the value is -1 is means there is a blink. I have written some code to detect blink onsets and offsets but I'm having some issues using shift function. Sample of my…
Docconcoct
  • 1,931
  • 3
  • 23
  • 41
0
votes
1 answer

R dplyr: Conditional Mutate based on Groups

Currently, I am working on the following problem: I am trying to split my dataset in groups and create a new variable that captures the group mean of all opposite cases that do not belong to this group - for a specific time frame. Here is a replica…
0
votes
2 answers

Mutate multiple columns with conditions using dplyr

I have a large dataset for which I want to create 50 new variables where the values are conditional on values in previous columns, and the name of the variables reflect this fact. To make it more intelligible, here is an example: df <- tibble("a" =…
Jo_
  • 59
  • 5
0
votes
1 answer

dplyr: create new column with values from other specified columns

I have a tibble: library(tibble) library(dplyr) ( data <- tibble( a = 1:3, b = 4:6, mycol = c('a', 'b', 'a') ) ) #> # A tibble: 3 x 3 #> a b mycol #> #> 1 1 4 a #> 2 2 5 b #> 3 …
Greg
  • 417
  • 4
  • 13
0
votes
0 answers

Object 'negative" not found error in R - During Sentiment Analysis

I am trying to do Sentiment Analysis in R by extracting the Tweets. Tweets are getting extracted fine. But getting this error when I try to Tokenize the tweets. Error I get is "Error in mutate_impl(.data, dots) : Evaluation error: object…
0
votes
1 answer

Labeling polygons with geom_sf, ggplot

I am attempting to label polygons from a spatial feature data frame using ggplot2. I am trying to replicate the description here under the heading, "Download Some Boundary Data: State/County/HUC" This is my code to try to get the lat and lon values…
mmoore
  • 174
  • 8
0
votes
1 answer

dplyr define a temporary variable in mutate function

I am working with dplyr package of R. Let's say I have a data frame of names and ids df <- data.frame(dID=c(1 ,2 , 1 ), name=c("a","a","b")) and I want to resolve each id from another database and get the information I…
user9224
  • 67
  • 6
0
votes
1 answer

Updating the store using redux actions

I need to update the store of my application using reducer. But I wanted to make it dynamic in a way that I need not to write different actions for updating the store at the same level. Lets say below my store looks like this... const store = {…
0
votes
3 answers

How to mutate a new column with yes or no value if at least one column from col7 to col10 is equal to 4 in r using dplyr?

I have a data as follows: col1 <- c(0.1,0.2,0.0,0.5,0.6) col2 <- c(2,2,4,5,6) col3 <- c(1,4,3,4,5) col4 <- c(2,3,4,4,6) col5 <- c(5,3,3,2,1) data.frame(col1,col2,col3,col4,col5) col1 col2 col3 col4 col5 1 0.1 2 1 2 5 2 …
say.ff
  • 285
  • 3
  • 13
0
votes
1 answer

Function behaving differently in mutate

I have a function that behaves incorrectly when passed through the mutate function from the dplyr package. The function takes a UK postcode and returns a postal area. It works fine with individual post codes or vectors of postcodes. Here is the…
CClarke
  • 161
  • 1
  • 10
0
votes
0 answers

Removing background noise on signal using dplyr & mutate using R

I am trying to remove the background noise from a signal in a dataset. To do this, I must subtract the signal at say 6 hours minus the signal at 0 hours. This signal changes depending on the Sample, Category, and Metal treatment. I realize this…
Marty999
  • 143
  • 1
  • 10
1 2 3
99
100