# # Reading data : one row for each strain ! # tab=readLines("don.txt") nl=length(tab) # # Compute overall min and max # minl = rep(0,nl) maxl = minl for (i in 1:nl) { v = as.numeric(strsplit(tab," ")[[i]][-1]) minl[i] = min(v) maxl[i] = max(v) } mini = floor(min(minl)) maxi = ceiling(max(maxl)) # # Declare a table with max size and fill it with data from lists # df1=rep(0,nl*maxi) dim(df1) = c(nl, maxi) cnames=rep(0,nl) for (i in 1:nl) { li=unlist(strsplit(tab[i]," ")) l1=length(li) xi=as.numeric(li[2:l1]) cnames[i] = li[1] for (k in 1:l1-1) { df1[i, round(xi[k])] = xi[k] } } # # Compute the number of columns containing not only zeroes # nz = 0 for (i in 1:maxi) { if (!all (df1[,i] == 0)) { nz = nz + 1 } } # # New table without columns of zeroes # df2=rep(0,nl*nz) dim(df2) = c(nl, nz) j = 1 for (i in 1:maxi) { if (!all (df1[,i] == 0)) { df2[,j] = df1[,i] j = j + 1 } } # # Ecriture du tableau sans colonnes de zeros transpose # Writing transposed table without columns of zeroes # write.table(t(df2),"sor.txt",quote=FALSE,col.names = cnames,row.names = FALSE)