Skip to content
Snippets Groups Projects
Commit a7e844bd authored by Samuel Mondy's avatar Samuel Mondy
Browse files

Update loop_categorization_20191128.R

parent 1444f0ce
No related branches found
No related tags found
No related merge requests found
#Function
#create groups according quantile distribution
#b matrix with results of analysis
#n number of seps for quantiles analysis
category <- function(file,n=0.2,name)
{
b<-read.table(file, header = T,stringsAsFactors = F,sep="\t")
output<-b
for(j in 1:dim(b)[2])
{
if(is.numeric(b[1,j]))
{
quant <- quantile(b[,j],na.rm=T,probs=seq(0,1,n))
for (i in 1:length(quant))
{
a <- which(b[j]>=quant[i]&b[j]<=quant[i+1])
output[a,j] <- paste(colnames(output)[j],round(quant[i],2),round(quant[i+1],2),sep="_")
}
}
else
{
output[,j]<-b[,j]
}
}
write.table(output,file=name,quote=F,sep="\t",row.names = F)
}
setwd("//pommard/agro-users$/evanschaik/Mes documents/Solca/Amplicon/16s")
b=read.csv("Solca_reference_1.3_DIRTY.csv", header = T,stringsAsFactors = F)
category <- function(b,n)
{
n=0.2
output <- b
for(j in 7:dim(b)[2])
{
quant <- quantile(b[,j],na.rm=T,probs=seq(0,1,n))
for (i in 1:length(quant))
{
a <- which(b[j]>=quant[i]&b[j]<=quant[i+1])
output[a,j] <- paste(colnames(output)[j],round(quant[i],2),round(quant[i+1],2),sep="_")
}
}
return(output)
}
temp <- category(b,0.2)
write.table(temp,file="essai_b1ca_1.0.txt",quote=F,sep="\t",row.names = F)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment