r - 拆分并计算唯一值
问题描述
我想从数据框中找到唯一公司名称的数量:
/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”的特殊性。我将此数字计算为斜线、组织、公司名称、斜线,因此尝试将其分成四列。
解决方案
编码:
length(unique(tolower(companyname$X3)))
将返回数据框X3
列中唯一公司的数量companyname
。
推荐阅读
- jmeter - JMeter JDBC requets 中是否可以批量更新
- spring - Spring Rest Doc junit 5 参数化测试支持
- authentication - 使用 MarkLogic 在 HTTP 服务器上设置应用程序级身份验证
- reactjs - 有没有办法在 create-react-app 中显示开发构建文件?
- python - 如何从已安装的 Drive 文件夹中永久删除?
- vue.js - Nuxt 在拆分 .vue 文件时会生成不需要的路由。如何只获得我想要的路线?
- javascript - React hooks useEffect 在添加空依赖数组后不会停止获取
- java - KafkaListenerEndpointContainer 无法使用 Spring Kafka 创建 Kafka 事务
- asp.net - IIS Web 应用程序无法在同一网络上访问,但 Apache 应用程序可以
- sas - 如何突出显示直到某一点的所有内容