-5

I have a data file like so ...

Control,3
Test,3
Control,3
Control,3
Test,1
Control,3
Control,1

I want to load them into 2 vectors test and control. Any ideas?

Gavin Simpson
  • 170,508
  • 25
  • 396
  • 453

1 Answers1

3

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?

Gavin Simpson
  • 170,508
  • 25
  • 396
  • 453