2

私はこれを必要とする:

"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

ありがとう

4

1 に答える 1

1

シーケンス ('v1') のベクトルを作成し、 'v1' と""`の 'v1' でベクトル ( c("X", "Y", ""))を複製します。lengthreplace 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連結 ( ) し、 を分割します。cvectorscan"X Y""X", "Y"

scan(text=c(rbind(rep("X Y", length(v1)),  v1)), what = "", quiet=TRUE)
于 2016-08-30T09:59:26.100 に答える