简体   繁体   English

计算具有某些单词的列中的频率

[英]Counting Frequency in a column with certain words

New to R, and need some help, I have a large dataset where it is difficult to shift (I had to collapse it down to 10.000 rows). R 的新手,需要一些帮助,我有一个很难移动的大型数据集(我不得不将其折叠到 10.000 行)。

I essentially need to grab the frequency for the color red and blue within column, but the values can range from "RED", "RED.", "Red", "red.", "rEd", etc. There are multiple ways that it is written that it is difficult to scroll down and input each one.我基本上需要在列中获取红色和蓝色的频率,但值的范围可以是“RED”、“RED.”、“Red”、“red.”、“rEd”等。有多种方法据说很难向下滚动并输入每一个。

I have tried this:我试过这个:

table(DATAFRAME$COLOR=="RED")
table(DATAFRAME$COLOR=="RED.")
table(DATAFRAME$COLOR=="Red")
table(DATAFRAME$COLOR=="Red.")
table(DATAFRAME$COLOR=="rEd/Blue")

Is there an easier way to just grab any values that has red/blue?有没有更简单的方法来获取任何具有红色/蓝色的值?

This should be able to do what you need, although without a MWE I can't be sure这应该能够做你需要的,虽然没有 MWE 我不能确定

df<-data.frame(color =c("red", "Red", "Red", "RED", "rED", "blue", 'yelow'), var1=1:7)

sum(grepl("red", df$color, ignore.case = T))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM