[R] numeric(0)

Liaw, Andy andy_liaw at merck.com
Wed Dec 29 14:54:34 CET 2004


`names' is a builtin R function for extracting names of elements in a
vector, or names of components in a list.  If I use

nm <- c("A","C","G","T")
rownames(mscore) <- colnames(mscore) <- nm

I don't get any error.

Andy

> From: dax42
> 
> Dear all,
> 
> I am trying to calculate a score for a string sequence consisting of 
> the following four letters: ACGT.
> I have got a matrix giving the scores for each pair of letters.
> So for example the string ACCT has got the pairs: AC, CC and CT.
> 
> The matrix has got the following form:
> names<-c("A","C","G","T");
> mscore<-matrix(0,4,4);
> rownames(mscore)<-names;
> colnames(mscore)<-names;
> 
> So for the first example pair above I could get the score 
> contained in 
> the matrix with the following code:
>  >> mscore["A","C"]
> 
> I am now trying to sum up all the scores with the following code:
> 
> score<-0;
> 
> for(j in 1:length(sequence)-1){
> 	score<-score+mscore[sequence[j],sequence[j+1]];
> }
> 
> where sequence is the string sequence.
> Unfortunately, it does not work and I get the following error message:
> 
> Error in "[<-"(`*tmp*`, 1, i, value = numeric(0)) :
> 	nothing to replace with
> 
> What does this mean? Strangely, the command
> "print(score+mscore[sequence[j],sequence[j+1]])"
> works, so it really is the assignment which won't work. Why is that?
> I am running R 2.0 series (GUI version) on Mac OSX 10.3.7.
> 
> Any suggestions are welcome.
> Thanks a lot,
> Dax
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
> 
>




More information about the R-help mailing list