I am trying to add a new column to a dataframe, however I need to create many columns for 5 or so dataframes. So I want to write a function. Since all the columns will be the same for each dataframe, this is what I had in mind:
n = c(2,3,5)
f = c("two", "three", "five")
q = c(1,1.5,2.5)
df= data.frame(n,f,q)
fxn_foo <- function(x){
x$egret <- (x$n)/2
}
fxn_foo(df)
df$egret
Why does this produce Null? Are my arguments misspecified? Do I need to specify that the argument is a dataframe?