I am using R dplyr::mutate
to conditionally change a data frame variable value. The df_forecast is derived from a CSV file input using stringsAsFactors=F
.
The variable attribute Acres
is a string, later to be cast to a factor, which contains '10-Jan' (1/10/2019). I am attempting to mutate the value of Acres '10-Jan' to '1 to 10', but the mutate is not making any changes inside the data frame.
This same failure update issue is on the second code example for 'YearBuilt' below: trying to clean / change '15' to '2015'.
I am using R Studio (3.5).
dplyr effort explored:
I have tried equal assignment
'mutate(df_forecast$Acres = case_when...' which resulted in this error msg: 'Error: unexpected '=' in: "df_forecast %>% mutate(df_forecast$Acres ="'
I tried '==' to 'mutate(df_forecast$Acres == case_when...' which resulted with 'data.frame': 22745 obs. of 19 variables
df_forecast <- data.frame(forecast)
df_forecast %>%
mutate(df_forecast$Acres == case_when(df_forecast$Acres == "10-Jan" ~ "1 to 10")) %>%
##
str(df_forecast)
df_forecast %>%
mutate(df_forecast$YearBuilt == case_when(df_forecast$YearBuilt == "15" ~ "2015")) %>%
##
str(df_forecast)
=
beforecase_when
as it is an assignment operatormutate(df_forecast$Acres = case_when......
. Also you would also need aTRUE
condition. – Ronak Shahdput(head(<YourData>))
. – A. Stamdf_forecast
-data.frame? In your comment to Cettt it didn't look like it – Humpelstielzchen