mutate function no result

Hi ,
mutate function no resull....

Hi,
the mutate function not changed the type of the variable in to character.... pls help me
typeof(penguins$island)

penguins %>% mutate(island=as.character(island))

typeof(penguins$island)

result ;;;;;;
[1] "integer"
[1] "integer"

thanks,
K.R.Manikandan

In R, one needs awareness of the difference between calculation and assignment. sometimes we might write code to do both, but we can also write code to do only one. The way you use mutate , you are only calculating and not assigning.

Consider this very trivial code :

(x <- 2)

x + 2

x

x <- x+ 2

x

the first time we see x+2 a calculation happens and a result is emitted, but it is not assigned anywhere, there is no variable name to refer to to see the result.
Therefore assignment <- is then used to retain the result, the second time we see it.

to summarize, you need to do

penguins <- penguins %>% mutate(island=as.character(island))
typeof(penguins$island)
1 Like