【发布时间】:2020-04-21 14:01:13
【问题描述】:
我需要用#2 中的函数创建一个直方图,有人有想法吗?我收到警告信息: 在 hist(as.integer(project.timeV)) 中:强制引入的 NAs
#1.
roundNorm <- function(m, sd) { #m is Mean, sd is Standard Deviation
x <- rnorm(1,m,sd)
roundUp.X <- ceiling(x)
return(roundUp.X)
}
#2.
project <- function(x) { # route 1: A-B-C-F, route 2: A-D-E-F
a.time <- roundNorm(10,3)
b.time <- roundNorm(10,3)
c.time <- 5
d.time <- 10
e.time <- roundNorm(5,2)
f.time <- 4
if(b.time+c.time > d.time+e.time){
projectLength <- a.time+b.time+c.time+f.time
criRoute <- "A,B,C,F"
answer <- c(projectLength,criRoute)
}
else {
projectLength <- a.time+d.time+e.time+f.time
criRoute <- "A,D,E,F"
answer <- c(projectLength,criRoute)
}
return(answer)
}
#3.
samp <- 1:10000
project.timeV <- sapply(samp,project)
hist(as.integer(project.timeV))
【问题讨论】:
-
什么是
project.timeV?它是一个字符串吗?比较as.integer('a') -
@MichaelChirico
project.timeV应该是我将用来制作直方图的向量
标签: r