# Re: [R] Problem with Freq function {prettyR}

From: <ukoenig_at_med.uni-marburg.de>
Date: Fri, 13 Jun 2008 18:32:54 +0200

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...
> >>
> >> Thanks in advance!
> >>
> >> 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
> > PLEASE do read the posting guide
> 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
>

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri 13 Jun 2008 - 17:17:09 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 13 Jun 2008 - 18:30:44 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.