jeudi 23 avril 2015

R: Return a data frame to the workspace, and name it from a function argument

I want to create a data frame within in a function and return it to the workspace, but additionally to be able to name that data frame each time I call that function (by passing a text string as function argument). Below is my best guess but doesn't do it.

func = function(named.df = "NA"){
  df <- data.frame(c(1,2,3), c('a','b','c'))
  assign(named.df, df)
}

func("my.data.frame")

Aucun commentaire:

Enregistrer un commentaire