How can we take log of particular columns?
Suppose we have following data
And a function that does three things
Subsets based on what 'model' is mentioned (one of the column names of df)
Outputs decal with 3 columns
Outputs callog with the log of those values
By excluding DATE from the cold variable we can apply the log only on model and OBS_Q column
dataprep.allcal<-function(df,model){
dfcal<<-subset(df, select=c("DATE",model, "OBS_Q"))
#need to use the <<- operator below
dfcallog<<-subset(df, select=c("DATE",model, "OBS_Q"))
cols<-colnames(dfcallog)
cols<-cols[!cols %in% 'DATE']
dfcallog[cols] <<- log(dfcallog[cols])
}
dataprep.allcal(df=df,model='sac')
Output will like this