0

Why when I load a data and run as.integer function get wrong results. Mean, it doen't convert data in integer format but the values are completely changed.

cetaceans_raw <- read.csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2018/2018-12-18/allCetaceanData.csv")


cetaceans_raw %>%   mutate(birthYear = as.integer(birthYear))

1 Answers1

1

r is likely importing the data as.factor(), and then when you use the as.numeric(), r gives the factors an indexed value 1:length(unique(birthYear)). try:

cetaceans_raw %>%   mutate(birthYear = as.integer(as.character(birthYear)))
ITM
  • 73
  • 9