I was playing around with the titanic dataset and was applying the basics which I had learned recently and faced the below error, please find the scenario below
titanic <- fread("titanic3.csv")
Next I just tried to check for empty string in a particular column
titanic[embarked==""]
I get 3 rows as having an empty string in this column.
Next I found that there were missing values (NA) for age so I took an average and substituted the missing age values according to the sex,
titanic <- titanic %>% group_by(sex) %>% mutate(age=if_else(is.na(age), mean(age, na.rm = TRUE), age))
After this I noticed in the View(titanic) that there were empty strings in the 'boat' column of the data frame as well.
So, just like the first query of 'embarked' column I tried to find the empty strings in the 'boat' column using the following query so that I can replace it with NA but I get the error message as follows.
titanic[boat=='']
Error in `[.data.frame`(titanic, boat == "") : object 'boat' not found
I noticed that I am getting this error message only after I had refreshed the 'age' column in the titanic dataframe with the mean age values. But I run this same code before refreshing the dataframe I do not get this error message.
I am not able to understand why I am getting this error or mistake that I am doing!