I would like to mutate a new column using different length values from the Código column on this dataframe.
ods <- readODS::read_ods('http://www.arcotel.gob.ec/wp-content/uploads/2016/09/proyeccion_cantonal_total_2010-2020_seg%C3%BAn_INEC1.ods', skip = 2)
I've tried using case_when inside a mutate like this:
mutate(ods, Provincia = case_when(
length(ods$Código) == 3 ~ str_extract(ods$Código, '[[:digit:]]{1}'),
length(ods$Código) == 4 ~ str_extract(ods$Código, '[[:digit:]]{2}')
))
It's supposed to create a new Provincia column with the first digit from Código whenever the length of its value is 3, otherwise should extract two digits. When running the above code I only get NA's
ncharhere and notlength- paqmo