Suppose I have the following lists, where "names" is a complete list of names (for example, in a class):
names<-as.matrix(c("Paul", "Tyler", "Roberta", "Greg", "Tiffany"))
Suppose I have a secondary list of names that includes only female names:
female_names<-as.matrix(c("Roberta", "Tiffany", "Michelle", "Ashley"))
I am trying to create another "woman" variable that takes the value 1 if the element in the "names" matches one of the "female names" in the second list at the top.
women<-as.matrix(rep(0, 5))
for(i in 1:nrow(names)){
for(j in 1:nrow(female_names)){
if(names[i,1]==female_names[j,1]){women[i]<-1}
}
}
However, when I summarize a new woman with variables, all values are 0, which should not be.
summary(women)
, 1 . ?