[英]Using grepl() to remove values from a dataframe in R
I have a data.frame
with 1 column, and a nondescript number of rows. 我有一个
data.frame
其中有1列,并且行数没有描述。
This column contains strings, and some strings contain a substring, let's say "abcd"
. 该列包含字符串,有些字符串包含子字符串,例如
"abcd"
。
I want to remove any strings from the database that contain that substring. 我想从数据库中删除包含该子字符串的所有字符串。 For example, I may have five strings that are
"123 abcd"
, and I want those to be removed. 例如,我可能有五个字符串
"123 abcd"
,并且希望将其删除。
I am currently using grepl()
to try and remove these values, but it is not working. 我目前正在使用
grepl()
尝试删除这些值,但无法正常工作。 I am trying: 我在尝试:
data.frame[!grepl("abcd", dataframe)]
but it returns an empty data frame. 但它返回一个空的数据帧。
我们可以使用grepl
来获取逻辑向量,取反( !
),然后使用它来对'数据'进行子集化
data[!grepl("abcd", data$Col),,drop = FALSE]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.