异步控制器和Ajax请求(Asynchronous controller AND Ajax request)
我有一个异步控制器,我知道该操作将异步工作(没有其他操作等待)并在完成任务后返回。
所以我的问题是如何对动作发出异步Ajax请求。 我认为结果都是一样的。
I have an asynchronous controller, I know the action will work asynchronously (no other action wait for that) and returns after completion of the task.
So my question is how it is deferent from making an asynchronous Ajax request to an action. I think both are same in result.
原文:
最满意答案
您可以尝试以下表达式:
x <- "weg|laan" # or paste(c("weg", "laan"), collapse="|") df$test <- ifelse(grepl(x, df_weg), 1, 0)
|
在regex
意味着“或”作为一种更直接的方式,感谢@DavidArenburg,因为您需要0/1输出,您只需将
grepl
的逻辑结果转换为整数:as.integer(grepl("weg|laan", df_weg))
或者,如果你想做代码转换(但不太好的实践):
+grepl("weg|laan", df_weg)
You can try the following expression:
x <- "weg|laan" # or paste(c("weg", "laan"), collapse="|") df$test <- ifelse(grepl(x, df_weg), 1, 0)
|
in aregex
means "or"As a more direct way, thanks to @DavidArenburg, as you need a 0/1 output, you can just convert the logical result of
grepl
to integer:as.integer(grepl("weg|laan", df_weg))
or, if you want to do codegolfing (but less good pratice):
+grepl("weg|laan", df_weg)
相关问答
更多-
在与grepl进行模式匹配之前(使用小写模式)将所有输入文本df $ HorseName转换为小写形式可以解决此问题。 > df$Type <- ifelse(grepl('grey',tolower(df$HorseName)),'Grey', + ifelse(grepl('chestnut',tolower(df$HorseName)),'Chestnut', + 'others')) > df ...
-
ifelse不在R工作(ifelse not working in R)[2022-10-04]
我认为列'a'是factor类。 如果是这种情况,请将列转换为character类,然后应用代码 let$a <- as.character(let$a) let$b <- ifelse(grepl("come", let$a), "home", ifelse(grepl("to", let$a), "where", ifelse(grepl("sorted", let$a), "done", ifelse(grepl("look", let$a), ... -
`ifelse`语句根据匹配的字符串返回多个列(`ifelse` statement to return a number of columns based on matching strings)[2023-09-24]
而不是grepl你可以使用%in% 。 此外,如果您所做的只是选择要打印的特定行和列,则可以使用subset 。 > keepcols = c('ticker','comp_name','exp_rpt_date_qr1','exp_rpt_date_qr2','time_of_day_desc') > subset(earnings, ticker %in% tickers, select = keepcols) ticker comp_name exp_rpt_date_qr1 exp_ ... -
MySQL不支持grepl() 。 您可以使用%like%或先收集数据,然后使用grepl() 。 有关在dply / MySQL中使用grepl的更多信息和示例,请参阅此问题 。 MySQL doesn't support grepl(). You can either use %like% or collect the data first, then use grepl(). See this question about using grepl in dply/MySQL for more info ...
-
for (target in c('testing','evaluating','analyzing') ) { test[grepl(target, test$url),'subdir' ] <- target } test url content subdir 1 google.com/testing/duck 1 testing 2 google.com/evaluating/d ...
-
我认为你有一个等级问题。 R按顺序测试这些,因此您必须以适当的方式进行排列。 这是一个帮助的链接: https : //www.programiz.com/r-programming/if-else-statement 。 ac$new <-ifelse(apply(sapply(c("struck","bird","crash"), grepl, as.character(s$s)), 1, all) ,"struck by bird and crashed", ifelse(app ...
-
对于复杂的操作,首先将操作转换为函数然后将其应用于每个案例通常很有用。 例如, get_sector <- function(x, sector) { apply(x, 1, function(y) { as.numeric(any(grepl(sector, y), na.rm = TRUE)) }) } jobdata$private <- get_sector(jobdata, "Private") jobdata$public <- get_sector(jobdata, "Pub ...
-
由于'var1'是一个factor ,它会在ifelse被强制转换为整数值。 我们可以通过as.character来避免它 mutate(df, var2=ifelse(grepl('^AB',var1), 'AB-starter', as.character(var1))) 或者在创建data.frame ,使用stringsAsFactors=FALSE As 'var1' is a factor, it gets coerced to integer value within ifelse. We ...
-
grepl返回一个逻辑向量,你需要grep(..., value=TRUE) : df %>% mutate(col2 = ifelse(col1 %in% c("dog", grep("cat", col1, value=T)), "animal", ifelse(col1 %in% c(grep("carrot", col1, value=T), "broccoli", "squash"), "vegetable", ...
-
您可以尝试以下表达式: x <- "weg|laan" # or paste(c("weg", "laan"), collapse="|") df$test <- ifelse(grepl(x, df_weg), 1, 0) | 在regex意味着“或” 作为一种更直接的方式,感谢@DavidArenburg,因为您需要0/1输出,您只需将grepl的逻辑结果转换为整数: as.integer(grepl("weg|laan", df_weg)) 或者,如果你想做代码转换(但不太好的实践): +grep ...