如何在缺少值的地方连接点? [英] How to connect dots where there are missing values?
本文介绍了如何在缺少值的地方连接点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
让我们举个例子:
test=c(1,5,NA,5,4,1,NA,3,3,5,4,2)
plot(test,type="l")
这将绘制测试但不会连接点.是否有一种方法可以忽略NA并连接点,从而获得漂亮的图形?
This will plot test but will not connect the dots.Is there a way we can ignore the NAs and connect the dots so we get pretty graph?
推荐答案
无法忽略丢失的值.您需要将它们替换为插值.
There isn't a way to ignore the missing values. You need to replace them with interpolated values.
# using base packages only
plot(approx(test, xout=seq_along(test))$y, type="l")
# or, using zoo
library(zoo)
plot(na.approx(test), type="l")
这篇关于如何在缺少值的地方连接点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文