Is it possible to append a column to data frame in the following scenario?
在以下场景中,是否可能将列附加到数据帧?
dfWithData <- data.frame(start=c(1,2,3), end=c(11,22,33))
dfBlank <- data.frame()
..how to append column start
from dfWithData
to dfBlank
?
. .如何将列从dfWithData添加到dfBlank?
It looks like the data should be added when data frame is being initialized. I can do this:
看起来应该在初始化数据帧时添加数据。我可以这样做:
dfBlank <- data.frame(dfWithData[1])
but I am more interested if it is possible to append columns to an empty (but inti)
但是我更感兴趣的是是否可以将列附加到空(但inti)
2 个解决方案
#1
2
I would suggest simply subsetting the data frame you get back from the RODBC call. Something like:
我建议简单地将您从RODBC调用中返回的数据帧进行子设置。喜欢的东西:
df[,c('A','B','D')]
perhaps, or you can also subset the columns you want with their numerical position, i.e.
也许,或者你也可以用它们的数值位置来子集你想要的列,也就是。
df[,c(1,2,4)]
#2
1
dfBlank[1:nrow(dfWithData),"start"] <- dfWithData$start
#1
2
I would suggest simply subsetting the data frame you get back from the RODBC call. Something like:
我建议简单地将您从RODBC调用中返回的数据帧进行子设置。喜欢的东西:
df[,c('A','B','D')]
perhaps, or you can also subset the columns you want with their numerical position, i.e.
也许,或者你也可以用它们的数值位置来子集你想要的列,也就是。
df[,c(1,2,4)]
#2
1
dfBlank[1:nrow(dfWithData),"start"] <- dfWithData$start