簡體   English   中英

將列名作為參數傳遞給R語言中的函數

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

我有一個功能:

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

請進一步指導。 謝謝:)

您需要使用另一種方式來訪問數據框中的列,而不是通過$ 還有另外兩種方式:

1。

print(content[[param]])

2。

print(content[,param])

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM