The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Rpre (1) [Avatar] Offline
#1
I wondef if table2flat has some errors.
In p159, table(mydata) will not generate the freq of mytable.
kokoko (1) [Avatar] Offline
#2
Re: chapter 7 table2flat function .P 158-159
Hi, i got the same problem, did you solve it?
hope for reply
jark (1) [Avatar] Offline
#3
Re: chapter 7 table2flat function .P 158-159
The problem is with the cbind() function not the custom table2flat() function. cbind() turns the numeric Freq vector into a character vector. Then as.data.frame changes Freq into an ordered factor. When the table2flat() function calls 1:df$Freq[i] the result of df$Freq[i] is coerced into a number which is the rank of factor that is returned. For example df$Freq[1] is "29" which is the fourth factor so you end up with 1:4 instead of 1:29.

One solution is to use cbind.data.frame(treatment, improved, Freq) instead of as.data.frame(cbind(treatment, improved, Freq))