私はこれを必要とする:
"X","Y",151,"X","Y",152,"X","Y",153,"X","Y",154,....."X","Y",334
しかし、私はこれしか得られません:
names<-c("X","Y",seq(152,334,by=1))
#"X","Y",151,152,153,154....334
ありがとう
シーケンス ('v1') のベクトルを作成し、 'v1' と""`の 'v1' でベクトル ( c("X", "Y", "")
)を複製します。length
replace the
v1 <- 152:334
v2 <- rep(c("X", "Y", ""), length(v1))
v3 <- replace(v2, v2 == "", v1)
head(v3, 10)
#[1] "X" "Y" "152" "X" "Y" "153" "X" "Y" "154" "X"
tail(v3, 10)
# [1] "331" "X" "Y" "332" "X" "Y" "333" "X" "Y" "334"
または、別のオプションとして、文字列 ( "X Y"
)length
を 'v1' の で複製し、'v1' を使用して、行列を にrbind
連結 ( ) し、 を分割します。c
vector
scan
"X Y"
"X", "Y"
scan(text=c(rbind(rep("X Y", length(v1)), v1)), what = "", quiet=TRUE)