尝试从控制台读取由单个字符空间分隔的整数行到2D数组中。我尝试过使用mod <- coxph(Surv(time, status) ~ as.character(sex) + age, data = lung)
mod %>%
tidy %>%
mutate(
estimate=exp(estimate),
conf.low=exp(conf.low),
conf.high=exp(conf.high)
) %>%
select(term, estimate, starts_with("conf"))
## term estimate conf.low conf.high
## 1 sex2 0.598566 0.4310936 0.8310985
## 2 age 1.017191 0.9989686 1.0357467
,但不能将其转换为整数。
必须从控制台读取的2D数组作为输入,如下所示
split(separator:maxSplits:omittingEmptySubsequences:)
这是我试过的代码
1 1 1 0 0 0
0 1 0 0 0 0
1 1 1 0 0 0
0 0 2 4 4 0
0 0 0 2 0 0
0 0 1 2 4 0
错误是
var arr = [[Int]]()
for i in 0 ... 5 {
var a = readLine()?.components(separatedBy: " ")
var arr[i] = [a?.split(separator: " ", maxSplits: 1, omittingEmptySubsequences: false)] as? Int
}
答案 0 :(得分:0)
尝试这个
for i in 0...5 {
arr += readLine()!.components(separatedBy: " ").map{ Int($0)! }
}
答案 1 :(得分:0)
for i in 0...5 {
var aux = [Int]()
readLine()?.split(separator: " ").map({
aux.append(Int($0)!)
})
arr.append(aux)
}