r – Error in file(file, rt) : invalid description argument in complete.cases program

r – Error in file(file, rt) : invalid description argument in complete.cases program

Its hard to tell without a completely reproducible example, but I suspect your problem is this line:

path<-paste(directory,/,id,.csv,sep=)

id here is a vector, so path becomes a vector of character strings, and when you call read.csv youre passing it all the paths at once instead of just one. Try changing the above line to

path<-paste(directory,/,id[i],.csv,sep=)

and see if that works.

It seems you have a problem with your file path.
You are passing the full vector id =c(1:332) to the file path name.
If your files are named 1.csv, 2.csv, 3.csv, etc..
You can change this line:

path<-paste(directory,/,id,.csv,sep=)

to

path<-paste(directory,/,i,.csv,sep=)

and leave out or rework the id input of your function.

r – Error in file(file, rt) : invalid description argument in complete.cases program

Instead of using a for to read the data in, you can try sapply. For example

mydata <- sapply(path, read.csv).

Since path is a vector, sapply will iterate the vector and apply read.csv to it. Therefore, there will be no need for the for loop and your code will be much cleaner.

From there you will have a matrix which each of your files and their respective information from which you can extract the observations.

To find the observations, you can do mydata[2,1][[1]]. Remember that the rows will be your factors and your columns will be your files.

Leave a Reply

Your email address will not be published.