How to connect dots where there are missing values?

后端 未结 4 1649
天涯浪人
天涯浪人 2021-01-04 19:01

lets take this example:

       test=c(1,5,NA,5,4,1,NA,3,3,5,4,2)

      plot(test,type=\"l\")

This will plot test but will not connect the

4条回答
  •  说谎
    说谎 (楼主)
    2021-01-04 19:27

    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")
    

提交回复
热议问题