Basic mathematical operations in R-console
Quotient:
syntex divident/divisor=quotient
Ex. > 7/2
[1] 3.5
Integral quotient:
syntex divident%/%divisor=integral quotient
Ex.
> 7%/%2
[1] 3
Remainder:
syntex divident%%divisor=remainder
Ex.
> 10%%3
[1] 1
Length of a string
syntex length('var')
Ex.
> x=seq(1,9,0.5)
> x
[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 8.5 9.0
> length(x)
[1] 17
Repeat n times a set of data
syntex new _var=rep(existing_var, c(n))
Ex.
> y=rep(x,c(5))
> y
[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 8.5 9.0 1.0 1.5
[20] 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 8.5 9.0 1.0 1.5 2.0 2.5
[39] 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 1.0 1.5 2.0 2.5 3.0 3.5
[58] 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5
[77] 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0
> length(y)
[1] 85
Quotient:
syntex divident/divisor=quotient
Ex. > 7/2
[1] 3.5
Integral quotient:
syntex divident%/%divisor=integral quotient
Ex.
> 7%/%2
[1] 3
Remainder:
syntex divident%%divisor=remainder
Ex.
> 10%%3
[1] 1
Length of a string
syntex length('var')
Ex.
> x=seq(1,9,0.5)
> x
[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 8.5 9.0
> length(x)
[1] 17
Repeat n times a set of data
syntex new _var=rep(existing_var, c(n))
Ex.
> y=rep(x,c(5))
> y
[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 8.5 9.0 1.0 1.5
[20] 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 8.5 9.0 1.0 1.5 2.0 2.5
[39] 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 1.0 1.5 2.0 2.5 3.0 3.5
[58] 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5
[77] 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0
> length(y)
[1] 85
No comments:
Post a Comment