I created a data frame in r called "test". When I am trying to add a column it throws me an error. Below is the code i use to create a column:
test$survived[test$sex == "male"] <- 1
Error I get:
Error in $<-.data.frame(*tmp*, "survived", value = numeric(0)) :
replacement has 0 rows, data has 418
I also tried using ifelse but it gives me the same error message. I have just started using R. Would greatly appreciate your help.