首页 > 解决方案 > 拆分并计算唯一值

问题描述

我想从数据框中找到唯一公司名称的数量:

/organization/-fame
/ORGANIZATION/-QOUNTER
/organization/-qounter
/ORGANIZATION/-THE-ONE-OF-THEM-INC-
/ORGANIZATION/0NDINE-BIOMEDICAL-INC
/organization/0ndine-biomedical-inc

我已经使用split函数分隔了上面的公司名称,

split_prod <- str_split_fixed(rounds2$company_permalink,"/", 4)

并转换为新的数据框:

companyname <- data.frame(split_prod, stringsAsFactors = FALSE)

我得到了如下四列的输出:

    X1     X2                     X3                   X4
        organization        -fame
        ORGANIZATION        -QOUNTER
        organization        -qounter
        ORGANIZATION        -THE-ONE-OF-THEM-INC-
        organization        0-6-com
        ORGANIZATION        004-TECHNOLOGIES
        organization        01games-technology
        ORGANIZATION        0NDINE-BIOMEDICAL-INC
        organization        0ndine-biomedical-inc

我现在如何计算唯一公司名称的数量?我努力了:

    `distinct(rounds$X3)`  ----- not working
    `length(unique(rounds$X3)` --- wrong output number i m getting.

请帮忙。另外,我不确定我使用拆分功能的方式是否正确。我关心数字“4”的特殊性。我将此数字计算为斜线、组织、公司名称、斜线,因此尝试将其分成四列。

标签: rdataframe

解决方案


编码:

length(unique(tolower(companyname$X3)))

将返回数据框X3列中唯一公司的数量companyname


推荐阅读