I want to read files with extension .output with the function read.table. I used pattern=".output" but its'not correct. Any suggestions?
Asked
Active
Viewed 349 times
0
-
3please share the exact command you are using to load the data. The function `read.table` has no `pattern` argument. – zelite Mar 02 '20 at 19:50
-
is there something i can use to read files with a specific extension with read.table function? – tskir93 Mar 02 '20 at 19:56
-
1Does this answer your question? [Opening all files in a folder, and applying a function](https://stackoverflow.com/questions/9564489/opening-all-files-in-a-folder-and-applying-a-function) – zelite Mar 02 '20 at 20:27
-
i still getting an empty list file so maybe the problem is on the address of the folder. – tskir93 Mar 02 '20 at 20:43
2 Answers
0
As an example, heres how you could read in files with the extension ".output" and create a list of tables
list.filenames <- list.files(pattern="\\.output$")
trialsdata <- lapply(list.filenames,read.table,sep="\t")
or if you just want to read them one at a time manually just include the extention in the filename argument.
read.table("ACF.output",sep=...)

Daniel O
- 4,258
- 6
- 20
-
i have already set my work directory as setwd("./data"). The files i want are in the same folder but with the above commands i am getting an empty list. – tskir93 Mar 02 '20 at 20:04
-
when setting the WD you need the full file path setwd("C:\\Users\\username\\folder") or setwd("C:/Users/username/folder") – Daniel O Mar 02 '20 at 20:08
-
@tskir93 check your working directory is what you think it is using `getwd()` – rg255 Mar 03 '20 at 09:26
-
just try list.files() and all files in the folder will be listed. If they don't then you have not properly set up your working directory. – Daniel O Mar 03 '20 at 20:22
0
So finally because i didn't found a solution(something is going wrong with my path) i made a text file including all the .output files with ls *.output > data.txt
.
After that using :
files = read.table("./data.txt")
i am making a data.frame including all my files and using
files[] <- lapply(files, as.character)
Finally with test = read.table(files[i,],header=F,row.names=1)
we could read every file which is stored in i (i = no of line).