Zoppoli, Gabriele (NIH/NCI) [G]
2010-Jan-29 03:55 UTC
[R] how to create a histogram from a matrix?
Hi, I'm trying to create a frequency histogram for all the values in a table, but when I try to do so, an error is returned, saying that I cannot create a histogram with an obkect of that class. Here's what I do:>library(lattice) >table<-read.table("C:/.../table",header=TRUE,sep="\t") >histogram(table)Please help me!!! Thanks Gabriele Zoppoli, MD Ph.D. Fellow, Experimental and Clinical Oncology and Hematology, University of Genova, Genova, Italy Guest Researcher, LMP, NCI, NIH, Bethesda MD Work: 301-451-8575 Mobile: 301-204-5642 Email: zoppolig at mail.nih.gov
Tena koe Gabriele read.table() creates a data frame not a matrix. The distinction is important. A data frame is a special kind of list: it is a list of column vectors all of the same length. Because it is a list, each column can be of a different type (i.e., integer, numeric, character, factor etc). A matrix is a vector with a dim(ension) attribute and as such all elements must be of the same type. Try: library(lattice) testData <- rnorm(100) histogram(testData) # should be ok testData <- as.data.frame(testData) histogram(testData) # will generate an error testData <- unlist(testData) histogram(testData) # should be ok HTH .... Peter Alspach> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of Zoppoli, > Gabriele (NIH/NCI) [G] > Sent: Friday, 29 January 2010 4:56 p.m. > To: r-help at r-project.org > Subject: [R] how to create a histogram from a matrix? > > > Hi, > > I'm trying to create a frequency histogram for all the values > in a table, but when I try to do so, an error is returned, > saying that I cannot create a histogram with an obkect of > that class. Here's what I do: > > >library(lattice) > >table<-read.table("C:/.../table",header=TRUE,sep="\t") > >histogram(table) > > Please help me!!! > > Thanks > > Gabriele Zoppoli, MD > Ph.D. Fellow, Experimental and Clinical Oncology and > Hematology, University of Genova, Genova, Italy Guest > Researcher, LMP, NCI, NIH, Bethesda MD > > Work: 301-451-8575 > Mobile: 301-204-5642 > Email: zoppolig at mail.nih.gov > ______________________________________________ > R-help at r-project.org mailing list > 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. >