我在下面有一个示例数据框:
df <- data.frame(ID=c("131","156","178","196"), Date=c("03/31/2016","03/31/2016","03/31/2016","03/31/2016"))
df
ID Date
1 131 03/31/2016
2 156 03/31/2016
3 178 03/31/2016
4 196 03/31/2016
我想在此数据框中添加一个新列,其格式如下:=BDH("ID CUSIP", "PX_Last","Date")
。新数据框应如下所示:
ID Date NewCol
1 131 03/31/2016 =BDH("131 CUSIP", "PX_Last", "03/31/2016")
2 156 03/31/2016 =BDH("156 CUSIP", "PX_Last", "03/31/2016")
3 178 03/31/2016 =BDH("178 CUSIP", "PX_Last", "03/31/2016")
4 196 03/31/2016 =BDH("196 CUSIP", "PX_Last", "03/31/2016")
如您所见,ID
和Date
来自现有数据框,但CUSIP
和PX_Last
不是。请帮助,谢谢!
答案 0 :(得分:2)
这样可以吗?
df$NewCol <- paste0("=BDH(\"", df$ID, " CUSIP\", \"PX_Last\", \"", df$Date, "\")")