I have several matlab files which I need to read in R, and combine them into a single text file for further analysis. Each matlab file has 3 columns, and a different number of rows. Each column represents a numeric parameter to describe a single cell, and each row in an observation at a different time point.
I attempted using the code below, but the problem is it combines all rows of a matlab file into columns in the combined file, ruining the order of data. An example to illustrate this is here Of course entries of this example are just to explain the idea.
Current code:
setwd("C:/Users/Administrator/Documents") #define directory with all files to be combined
library(R.matlab) #load the library needed to read matlab files
all_files = list.files() #list all files in that directory
dataFiles = lapply (all_files, readMat) #read all files in the directory using readMat function
dataFiles_converted <- matrix(unlist(dataFiles), ncol = 3, byrow = FALSE) #list to matrix conversion
write.table(dataFiles_converted,"AllFilesCombined.txt", sep = "\t", row.names = FALSE, col.names = c("parameter1","parameter2","parameter3")) #write all the combined data to a tab delimited text file
Any suggestions of how to edit this code so I get a tidy combined text file?
image to explain: https://ibb.co/fwbnV8