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 ?
- Antony                                        
--
View this message in context:
http://r.789695.n4.nabble.com/MODE-VARIANCE-NTH-PERCENTAILE-tp4636112.html
Sent from the R help mailing list archive at Nabble.com.
Din't you try sapply function?
I tried it for you. 
Just convert your matrix into a data frame using as.data.frame and then 
*> rantony*
     ABC PQR XYZ MNO
[1,]   3   6   7  15
[2,]   2  12  24  15
[3,]  20   5   1   2
[4,]  25  50  15  35
*> rantony=as.data.frame(rantony)*
*> sapply(rantony,var)* #calculates column wise variance
      ABC       PQR       XYZ       MNO 
137.66667 457.58333  99.58333 185.58333 
*> sapply(rantony,Mode)*  #calculates column vise Mode, where the mode
function is available in
http://cran.r-project.org/web/packages/prettyR/index.html  prettyR  package
      ABC       PQR       XYZ       MNO 
">1 mode" ">1 mode" ">1 mode"     
"15"
# the above means there are no modes in first three columns and in the last
column Mode is 15> sapply(rantony,quantile) 
       ABC   PQR   XYZ   MNO
0%    2.00  5.00  1.00  2.00
25%   2.75  5.75  5.50 11.75
50%  11.50  9.00 11.00 15.00
75%  21.25 21.50 17.25 20.00
100% 25.00 50.00 24.00 35.00
--
View this message in context:
http://r.789695.n4.nabble.com/MODE-VARIANCE-NTH-PERCENTAILE-tp4636112p4636142.html
Sent from the R help mailing list archive at Nabble.com.
Thank you chamilka. From: chamilka [via R] [mailto:ml-node+s789695n4636142h40@n4.nabble.com] Sent: Wednesday, July 11, 2012 8:13 PM To: Akkara, Antony (GE Energy, Non-GE) Subject: Re: MODE , VARIANCE , NTH PERCENTAILE Din't you try sapply function? I tried it for you. Just convert your matrix into a data frame using as.data.frame and then> rantonyABC PQR XYZ MNO [1,] 3 6 7 15 [2,] 2 12 24 15 [3,] 20 5 1 2 [4,] 25 50 15 35> rantony=as.data.frame(rantony)> sapply(rantony,var) #calculates column wise varianceABC PQR XYZ MNO 137.66667 457.58333 99.58333 185.58333> sapply(rantony,Mode) #calculates column vise Mode, where the modefunction is available in prettyR <http://cran.r-project.org/web/packages/prettyR/index.html> package ABC PQR XYZ MNO ">1 mode" ">1 mode" ">1 mode" "15" # the above means there are no modes in first three columns and in the last column Mode is 15> sapply(rantony,quantile)ABC PQR XYZ MNO 0% 2.00 5.00 1.00 2.00 25% 2.75 5.75 5.50 11.75 50% 11.50 9.00 11.00 15.00 75% 21.25 21.50 17.25 20.00 100% 25.00 50.00 24.00 35.00 ________________________________ If you reply to this email, your message will be added to the discussion below: http://r.789695.n4.nabble.com/MODE-VARIANCE-NTH-PERCENTAILE-tp4636112p46 36142.html To unsubscribe from MODE , VARIANCE , NTH PERCENTAILE, click here <http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscrib e_by_code&node=4636112&code=YW50b255LmFra2FyYUBnZS5jb218NDYzNjExMnwxNTUx OTQzMDI5> . NAML <http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_view er&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.Bas icNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.tem plate.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml -instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemai l.naml> -- View this message in context: http://r.789695.n4.nabble.com/MODE-VARIANCE-NTH-PERCENTAILE-tp4636112p4636144.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]]
Hi,
Just try:?dat4<-read.table(text="
?ABC PQR XYZ MNO
?? 3? 6? 7? 15
?? 2? 12? 24? 15
?? 20? 5? 1? 2
? 25? 50? 15? 35 
?",sep="",header=TRUE)
?apply(dat4,2,quantile)
?
?apply(dat4,2,var) 
#For mode calculation, use package ?modalvalue {rattle}
A.K.
,
----- Original Message -----
From: Rantony <antony.akkara at ge.com>
To: r-help at r-project.org
Cc: 
Sent: Wednesday, July 11, 2012 3:38 AM
Subject: [R] MODE , VARIANCE , NTH PERCENTAILE
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 ?
- Antony? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 
--
View this message in context:
http://r.789695.n4.nabble.com/MODE-VARIANCE-NTH-PERCENTAILE-tp4636112.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
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