0

I have a dataset with column called "id". I want to create a dummy variable, which is equal to 1 if "id" ends with digit 9.

UPD: "id" is represented by floating point number with 2 digit precision and various size. So, it may be 2.09, it may be 200.09.

d$end.9 <- as.numeric(str_sub(as.character(d$id), start= -1)==9)

This does not give correct result as as.character(d$id) gives, for example, 2.090000123 for d$id of 2.09 etc. I suppose the reason for this is how float numbers are handled by computers. How to achieve my goal then?

user3349993
  • 309
  • 1
  • 3
  • 14

0 Answers0