0

(a)  Investigate the frequency distributions for the categorical predictors.

I have tried the below but can’t seem to get it to work. Any ideas on how to fix this?

library(mlbench)
data(Soybean)
str(Soybean)

soy = Soybean[,-c(1,2)]

> table(soy)
Error in table(soy) : attempt to make a table with >= 2^31 elements

par(mfrow = c(17, 2))
for (i in 1:34) {
  hist(soy[ ,i], xlab = names(soy[i]), main = paste(names(soy[i]), "Histogram"), col="deepskyblue")  
}
Error in hist.default(soy[, i], xlab = names(soy[i]), main = paste(names(soy[i]),  : 
  'x' must be numeric

> barplot(prop.table(table(soy)))
Error in table(soy) : attempt to make a table with >= 2^31 elements

What am I doing wrong?

bandcar
  • 649
  • 4
  • 11
  • your title clearly indicates that you have a factor/ you use barplots on factors and not histograms. ie `barplot(table(soy[,i]))` – Onyambu Jun 22 '22 at 21:18
  • I just tried this and fully expanded the plot window but it says figure margins are too large. – bandcar Jun 22 '22 at 21:20
  • according to the question, do you need the plots or the results? – Onyambu Jun 22 '22 at 21:22
  • try `barplot(table(soy[,1]))` – Onyambu Jun 22 '22 at 21:23
  • Here is the full question: "(a)  Investigate the frequency distributions for the categorical predictors. Are any of the distributions degenerate in the ways discussed earlier in this chapter?" It doesn't specify, but since a similar question on this assignment used plots, I figured this one would also need a plot. But thinking on it, the results would probably be just as effective – bandcar Jun 22 '22 at 21:24
  • `barplot(table(soy[,1]))` gave me the same error :/ – bandcar Jun 22 '22 at 21:25
  • try run `dev.off()` then run `barplot(table(soy[,1]))` – Onyambu Jun 22 '22 at 21:26
  • Well, it plotted the bar plot, but it only shows results for 0 and 1. – bandcar Jun 22 '22 at 21:32
  • Yes, soy[,1] has only 0's and 1's. Hope this solves your problem – Onyambu Jun 22 '22 at 21:34
  • oh, that's right! Okay, yes it does. Thank you! – bandcar Jun 22 '22 at 21:35

0 Answers0