as.character() will enable me to do this in a loop (so thanks!).

It looks like you guys are suggesting I accomplish this in some kind of
vectorized fashion (David: yes, the number of rows are not equal - and I
need to compare ALL pairs, not just adjacent pairs, so to vectorize, I
suppose I'd have to use the dyadic(?).

But I have a rather complicated conditional, so if my dataframes were huge
or I had to do this many, many times, I would think about how to vectorize
this, but in my case, just running through in a loop suits my needs.

Thanks!

Jonathan




On Thu, May 5, 2011 at 6:39 PM, Ista Zahn <izahn@psych.rochester.edu> wrote:

> Hi Jonathan,
>
> On Thu, May 5, 2011 at 6:28 PM, J <jonsleepy@gmail.com> wrote:
> > Hi, I'm requesting you don't berate me for asking this question:
> >
> > I clearly don't have the gist of factors.
> >
> > I have two dataframes, A and B.
> >
> > Each of them has a column containing strings (they're labels).
> >
> > I want to, one-by-one in a loop, compare the particular string in an
> entry from dataframe A to an entry in B, to see if they're the same.
>
> This is probably not the best way. Much easier to compare them all in one
> go.
>
> >
> > The problem, when posing the question:
> > searchID1 <- A[['label']][i]
> > possMatch1 <- B[['label']][j]
> > searchID1 == possMatch1
> >
> > I get the error:
> > Error in Ops.factor(searchID1, possMatch1) :
> >  level sets of factors are different
> >
> > I presume this is because the set of possible values in the 'labels'
> columns, respectively in A and B, differ.  In my case, I'm not interested in
> this at all; I just want to compare individual entries from the two
> dataframes in a pair-wise fashion.
> >
> > Can I strip the "factors" associated with the entries?  Is there a better
> way?
>
> Yes, you can "strip the factors" using as.character(). Alternatively,
> you could use set the factor levels using factor() or levels. Either
> way, I would just do
>
> A$label == B$label
>
> Instead of a loop.
>
> Best,
> Ista
> >
> > Jonathan
> >
> >
> >        [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help@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.
> >
>
>
>
> --
> Ista Zahn
> Graduate student
> University of Rochester
> Department of Clinical and Social Psychology
> http://yourpsyche.org
>

	[[alternative HTML version deleted]]

