dragonp 发表于 2016-1-24 20:24 ![](https://bbs-cdn.datacourse.cn/static/image/common/back.gif)
for (j in 1:dfFreq){
书中这里也是有问题的,如果Freq返回的只有0,如:for(j in 1:0) print("haha"), ...
有0数据的时候确实有问题唉, 换了一下代码,终于行了
table2flat = function(mytable){
df = as.data.frame(mytable)
rows = nrow(df)
cols = ncol(df)
x = NULL
for(i in 1 : rows){
while(df$Freq
> 0){
# " for (j in 1:df$Freq)" isn't proper in "0" condition
row = df[i, c(1:(cols - 1))]
x = rbind(x, row)
df$Freq = df$Freq - 1
}
}
row.names(x) = c(1:nrow(x))
return(x)
}