在data.frame中的两列之间添加列 [英] Adding a column between two columns in a data.frame

查看:223
本文介绍了在data.frame中的两列之间添加列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据框,列有a,b和c。我想在b和c之间添加一个新的列d。我知道我可以通过使用cbind添加d,但是如何将它插入两列之间?

解决方案

只是一个R初学者,但我认为这也可以:



添加到您的新列中:

  df $ d<  -  list / data 

然后你可以重新排序。

  df<  -  df [,c(a,b,d,c)] 


I have a data frame that has columns a, b, and c. I'd like to add a new column d between b and c. I know I could just add d at the end by using cbind but how can I insert it in between two columns?

解决方案

Just an R beginner, but I think this also works:

Add in your new column:

df$d <- list/data

Then you can reorder them.

df <- df[,c("a","b","d","c")]

这篇关于在data.frame中的两列之间添加列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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