-5

我有一个像这样的数据文件......

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

我想将它们加载到 2 个向量测试和控制中。有任何想法吗?

4

1 回答 1

3

尝试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

但是,您需要read.csv(file = "foo.csv", header = FALSE)并替换foo.csv为文件的路径和名称。

然后

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

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

假设我已经明白你想要什么?

于 2013-01-09T16:01:25.197 回答