我有2个数据帧.
我想首先根据第二个数据帧更改数据类型.让我们假设我有以下数据框架,我用作模板.
> template
id <- c(1,2,3,4)
a <- c(1,4,5,6)
b <- as.character(c(0,1,1,4))
c <- as.character(c(0,1,1,0))
d <- c(0,1,1,0)
template <- data.frame(id,a,b,c,d, stringsAsFactors = FALSE)
> str(template)
'data.frame': 4 obs. of 5 variables:
$ id: num 1 2 3 4
$ a : num 1 4 5 6
$ b : chr "0" "1" "1" "4"
$ c : chr "0" "1" "1" "0"
$ d : num 0 1 1 0
Run Code Online (Sandbox Code Playgroud)
我正在寻找下面的东西.
我有一个数据框,我试图根据 col_type 转换 dt 每个变量的类。
查找下面的示例以了解更多详细信息。
> dt
id <- c(1,2,3,4)
a <- c(1,4,5,6)
b <- as.character(c(0,1,1,4))
c <- as.character(c(0,1,1,0))
d <- c(0,1,1,0)
dt <- data.frame(id,a,b,c,d, stringsAsFactors = FALSE)
> str(dt)
'data.frame': 4 obs. of 5 variables:
$ id: num 1 2 3 4
$ a : num 1 4 5 6
$ b : chr "0" "1" "1" "4"
$ c : chr "0" "1" "1" "0"
$ d : num 0 1 1 0
Run Code Online (Sandbox Code Playgroud)
现在,我尝试根据下面的数据框转换每列的类。
> var
var …Run Code Online (Sandbox Code Playgroud) "1"是字符值,其他1是数字.甚至,当我尝试执行下面的行时,它给了我真实.
as.character("0")==as.numeric(0)
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助我理解,为什么?
我正在尝试使用gcloud init命令来验证我的帐户mac os,它向我抛出与 相关的错误SSL Certificate。我正在使用python 3.7最新版本的 google clound sdk。
> gcloud info --run-diagnostics\n\nNetwork diagnostic detects and fixes local network connection issues.\nChecking network connection...done.\nERROR: Reachability Check failed.\n Cannot reach https://cloudresourcemanager.googleapis.com/v1beta1/projects with httplib2 (SSLCertVerificationError)\n Cannot reach https://www.googleapis.com/auth/cloud-platform with httplib2 (SSLCertVerificationError)\n Cannot reach https://cloudresourcemanager.googleapis.com/v1beta1/projects with requests (SSLError)\n Cannot reach https://www.googleapis.com/auth/cloud-platform with requests (SSLError)\nNetwork connection problems may be due to proxy or firewall settings.\nRun Code Online (Sandbox Code Playgroud)\n我不支持任何公司代理。
\n更新:输出gcloud info --run-diagnostics --verbosity debug
从Option [Double]到Double,我遇到了一个问题.我收到以下异常错误:
scala.Some cannot be cast to java.lang.Double
val ty = ttnew.distinct().leftOuterJoin(rank).map{ case ((key),(c,d)) => (key,c._1,c._2,c._3,d.getOrElse(Double).asInstanceOf[Double]) }
Run Code Online (Sandbox Code Playgroud)
请帮忙!
The H2O R package is a great resource for building predictive models. But I am concerned with the security aspect of it.
Is it safe to use patient data with H2O in terms of security vulnerabilities ?
我正在尝试通过ActionButton单击更新文本和绘图。
我的尝试-
library(shiny)
library(ggplot2)
library(shinyWidgets)
ui <- fluidPage(
actionGroupButtons(
inputIds = c("Bar", "Histogram", "Line"),
labels = list("Bar", "Histogram","Line"),
status = "danger",
fullwidth = T
),
plotOutput('plot',height = '563px'),
verbatimTextOutput('text')
)
server <- function(input, output) {
output$plot <- renderPlot({
if(req(input$Bar)!=0) {
isolate({
data <- iris
ggplot(data, aes(Species,Petal.Length)) +
geom_bar(stat="identity")
})
} else if(req(input$Histogram)>0){
isolate({
data <- iris
ggplot(data, aes(Petal.Length)) +
geom_histogram()
})
} else if(req(input$Line)>0){
isolate({
data <- iris
ggplot(data, aes(Petal.Length,Sepal.Length)) +
geom_line()
})
}
})
output$text <- renderText({ …Run Code Online (Sandbox Code Playgroud) 我从大数据框中取样.我想前n从因素每个类别的每个ID.我已经尝试过使用嵌套for循环,但我认为它并不是有效的方式.请在下面找到数据和我的尝试.
id = c(1,1,1,1,1,1,2,2,2,2,2,2,2)
category = c("A","A","A","B","B","B","A","A","A","A","B","B","B")
factor= c("A1","A2","A3","B1","B2","B3","A2","A1","A3","A4","B2","B1","B3")
rank = c(2,1,5,2,1,6,12,10,8,9,23,12,10)
df = data.frame(id,category,factor,rank)
df$rank <- as.integer(df$rank)
cat <- as.data.frame(table(df$category))
list1 <- list()
list2 <- list()
for(i in 1:length(unique(df$id))){
for(j in 1:nrow(cat))
{
list1[[j]] <- df[order(rank),][id==df[,id[i]]&category==cat[[1]][j] ,][1:2]
}
rbind_list1 <- rbindlist(list1)
list2[[i]] <- rbind_list1[rowSums(is.na(rbind_list1)) != ncol(rbind_list1),]
}
final <- do.call(rbind, list2)
df <- final[rowSums(is.na(final)) != ncol(final),]
DESIRED OUTPUT:
id category factor rank
1 A A2 1
1 A A1 2
1 B B1 …Run Code Online (Sandbox Code Playgroud) 我试图取代NA使用regex类似的功能gsub-
样本数据-
a<-c(NA,1:5,NA,NA,1:3, rep(NA,round(runif(1,0,100))))
Run Code Online (Sandbox Code Playgroud)
如何NA在pattern匹配字段中进行识别。
对于例如 gsub("identify NA", 0, a)
注意-我知道其他可以替换的方法NA,但是我正在尝试NA使用确定regex。
编辑-我的目的是了解为什么正则表达式无法识别NA?