本文介绍了忽略dplyr包中的大小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为国家"的变量,我想创建一个子集,其中国家"等于印度,印度,阿联酋和阿联酋.如何在 dplyr

I have a variable called "Country" and I would like to create a subset where "Country" equals india, INDIA, UAE and uae. How to do using ignore case in dplyr

我尝试过 B< -subset(a,country%in%c("india","INDIA","uae","UAE"))

推荐答案

要对dplyr中的子集使用过滤器.这是一个示例:

To subset in dplyr you would use filter. Here is an example:

library(dplyr)

df <- data_frame(country = c("india", "INDIA", "uae", "UAE", "US", "Germany", "Some other Country"), val = c(1:7))

some.countries <- df %>% filter(grepl("india|uae", country, ignore.case = TRUE))
some.countries
#Source: local data frame [4 x 2]
#
#  country   val
#    (chr) (int)
#1   india     1
#2   INDIA     2
#3     uae     3
#4     UAE     4

这篇关于忽略dplyr包中的大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 03:42