[R] how to make a series with decimal increment

Gavin Simpson gavin.simpson at ucl.ac.uk
Wed Jun 14 18:44:00 CEST 2006


On Tue, 2006-06-13 at 05:24 +0000, anil kumar rohilla wrote:
>   Hi List, 
>        I am new to this Rsoftware, i want to make a sereis for example
> which is having values like this, s<- 0,0.1,0.2,0.3,0.4........,1  
> 
> i tryed this statement 
> s<-0:0.1:1
> but this giving an error megssage.
>  but by default increment 1 it is taking ,,,,,so what to do ,,
> 
> i want to use this varible in for loop..
> 
> like for(j in s)
> 
> thanks in advance
> 
> with regards
> anil kumar

Hi Anil,

see ?seq for the solution, which is:

s <- seq(0, 1, by = 0.1)
for(i in s) {
  print(i)
}

if you need the sequence for something else, if not:

for(i in seq(0, 1, by = 0.1)) {
  print(i)
}

Note the braces "{" & "}" are superfluous here but you'll need them if
you are doing anything more complicated in your loop.

HTH

G

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
*  Note new Address, Telephone & Fax numbers from 6th April 2006  *
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Gavin Simpson
ECRC & ENSIS                  [t] +44 (0)20 7679 0522
UCL Department of Geography   [f] +44 (0)20 7679 0565
Pearson Building              [e] gavin.simpsonATNOSPAMucl.ac.uk
Gower Street                  [w] http://www.ucl.ac.uk/~ucfagls/cv/
London, UK.                   [w] http://www.ucl.ac.uk/~ucfagls/
WC1E 6BT.
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



More information about the R-help mailing list