我在绘制特殊行时遇到困难

时间:2019-05-12 15:20:31

标签: r

我有一个数据集,我想从中绘制一个特定的行。

我试图以这种粗略的方式做到这一点:

person7_loss = c(weigh_loss$Jan[weigh_loss$Individuals == "Person 7"], 
             weigh_loss$Feb[weigh_loss$Individuals == "Person 7"],
             weigh_loss$Mar[weigh_loss$Individuals == "Person 7"],
             weigh_loss$Apr[weigh_loss$Individuals == "Person 7"],
             weigh_loss$Mai[weigh_loss$Individuals == "Person 7"],
             weigh_loss$Jun[weigh_loss$Individuals == "Person 7"],
             weigh_loss$Jul[weigh_loss$Individuals == "Person 7"],
             weigh_loss$Aug[weigh_loss$Individuals == "Person 7"],
             weigh_loss$Sep[weigh_loss$Individuals == "Person 7"],
             weigh_loss$Oct[weigh_loss$Individuals == "Person 7"],
             weigh_loss$Nov[weigh_loss$Individuals == "Person 7"],
             weigh_loss$Des[weigh_loss$Individuals == "Person 7"])

但是我认为有一种更简单的方法。

我想象过类似的事情:

person1 = weigh_loss[1,5:16]
plot(x = person1, type = "h", ylim = c(0, 120), ylab = "Þyngd",
     xlab = "Mánuður")

1 个答案:

答案 0 :(得分:0)

一个更简单的选择是在过滤行之后unlist

person7_loss <- unlist(weigh_loss[weigh_loss$Individuals == "Person 7", nm1])

其中“ nm1”是感兴趣的列

nm1 <- 5:16

如果有多行,则转置经过过滤的输出并将其转换为vector以保持顺序

c(t(weigh_loss[weigh_loss$Individuals == "Person 7",nm1]))