R中的等级数是否有限制?

时间:2017-12-19 12:00:03

标签: r levels

我想知道某个因素的等级数是否有限制?

我正在尝试重组Xing的一些课程。可选择的行业大约有135个不同的行业。 我的代码看起来像那样,正如我所提到的,在我的实际代码中有135个不同的行业。

companyIndustryLevels <- c("","ACADEMIA", "ACCOUNTING", "AEROSPACE")
levels(samples[[1]]$Industry) <- companyIndustryLevels

以下组合工作正常,可在筛选列表时选择。

genderLevels <- c("M","F")
companySizeLevels <- c("","1","1-10","11-50","51-200","201-500","501-1000","1001-5000","5001-10000","10001+")
levels(samples[[1]]$Gender) <- genderLevels
levels(samples[[1]]$CompanySize) <- companySizeLevels

所以问题是,在查看列表时,行业专栏只显示1级因子,而不是135级。

编辑: 我使用的是RStudio版本11.1.383和R版本3.4.3。 正如您在下面的可复制示例中所见,其他列如“性别”,“Beschäftigungsart”,“位置”,“Unternehmensgroesse”也达到了水平。 在RStudio中的视图窗口中选择过滤器时,我可以按照“Industrie”列的级别过滤所有列。

View(structure(
  list(
    ID = 1,
    Gender = structure(1L, .Label = c("M",
                                      "F"), class = "factor"),
    Bildungseinrichtungen = structure(1L, .Label = "", class = "factor"),
    Abschluss = structure(1L, .Label = "", class = "factor"),
    Studienfach = structure(1L, .Label = "", class = "factor"),
    Beschäftigungsart = structure(
      1L,
      .Label = c(
        "",
        "FULL_TIME_EMPLOYEE",
        "PART_TIME_EMPLOYEE",
        "INTERN",
        "FREELANCER",
        "OWNER",
        "PARTNER",
        "BOARD_MEMBER",
        "VOLUNTEER"
      ),
      class = "factor"
    ),
    Station.Start = NA,
    Station.Ende = NA,
    Bezeichnung = NA,
    Position = structure(
      1L,
      .Label = c(
        "",
        "STUDENT_INTERN",
        "ENTRY_LEVEL",
        "PROFESSIONAL_EXPERIENCED",
        "MANAGER_SUPERVISOR",
        "EXECUTIVE",
        "SENIOR_EXECUTIVE"
      ),
      class = "factor"
    ),
    Unternehmen = structure(1L, .Label = "AMA", class = "factor"),
    Unternehmensgroesse = structure(
      1L,
      .Label = c(
        "",
        "1",
        "1-10",
        "11-50",
        "51-200",
        "201-500",
        "501-1000",
        "1001-5000",
        "5001-10000",
        "10001+"
      ),
      class = "factor"
    ),
    Industrie = structure(
      1L,
      .Label = c(
        "ACADEMIA",
        "ACCOUNTING",
        "AEROSPACE",
        "AGRICULTURE",
        "AIRLINES",
        "ALTERNATIVE_MEDICINE",
        "APPAREL_AND_FASHION",
        "ARCHITECTURE_AND_PLANNING",
        "ARTS_AND_CRAFTS",
        "AUTOMOTIVE",
        "BANKING",
        "BIOTECHNOLOGY",
        "BROADCAST_MEDIA",
        "BUILDING_MATERIALS",
        "BUSINESS_SUPPLIES_AND_EQUIPMENT",
        "CHEMICALS",
        "CIVIC_AND_SOCIAL_ORGANIZATIONS",
        "CIVIL_ENGINEERING",
        "CIVIL_SERVICE",
        "COMPOSITES",
        "COMPUTER_AND_NETWORK_SECURITY",
        "COMPUTER_GAMES",
        "COMPUTER_HARDWARE",
        "COMPUTER_NETWORKING",
        "COMPUTER_SOFTWARE",
        "CONSTRUCTION",
        "CONSULTING",
        "CONSUMER_ELECTRONICS",
        "CONSUMER_GOODS",
        "CONSUMER_SERVICES",
        "COSMETICS",
        "DAYCARE",
        "DEFENSE_MILITARY",
        "DESIGN",
        "EDUCATION",
        "ELEARNING",
        "ELECTRICAL_ENGINEERING",
        "ENERGY",
        "ENTERTAINMENT",
        "ENVIRONMENTAL_SERVICES",
        "EVENTS_SERVICES",
        "FACILITIES_SERVICES",
        "FACILITY_MANAGEMENT",
        "FINANCIAL_SERVICES",
        "FISHERY",
        "FOOD",
        "FUNDRAISING",
        "FURNITURE",
        "GARDENING_LANDSCAPING",
        "GEOLOGY",
        "GLASS_AND_CERAMICS",
        "GRAPHIC_DESIGN",
        "HEALTH_AND_FITNESS",
        "HOSPITALITY",
        "HUMAN_RESOURCES",
        "IMPORT_AND_EXPORT",
        "INDUSTRIAL_AUTOMATION",
        "INFORMATION_SERVICES",
        "INFORMATION_TECHNOLOGY_AND_SERVICES",
        "INSURANCE",
        "INTERNATIONAL_AFFAIRS",
        "INTERNATIONAL_TRADE_AND_DEVELOPMENT",
        "INTERNET",
        "INVESTMENT_BANKING",
        "JOURNALISM",
        "LEGAL_SERVICES",
        "LEISURE_TRAVEL_AND_TOURISM",
        "LIBRARIES",
        "LOGISTICS_AND_SUPPLY_CHAIN",
        "LUXURY_GOODS_AND_JEWELRY",
        "MACHINERY",
        "MANAGEMENT_CONSULTING",
        "MARITIME",
        "MARKETING_AND_ADVERTISING",
        "MARKET_RESEARCH",
        "MECHANICAL_INDUSTRIAL_ENGINEERING",
        "MEDIA_PRODUCTION",
        "MEDICAL_DEVICES",
        "MEDICAL_SERVICES",
        "MEDICINAL_PRODUCTS",
        "METAL_METALWORKING",
        "METROLOGY_CONTROL_ENGINEERING",
        "MINING_AND_METALS",
        "MOTION_PICTURES",
        "MUSEUMS_AND_CULTURAL_INSTITUTIONS",
        "MUSIC",
        "NANOTECHNOLOGY",
        "NON_PROFIT_ORGANIZATION",
        "NURSING_AND_PERSONAL_CARE",
        "OIL_AND_ENERGY",
        "ONLINE_MEDIA",
        "OTHERS",
        "OUTSOURCING_OFFSHORING",
        "PACKAGING_AND_CONTAINERS",
        "PAPER_AND_FOREST_PRODUCTS",
        "PHOTOGRAPHY",
        "PLASTICS",
        "POLITICS",
        "PRINTING",
        "PRINT_MEDIA",
        "PROCESS_MANAGEMENT",
        "PROFESSIONAL_TRAINING_AND_COACHING",
        "PSYCHOLOGY_PSYCHOTHERAPY",
        "PUBLIC_HEALTH",
        "PUBLIC_RELATIONS_AND_COMMUNICATIONS",
        "PUBLISHING",
        "RAILROAD",
        "REAL_ESTATE",
        "RECREATIONAL_FACILITIES_AND_SERVICES",
        "RECYCLING_AND_WASTE_MANAGEMENT",
        "RENEWABLES_AND_ENVIRONMENT",
        "RESEARCH",
        "RESTAURANTS_AND_FOOD_SERVICE",
        "RETAIL",
        "SECURITY_AND_INVESTIGATIONS",
        "SEMICONDUCTORS",
        "SHIPBUILDING",
        "SPORTS",
        "STAFFING_AND_RECRUITING",
        "TAX_ACCOUNTANCY_AUDITING",
        "TELECOMMUNICATION",
        "TEXTILES",
        "THEATER_STAGE_CINEMA",
        "TIMBER",
        "TRAFFIC_ENGINEERING",
        "TRANSLATION_AND_LOCALIZATION",
        "TRANSPORT",
        "VENTURE_CAPITAL_AND_PRIVATE_EQUITY",
        "VETERINARY",
        "WELFARE_AND_COMMUNITY_HEALTH",
        "WHOLESALE",
        "WINE_AND_SPIRITS",
        "WRITING_AND_EDITING",
        "PHARMACEUTICALS"
      ),
      class = "factor"
    )
  ),
  .Names = c(
    "ID",
    "Gender",
    "Bildungseinrichtungen",
    "Abschluss",
    "Studienfach",
    "Beschäftigungsart",
    "Station.Start",
    "Station.Ende",
    "Bezeichnung",
    "Position",
    "Unternehmen",
    "Unternehmensgroesse",
    "Industrie"
  ),
  row.names = 1L,
  class = "data.frame"
))

1 个答案:

答案 0 :(得分:2)

似乎RStudio的数据查看器(View())中的过滤选项提供了factor的下拉菜单,其级别数为{{1} }})小于nlevels()。否则,它默认为搜索字段:

65

请注意,这与R本身无关,正如评论中已经提到的那样。