Hello, I am trying to make a new column in my data using mutate and if_else functions.
This is the code I am using:
BWt <- BW %>%
mutate( PMday = if_else (Time_Weight = 2, true = Study_Day, false = 0))
And I obtaining this error message:
Error: Problem with mutate()
column PMday
.
i PMday = if_else(Time_Weight = 2, true = Study_Day, false = 0)
.
x unused argument (Time_Weight = 2)
Run rlang::last_error()
to see where the error occurred.
The structure of the data is the following:
str(BW) # Check data structure
'data.frame': 144 obs. of 7 variables:
Date : chr "31-Mar-21" "31-Mar-21" "31-Mar-21" "31-Mar-21" ...
Study_Day : int 0 0 0 0 0 0 0 0 0 0 ...
Time_Weight : int 1 1 1 1 2 1 2 1 1 2 ...
Pen : int 1 1 1 5 5 1 1 1 5 5 ...
Animal_ID : int 2 8 3 4 4 7 7 6 9 9 ...
Treatment_Group: chr "A" "B" "E" "C" ...
Weight_kg : num 16.2 14.1 17.7 15 14.4 17.3 16.4 18.1 17.1 16.8 ...
I also have tried ifelse() but I get a similar error message:
Error: Problem with mutate()
column PMday
.
i PMday = ifelse(Time_Weight = 2, true = Study_Day, false = 0)
.
x unused arguments (Time_Weight = 2, true = Study_Day, false = 0)
Run rlang::last_error()
to see where the error occurred.
Hope this information helps to get some advice. Let me know if you need to know anything else.
Many thanks!
Beatriz