Re: [R] level sets of factors are different

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Sat 07 Jan 2006 - 23:42:12 EST

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 Sat Jan 07 23:50:07 2006

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:41:54 EST