For instance given:
dim1 <- c("P","PO","C","T")
dim2 <- c("LL","RR","R","Y")
Here's a simple way to solve:
mxCol=function(df, colIni, colFim){ #201609
if(missing(colIni)) colIni=1
if(missing(colFim)) colFim=ncol(df)
if(colIni>=colFim) { print('colIni>=ColFim'); return(NULL)}
dfm=cbind(mxC=apply(df[colIni:colFim], 1, function(x) colnames(df)[which.max(x)+(colIni-1)])
,df)
dfm=cbind(mxVal=as.numeric(apply(dfm,1,function(x) x[x[1]]))
,dfm)
returndfm
}