Creating a data frame in R
I have created a dataframe in r called "test". When I try to add a column it throws me an error. Below is the code I am using to create the column:
test$survived[test$sex == "male"] <- 1
Mistake:
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 just started using R. Thanks a lot for your help.
0
source to share
1 answer