# [R] Problem with Freq function {prettyR}

ukoenig at med.uni-marburg.de ukoenig at med.uni-marburg.de
Fri Jun 13 18:32:54 CEST 2008

```Thanks a lot, Jim!

> Since this is a contributed package, you should be contacting the
> maintainer (as mentioned in the posting guide).
sorry....

>
> Anyway, the problem occurs because in the second case you have a factor
> in the first column and numeric in the second. This part of the code
> will illustrate what I mean:
>
> for (i in 1:nfreq) {
>          if (display.na)
>              nna <- sum(is.na(x[[i]]))
>          else nna <- 0
>          xt <- na.omit(x[[i]])
>          if (is.null(levels))
>              levels <- unique(xt)
>          if (is.numeric(x[[i]]))
>              xt <- factor(xt, levels = levels)
>
> So the first time through this loop the levels variable is set to
> c("m","f"). On the second time levels is no longer NULL, so when the xt
> variable is created it is essentially this:
>
> xt <- factor(xt, levels = c("m","f"))
>
> and since xt contains only numbers you get
>
> [1] <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
> Levels: m f
>
> Best,
>
> Jim
>
>
>
> ukoenig at med.uni-marburg.de wrote:
> > Does someone have an idea?
> > Thanks a lot!
> >
> > Udo
> >
> >
> > Quoting Udo <ukoenig at med.uni-marburg.de>:
> >
> >> Dear list,
> >> I have a problem with freq from prettyR.
> >>
> >> Please have a look at my syntax with a litte example:
> >>
> >>
> >> library(prettyR)
> >>
> >> #Version 1
> >> test.df<-data.frame(q1=sample(1:4,8,TRUE),
> gender=sample(c("f","m"),8,TRUE))
> >> test.df
> >> freq(test.df) #No error message
> >>
> >> #Version 2
> >> test.df<-data.frame(gender=sample(c("f","m"),8,TRUE),
> q1=sample(1:4,8,TRUE))
> >> test.df
> >> freq(test.df)
> >>
> >> Error message: "Error in vector("integer", length) : Vector size can´t be
> NA"
> >>
> >> Can someone tell me, why an error message occurs in version two? I am
> >> helpless...
> >>
> >>
> >> Udo K ö n i g
> >>
> >> --------------------------------------------
> >>
> >> Clinic for Child an Adolescent Psychiatry
> >> Philipps University of Marburg / Germany
> >>
> >
> > ______________________________________________
> > R-help at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> --
> James W. MacDonald, M.S.
> Biostatistician
> Affymetrix and cDNA Microarray Core
> University of Michigan Cancer Center
> 1500 E. Medical Center Drive
> 7410 CCGC
> Ann Arbor MI 48109
> 734-647-5623
>

```