2

I have the following vector, called c_vector:

c_vector <- c("0, 1, 2, 3", "4, 5, 7", "8, 9, 1")

I need to convert c into the following numeric vector

c_vector <- c(0, 1, 2, 3, 4, 5, 7, 8, 9 ,1)

How can I achieve this? Thank you.

2 Answers 2

2

Maybe you can try the code below

c_vector<-as.numeric(unlist(strsplit(c_vector,", ")))
2

We can use scan directly

scan(text = c_vector, what = numeric(), sep=",")
#[1] 0 1 2 3 4 5 7 8 9 1

EDIT: Comments from @A5C1D2H2I1M1N2O1R2T1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.