# your data
x <- c(7, NA, 90, 3, 57, NA)
y <- c(9,8,4,NA, 9, 9)
# 1.)
plot(x~y, type="b", data=na.omit(data.frame(x,y)))
# 2.)
plot(x~y, type="b", subset=complete.cases(x,y))
# 3.)
s <- complete.cases(x,y)
plot(y[s], x[s], type="b")
@ mochalatte, Answer to questions in the comment:
The ~ (tilde) operator characterizes formulas in R. The variable on the left (in our example x) is the dependent variable.The variable on the right side (in our example y) is the independent variable. Usually a dependent variable x is explored by one or more independent variables. If you change like y~x then your dependent and independent variable is also changing. see: Use of ~ (tilde) in R programming Language and In R formulas, why do I have to use the I() function on power terms, like y ~ I(x^3)
Meaning of subset=complete.cases(x,y):
- complete.cases: returns a logical vector indicating which cases are complete, i.e., have no missing values.
- subset: returns subsets of vectors, matrices or data frames which meet conditions.
In our case x,y without NA.
Hope this helps.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…