Questions tagged [mutate]
426 questions
-1
votes
1 answer
How can I calculate a death/cases rate variable in Python similar to mutate() in R?
data1 = pd.read_csv("current-data-on-the-geographic-distribution-of-covid-19-cases-worldwide.csv")
data1.head()
The output:
daterep day month year cases deaths countriesandterritories geoid countryterritorycode popdata2018…

nur
- 1
-1
votes
1 answer
Improving code - create new column using R which counts distinct entries in one column of a data set filtered by another column
I have some working code (below) which, for the second column it creates it: creates a new data frame, filtering the original data frame by a specific column; counts distinct entries of another column for this filtered data frame; left joins this…

Dan
- 1
- 2
-1
votes
2 answers
How replace special character string in data frame ? R
I have the following data frame called result.
MANUAL.ID
AUTO.ID
loc
NA
PYPPYP
L2
PIPpip
NA
L1
Barbar
NA
L5
NA
Pippip
L3
NA
Pippip,BerBar
L3
I try to replace all the different forms of a same tag by the right one. For example…

lobarth
- 43
- 6
-1
votes
2 answers
Using an ifelse in mutate when summarizing
I have a dataframe with one date column and several columns with values (measured concentrations). I am mutating the dataframe and summarizing to years with averages of the values. This works fine:
library(dplyr)
df <-…

Martin Liungman
- 37
- 5
-1
votes
1 answer
R mutate produces error 'Must be size 1, not 10'
Here is my df
Airline
Destination
delayed
ontime
Total_Arrivals
Alaska
Los Angelos
62
497
559
Alaska
Phoenix
12
221
233
Alaska
San Diego
20
212
232
Alaska
San Francisco
102
503
605
Alaska
Seatlle
305
1841
2146
AM West
Los…

g.senorsenor
- 37
- 8
-1
votes
2 answers
Convert temperature data from Kelvin to Celsius in multiple columns
I have a dataset with multiple columns of temperature data in Kelvin. I want to convert it to celsius.
Sr. StationID MaxTemp MinTemp MeanTemp Prec
1 5320 280 270 275 1.2
I am using this code which helps to…

Sana
- 65
- 6
-1
votes
1 answer
Why does my mutate function only work for single digit values
I want to use the age variable in my data to create an 'age category' variable with different age brackets. This is the code I ran
New_Data <- New_Data %>% mutate(Age_category = case_when(New_Data$Age <1 ~ "<1",
New_Data$Age >=1 &…
-1
votes
1 answer
Adding and calculating new variables as rows in R-studio
I'm a beginner in R-studio. I have a list in long format with collected data variables regarding 312 companies. From this data I want to calculate new variables and add them as rows, not columns. For example total debt / total assets for all…

Antoineverdict
- 1
- 1
-1
votes
1 answer
How can i create a variable in R that is dependent of two other variables, and must have a certain value?
db %>%
mutate(esc=ifelse((fn<100) | ((fn>100 & tt < 20) | (fn <300 & tt < 20)), "Yes", "No")
In my database I want to make a variable 'esc', which is dependent of the values of fn and tt. I want the esc to be Yes or No, and it should be yes in…
-1
votes
1 answer
Creating a new variable by decades using mutate()
I'm new at R and Stackoverflow, first hi, nice to met you all!
I've been trying for a while to fulfill some work but I can't, don't know if some of you could help me at this point anything is more than accepted. I tried but I keep getting nothing,…

AB3
- 3
- 1
-1
votes
2 answers
How to capitalize the first letter in a list of columns?
Here is my dataframe:
col1 <- c("hello my name is", "Nice to meet you", "how are you")
col2 <- c("dog", "Cats", "Frogs are cool")
col3 <- c("Pause", "breathe in and out", "what are you talking about")
df <- data.frame(col1, col2, col3)
I want to…

hy9fesh
- 589
- 2
- 15
-1
votes
1 answer
How can I create a new column in R with aggregated values from another column
I would like to create a column with aggregated values from the column country
To an aggregated/classified column of subregions. For example,

Costa Wesele
- 1
- 1
-1
votes
1 answer
R combine rows with single column entry into new row
How would I combine any row with a single column entry into a single combined input in a new column? e.g. when column A has value, but B-C are empty, I would like to merge the row entries into a single input in column D.
original file is a txt file…

ctk1100
- 13
- 4
-1
votes
2 answers
Count multiple columns in a data frame in one output table
I have some survey data and I want to get a summary count of multiple columns.
So far I have worked out how to calculate each one individually and create a % column:
help_bk <- likemind %>%
count((help_book_1), name = "count") %>%
…

Ellie
- 1
-2
votes
0 answers
Remove characters after the last occurrence
I have a string that looks like:
exampleList <- c("CO-0891-VI05-T1-1", "CO-0891-VI05-T1-1-166", "CO-0891-VI05-T1-2", "CO-0891-VI05-T1-2-177", "AI-0022-FR07A-T1-1", "AI-0022-FR07A-T1-1-10")
I wish to remove everything after the last underscore (-)…

fdpr
- 1
- 1