[Rd] Matrices given to pt? [was: [R] for loops and counters]

From: François Pinard <pinard_at_iro.umontreal.ca>
Date: Sun 16 Jul 2006 - 01:34:40 GMT

Hi, people.

I was a bit intrigued by the message quoted below. Indeed, if pt() is given a matrix, it returns a matrix. Should this feature be documented? ?pt speaks about "a vector of quantiles", and says nothing about the type of what it returns.

The same might presumably apply to other distribution-related functions.

From: Martyn Plummer <plummer@iarc.fr>
Date: Thu Apr 10 10:07:01 2003
Subject: [R] for loops and counters


You didn't say what goes wrong, but you mind find this version more useful

tstat <- (matrix(means, k,k, byrow=TRUE) - matrix(means, k,k,byrow=FALSE))/rms pvalue <- 2*(1-pt(abs(tstat), df=df))

S is designed to allow you to work with "whole objects", which means that for loops can (and should) be avoided.


On 05-Oct-99 Peter B. Mandeville wrote:
> I am trying to assign values to a vector (pvalue). Similar code works in C
> but not in R. What am I doing wrong?

> r <- pvalue <- 0
> for(i in (1:(k-1))){
> for(j in (i+1):k){
> r <- r+1
> tstat <- (means[i]-means[j])/rms
> pvalue[r] <- 2*(1-pt(abs(tstat),df))
> }
> }

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

François Pinard   http://pinard.progiciels-bpi.ca

R-devel@r-project.org mailing list
Received on Sun Jul 16 11:37:20 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 18 Jul 2006 - 12:27:05 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.