R 出现在水平(…)和箱线图中的下降观察值/病例

R 出现在水平(…)和箱线图中的下降观察值/病例,r,R,我很难从数据框中删除观测值,因为它们会在图表上显示为轴标签 当我使用类似于这个片段的代码时 #***** D A T A M A N I P U L A T I O N B R E **** #* * #* * #* Deals with relevant su

我很难从数据框中删除观测值,因为它们会在图表上显示为轴标签

当我使用类似于这个片段的代码时

#*****   D A T A    M A N I P U L A T I O N   B R E   ****
#*                                                        *
#*                                                        *
#* Deals with relevant substrates only                    *
#* for the mortars BMG and PA only                        *
#* This is in connection with BRE certificated product    *
#* and change of polymer 14SSP0016                        *
#*                                                        *
#*                                                        *
#*********************************************************
#
#

###  Firstly Create a new variable with the substrates of interest renamed to a common system
  blk <- c("block", "Breeze Block", "breezeblk", "conc.blk")
  brk <- c("LBC Common", "lbccommon", "brk.common")
  cnc <- c("ConcreteDense", "Coping Slab", "denseconc", "conc.dense")
  eng <- c("engbrick", "brk.eng")
  mydata$sub.genl <- mydata$substrate
  mydata$sub.genl <- mapvalues( mydata$substrate, 
  from=c( blk[1],blk[2],blk[3],blk[4],  brk[1],brk[2],brk[3], cnc[1],cnc[2],cnc[3],cnc[4],        eng[1], eng[2], "tile" ), 
    to=c( blk[4],blk[4],blk[4],blk[4],  brk[3],brk[3],brk[3], cnc[4],cnc[4],cnc[4],cnc[4], eng[2], eng[2], "tile"  ) )
#  head(mydata)    
## Works OK, length(mydata$id) = 622
##

### Secondly Keep those cases on the keep.list, Drop all others
  keep.list <- c(blk[4], brk[3], cnc[4], eng[2], "tile")
  mydata.bre1 <- subset(mydata, sub.genl %in% keep.list  )
  droplevels(mydata.bre1)$sub.genl
#  as.factor(as.character(mydata.bre1$sub.genl))
#  mydata.bre1$product <- mydata.bre1$sub.genl[ , drop=TRUE]
#  levels(mydata.bre1$sub.genl)
## Gives about 445 cases
##

### Thirdly select the products BMG and PA then Drop others
  mydata.bre2 <- subset(mydata.bre1, product %in% c("PA", "BMG"))  
  droplevels(mydata.bre2)$product
#  as.factor(as.character(mydata.bre2$product))
#  mydata.bre2$product <- mydata.bre2$product[ , drop=TRUE]
#  levels(mydata.bre2$product)
## Works OK length(mydata.bre2$id) = 189
##

### Fourthly drop unwanted variables e.g. $mortar
  drop.list <- c(4,9,11,13:15) 
  mydata.bre2 <- subset(mydata, select = -drop.list )
  names(mydata.bre2)
## Works OK 
##

#
#
######   E N D   ********************************* 
结果是

 [1] ""                            "3937939379"                 
 [3] "610 + K622"                  "BMG"                        
 [5] "CAPATECT ROLLKLEBER 615"     "DMG"                        
 [7] "DOC"                         "HP BASECOAT"                
 [9] "LA"                          "PA"                         
[11] "pBMG"                        "pTC (10mm) "                
[13] "pTC (6mm) "                  "Swimming Pool Mortar + mesh"
[15] "SWIMMING POOL MORTAR 2"      "SWIMMING POOL MORTAR 3"     
[17] "UF BASECOAT" 
当只有cPA时,BMG应在场。 同上

   levels(mydata.bre1$sub.genl)
 [1] ""                              "conc.blk"                     
 [3] "BMG"                           "brk.common"                   
 [5] "brk.eng"                       "conc.dense"                   
 [7] "CPB"                           "eps"                          
 [9] "EPS"                           "LA"                           
[11] "mf"                            "MF"                           
[13] "OrangePS"                      "OSB"                          
[15] "PCR Y Wall Board grainy side"  "PCR Y Wall Board mottled side"
[17] "phenolic"                      "Phenolic"                     
[19] "ply"                           "pvcsheet"                     
[21] "RockPanelLabelledSide"         "RockPanelUnLabelledSide"      
[23] "tile"                          "XPS"                          
仅仅

 keep.list

[1] "conc.blk"   "brk.common" "conc.dense" "brk.eng"    "tile"      
should be present
然后当我试着策划

#  
 boxplot(bondMPa~product, data=mydata.bre2, main="Bond strength versus product", 
         xlab="", ylab="Bond strength (MPa)")  
 X11()
 boxplot(bondMPa~product+sub.genl, data=mydata.bre2, main="Bond strength versus product and substrate for BRE", 
         xlab="", ylab="Bond strength (MPa)", cex.axis=0.4, las=2) # This is a useful chart
结果是混乱,因为R试图用所有$product绘制所有$sub.genl的笛卡尔乘积,而不管是否删除了哪些案例

在我看来,一切都取决于落差。也许我需要的不仅仅是滴水,也许我需要根除或类似


是否可以就此提供建议?

有一个功能可以删除未使用的因子级别。看到了吗?Droplevels没有为任何对象指定级别。尝试类似mydata.bre1=droplevelsmydata.bre1的操作
#  
 boxplot(bondMPa~product, data=mydata.bre2, main="Bond strength versus product", 
         xlab="", ylab="Bond strength (MPa)")  
 X11()
 boxplot(bondMPa~product+sub.genl, data=mydata.bre2, main="Bond strength versus product and substrate for BRE", 
         xlab="", ylab="Bond strength (MPa)", cex.axis=0.4, las=2) # This is a useful chart