lundi 22 août 2016

ifelse | Mismatch

My objective is to compare elements in two vectors.

Here's my first Tibble:

Post_Rev
# A tibble: 12 x 2
   Fiscal.Quarter.ID        Rev
       <S3: yearqtr>      <dbl>
1            2014 Q1 3889692022
2            2014 Q2 3763028239
3            2014 Q3 4092263526
4            2014 Q4 4865950809
5            2015 Q1 4015879019
6            2015 Q2 4112382310
7            2015 Q3 4247783642
8            2015 Q4 5040074056
9            2016 Q1 4100946981
10           2016 Q2 4021051564
11           2016 Q3 4373665674
12           2016 Q4 5064779447

Here's my second vector:

Total_Rev
 [1] 3889692022 3763028239 4092263526 4865950809 4015879019 4112382310 4247783642 5040074056
 [9] 4100946981 4021051564 4373665674 5064779447

As we can see, the two vectors i.e. Rev in Post_Rev and Total_Rev are equal. I will also show you class type.

class(Post_Rev$Rev)
[1] "numeric"

class(Total_Rev)
[1] "numeric"

However, when I run ifelse, it throws "unequal rows" for some rows:

ifelse(Post_Rev$Rev != Total_Rev,TRUE,FALSE)
 [1] FALSE  **TRUE** FALSE FALSE FALSE FALSE FALSE FALSE  **TRUE  TRUE** FALSE FALSE

What could be the reason? Is there anyway I can find out about the reason? I'd appreciate your thoughts.

I tried Wickham's if_else function:

if_else(Post_Rev$Rev != Total_Rev,TRUE,FALSE)
 [1] FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE FALSE

I got the same result. I am unsure why this is happening.

Aucun commentaire:

Enregistrer un commentaire