开发者

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

开发者 https://www.devze.com 2023-02-05 10:37 出处:网络
This question already has an answer here: Pass arguments to function (1开发者_高级运维 answer) Closed 1 year ago.
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

精彩评论

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