On Tue, Apr 7, 2009 at 8:13 AM, Melissa2k9 <m.mcquil...@lancaster.ac.uk>wrote:
> > I am trying to make a sequence and am using a for loop for this. I want to > start off with an initial value ie S[0]=0 then use the loop to create other > values. This is what I have so far but I just keep getting error messages. > R only allows positive integer subscripts, and defines s[0] as the empty vector. You might think that assigning to an empty vector would give an error, but R semantics say instead that this is a no-op. This is so that things like s[ <<some boolean condition>> ] <- value will assign the value to all elements of s meeting the condition -- while allowing for the possibility that none of them meet that condition. If you try to assign to an illegal individual element, however, you do get an error: s[[0]] <- 45 # gives an error R's subscripting semantics are very convenient for many operations, but do take some getting used to. -s [[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.