0

I am trying to delete any rows with "George" and "Andrea", then check the correlation between Name and Science_score (just for an example)

df1 = data.frame(Name = c('George','Andrea', 'Micheal','Maggie','Ravi','Xien','George'), 
             Grade_score=c(4,6,2,9,5,7,8),
             Mathematics1_score=c(45,78,44,89,66,49,72),
             Science_score=c(56,52,45,88,33,90,47))
df1
object_table1 <- table(df1$Name,df1$Science_score)
object_table1
df2<-df1[!(df1$Name=="George" | df1$Name=="Andrea"),]
df2
object_table2 <- table(df2$Name,df2$Science_score)
object_table2

when I print df2, there is no "George" or "Andrea" here, however, when I use table(), "George" and "Andrea" come back liking a ghost! This confused me for hours! For hell where object_table2 get the information of "George" or "Andrea"?

adam wu
  • 47
  • 5
  • 1
    First run `df2 <- droplevels(df2)`. `Name` in `df1` is factor, although the default behavior has changed in R4.0.0. – Ronak Shah May 10 '20 at 05:19
  • thank you very much! This is so strange for R! When we mention "factors", how should I know this column is factor or not? if this column is not a factor, it will not happen? – adam wu May 10 '20 at 05:21

0 Answers0