Hi,

it's true, simply adding the parenthesis does the trick.
Anyways, I am trying to do it without the loop now.

Thanks for helping out!
Cheers, Dax

Am 29.12.2004 um 14:45 schrieb (Ted Harding):

On 29-Dec-04 dax42 wrote:
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

You've fallen into a classic trap: 1:length(sequence)-1 does not mean what one might naturally expect.

sequence<-(1:10)
length(sequence)
[1] 10
1:length(sequence)-1
[1] 0 1 2 3 4 5 6 7 8 9
1:(length(sequence)-1)
[1] 1 2 3 4 5 6 7 8 9

In other words, "1:length(sequence)" is constructed first, then
1 is subtracted from every element. As a result, you tried to
read from sequence[0], which isn't there.

However, you can make it evaluate "length(sequence)-1" before
constructing 1:(length(sequence)-1), by using the parantheses
to force precedence.

Cheers,
Ted.


-------------------------------------------------------------------- E-Mail: (Ted Harding) <[EMAIL PROTECTED]> Fax-to-email: +44 (0)870 094 0861 [NB: New number!] Date: 29-Dec-04 Time: 13:45:25 ------------------------------ XFMail ------------------------------

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html



______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to