4
I would like to create a column on dataframe
teste
with the second highest value of the respective line, as I did to find Min and Max.
library("matrixStats")
teste <- read.table("https://raw.githack.com/fsbmat/StackOverflow/master/teste.txt",header = TRUE)
teste$ML_anual <- round(rowSums(teste[,c("LIQ_Jan2013","LIQ_Fev2013","LIQ_Mar2013","LIQ_Abr2013","LIQ_Mai2013","LIQ_Jun2013","LIQ_Jul2013","LIQ_Ago2013","LIQ_Set2013","LIQ_Out2013","LIQ_Nov2013","LIQ_Dez2013")],na.rm = T)/12,digits=2)
teste$Min <- round(rowMins(as.matrix(teste[,c("LIQ_Jan2013","LIQ_Fev2013","LIQ_Mar2013","LIQ_Abr2013","LIQ_Mai2013","LIQ_Jun2013","LIQ_Jul2013","LIQ_Ago2013","LIQ_Set2013","LIQ_Out2013","LIQ_Nov2013","LIQ_Dez2013")]),na.rm = T),digits=2)
teste$Max <- round(rowMaxs(as.matrix(teste[,c("LIQ_Jan2013","LIQ_Fev2013","LIQ_Mar2013","LIQ_Abr2013","LIQ_Mai2013","LIQ_Jun2013","LIQ_Jul2013","LIQ_Ago2013","LIQ_Set2013","LIQ_Out2013","LIQ_Nov2013","LIQ_Dez2013")]),na.rm = T),digits=2)
The original database has 130,000 lines, so I’d like to find a function that doesn’t require a loop for
to speed up the process!