Skip to content

Instantly share code, notes, and snippets.

@maromato
Created February 14, 2016 05:07
Show Gist options
  • Save maromato/8c329e7e848489ea072c to your computer and use it in GitHub Desktop.
Save maromato/8c329e7e848489ea072c to your computer and use it in GitHub Desktop.
Input multiple files from the folder into one data table
#making a list of the files in the folder "est"
estDataFiles <- list.files("est", pattern = "\\.txt$", full.names=TRUE)
estDataFiles
#inpu the files
listoftables <- lapply(estDataFiles, read.table, header=T, sep="\t")
names(listoftables) <- estDataFiles
#confirmation
head(listoftables[[1]])
length(names(listoftables))
head(listoftables[[1]][,1])
head(listoftables[[1]][,2])
head(listoftables[[1]][,3])
head(listoftables[[1]][,4])
#making a matrix file consists of column for gene expression data (column 4)
i=1
x <- NULL
for (i in 1:length(names(listoftables))) x <- cbind(x,listoftables[[i]][,4])
head(x)
rownames(x) <-listoftables[[1]][,1]
colnames(x)<-estDataFiles
#confirmation
head(x)
#writing a table
write(x, file="summary_est.txt",sep="\t")
ranking <- rank(x[,9])
obj <- nrow(x)-51 < ranking
x[obj,]
x <- read.table("summary_est_mod.txt",header=T,sep="\t")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment