Modify
Sometimes we might want the output to be the same as the input, then in that case we can use the modify function rather than map
df <- data.frame(x=1:3,y=6:4)
map(df, .f=~.x*3)
#> $x
#> [1] 3 6 9
#>
#> $y
#> [1] 18 15 12
modify(.x=df,.f=~.x*3)
#> x y
#> 1 3 18
#> 2 6 15
#> 3 9 12
Note that modify()
always returns the same type of output (which is not necessarily true with map()
). Additionally, modify()
does not actually change the value of df
.