[R] ifelse statement with two vectors of different length
Adel
adel.daoud at sociology.gu.se
Wed Dec 18 16:04:33 CET 2013
Dear Arun
Thanks for your reply, it made me realize that the problem was not in the
code but in the levels() of the factors. Some countries had some extra
spacing which made the ifelse() function not work. So if I modify your code
(added space to countrydiff), it will then look something like this:
countrydiff <- c("Albania ", "Algeria ", "Belarus ", "Canada ",
"Germany ")
long_df <- data.frame(country_name = c("Algeria", "Guyana", "Hungary",
"Algeria", "Canada", "Iran", "Iran", "Norway","Uruguay", "Zimbabwe") )
I had to use the gsub to fix this first.
Interestingly, the setdiff() function did not react on spacing difference
which I used before coming to the ifelse statement and therefore I did not
react on this in the first place
#no reaction from R on spacing diff.
setdiff(countrydiff, long_df$country_name)
Nevertheless, thanks again for being helpful!
Adel
--
View this message in context: http://r.789695.n4.nabble.com/ifelse-statement-with-two-vectors-of-different-length-tp4682401p4682403.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list