📌  相关文章
📜  在 R 编程中将数字对象转换为字符- as。字符()函数

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

在 R 编程中将数字对象转换为字符- as。字符()函数

R 语言中的as.character()函数用于将数字对象转换为字符对象。

示例 1:

# R program to convert a numeric object
# to character object
  
# Calling as.character() function
as.character(1)
as.character(2 + 3)
as.character(1.5)

输出:

[1] "1"
[1] "5"
[1] "1.5"

示例 2:

# R program to convert a numeric object
# to character object
  
# Creating a vector
x1 <- c(1, 2, 3, 4)
x2 <- c(-1, 2, 1.5, -3)
  
# Calling as.character() function
as.character(x1)
as.character(x2)

输出:

[1] "1" "2" "3" "4"
[1] "-1"  "2"   "1.5" "-3"