Hi Chintau,

For A, try

# some data
set.seed(123)
X <- matrix(rnorm(1013*6), ncol = 6)
group <- rep(0:1, each = 3)

# option 1
result <- apply(X, 1,
         function(x) wilcox.test(x ~ group, paired = TRUE)$p.value)
result

# option 2
res <- rep(NA, NROW(X))
for(i in 1:NROW(X)){
res[i] <- wilcox.test(X[i, ] ~ group, paired = TRUE)$p.value
 }
res

# are equal?
all.equal(result, res)

For B, see http://cran.r-project.org/other-docs.html

HTH,
Jorge


On Fri, Sep 9, 2011 at 1:14 AM, Chintanu <> wrote:

> Hi,
>
> Two queries, if I may ask:
>
> A. I wish to retrieve the p-values from wilcox test for EACH gene  --- such
> that Samples 1-3 is considered as one group while the rest remains in the
> other group.
>
> There is 1013 genes in the dataframe as attempted to exemplify in the table
> below.
>
>
>                    |Sample 1 | Sample2 | sample3 | SDample4 | sample 5 |
> sample 6
> _________________________________________________________________________
> Gene 1        | 2.4          | 3.5          | 4.2          | 6.2
> | 2.4          | 6.3
> Gene 2        | 6.4          | 6.5          | 2.2          | 8.2
> | 4.4          | 2.3
> ----
> -----
> Gene 1013  | 1.4          | 2.5          | 3.2          | 4.2            |
> 5.4           | 7.3
>
>
> Accordingly, the following function is made.
>
> funn <- function (x,y)
> {
>
> for (i in 1:1013)
>  {
>
>  wil <- wilcox.test(as.numeric(x), as.numeric (y), paired=TRUE);
>  print (wil);
>  }
>
> return (wil);
>
> }
>
>
> However, I think it is somewhat incorrect as commands like the following
> generates several warnings (and it gives more than just the p-value).
>
>
> funn (c(file [,1]:file [,3]), c(file[,4]:file [,6])) # "file" is the
> dataframe.
>
>
> B. Any good books/weblink you could advise which focus more on the
> programming side of r, such as function-building ? The few books that I
> have
> gone thorugh have very less on such aspect - they focus more on statistical
> aspects and use of built-in functions.
>
> Thank you.
>
> Cheers,
> Chintanu
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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.
>

	[[alternative HTML version deleted]]

