函式名
功能例子
例子效果
print()
列印print ( "hello world")
"hello world"
c()把多個向量拼成陣列
[1] "red" "green"
[1] "character"
list()
組合出列表變數
list1<-list(c(2,5,3),21.3,sin); print(list1)
[[1]]
[1] 2 5 3
[[2]]
[1] 21.3
[[3]]
function (x) .primitive("sin")
matrix()
生成 矩陣型 變數
m=matrix(c('a','a','b'),nrow=2,ncol=3,byrow=true); print(m)
[,1] [,2] [,3]
[1,] "a" "a" "b"
[2,] "a" "a" "b"
if() {}
決策x<-30l; if(is.integer(x))
"x is an integer"
if() {} else {}
決策if ... else if ... else
決策switch(exp , case1, case2, case3...)
決策x<-switch(3,"one","two","three"); print(x)
"three"
repeat }
迴圈v <- c("hello","loop") cnt <- 2 repeat }
[1] "hello" "loop"
[1] "hello" "loop"
[1] "hello" "loop"
[1] "hello" "loop"
while
一次又一次地執行相同的**,直到滿足停止條件
while (exp)
v <- c("hello","while loop") cnt <- 2 while (cnt < 7)
[1] "hello" "while loop"
[1] "hello" "while loop"
[1] "hello" "while loop"
[1] "hello" "while loop"
[1] "hello" "while loop"
forfor (exp)
v <- letters[1:4]; for ( i in v)
[1] "a"
[1] "b"
[1] "c"
[1] "d"
cbind()
連線多個向量,每個向量為一列
city <- c("tampa","seattle","hartford","denver")
state <- c("fl","wa","ct","co")
zipcode <- c(33602,98104,06161,80294)
addresses <-cbind(city,state,zipcode); print(address)
city state zipcode
[1,] "tampa" "fl" "33602"
[2,] "seattle" "wa" "98104"
[3,] "hartford" "ct" "6161"
[4,] "denver" "co" "80294"
rbind()
上下合併兩個資料幀 (類似 sql 的union all)
city <- c("tampa","seattle","hartford","denver")
state <- c("fl","wa","ct","co")
zipcode <- c(33602,98104,06161,80294)
all.addresses <- rbind(addresses,addresses); print(all.addresses)
city state zipcode
[1,] "tampa" "fl" "33602"
[2,] "seattle" "wa" "98104"
[3,] "hartford" "ct" "6161"
[4,] "denver" "co" "80294"
[5,] "tampa" "fl" "33602"
[6,] "seattle" "wa" "98104"
[7,] "hartford" "ct" "6161"
[8,] "denver" "co" "80294"
merge()
合併兩個資料幀,資料幀必須具有相同的列名,在其上進行合併
swift 函式語法 格式
import uikit swift中函式的格式如下 func 函式名 引數列表 返回值型別 func 是關鍵字,多個引數列表之間使用逗號隔開,也可以沒有引數 使用箭頭 指向返回值型別 如果函式沒有返回值,返回值為void,並且 可以省略 1沒有引數沒有返回值的方法 func about1 void...
Python 常用函式,語法
這裡記錄一些我用python深度學習的七七八八常用函式或者小技巧啥啥的吧 畢竟好記性不如爛筆頭 嗯 會再更噠 1.strip string1.strip string2 一句話來說就是去除字串string1裡面包含的字串行string2 str 00000003210runoob0123000000...
筆記 TypeScript函式語法
宣告方式function 函式名 資料型別let 函式名 function 資料型別function 函式名 引數1 資料型別,引數2 資料型別 返回值資料型別function 函式名 引數1 資料型別,引數2 資料型別 返回值資料型別function 函式名 引數1 資料型別,引數2 資料型別 預...