Sorry if this is a duplicate, but I can’t seem to find the information anywhere else on SO, even though it seems like such a simple problem. I have a data frame with several columns as factors. Some of those are integers, and some are strings. I would like to extract the rows that correspond to a particular factor. For example,
my_data <- read.table(file = "my_data.txt", header = TRUE) my_data[ my_data$age == 20, ]
This works, but if I then try
my_data[ my_data$gender == "male", ]
This produces no matches. I realized they are not the same thing, as checking the class of
my_data$name gives factor, while I’m checking it against a string.
Any ideas what I’m doing wrong here?
Data sample: Size Age Gender Value 1 20 male 0.5 4 22 female 0.7 3 14 female 0.3