在r中使用匹配的子集

时间:2018-04-05 18:50:43

标签: r match subset

我有一个名为finalr的数据集,列出了不同大学的候选人。我想找到有多少候选人接受每所大学的录取通知并将其排在不同的级别。

  yes<-subset(finalr,finalr$Offer.Decision=="yes")
  no<-subset(finalr,finalr$Offer.Decision=="no")
  yes$School<-gsub(" ","",yes$School, ignore.case=T)
  freq<-as.data.frame(sort(table(yes$School),decreasing=TRUE),stringsAsFactors=FALSE)

  # rank universities in different levels
  platinum<-freq[1:13,]
  gold<-freq[14:26,]
  silver<-freq[27:69,]

 platinum

  [1]  "BostonCollege"               "UniversityofMichigan"           "UniversityofNotreDame"      
  [4]  "PennsylvaniaStateUniversity" "ColumbiaUniversity"             "NewYorkUniversity"          
  [7]  "CarnegieMellonUniversity"    "CornellUniversity"              "DukeUniversity"             
  [10] "GeorgetownUniversity"        "UniversityofVirginia"           "VirginiaTech"               
  [13] "WesleyanUniversity"       

   class(platinum)

   [1] "character"

    platinumschool<-subset(finalr,match(finalr$School,platinum)==TRUE)
    platinumschool$School

   "DartmouthCollege" "DartmouthCollege" "DartmouthCollege" "DartmouthCollege" 
   "DartmouthCollege"
   [6] "DartmouthCollege"

当我尝试将所有学校从铂金中分配到最后时,platinumschool只显示在BostonCollege的记录,但是错过了其他。你能帮我分一下所有的记录吗?

0 个答案:

没有答案