I understand that magrittr::inset()
should be able to assign a vector to a new column in a dataframe (as a sort of opposite of extract()
). But I don't understand how the syntax should work.
Say I've got, as a toy example:
df = data.frame( id = 1:26, letter = letters)
newvalue = rnorm(26)
I'd like to add newvalue as a new column to df within a magrittr chain. I'm assuming it's something like:
df %>%
inset('new_column_name', newvalue)
But that doesn't work, presumably because I don't quite understand what the syntax for [<-
(for which inset()
is an alias) should look like.
Outside of a magrittr chain, I could do:
df['new_column_name'] <- newvalue
But my question is how to do it within a chain, where I've already done various and asundry operations.