Convert txt file to vector

I have data in the *.txt file like this.

rep trt y
1 7 34.55
1 7 65.88
1 7 34.66
2 8 45.66
2 8 34.55
2 8 32.09
3 9 38.99
3 9 33.44
3 9 35.67

How to convert into this form.

rep=c("1","1","1","2","2","2","3","3","3")
trt=c("7","7","7","8","8","8","9","9","9")
y=c("34.55","65.88","34.66","45.66","34.55","32.09","38.99","33.444","35.67")

Thank you for your suggestion.

You can read the file into a data frame and then use the $ operator to define vectors that contain the values in the data frame columns. Try something like

DF <- read.csv("MyFile.txt", sep = " ") # I guess the data separator is a space.
rep <- DF$rep
trt <- DF$trt
y <- DF$y

However, do you really need to use vectors instead of leaving the data in the data frame?

1 Like

Thank you for your suggestion. This is what I am looking for. :smiling_face_with_three_hearts:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.