Richard, WOW! A totally new way to think about loop indices, many, many, thanks!John
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 GRECC (BT/18/GR) Baltimore, MD 21201-1524 (Phone) 410-605-7119 (Fax) 410-605-7913 (Please call phone number above prior to faxing) >>> "Richard M. Heiberger" <r...@temple.edu> 01/07/15 10:27 PM >>> tmp <- data.frame(a=rnorm(10), b=rnorm(10)) for (i in names(tmp)) hist(tmp[[i]], main=paste("histogram of", i)) On Wed, Jan 7, 2015 at 10:13 PM, John Sorkin <jsor...@grecc.umaryland.edu> wrote: > 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: > > > colnames<-names(smdata) > colnames > [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]] > and > Histogram of smdata[,colnames[i]] > > > How can I get the titles > Histogram of smdata[,X13594_pre] > and > 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 > GRECC (BT/18/GR) > 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. > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. 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. ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.