R语言cast函数数据分类的使用方法
(2017-01-26 10:28:58)
标签:
财经 |
分类: 博 |
library(reshape)
set.seed(20)
gcz<-data.frame(subj=rep(1:4,rep(3,4)),time=rep(1:3),x=rnorm(12),y=rnorm(12))
mgcz=melt(gcz,measure=c('x','y'))
cast(subj~variable+time,data=mgcz)
1
1 1.1626853 -0.58592447
1.7854650 -0.62812676 1.3232209
-1.52135057
2
2 -1.3325937 -0.44656677
0.5696061 -0.43742787 0.9705776
0.02822264
3
3 -2.8897176 -0.86901834 -0.4617027 -0.08578219
0.3892144 0.23668737
4
4 -0.5555409 -0.02013537 -0.1503822 -0.14444023
0.7222297 0.36990686
set.seed(20)
gcz<-data.frame(subj=rep(1:4,rep(3,4)),time=rep(1:3),x=rnorm(12),y=rnorm(12))
gcz
1
1 1
1.16268529 -0.62812676
2
1 2
-0.58592447 1.32322085
3
1 3
1.78546500 -1.52135057
4
2 1
-1.33259371 -0.43742787
5
2 2
-0.44656677 0.97057758
6
2 3
0.56960612 0.02822264
7
3 1
-2.88971761 -0.08578219
8
3 2
-0.86901834 0.38921440
9
3 3
-0.46170268 0.23668737
10
4 1
-0.55554091 -0.14444023
11
4 2
-0.02013537 0.72222970
12
4 3
-0.15038222 0.36990686
mgcz=melt(gcz,measure=c('x','y'))
mgcz
1
1 1
x 1.16268529
2
1 2
x -0.58592447
3
1 3
x 1.78546500
4
2 1
x -1.33259371
5
2 2
x -0.44656677
6
2 3
x 0.56960612
7
3 1
x -2.88971761
8
3 2
x -0.86901834
9
3 3
x -0.46170268
10
4 1
x -0.55554091
11
4 2
x -0.02013537
12
4 3
x -0.15038222
13
1 1
y -0.62812676
14
1 2
y 1.32322085
15
1 3
y -1.52135057
16
2 1
y -0.43742787
17
2 2
y 0.97057758
18
2 3
y 0.02822264
19
3 1
y -0.08578219
20
3 2
y 0.38921440
21
3 3
y 0.23668737
22
4 1
y -0.14444023
23
4 2
y 0.72222970
24
4 3
y 0.36990686
cast(subj~variable+time,data=mgcz)
1
1 1.1626853 -0.58592447
1.7854650 -0.62812676 1.3232209
-1.52135057
2
2 -1.3325937 -0.44656677
0.5696061 -0.43742787 0.9705776
0.02822264
3
3 -2.8897176 -0.86901834 -0.4617027 -0.08578219
0.3892144 0.23668737
4
4 -0.5555409 -0.02013537 -0.1503822 -0.14444023
0.7222297 0.36990686
cast(subj~variable+time,subset=variable=='x',data=mgcz)
1
1 1.1626853 -0.58592447
1.7854650
2
2 -1.3325937 -0.44656677
0.5696061
3
3 -2.8897176 -0.86901834 -0.4617027
4
4 -0.5555409 -0.02013537 -0.1503822
前一篇:latex数学符号(二)

加载中…