學習重點
查詢資料類型
class(2L)
## [1] "integer"
class(2)
## [1] "numeric"
class(T)
## [1] "logical"
class(Sys.time())#時間類型
## [1] "POSIXct" "POSIXt"
Sys.time()
## [1] "2019-03-04 11:56:25 CST"
class(Sys.Date())
## [1] "Date"
Sys.time()
## [1] "2019-03-04 11:56:25 CST"
a <- 1
b <- 3
sprintf("I want to print %s and %f",a,b)
## [1] "I want to print 1 and 3.000000"
賦值
try<-8
class(try)
## [1] "numeric"
數值
a <- 1
b <- 1.0
c <- 1.2
class(a)
## [1] "numeric"
class(b)
## [1] "numeric"
class(c)
## [1] "numeric"
整數
a <- 1L
b <- 1.0L
c <- 1.2L
class(a)
## [1] "integer"
class(b)
## [1] "integer"
class(c)
## [1] "numeric"
邏輯值
vec<-c(3,4,5)
vec
## [1] 3 4 5
3 %in%vec
## [1] TRUE
數學運算
10%%3
## [1] 1
T+T
## [1] 2
T==1
## [1] TRUE
T==1L
## [1] TRUE
練習題
height <- 176
weight <- 56
print(c(height,weight))
## [1] 176 56
bmi <- weight/(height/100)^2
bmi
## [1] 18.07851