Re: [R] compare strings

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Sat, 01 Dec 2007 09:55:58 +0100

Bernd Jagla wrote:
> It helps writing down these question, you are then getting much closer to an
> answer...
>
> summary(as.integer(t3[,2]) == as.integer(t3[,4]) & as.integer(t3[,3]) ==
> as.integer(t3[,5]))
>
> will compare two pairs of column pairs and give a count of flase and true
> rows...
>
>
If they really are factors with different level sets, I think you might prefer as.character() there.

 > x <- factor(c("a","b"))
 > y <- factor(c("b","c"))
 > x==y

Error in Ops.factor(x, y) : level sets of factors are different  > as.integer(x)==as.integer(y)
[1] TRUE TRUE
 > as.character(x)==as.character(y)
[1] FALSE FALSE Also, extending the above slightly:
 > d <- as.character(x)==as.character(y)  > table(d)
d
FALSE TRUE
    2 1
 > which(!d)
[1] 1 2

> -B
>
> |-----Original Message-----
> |From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-project.org] On
> |Behalf Of Bernd Jagla
> |Sent: Friday, November 30, 2007 10:25 PM
> |To: r-help_at_r-project.org
> |Subject: [R] compare strings
> |
> |Sorry for the question, but I really cannot find the right search terms to
> |find an answer..
> |
> |
> |
> |I have a data frame with strings in some of the columns.
> |
> |I want to know all the rows where the strings in both columns are equal.
> |
> |
> |
> |How do I do this?
> |
> |
> |
> |Thanks,
> |
> |
> |
> |Bernd
> |
> |
> | [[alternative HTML version deleted]]
> |
> |______________________________________________
> |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.
>
> ______________________________________________
> 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.
>

-- 
   O__  ---- Peter Dalgaard             ุster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard_at_biostat.ku.dk)                  FAX: (+45) 35327907

______________________________________________
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 Sat 01 Dec 2007 - 09:00:38 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 Sat 01 Dec 2007 - 11:30:17 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.