我想知道是否有更好的方法是将线性回归系数作为 dplyr 中的列。这是一些示例数据。
mydata <-
data.frame(
Site = c(1,1,1,1,1,1,1,1),
Site1 = c(2,3,2,3,2,3,2,3),
Age = c(17, 52, 19, 18, 62, 53, 41, 24),
Gender = c(1,2,1,1,2,2,2,1),
Outcome = c(1,1,1,1,0,0,0,1)
)
Run Code Online (Sandbox Code Playgroud)
我写了这个辅助函数来变成summary(.data)$coefficients
列
GetCoefficients <- function(.data){
AllData <- data.frame()
AllData[1, ] <- ""
col_names <- colnames(summary(.data)$coefficients)
row_names <- rownames(summary(.data)$coefficients)
row_len <- length(row_names)
col_len <- length(col_names)-1
x <- summary(.data)$coefficients
for (i in 1:length(x)){
AllData <- AllData %>%
mutate(!!paste0(row_names[ifelse(i%%row_len != 0, i%%row_len, row_len)],
"_",col_names[ceiling(i/col_len)]) := x[i])
}
return(AllData)
}
Run Code Online (Sandbox Code Playgroud)
使用辅助函数我可以将系数放入我的data.frame()
Linear_regression <- …
Run Code Online (Sandbox Code Playgroud) 我了解到我不应该AnyView()
在 SwiftUI 中使用。我已经编写了许多带有 switch 语句的函数来返回相应的视图,如下面的代码所示。我正在尝试学习将 switch 语句从AnyView()
struct T01: View{
var body: some View{
VStack{
showView(i: 1)
}
}
func showView(i: Int) -> some View{
switch(i){
case 0: return AnyView(viewOne)
case 1: return AnyView(viewTwo)
default: return AnyView(EmptyView())
}
}
var viewOne: some View {
Text("View One")
}
var viewTwo: some View {
Text("View Two")
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助!!!