如何在R中用每个条目的多个值拆分数值向量

如何在R中用每个条目的多个值拆分数值向量,r,vector,numeric,R,Vector,Numeric,我运行了“预测”函数,从R中的逻辑回归中得到结果。结果似乎是一个数字向量,但每个条目有两个值。我想把它放到一个2列的数据框中,但我不知道怎么做。 以下是数据的一些背景: head(fitted.results) 1 2 3 4 5 6 0 0 0 0 0 0 class(fitted.results) [1] "numeric" tail(fitted.results) 413 414 415 416 417 418 0 NA 1 0 NA NA len

我运行了“预测”函数,从R中的逻辑回归中得到结果。结果似乎是一个数字向量,但每个条目有两个值。我想把它放到一个2列的数据框中,但我不知道怎么做。 以下是数据的一些背景:

 head(fitted.results)
 1 2 3 4 5 6 
 0 0 0 0 0 0 
 class(fitted.results)
 [1] "numeric"
 tail(fitted.results)
 413 414 415 416 417 418 
  0  NA   1   0  NA  NA 
 length(fitted.results)
  418
 fitted.results[1]
 1 
 0 
它似乎属于数值类,但每个“行”有两个条目,尽管这可能不是正确的术语。因此,当我强制一个数据帧时,它只有一列。我尝试使用行数为418的“矩阵”,但得到的是相同的1列。例如:

d <- matrix(fitted.results, nrow = 418, byrow = TRUE)
d我同意:

library(data.table)
x <- rnorm(15)
y <- x + rnorm(15)
pr<-predict(lm(y ~ x))
dt<-data.table(No=names(pr),pr)

       No         pr
    1:  1  2.3247191
    2:  2  0.5848808
    3:  3  2.3866168
    4:  4 -1.0213651
库(data.table)

x无法判断,因为您没有提供可复制的代码,但它看起来像一个命名向量?因此,请尝试
cbind(名称(fitted.results),fitted.results)
。完美!正是我想要的。@DougC请确保在您的初始请求中添加尽可能多的信息。很乐意帮忙