I have a data.frame named factor_nonagg with 50 rows and 3 columns. I wrote a function category() with argument factors. I am making changes to factors in the function. When I pass the data.frame to this function, no changes are made in the data.frame. Can someone help me in making permanent changes to my data.frame?
n=50 category=function(factors){ for(i in 1:n){ if(factors[i,1]>=90) factors[i,1]<-2*.45 else if(factors[i,1]>=65) factors[i,1]<-1*.45 else factors[i,1]<-0 if(factors[i,2]>=.190) factors[i,2]<-2*.25 else if(factors[i,2]>=.140) factors[i,2]<-1*.25 else factors[i,2]<-0 if(factors[i,3]>=.03) factors[i,3]<-2*.30 else if(factors[i,3]>=.015) factors[i,3]<-1*.30 else factors[i,3]<-0 }} category(factor_nonagg)
return(factors)at the end of your function and if you want to use that value to overwrite yourfactor_nonaggobject, you need to use<-:factor_nonagg <- category(factor_nonagg).