I have files that looks like this:
$ head -n3 *.full.tsv
==> XOX.full.tsv <==
Probe Index Gene Symbol log2(FC) pval CV
1427747_a_at Lcn2 5.205 1.098e-02 0.455
1449326_x_at Saa2 4.585 3.614e-04 0.788
==> QUX.full.tsv <==
Probe Index Gene Symbol log2(FC) pval CV
1450783_at Ifit1 5.820 2.564e-02 0.256
1421008_at Rsad2 5.631 4.781e-02 0.292
==> FOO.full.tsv <==
Probe Index Gene Symbol log2(FC) pval CV
1434719_at A2m 7.823 1.753e-02 0.415
1427747_a_at Lcn2 6.696 4.255e-03 0.455
==> BAR.full.tsv <==
Probe Index Gene Symbol log2(FC) pval CV
1449647_at --- 2.227 5.194e-02 0.744
1455889_at Far2 2.210 7.342e-02 0.406
What I want to do then is to glob the files and combine them into single melted data frame that looks like this:
Filename Probe Index Gene Symbol log2(FC) pval CV
XOX 1427747_a_at Lcn2 5.205 1.098e-02 0.455
XOX 1449326_x_at Saa2 4.585 3.614e-04 0.788
QUX 1450783_at Ifit1 5.820 2.564e-02 0.256
QUX 1421008_at Rsad2 5.631 4.781e-02 0.292
FOO 1434719_at A2m 7.823 1.753e-02 0.415
FOO 1427747_a_at Lcn2 6.696 4.255e-03 0.455
BAR 1449647_at --- 2.227 5.194e-02 0.744
BAR 1455889_at Far2 2.210 7.342e-02 0.406
I tried this but doesn't give what I want
infiles <- paste("./","*.*.*.full.tsv",sep="")
dataFiles <- lapply(Sys.glob(infiles), read.table,sep="\t",header=TRUE,check.names=FALSE )
tmp <- do.call(rbind,dataFiles)
head(tmp)
Where I still cannot capture the file name:
Probe Index Gene Symbol log2(FC) pval CV
1 1427747_a_at Lcn2 5.205 1.098e-02 0.455
2 1449326_x_at Saa2 4.585 3.614e-04 0.788
How should I go about it?