r语言添加一列数据的方法有哪些

lewis 2016-08-17 18次阅读

在R语言中,添加一列数据的方法有以下几种:

  1. 使用$操作符向数据框中添加新列,例如:
dataframe$new_column <- new_data
  1. 使用transform()函数向数据框中添加新列,例如:
dataframe <- transform(dataframe, new_column = new_data)
  1. 使用mutate()函数来添加新列,例如:
library(dplyr)
dataframe <- dataframe %>% mutate(new_column = new_data)
  1. 使用cbind()函数将新列添加到数据框中,例如:
dataframe <- cbind(dataframe, new_column = new_data)


发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。