[Solved] Read data from text file and sort into a vector [closed]


Try read.csv()

dat <- read.csv(text = "Control,3
Test,3
Control,3
Control,3
Test,1
Control,3
Control,1", header = FALSE)

> dat
       V1 V2
1 Control  3
2    Test  3
3 Control  3
4 Control  3
5    Test  1
6 Control  3
7 Control  1

However, you’ll need read.csv(file = "foo.csv", header = FALSE) and replace foo.csv with the path to and name of your file.

Then

test <- with(dat, V2[V1 == "Test"])
control <- with(dat, V2[V1 == "Control"])

> test
[1] 3 1
> control
[1] 3 3 3 3 1

Presuming I have understood what you want?

1

solved Read data from text file and sort into a vector [closed]