name_masked
name_masked

Reputation: 9793

Appending column to a data frame - R

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)

Upvotes: 3

Views: 2726

Answers (2)

joran
joran

Reputation: 173697

I would suggest simply subsetting the data frame you get back from the RODBC call. Something like:

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)]

Upvotes: 2

Blue Magister
Blue Magister

Reputation: 13363

dfBlank[1:nrow(dfWithData),"start"] <- dfWithData$start

Upvotes: 2

Related Questions