📜  在 R 编程中打印到屏幕或文件 - cat()函数

📅  最后修改于: 2022-05-13 01:54:21.730000             🧑  作者: Mango

在 R 编程中打印到屏幕或文件 - cat()函数

R 语言中的cat()函数用于打印到屏幕或文件。

示例 1:

Python3
# R program to illustrate
# cat function
 
# Creating some string and print it
x <- "GeeksforGeeks\n"
y <- "Geeks\n"
 
# Calling cat() function
cat(x)
cat(y)
 
# Creating a sequence from 1 to 9
x <- 1:9
 
# Calling cat() function
cat(x, sep =" + ")
cat("\n")
cat(x, sep =" / ")


Python3
# R program to illustrate
# cat function
 
# Creating a sequence from 1 to 9
x <- 1:9
 
# Calling cat() function
 
# fill value TRUE will print
# a new line
cat(x, sep =" + ", fill = TRUE)
cat(x, sep =" / ", fill = FALSE)
 
# Printing new line
cat("\n")
 
# Each number from 1 to 9 will be
# assigned with alphabets a to i
cat(x, fill = 2, labels = paste("(", letters[1:9], "):"))


输出:

GeeksforGeeks
Geeks
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9
1 / 2 / 3 / 4 / 5 / 6 / 7 / 8 / 9

示例 2:

Python3

# R program to illustrate
# cat function
 
# Creating a sequence from 1 to 9
x <- 1:9
 
# Calling cat() function
 
# fill value TRUE will print
# a new line
cat(x, sep =" + ", fill = TRUE)
cat(x, sep =" / ", fill = FALSE)
 
# Printing new line
cat("\n")
 
# Each number from 1 to 9 will be
# assigned with alphabets a to i
cat(x, fill = 2, labels = paste("(", letters[1:9], "):"))        

输出:

1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9
1 / 2 / 3 / 4 / 5 / 6 / 7 / 8 / 9
( a ): 1 
( b ): 2 
( c ): 3 
( d ): 4 
( e ): 5 
( f ): 6 
( g ): 7 
( h ): 8 
( i ): 9