R - Colon (:) Operator - Sequence generator

Card Puncher Data Processing

About

The Colon (:) Operator generate regular sequences.

Usage

from:to  # sequence
a:b      # cross of factor

where:

  • from, starting value of sequence and to: (maximal) end value of the sequence.
  • a, b factors of the same length.

Example

Integer Sequence

> 1:4
[1] 1 2 3 4
> 6:pi
[1] 6 5 4

Real Sequence

> pi:6
[1] 3.141593 4.141593 5.141593

“cross” factor

> f1 <- gl(2, 3); f1
[1] 1 1 1 2 2 2
Levels: 1 2
> f2 <- gl(3, 2); f2
[1] 1 1 2 2 3 3
Levels: 1 2 3
> f1:f2 # a factor, the "cross"  f1 x f2
[1] 1:1 1:1 1:2 2:2 2:3 2:3
Levels: 1:1 1:2 1:3 2:1 2:2 2:3

Documentation / Reference

?":"
help(":")





Discover More
Card Puncher Data Processing
R - (Mathematical|Logical) Operators

& boolean and | boolean for xor exactly or ! not any any true all all true Not (!) Many operations in R are vectorized. < Less than > Greater than == Equal to <= Less than or equal...
R Elipse
R - Data Generator

where: See also:
Card Puncher Data Processing
R - Integer

The integer class Numeric format is the default number system. If you explicitly want an integer, you need to specify it with the Lsuffix. When using the combine function, integer must be also...
Card Puncher Data Processing
R - Special Character

R - Special Character



Share this page:
Follow us:
Task Runner