I'm trying to add a column to a dataframe within a function and when I run it I don't get any errors but the column is not in the dataframe in the global environment. This is my code:
scale.it<-function(df,var,newvar){
varn<-as.numeric(df[[var]])
last<-max(varn)
#df[[newvar]]<-varn/last
return(df[[newvar]]<-varn/last)
}
scale.it(go.cubs.go,"PAge","IPAge")
So essentially, I want my current dataframe go.cubs.go to have all of the current columns plus IPAge.
I know there is a scale function that already exists but I need to adapt this code later so I need to be able to add columns to dataframes in functions.
Any help is greatly appreciated!