2017-10-17 44 views

回答

0

使用table()函数。

table(df$city) 

给你每个城市的频率计数。假设每行代表一个酿酒厂(并且您没有州名重复的城市名称),应该为您提供每个城市酿酒厂的数量。

1

假设有没有重复的行 - 你可以检查此:

any(duplicated(df)) 

如果返回FALSE那么你可以使用table(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) 

返回:

AZ CA MN NY OR TX 1 3 1 1 1 3

+1

如果你想要状态vs Brew计数表:'table(df $ State,df $ Name)' – utubun