2
我有非常寬的數據幀,並且想要創建很多短數據幀?它看起來像這樣:在循環中選擇列
location = c("A","B","C","D","E","F","G","H")
V1a = c(1,5,3,2,1,2,5,6)
V2a = c(3,2,6,7,3,2,1,2)
V3a = c(1,0,5,2,2,0,2,5)
V1b = c(3,2,6,7,3,2,1,2)
V2b = c(1,5,3,2,1,2,5,6)
V3b = c(1,5,3,2,1,2,5,6)
x <- data.frame(location,V1a,V2a,V3a,V1b,V2b,V3b)
x
location V1a V2a V3a V1b V2b V3b
1 A 1 3 1 3 1 1
2 B 5 2 0 2 5 5
3 C 3 6 5 6 3 3
4 D 2 7 2 7 2 2
5 E 1 3 2 3 1 1
6 F 2 2 0 2 2 2
7 G 5 1 2 1 5 5
8 H 6 2 5 2 6 6
我想從循環創建(如果可能)3個數據幀,因爲這
x1 <- x[,c(1,2,5)]
x1
location V1a V1b
1 A 1 3
2 B 5 2
3 C 3 6
4 D 2 7
5 E 1 3
6 F 2 2
7 G 5 1
8 H 6 2
x2 <- x[,c(1,3,6)]
x2
location V2a V2b
1 A 3 1
2 B 2 5
3 C 6 3
4 D 7 2
5 E 3 1
6 F 2 2
7 G 1 5
8 H 2 6
x3 <- x[,c(1,4,7)]
x3
location V3a V3b
1 A 1 1
2 B 0 5
3 C 5 3
4 D 2 2
5 E 2 1
6 F 0 2
7 G 2 5
8 H 5 6
謝謝您的幫助!
這非常有幫助!謝謝! – Eco06