for loop - Plotting rows of different dataframes in R -


i have started using r , might basic thing, here problem: trying use loop plot first row , mean of remaining rows different dataframes, each 1 having own plot. first stored table names files <- c("file1, "file2", "file3"...)

then tried using loop plot for(i in files) {plot(c(1:13), i[1,])}

                    x    t     c     c.1  a.1   a.2     g   t.1  t.2   a.3  g.1   a.4 sample1            na -0.6  10.6 13.7 -4.7  5.6 -11.7 -13.8 -11.9 -6.4 -12.7  2.9   7.5 sample2           3.4 -1.5  -1.3 11.9 10.3  8.0  -8.0  -9.9   6.5 -0.5   3.4 -4.5   4.8 sample3           0.8 -5.7   3.9 20.3 14.0  8.1  -8.0  -9.8   5.9 -6.7   6.5 -3.9   9.0 sample4          15.9 -6.1  -5.8 14.8 22.4 15.4  -2.8  -9.4   9.4 -4.2  -0.8  1.5   4.5 

and having trouble. can plot if use name of file instead of i[1,], have many files. each table looks following, more rows , columns. also, know how change x axis instead of numbers , can assign nucleotide letter each position ? (x, t, c, a, c, a, a, g, t, t, a, g, a)

any ideas? thanks!

you need use get(i) in order refer object name given i.

for example:

for (i in files) {   plot(1:ncol(get(i)), get(i)[1, ], xaxt='n')   axis(1, at=1:ncol(get(i)), labels=colnames(get(i))) } 

the default x-axis suppressed xaxt='n', , plotted axis(1, ...). allow code generalise data.frames varying number of columns, i've used 1:ncol(get(i)), returns sequence of integers 1 number of columns of object name i.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -