提问人:John H 提问时间:11/17/2023 更新时间:11/17/2023 访问量:27
删除数据帧中第一列的第一个单词为小写的行
Removing rows in a dataframe where first word of first column is lowercase
答:
0赞
I_O
11/17/2023
#1
怎么样:
first_word_lowercase <-
function(sentence){w1 <- gsub('(\\w+).*', '\\1', sentence)
ifelse(w1 == tolower(w1), TRUE, FALSE)
}
d <- data.frame(first_col = c('Keep me', 'drop me'),
second_col = 1:2
)
## > d
## first_col second_col
## 1 Keep me 1
## 2 drop me 2
subset(d, !first_word_lowercase(first_col))
## first_col second_col
## 1 Keep me 1
评论
df[tolower(df$a)!=df$a,]
?