3

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?

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)

4

2 回答 2

2

我建议简单地对从 RODBC 调用返回的数据框进行子集化。就像是:

df[,c('A','B','D')]

也许,或者你也可以用它们的数字位置对你想要的列进行子集化,即

df[,c(1,2,4)]
于 2012-08-28T17:46:13.240 回答
2
dfBlank[1:nrow(dfWithData),"start"] <- dfWithData$start
于 2012-08-28T15:12:49.937 回答