> table2flat<-function(mytable){
+ df<-as.data.frame(mytable)
+ rows<-dim(df)[1]
+ cols<-dim(df)[2]
+ x<-NULL
+ for(i in 1:rows){
+ for(j in 1:df$
Freq[i]){
+ row<-df[i,c(1:(cols-1))]
+ x<-rbind(x,row)
+ }
+ }
+ row.names(x)<-c(1:dim(x)[1])
+ return(x)
+ }
加亮Freq里面的i指的是表格里面的29,7,7,13,17,21吗?
下面是程序输出的表格 > mydata<-table2flat(mytable)
> mydata
treatment improved
1 Placebo None
2 Placebo None
3 Placebo None
4 Placebo None
5 Treated None
6 Placebo Some
7 Placebo Some
8 Placebo Some
9 Placebo Some
10 Placebo Some
11 Treated Some
12 Treated Some
13 Placebo Marked
14 Placebo Marked
15 Placebo Marked
16 Placebo Marked
17 Placebo Marked
18 Treated Marked
19 Treated Marked
20 Treated Marked
不是很明白循环的次数,请大神们指教!!谢谢!