I cannot use the filter after mutations in dplyr

I can't figure out why I can get this to work.

datos = data.frame(año = 2001:2005, gedad = c(letters[1:5]))  
datos %>% mutate(año2 = año*1) %>% filter(año2 >= 2003)

      

The error says:

 Error in filter_impl(.data, dots) : object 'año2' not found

      

Just because I can't use a filter with a variable converted to mutation?

A subset works fine:

datos %>% mutate(año2 = año*1) %>% subset(año2>=2003)

      

R says:

   año gedad año2
3 2003     c 2003
4 2004     d 2004
5 2005     e 2005

      

Thanks in advance!

+1


source to share





All Articles