我需要检查一些字符串是否包含任何非英文字符.
x = c('Kält', 'normal', 'normal with, punctuation ~-+!', 'normal with number 1234')
grep(pattern = ??, x) # Expected output:1
Run Code Online (Sandbox Code Playgroud) 我正在尝试计算数据帧的多个统计信息.
我试过dplyr的summarise_each.但是,结果以平面单行返回,函数名称作为后缀添加.
有没有直接的方法 - 使用dplyr或基础r - 我可以在数据框中获得结果,列作为数据框的列,行作为汇总函数?
library(dplyr)
df = data.frame(A = sample(1:100, 20),
B = sample(110:200, 20),
C = sample(c(0,1), 20, replace = T))
df %>% summarise_each(funs(min, max))
# A_min B_min C_min A_max B_max C_max
# 1 13 117 0 98 188 1
# Desired format
summary(df)
# A B C
# Min. :13.00 Min. :117.0 Min. :0.00
# 1st Qu.:34.75 1st Qu.:134.2 1st Qu.:0.00
# Median :45.00 Median :148.0 Median :1.00
# …Run Code Online (Sandbox Code Playgroud) 我很难\在正则表达式中用作喋喋不休的人。任何想法如何使它起作用?
grep(pattern = '\', "text with \ backslash", value = T )
# Expected output: [1] "text with backslash"
Run Code Online (Sandbox Code Playgroud) 我从ifelse函数中得到了意想不到的结果 :
vector <- factor(c('x', 'x', 'y', 'z'), levels = c('x', 'y', 'z'))
ifelse(class(vector) == "factor", yes = levels(vector), no =
unique(vector)) # Returns character "x" and not the expected c("x", "y",
"z")
# Manual debug
class(vector) == "factor" # TRUE
levels(vector) # [1] "x" "y" "z"
Run Code Online (Sandbox Code Playgroud)
知道发生了什么事吗?
我正在尝试使用重命名列dplyr::rename,但失败了..
library(dplyr)
cars %>%
filter(speed > 20) %>%
rename(speed = new_speed)
# Error: Unknown variables: new_speed.
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?
我想知道是否有直接的方法将箱线图的填充分配为他们的IQR值?
library(ggplot2)
ggplot(mtcars, aes(factor(cyl), mpg)) +
geom_boxplot(aes(fill = ??)) # IQR values?
Run Code Online (Sandbox Code Playgroud)