为未找到对象错误的绘图结果子集化数据帧

时间:2018-03-30 18:11:03

标签: r dataframe subset with-statement

我有以下数据框称为植物:

    > head(plants)
     test.plant   test.soil root shoot total.dry.weight.plant phyl.distance.test.
1 pla med_plant plalan_soil  168   292                    460          0.05424804
2 pla med_plant plalan_soil  292   406                    698          0.05424804
3 pla med_plant plalan_soil  227   622                    849          0.05424804
4 pla med_plant plalan_soil  181   409                    590          0.05424804
5 pla med_plant plalan_soil  287   494                    781          0.05424804
6 pla med_plant plalan_soil  312   430                    742          0.05424804

我想为每个test.plant创建一个带有total.dry.weight.plant(y值)和phyl.distance.test(x值)的图。但是,我得到了所有尝试都出现同样的错误:

 plants[plants$test.plant == fespra_plant,]
Error in `[.data.frame`(plants, plants$test.plant == fespra_plant, ) : 
  object 'fespra_plant' not found

这是我的代码:

plants = read.csv("C:/Users../plants.csv",TRUE,sep=',')

DW = plants$total.dry.weight.plant
PD = plants$phyl.distance.test.

with(plants[plants$test.plant == fespra_plant,], plot(PD, DW))

我如何才能为每种测试植物制作情节?

为什么上面的代码如果运作良好仍然会绘制每件事情?

1 个答案:

答案 0 :(得分:0)

考虑by绘制 test.plant 因子的所有子集:

by(plants, plants$test.plant, function(sub) {
     DW <- sub$total.dry.weight.plant
     PD <- sub$phyl.distance.test.

     with(sub, plot(DW, PD))
})