Hi everyone!
I have a time series data in a sub-folder under a big folder. The file format is in txt file. The Directory is as follow:
C:/.../.../Astation/2018/L1_0101_0601_A.txt
C:/.../.../Astation/2018/L1_0101_0603_A.txt
C:/.../.../Astation/2018/L1_0101_0605_B.txt
.
.
and so on.
Firstly, I prepared the files for the analysis as follow:
library(stringr)
library(readr)
> parent.folder <-"C:/.../.../AStation/2018"
> sub.folders <- list.dirs(parent.folder, recursive=TRUE)[-1]
> r.scripts <- file.path(sub.folders)
> AStation_2018 <- list()
> for (j in seq_along(r.scripts)) {
> AStation_2018[[j]] <- dir(r.scripts[j],"\\.txt$")}
Until here, it is okay. After that, I would like to construct the dataframe using the file name in one column and values in txt file in another column.
For that, I start to row bind the files as follow:
> for (i in 1:length(AStation_2018)) {
> for (j in 1:length(AStation_2018[[i]])){
> files_com <- dir(".", pattern = ".txt$")
>
> AStation_2018_com <- rbindlist(sapply(AStation_2018[i], fread, simplify = FALSE), idcol = "file")
>
> }
> }
OR
for (i in 1:length(AStation_2018)) {
#print(i)
#print(AStation_2018[[i]])
#print(AStation_2018[[i]][1])
for (j in 1:length(AStation_2018[[i]])){
#print(length(AStation_2018[[i]]))
#print(AStation_2018[[i]][j])
#filename <- paste(str_sub(AStation_2018[[i]][j], 1, 14), j, sep= "_")
filename <- paste(str_sub(AStation_2018[[i]][j], 1, 14))
#print(filename)
complete_file_name = paste(r.scripts[i],'/', AStation_2018[[i]][j], sep="" )
#print(complete_file_name)
assign(filename, read_tsv(complete_file_name, skip = 14, col_names = FALSE))
}
}
But I couldn't perform this code. Is there any problem in my code?