如何创建矩阵的直方图?

时间:2021-01-26 07:17:38

标签: r

你能帮我用 rnorm 和 hist 函数创建下面矩阵的直方图吗?

还请您帮我回答以下问题吗?

  1. 假设这些是关于新品牌胡萝卜汁风味的调查结果,分别为 1、完全不满意和 4 非常满意,并确定是否存在大于 4 的值
  2. 创建总数据矩阵的直方图
  3. 创建您喜欢的一种状态的直方图,并确定它是否与总数据矩阵的直方图不同
m1 <-matrix(sample(x = 1:4, size = 35*15, replace = TRUE), nrow = 35, ncol = 15)
m1

getwd()
write.table(m1, file = "mymatrix.txt", sep = "\t", 
            col.names = TRUE, row.names = TRUE)
dir()
rm(m1)
dir()
m1
m1imported <- read.table(file = "mymatrix.txt", sep = "\t", 
                         header = TRUE, row.names = 1) # read any file
m1imported

us<-c("CALIFORNIA", "FLORIDA", "ARIZONA", "MICHIGAN", 
      "WASHINGTON", "GEORGIA", "TEXAS", "OHIO", "ALABAMA",
      "COLORADO","NEW JERSEY","VIRGINIA","MONTANA","OREGON","NEW YORK")

colnames (m1imported) = us
m1imported

num <- c(1:35)
rownames (m1imported) = num
m1imported

#I tried the following to create the histogram but gave me an error 
# Error in hist.default(m1imported) : 'x' must be numeric

hist(m1imported)

0 个答案:

没有答案