# How can I select every second value from any given vector?
# For instance:
a <- c(1,2,3,4,5,6)
# should yield
# 1,3,5
# and
# 2,4,6
# which we intend to place into two separate vectors.
#
# Please solve my problem and please try to avoid the use of functions!
# solution1 - sequence
s11<-seq(1,length(a),2)
s12<-seq(2,length(a),2)
# solution2 - use the matrix
mat<-matrix(a,nrow=2)
s21<-mat[1,]
s22<-mat[2,]
# solution3 - modulo
s31<-which(a%%2>0)
s32<-which(a%%2<=0)
# solution4 - logical subsetting with autoreplication
s41<-a[c(T,F)]
s42<-a[c(F,T)]
back