删除字符串长度大于 n 的所有行 [英] Remove all rows where length of string is more than n
本文介绍了删除字符串长度大于 n 的所有行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数据框 m
,我想删除 f_name
列的条目大于 3 的所有行.我假设我可以使用类似于
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屋!
查看全文