0

I want to create a graph individually for each column within the table. To do this I have created a list using the column names, and then loop using for through that column name list. My struggle is in using the column name within the for loop.

The code I have been trying to get to work is:

COL_NAMES_LIST <- c(colnames(TABLE_GRAPH))

# Loop through Column list, creating an individual graph for each.
for (UNIT in COL_NAMES_LIST) {

    # Creating Output File
    OUTPUT_FILE = paste("E:/_PROJECTS/GRAPHS/GRAPH_", UNIT, ".pdf", sep = "")

    # Graph Factors
    plot(TABLE_GRAPH$UNIT, type="o", col="blue",
        ylim=c(-1,1),
        xlab="Date",
        ylab="Frequency"
    )
}

As can be seen I am trying to read in just the single column from the graph in the plot command using TABLE_GRAPH$UNIT. This is not working for me, however if I were to manually write this command out of the loop, as TABLE_GRAPH$V1 then this does work. So I assume I am just missing a trick in getting it to work in the loop. Can anyone suggest a solution for me?

The table is being read from a csv and an example of the table being read is:

#  V1        V2        V3   
#  X20151209_343 0.6513831 0.7702191 0.7349007 
#  X20151229_363 0.6059951 0.7068856 0.6653007 
#  X20160606_158 0.8957479 0.9540729 0.9391808 
#  X20160815_228 0.1351092 0.4825607 0.2410946 
#  X20160914_258 0.8657319 0.9133682 0.8884921 
nrussell
  • 18,382
  • 4
  • 47
  • 60
Jonathan
  • 9
  • 2

0 Answers0