Hi everyone, I'm really new to R so I apologize if the answer to this is obvious.
I was trying to change instances of "NA" from the "Country" column of my data to the country that matches the city that the data is located in. It seemed to work, however, it changed all other data under "Country" to "1", and doesn't seem to have replaced the other "NA" when I tried to do the same for other missing country data that had a value for "City". Here's the code I used:
Apartify_GroupA_new <- Apartify_GroupA_new %>%
mutate(Country = ifelse(is.na(Country) & Apartify_GroupA_new$City == "Beijing",
"China",
Country))
diagnose(Apartify_GroupA_new)
Here is a screenshot of what happened to my data:
Here is another example where the "if else" function seems to have partially worked:
Apartify_GroupA_new <- Apartify_GroupA_new %>%
mutate(Bedrooms = ifelse(is.na(Bedrooms) & Apartify_GroupA_new$Beds == "1",
"1",
Bedrooms),
ifelse(is.na(Bedrooms) & Apartify_GroupA_new$Beds == "2",
"2",
Bedrooms),
ifelse(is.na(Bedrooms) & Apartify_GroupA_new$Beds == "4",
"4",
Bedrooms))
diagnose(Apartify_GroupA_new)
I really appreciate any help!