Skip to content
Back to formatted view

Raw Message

Message-ID: <4FFE958D.1000301@bitwrit.com.au>
Date: 2012-07-12T09:14:53Z
From: Jim Lemon
Subject: MODE , VARIANCE , NTH PERCENTAILE
In-Reply-To: <1341992318944-4636112.post@n4.nabble.com>

On 07/11/2012 05:38 PM, Rantony wrote:
> Hi,
> Here i have an matrix like this,
>
> ABC    PQR    XYZ   MNO
> ------   -------   ------   --------
> 3            6        7          15
> 2          12        24        15
> 20         5         1           2
> 25          50      15         35
>
> i need to get the
>                                        "MODE" - for each column-wise
>                                        "VARIANCE" - for each column-wise
>                                        "25TH-PERCENTAILE" -for each
> column-wise
>
> i tried alots, and it was difficult to get. Someone can help me out please ?
>
Hi Rantony,
Try this:

testdat<-matrix(c(3,2,20,25,6,12,5,50,7,24,1,15,15,15,2,35),nrow=4)
colnames(testdat)<-c("ABC","PQR","XYZ","MNO")
library(prettyR)
# make a function for 25th percentile
q25<-function(x,na.rm) return(quantile(x,prob=0.25,na.rm=na.rm))
testdesc<-describe(testdat,num.desc=c("Mode","var","q25"),xname="testdat")
print(testdesc)

Note that the values in the data frame "testdesc" are numeric, except 
for the first column, as there are text messages that no mode exists for 
columns ABC, PQR and XYZ. When "testdesc" is printed, it is converted to 
a matrix, which coerces everything to character type.

Jim