Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在R Studio中,在具有558行和4列的df中,如何计算列中非数值的频率_R_Count_Rstudio_Frequency - Fatal编程技术网

在R Studio中,在具有558行和4列的df中,如何计算列中非数值的频率

在R Studio中,在具有558行和4列的df中,如何计算列中非数值的频率,r,count,rstudio,frequency,R,Count,Rstudio,Frequency,RStudio的新成员。我有一个包含558行和4列的df。州和城市在df中不断重复 我想知道如何计算每个州有多少家啤酒厂。各栏分别为: Brew_ID Name City State 1 NorthGate Brewing Minneapolis MN 使用table()函数 table(df$city) 提供每个城市的频率计数。假设每一行代表一家啤酒厂(并且您在各州没有重复的城市名称),这将为您提供每个城市的啤酒厂数量。假

RStudio的新成员。我有一个包含558行和4列的df。州和城市在df中不断重复

我想知道如何计算每个州有多少家啤酒厂。各栏分别为:

Brew_ID  Name               City         State  
1        NorthGate Brewing  Minneapolis  MN
使用table()函数

table(df$city)

提供每个城市的频率计数。假设每一行代表一家啤酒厂(并且您在各州没有重复的城市名称),这将为您提供每个城市的啤酒厂数量。

假设没有重复的行-您可以通过以下方式进行检查:

  any(duplicated(df)) 
如果返回
FALSE
,则可以使用
表(df$State)

例如:

  Brew_ID <- c(1,2,3,4,5,6,7,8,9,10)
  Name <- c("NorthGate Bewing", "BrewDog", "BigBrew", "Hop Head", "Yadda",    "Blah Brew", "LaLa brew", "Smith's", "Harold's", "Wendy's")
  City <- c("Minneapolis", "New York", "Phoenix", "Sacremento", "Los Angeles", "San Francisco", "Portland", "Houston", "Dallas", "Austin")
  State <- c ("MN", "NY", "AZ","CA", "CA", "CA", "OR", "TX", "TX", "TX")

  df <- data.frame (Brew_ID, Name, City, State)

  table(df$State)

Brew\u ID,如果您想要状态与Brew计数表:
表(df$State,df$Name)