when running this script on just one file in a folder:
emboss<-read.table("emboss_012.ss",header=T)
x<-table(emboss[,2],emboss[,3])/NROW(emboss[,3])
y<-as.vector(t(x))
nms <- expand.grid(colnames(x), rownames(x))
names(y) <- paste( nms[,2],nms[,1],sep="")
write.table(t(y), file = "test3.csv",append=TRUE)
I get the desired result
However doing this in one go for all files in the folder results in random NA's appearing. I am doing this by:
runForAll <- function(x) {
emboss <- read.table(x,header=T)
x <- table(emboss[,2],emboss[,3])/NROW(emboss[,3])
y <- as.vector(t(x))
nms <- expand.grid(colnames(x), rownames(x))
names(y) <- paste( nms[,2],nms[,1],sep="")
return(t(y))
}
my.files <- list.files(pattern = "emboss_\\d+\\.ss")
outputs <- lapply(my.files, FUN = runForAll)
library(plyr)
one.header.output <- rbind.fill.matrix(outputs)
write.table(one.header.output, file = "nontpsec.csv")
and my files are located here:
https://drive.google.com/folderview?id=0B0iDswLYaZ0zWjQ4RjdnMEUzUW8&usp=sharing
this is very weird and can't why it is happening, especially as all the other data is correct, even when looping through all files in one go.