[R] Help in error removal

David Winsemius dwinsemius at comcast.net
Tue Jul 12 15:32:10 CEST 2011


On Jul 12, 2011, at 7:27 AM, Mitra, Sumona wrote:

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

You see to think there is a "++" operation in R. That is not so.

> 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 do not understand what that means. You should offer either a minimal  
dataset or at the very least the results of str(a).

>
> I uploaded the data frame as "a":-

If by that you mean you made a failed effort at attaching the data in  
a file, then you need to read the Posting Guide for what the server  
will accept as a file type.

>
> a <- read.csv("a.csv", header= TRUE, row.names=1)
>
> and then I started the script:-
>
> pearson <- function(a){
> r <- matrix[x,y]
> for(x in as.vector(a[,1], mode="double")){

I do not see a need for as.vector here or at any point later.  a[,1]  
would already be a vector and if it is not numeric to begin with, then  
you are going to get junk.

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

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list