How to find max, min, mean, 5th,10th Percentile for all the variables in the dataset. Functions colMax()
and colMin()
are not working in my R(version 3.5), apply(dat, MARGIN = 2, function(x) min(x, na.rm=TRUE))
and apply(dat,2,min, na.rm=TRUE)
are not giving correct results for all variables(giving correct results for some variables(Columns)) when I cross verified with min(dat$col1 ,na.rm=TRUE)
. using colMeans(dat, na.rm=TRUE)
for finding mean but my dat(File-name) contains charater type variables, Now need to find mean for only numeric variables by neglecting charater variables. Thanks
I consider this could help:
#Sample data
data("iris")
iris
Data <- iris[,-5]
#Compute
compute <- function(x)
{
max <- max(x, na.rm=T)
min <- min(x, na.rm=T)
meanv <- mean(x, na.rm=T)
q5 <- quantile(x, 0.05)
q10 <- quantile(x, 0.10)
ent <- data.frame(max=max, min=min, meanv=meanv, q5=q5, q10=10)
rownames(ent) <- NULL
return(ent)
}
apply(Data, 2, compute)