[R] Getting column names in the titles of histograms generated automatically

John Sorkin JSorkin at grecc.umaryland.edu
Thu Jan 8 04:13:33 CET 2015

I am trying to automatically produce a series of histograms from every column of data frame with many columns.
The columns names of a shortened from of the data frame follow:

[1] "X13594_pre" "X15568_pre"

I want to have 
X13594_pre in the title of the first histogram and 
X15568_pre in the title of the second histogram.

I use the following code to automatically generate my histograms:

for (i in 1:2){hist(smdata[,colnames[i]])}

The titles of the histograms produced are:
Histogram of smdata[,colnames[i]]
Histogram of smdata[,colnames[i]]

How can I get the titles 
Histogram of smdata[,X13594_pre]
Histogram of smdata[,X15568_pre]

John David Sorkin M.D., Ph.D.
Professor of Medicine
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology and Geriatric Medicine
Baltimore VA Medical Center
10 North Greene Street
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing) 

Confidentiality Statement:
This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. 

More information about the R-help mailing list