for (i in 1:10){print(i)}
## [1] 1
## [1] 2
## [1] 3
## [1] 4
## [1] 5
## [1] 6
## [1] 7
## [1] 8
## [1] 9
## [1] 10
for(i in seq(0, 30, 6)){
print(i)
}
## [1] 0
## [1] 6
## [1] 12
## [1] 18
## [1] 24
## [1] 30
newdata=NULL
for (i in 1:10){newdata[i]=i}
newdata
##  [1]  1  2  3  4  5  6  7  8  9 10
str(newdata)
##  int [1:10] 1 2 3 4 5 6 7 8 9 10
afun=function(x){x^3+3*x+20}
afun(newdata)
##  [1]   24   34   56   96  160  254  384  556  776 1050
lapply(newdata,afun)
## [[1]]
## [1] 24
##
## [[2]]
## [1] 34
##
## [[3]]
## [1] 56
##
## [[4]]
## [1] 96
##
## [[5]]
## [1] 160
##
## [[6]]
## [1] 254
##
## [[7]]
## [1] 384
##
## [[8]]
## [1] 556
##
## [[9]]
## [1] 776
##
## [[10]]
## [1] 1050
str(lapply(newdata,afun))
## List of 10
##  $: num 24 ##$ : num 34
##  $: num 56 ##$ : num 96
##  $: num 160 ##$ : num 254
##  $: num 384 ##$ : num 556
##  $: num 776 ##$ : num 1050
bfun=function(x,y){x*x*y+10}
bfun(1,2)
## [1] 12
afun(1)
## [1] 24
ls()
## [1] "afun"    "bfun"    "i"       "newdata"
rm(afun)
rm(list = ls())
avector=c(1,2,3,10,20)

bvector=c(10,20,30)

avector+bvector
## Warning in avector + bvector: longer object length is not a multiple of
## shorter object length
## [1] 11 22 33 20 40
bvector*avector
## Warning in bvector * avector: longer object length is not a multiple of
## shorter object length
## [1]  10  40  90 100 400
avector/bvector
## Warning in avector/bvector: longer object length is not a multiple of
## shorter object length
## [1] 0.1 0.1 0.1 1.0 1.0