Create a data frame from an existing data frame with some condition.
I am looking for an easy way to frame NA's in my dataset:
I have to frame different age mean for each gender. Unfortunately I see no possibility to do it without creating new column and then putting in again into the dataset. Even I tried below codes but it is not working:
mans <- train[train[, "Gender"]=="male", ]
womens <- train[train[, "Gender"]=="female", ]
mf <- mean(train$Age, na.rm = TRUE)
mm <- mean(train$Age, na.rm = TRUE)
train[train$Age == NA & train$Gender == "male", "Age"] <- mf
- Error in '[<-.data.frame
(tmp`, mans$Age == NA & mans$Sex == "male",
- missing values are not allowed in subscripted assignments of data frames
Thanks in advance.