On 12 July 2011 12:27, Mitra, Sumona <sumona.mi...@kcl.ac.uk> wrote:

> Dear all,
>
> I am new to programming in R.
>


You sure are ;-)

 I deal with microarray data,which is a data frame object type. I need to
> carry out a few statistical procedures on this, one of them being the
> pearson corelation. I need to do this between each row which is a gene. So
> the desired result is a square matrix with the pearson corelation value
> between each row. So the first column would be (1,1)=0,(1,2),(1,3) and so
> on.
>
> I uploaded the data frame as "a":-
>
> a <- read.csv("a.csv", header= TRUE, row.names=1)
>
> and then I started the script:-
>
> pearson <- function(a){
>  r <- matrix[x,y]
>

I bet the problem you are getting is here. You want r to be a x by y matrix.
To do this, try r<- matrix(nrow=x, ncol=y). But you haven't defined the x
and y, unless we are missing that part of your code.

As I understand it, you want the correlation matrix between all the rows of
your matrix. If so, then look at the help file for cor. (ie type "?cor".)
You will find that it automatically prints the correlatoins between all
columns of a matrix. So, once your data is correctly read in, you should be
able to just do:

cor(t(a))






>  for(x in as.vector(a[,1], mode="double")){
>  x++{
>  for(y in as.vector(a[2,], mode="double")){
>  y <- x+1
>  x++
>

This code looks like a horrible mess. It's almost never right to loop
through your vectors. In addition, there is no such thing as "++", as
somebody mentioned.



>  {
>  r <- (cor.test(as.vector(as.matrix(a)[x,], mode="double"),
> as.vector(as.matrix(a)[y,], mode="double"))$p.value)
>  }
>  }
>  }
>  r[x,y]==r[y,x]
>  }
>  return(r)
>  }
>
> However whenever I run it,I get the error:-
>
> > pearson(a)
> Error in matrix[x, y] : object of type 'closure' is not subsettable
>
> Please help!
>
> Best Regards
> Sumona Mitra
>
> ______________________________________________
> 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]]

______________________________________________
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.

Reply via email to