Set the column names of the data frame as the graph header of each column

I have a data frame with 36 columns and over 3000 rows. I use the plot function internally for loopto plot each column. I want the chart name to display as the column name. How can i do this?

for(i in c(1:36)){
  plot(DowData[,i],type="l",main="colnames(DowData)[i]")
}
+4
source share
2 answers

Using lapply, you can iterate over column names:

 invisible(lapply(colnames(DowData),function(x){
      plot(DowData[,x],main=x,type="l")
    }))
+7
source
data <- read.csv("sample.csv",header=T,sep=",")
for ( i in seq(1,length( data ),1) ) plot(data[,i],ylab=names(data[i]),type="l")

This should work

+1
source

All Articles