I’ve created a matrix of values from a simulation that is stored in 20×7 matrix (20 observations across 7 columns of numbers; the matrix is called output). The columns are output from a simulation.
After running the simulation, I included column names:
colnames(output) <- c('level', 'value1','value2','value3',
'value4','value5','value6')
And the matrix looks nice and clean. when observing:
output
Is there a way to plot these columns from the matrix? I’ve tried the code below (and other variants), but it will not work.
plot(level$output, value1$output)
thanks!
To index the matrix you use
output[,'level'], i.e. “any row, the ‘level’ column”.For your interest, you could also make a data frame from your matrix and plot like so:
Not worth doing if all you are doing with
outputis plotting, but if you are doing other sorts of analysis onoutputin R, a dataframe can be handy (and then you can refer to columns likeoutput$level,output$value1whereas with a matrix you have to dooutput[,'level']).