I'm trying to update a data frame column inside a function based on a filtered column.
#example dataframe
my.df = data.frame(A=1:10)
#define function to classify column passed as argument 2 based on argument 3
classify = function(df, col, threshold){
df[df$col<threshold, 2] <- "low"
df[df$col>=threshold, 2] <- "high"
return(df)
}
#assign output to new.df
new.df = classify(my.df, A, 5)
I'd expect the new column to contain character values of 'low' or 'high', but instead they're all <NA>
.