Crating data
using c(...)
> y=c(1,2,3,4,5)
> y
[1] 1 2 3 4 5
use of : for from:to
> x<-1:10
> x
[1] 1 2 3 4 5 6 7 8 9 10
using seq()
> a<-seq(1,10, 0.5); b<-seq(1,10, by =0.5)
> a
[1] 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0
[16] 8.5 9.0 9.5 10.0
> b
[1] 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0
[16] 8.5 9.0 9.5 10.0
> c<-seq(1,10, length=10); d=seq(1,10, length=15) # did I say that "<-" and "=" both assigns value
> c
[1] 1 2 3 4 5 6 7 8 9 10
> d
[1] 1.000000 1.642857 2.285714 2.928571 3.571429 4.214286 4.857143
[8] 5.500000 6.142857 6.785714 7.428571 8.071429 8.714286 9.357143
[15] 10.000000
> f=seq(1,10, by=2); g=seq(1,10, by=3)
> f
[1] 1 3 5 7 9
> g
[1] 1 4 7 10
using rep()
> h=rep(1:5,2); i=rep(1:5, times=2)
> h
[1] 1 2 3 4 5 1 2 3 4 5
> i
[1] 1 2 3 4 5 1 2 3 4 5
> j=rep(1:5, each=2); k=rep(1:5, c(2,3,1,2,2))
> j
[1] 1 1 2 2 3 3 4 4 5 5
> k
[1] 1 1 2 2 2 3 4 4 5 5
> l=rep(1:5, each=3 , times=2)
> l
[1] 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5
> m=rep(1:5, each=2, len=8);n=rep(1:5, each=2, len=12)
> m
[1] 1 1 2 2 3 3 4 4
> n
[1] 1 1 2 2 3 3 4 4 5 5 1 1
use of gl to make factors
> gl(4,5)
[1] 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4
Levels: 1 2 3 4
> gl(4,5, labels=c("A","B","C","D"))
[1] A A A A A B B B B B C C C C C D D D D D
Levels: A B C D
> gl(4,1,20)
[1] 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4
Levels: 1 2 3 4
use of sequence
> sequence(c(8:1))
[1] 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 1 2 3 4 5 6 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1
0 comments:
Post a Comment