[R] How can we compare corresponding values of x and y (first value of x exacly matches with the first value of y)?

Jim Lemon jim at bitwrit.com.au
Fri Aug 17 12:25:17 CEST 2012


On 08/17/2012 07:48 PM, Sri krishna Devarayalu Balanagu wrote:
> df<- data.frame  (
>      "RowId" = 4:7,
>      "x"=c("1_1", "2_2", "3_3", "3_3"),
>       "y"=c("1_1", "3_3", "2_2", "3_3")
>                           )
>
> How can we compare corresponding values of x and y (first value of x exacly matches with the first value of y)?
> If they were not matced exactly how can we get the row id?
> In this case the row ids were 5 and 6.
>
Hi Sri krishna Devarayalu Balanagu,
how about this:

df$RowId[which(df$x != df$y)]

Jim



More information about the R-help mailing list