Following How to convert column types in R tidyverse I am trying to convert doubles (numeric) into integers.
For example, using the iris data:
iris1 <- iris %>%
mutate_at(vars(Petal.Length), integer)
The above throws an error, which I cannot understand despite following the recommended trouble shooting:
Error: Problem with `mutate()` column `Petal.Length`.
ℹ `Petal.Length = (function (length = 0L) ...`
.x invalid 'length' argument
Using the same line of code to convert to factor and the results are fine:
iris1 <- iris %>%
mutate_at(vars(Petal.Length), factor)
class(iris1$Petal.Length)
Can someone explain to me the reason for the error and how I can convert to integer. Ideally I am looking for a solution friendly to the pipe operator %>%
.