开发者

Passing column name as parameter to function in R language [duplicate]

This question already has an answer here: Pass arguments to function (1开发者_高级运维 answer) Closed 1 year ago.

I have got a function :

aggreg <- function(fileName, param){   
  contents <- read.csv(fileName, header=T)
  #print(contents)  #This displays all contents
  print(contents$param) #gives NULL
}

> aggreg("test.csv","Close.Price")
> NULL

Please guide further. Thanks:)


you need to use another way of accessing the columns in the dataframe than via $. There are two other ways:

1.

print(content[[param]])

2.

print(content[,param])
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜