Questions tagged [mutate]

426 questions
0
votes
1 answer

Trying to make a combination analysis but during the mutation the 1's are changed to 0's

I am trying to make a combination analysis that shows the results in a plot. I have a data frame with 9 columns and each column consists of different percentages or NA's if a value was not present in the sample. The example code I have used for this…
0
votes
0 answers

Use a function to create variables with mutate in dplyr

I have the following code library(dplyr) p <- data.frame(a = rep(0:2, times = 5)) %>% mutate(a1 = a == 1,a2 = a == 2) I want to put the expressions in mutatein a function (or a list, I do not really care) so that I define them before running…
0
votes
3 answers

Creating new column based on condition using column header: R

I would like to create another column category based whether a non-0 integer exists depending on the column header. Specifically, if all non-0 integers are in headers containing "rural", then the value in category would be "rural". If all non-0…
ltong
  • 501
  • 1
  • 8
0
votes
0 answers

Bulding a pyramid plot with percentage

I'm trying to built a pyramid plot in R. Starting from a dataset with only two variable (Gender and Age), i have been able to modifying it including three variable (Sex, Age group of five years, and Population; the latter referring to the absolute…
SBell
  • 1
  • 1
0
votes
0 answers

SWR mutate() function in NEXTJS not fetching new data from endpoint in production environment

In a NEWXTJS project, I'm using the SWR library to fetch an array of objects from a MongoDB database. The objects in the array are rendered in a table that is editable, meaning the user can modify a cell, and then its value is updated in the MongoDB…
0
votes
1 answer

Mutate does not retrieve the new data when it is executed after a modification of that data

I am working on NEXTjs with a frontend component that renders a table with the Estados component, whose data is obtained by calling the endpoint api/estados/administrativos/lista in the backend. In the table, it is possible to make changes and these…
0
votes
1 answer

How to change rownames with same pattern of names

Let's suppose I would like to change the names of rows in dataset, without varying the different characters mtcars %>% rownames_to_column(., var = 'Car') For example: where there is 'MERC' is wanted to be replaced with 'CERM' where 'MAZDA' is…
12666727b9
  • 1,133
  • 1
  • 8
  • 22
0
votes
1 answer

R data frame dplyr separate_rows function on specific condition

I have a data frame in long format, and I would like to separate the name column in separate rows using the delimiter comma, by the grade only equals to 12 and leave the rest. df: class grade name english 12 peter,leo english 10 …
Peter Chung
  • 1,010
  • 1
  • 13
  • 31
0
votes
1 answer

R states column doesn't exist, but I can clearly see it. Returns Error in 'select()'

I am in the beginning of learning how to use R, and I am assuming this is an issue with how I am formatting my code but I have tried every way I have looked up and know how. When looking at my spotify dataset, I wanted to mutate a column, creating…
Javad
  • 1
0
votes
2 answers

Replace value on specific column if condition is met

I have a wide df with columns representing the months of many given years and the changes of colour in each month: df <- data.frame(id = as.integer(c(123,124,125,126)), change = as.integer(c(0,1,0,1)), change_date =…
Nao
  • 333
  • 2
  • 11
0
votes
1 answer

I want the 10 week weight to be higher than the 6 week weight, and the 40 week weight to be higher than the 10 week weight, etc

According to my follow-up data, I want the 10 week weight to be higher than the 6 week weight, and the 14 week weight to be higher than the 10 week weight, etc. here you can see data I am trying this code: wght_data %>% mutate( wght_correct =…
0
votes
2 answers

How to carry lag values and sum with another attribute using R?

Required library library(tidyverse) library(lubridate) Create data df <- data.frame(AreaID = c('1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1','2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2'), Period =…
0
votes
2 answers

Trying to de-normalize the data with dlpyr

I have a relatively simple problem that is driving me crazy. means <- tibble( Sepal.Length = 5.84, Sepal.Width = 3.06, Petal.Length = 3.76, Petal.Width = 1.20 ) sds <- tibble( Sepal.Length = 0.828, Sepal.Width = 0.436, Petal.Length =…
user23438
  • 445
  • 3
  • 11
0
votes
0 answers

How to troubleshoot mutate function error

I have a data frame of Flickr photos with geo information (lat and long). The photos are dust storm photos and I’m trying to use these data to study the occurrence of duststorms in the US. With the long and lat info, I’m trying to determine the…
Festus
  • 1
  • 1
0
votes
1 answer

Subjecting multiple dependent variables to multiple models, to produce a dataframe of list columns

I've got a long hand way of applying each of a set of models to nested data, while giving each list-column output a sensible name in the tibble. I have a lot of models though, and want to have a more slick, vectorised way of doing this rather than…