我正在使用R语言,我的数据集中有一列包含每行不同大小写字母。我想要统计每行大写字母的数量,并创建一个新列来显示这个数字。我的列看起来像这样(整个数据集中有更多行):
gctaggggggatggttactactGtgctatggactac
gGaagggacggttactaCgTtatggactac
gcGaggggattggcttac
是否有一种简单的方法来创建一个列,列出每行大写字母的数量?谢谢。
t = c("gctaggggggatggttactactGtgctatggactac", "gGaagggacggttactaCgTtatggactac", "gcGaggggattggcttac")
sapply(regmatches(t, gregexpr("[A-Z]", t, perl=TRUE)), length)
plyr
和 stringr
。ldply(str_match_all(t,"[A-Z]"),length)
using str_count:
t <- c("gctaggggggatggttactactGtgctatggactac", "gGaagggacggttactaCgTtatggactac", "gcGaggggattggcttac")
str_count(t, "[A-Z]")