删除字符串长度大于n的所有行 [英] Remove all rows where length of string is more than n
本文介绍了删除字符串长度大于n的所有行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数据框 m
,我想删除所有 f_name
列有更大条目的行我假设我可以使用类似于
I have a dataframe m
and I want to remove all the rows where the f_name
column has an entry greater than 3. I assume I can use something similar to
m <- m[-grep("nchar(m$f_name)>3", m$f_name]
推荐答案
如果你想保留那些f_name中的条目长度不超过3的行,那么怎么样:
To reword your question slightly, you want to retain rows where entries in f_name have length of 3 or less. So how about:
subset(m, nchar(as.character(f_name)) <= 3)
这篇关于删除字符串长度大于n的所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文