将列附加到数据帧 - R [英] Appending column to a data frame - R

查看:66
本文介绍了将列附加到数据帧 - 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()

..如何从 dfWithData 添加列开始 dfBlank

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

但是如果可以将列附加到空(但inti)

but I am more interested if it is possible to append columns to an empty (but inti)

推荐答案

我建议简单地对从RODBC呼叫中获取的数据帧进行子集化。如下:

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

这篇关于将列附加到数据帧 - R的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆