-1

Im a beginner and Im sorry this question is very similar to one I have asked before, only this time I trying to use for-loops.

I want to do this on my data

In the ex. on this page, they only show how to do it for one column. I want to use for-loops to be able to do it for ALL columns. I have modified this, from the "Answer" section on the linked page:

for (i in x) {freq = table(cut,na.rm=TRUE)}

This returns the error all arguments must have the same length

Do anyone know what Im doing wrong? Columns in my vector are of different lengths, so all except one has a lot of NA.

Again, sorry for naive and very similar question...

Jilber Urbina
  • 58,147
  • 10
  • 114
  • 138
user2966591
  • 93
  • 1
  • 9
  • If you please update your question with a [minimal, reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610) it will be much easier to help you. Cheers. – Henrik Nov 25 '13 at 11:32
  • Yes, but its all in the linked page, and I really dont get how to format (coding) the questions correctly.. – user2966591 Nov 25 '13 at 11:40
  • 1
    Don't use a for-loop. Instead, use `lapply`, like `lapply(mydf, function(i) FUNCTION_I_WANT_TO_DO_TO_EACH_COLUMN)`. – Thomas Nov 25 '13 at 11:50

1 Answers1

2

The problem comes from you using na.rm = TRUE as if it was a valid option to table. It is not, hence it is treated as one of the ... arguments to table and since length(TRUE) is not equal to length(cut), you get the error.

You probably meant to use useNA = "no" instead.

flodel
  • 87,577
  • 21
  • 185
  • 223