Re: [R] level sets of factors are different

From: Richard van Wingerden <ros110_at_gmail.com>
Date: Sun 08 Jan 2006 - 03:59:25 EST

Thanks!

The as.character fixed it!

Regards,
Richard

On 1/7/06, Prof Brian Ripley <ripley@stats.ox.ac.uk> wrote:
> The message is really explicit.
>
> You are trying to compare the equality of two factors with different level
> sets. Such factors are not comparable (and this is discussed on ?factor).
> You didn't give a reproducible example, and you have not told us what you
> are trying to do, so all we can do is repeat R's report that what you
> actually did is not sensible.
>
> On Sat, 7 Jan 2006, Richard van Wingerden wrote:
>
> > Hi,
> >
> > I have two data frames A en B.
> > I want to filter B with values of A
> >
> > data_frame_b
> > names <- colnames(data_frame_b[1:1, ])
> >
> > filtera <- data.frame(data_frame_a[1:1])
>
> This is bit strange. data_frame_a[1:1] is data_frame_a[1] and is a
> single-column data-frame. I think you might just as well use
>
> filtera <- data_frame_a[[1]]
>
> which is (probably) a factor. You then seem to want to extract values
> equal to its first element, so maybe you actually wanted
> columnX == as.character(data_frame_a[1,1]) ?
>
> >
> > print(nrow(filtera))
> >
> > if (nrow(filtera)>0){
> >
> > filtered_frame_b <- subset(data_frame_b, ColumnX == filtera[1, 1], names)
> > }
> > The results are:
> >
> > [1] 124
> > Error in Ops.factor(ColumnX, filtera[1, 1]) :
> > level sets of factors are different
> >
> >
> > What is wrong??
> >
> > Richard
>
>
> --
> Brian D. Ripley, ripley@stats.ox.ac.uk
> Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
> University of Oxford, Tel: +44 1865 272861 (self)
> 1 South Parks Road, +44 1865 272866 (PA)
> Oxford OX1 3TG, UK Fax: +44 1865 272595
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sun Jan 08 04:07:34 2006

This archive was generated by hypermail 2.1.8 : Sun 08 Jan 2006 - 06:29:38 EST