1. 程式人生 > >R語言的輸出:cat() print() paste() 輸入:scan() readline()

R語言的輸出:cat() print() paste() 輸入:scan() readline()

 

x=3
print(x)
paste("x=",x)
cat("x=",x)
cat("x=",x,sep = "") #預設的分隔符是空格

#paste( ,sep=" ",collapse=NULL)向量轉化為字元並連線
#sep:分割組的字串 collapse:可選的字串分割結果串

#paste( ,sep=" ",collapse=NULL)向量轉化為字元並連線
#sep:分割組的字串 collapse:可選的字串分割結果串
paste(1:9,c("st","nd","rd",rep("th",6)))
paste(1:9,c("st","nd","rd",rep("th",6)),sep = "?")
paste(1:9,c("st","nd","rd",rep("th",6)),collapse = ",")#預設的分隔符是空格
paste(1:9,c("st","nd","rd",rep("th",6)),sep = "",collapse = ",")

 

#cat( ... , file = "", sep = " ", fill = FALSE, labels = NULL,append = FALSE)
#file:一個檔案連結或檔名,若不寫則表示輸出到控制檯;
#sep:分隔符
#append:是否追加,當且晉檔引數file是檔名而非連結時,此引數才有效

cat(c("AB","C"),c("E","F"),"n",sep = '/')
print(c("AB","C"))

#cat( ... , file = "", sep = " ", fill = FALSE, labels = NULL,append = FALSE)
#file:一個檔案連結或檔名,若不寫則表示輸出到控制檯;
#sep:分隔符
#append:是否追加,當且晉檔引數file是檔名而非連結時,此引數才有效

 

關於輸入:scan() 與 readline()

> x=scan()
1: 6
2: 9
3: 11
4: 19
5: 
Read 4 items
> x
[1]  6  9 11 19
> y=readline()#只能輸入一行
11
> y
[1] "11"