-1

I am trying to perform the following:

Analyse_Store <- function("x"){
 datapaste"x" <- read.table(file = "x".txt, sep=";", header = TRUE)
    }

So basically I am trying to read a table named "x" and assign it to the name datapaste"x" unfortunately this does not work as expected and I cannot find any help online. Thanks in advance

Raphael
  • 106
  • 7
  • 4
    That `function("x")` isn't valid R. Is that an argument named `x`? – Spacedman Jan 23 '17 at 21:13
  • 4
    Read it into a list. See gregor's answer to [this post](http://stackoverflow.com/questions/17499013/how-do-i-make-a-list-of-data-frames) for a discussion and tips. – lmo Jan 23 '17 at 21:14
  • 4
    Yup - you really should read into a list instead. I won't downvote the current answers since they aren't "wrong". But they're wrong. – Dason Jan 23 '17 at 21:51

1 Answers1

0

Use assign to read table into the variable named x.

The following function will take argument x and assign x.txt from working directory to a variable x inside the function.

Analyse_Store <- function(x){
        assign(paste("datapaste",x,sep=""), read.table(file = paste(x,".txt",sep=""), sep=";", header = TRUE))
}

Usage would be

datapastex = Analyse_Store("x")

Unless you are further processing the table inside the function, I don't see much use for a function in this case. You could just do

datapastex = read.table(file = "x.txt", sep=";", header = TRUE)
d.b
  • 29,772
  • 5
  • 24
  • 63