I have a dataframe df, it contains 10 different variables, including group.name, group.student, and other variables.
I firstly want to select the group with name "papaya", I do dfByGroup = df[group.name=="papaya",]
, the result is fine.
Then I want to select a specific person called "julia" from the above subset, I do dfByJulia <- dfByGroup[group.student=="julia",]
, and I view the results with View(dfByJulia)
, unfortunately, I can still see rows with students' names other than "julia".
Actually the student name "julia" is unique in my data, so I also tried select julia's rows directly from the original data dfByJulia<- df[student.name=="julia",]
. This time, the subset data is correct.
Why does this happen? Why cannot I do subsetting from a subset with [
operator? Why must I do it on the original dataframe?