【发布时间】:2021-07-14 18:05:01
【问题描述】:
我使用以下代码创建了一个向量:
vectorA<-c(1.125,2.250,3.501)
我在数据框中存储了另一个向量:
vectordf<-data.frame()
vectordf[1,1]<-'1.125,2.250,3.501'
vectorB<-vectordf[1,1]
我需要vectorB 与vectorA 相同,这样我才能在另一个函数中使用它。现在这两个向量是不同的,如下所示:
printerA<-paste("vectorA=",vectorA)
printerB<-paste("vectorB=",vectorB)
print(printerA)
print(printerB)
dput(vectorA)
dput(vectorB)
[1] "vectorA= 1.125" "vectorA= 2.25" "vectorA= 3.501"
[1] "vectorB= 1.125 2.250 3.501"
c(1.125, 2.25, 3.501)
"1.125 2.250 3.501"
如何将vectorB 转换为与vectorA 相同的格式?我尝试过使用 as.numeric、as.list、as.array、as.matrix。
【问题讨论】:
-
vectorB <- scan(text = '1.125,2.250,3.501', sep = ",")?