Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a dataframe with numeric entries like this one

test <- data.frame(x = c(26, 21, 20), y = c(34, 29, 28))

How can I get the following vector?

> 26, 34, 21, 29, 20, 28

I was able to get it using the following, but I guess there should be a much more elegant way

X <- test[1, ]
for (i in 2:dim(test)[ 1 ]){
   X <- cbind(X, test[i, ])
   } 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.2k views
Welcome To Ask or Share your Answers For Others

1 Answer

You can try as.vector(t(test)). Please note that, if you want to do it by columns you should use unlist(test).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...