I want to print the output as a one line for each variable dd and vv
df=c(1:20)
df=matrix(df,ncol = 5,nrow = 4, byrow = T)
x=c(1.5,7.5,12.5,19.5)
for (j in 1:4) {
for (i in 1:4) {
if( sum(df[j,i],df[j,i+1])/2 ==x[j])
{xx=c(df[j,i],df[j,i+1]) }
}
dd=as.vector((df[j,i+1]-df[j,i])/6)
vv=as.vector(xx)
print(c(vv,dd))
}
I got the following
[1] 1.0000000 2.0000000 0.1666667
[1] 7.0000000 8.0000000 0.1666667
[1] 12.0000000 13.0000000 0.1666667
[1] 19.0000000 20.0000000 0.1666667
and what I want to print from my code is
[1] 1 2 7 8 12 13 19 20
and
[1]0.1666667 0.1666667 0.1666667 0.1666667