gpt4 book ai didi

r - 如何从 Stata 或 R 中的观察中删除某些特定单词?

转载 作者:行者123 更新时间:2023-12-04 12:27:24 27 4
gpt4 key购买 nike

我在互联网上做了一些研究,到目前为止,我刚刚发现可以使用 susbstr 从观察中删除第一个/最后一个字母,但不是像 CTRL+F-findandreplace 这样的命令.这里的技巧是我不一定知道我要删除的词在哪里!

我的数据集如下所示:

Hosp_code   Hosp    Hosplat Hosplon
RRK RRK - UNIVERSITY HOSPITALS BIRMINGHAM NHS FOUNDATION TRUST 52.453271 -1.9362835
RLU RLU - BIRMINGHAM WOMEN'S NHS FOUNDATION TRUST 52.453184 -1.9422432
5MX 5MX - HEART OF BIRMINGHAM TEACHING PCT 52.471575 -1.9367724
NO0 NO0 - HEALTHHARMONIE LIMITED 52.470965 -1.9243192
NLU NLU - SK:N (LASERCARE CLINICS LTD) 52.470838 -1.9220819
NXX NXX - SCRIVENS LTD 52.47148 -1.91341
AGL AGL - ADDITIONAL COMMUNITY MEDICAL SERVICES LTD 52.477343 -1.917197
5M1 5M1 - SOUTH BIRMINGHAM PCT 52.445922 -1.8928915
NQR NQR - PRIMECARE PRIMARY CARE 52.484113 -1.9173169
RXT RXT - BIRMINGHAM AND SOLIHULL MENTAL HEALTH NHS FOUNDATION TRUST 52.484113 -1.9173169
RRJ RRJ - THE ROYAL ORTHOPAEDIC HOSPITAL NHS FOUNDATION TRUST 52.421133 -1.9608273
RXK RXK - SANDWELL AND WEST BIRMINGHAM HOSPITALS NHS TRUST 52.48982 -1.9294268
RQ3 RQ3 - BIRMINGHAM CHILDREN'S HOSPITAL NHS FOUNDATION TRUST 52.485173 -1.8944604
RYW RYW - BIRMINGHAM COMMUNITY HEALTHCARE NHS TRUST 52.487323 -1.8858108
5PG 5PG - BIRMINGHAM EAST AND NORTH PCT 52.491369 -1.886036
NIT NIT - SOUTH DOC SERVICES LIMITED HQ 52.401796 -1.9620201
RR1 RR1 - HEART OF ENGLAND NHS FOUNDATION TRUST 52.477876 -1.8275305
NIS NIS - COVENTRY AND WARWICKSHIRE DIAGNOSTIC SERVICES LIMITED 52.462504 -1.8159336
NDT NDT - WEST MIDLANDS DIAGNOSTIC SERVICES LTD 52.462504 -1.8159336
5PF 5PF - SANDWELL PCT 52.523328 -2.0026388
TAJ TAJ - BLACK COUNTRY PARTNERSHIP NHS FOUNDATION TRUST 52.519255 -2.0188053
NEP NEP - TICCS ULTRASOUND LIMITED 52.510017 -1.8113152
NL7 NL7 - ASSURA VERTIS URGENT CARE CENTRES (BIRMINGHAM) 52.542091 -1.8778985
NNT NNT - ASSURA KINGSTANDING 52.542091 -1.8778985
5QW 5QW - SOLIHULL PCT 52.391695 -1.8081752
NR9 NR9 - JOHN TAYLOR HOSPICE COMMUNITY INTEREST COMPANY 52.527341 -1.8234016
RYK RYK - DUDLEY AND WALSALL MENTAL HEALTH PARTNERSHIP NHS TRUST 52.508312 -2.0844533

我想删除:- 前三个字母(例如 RRK -)- 任何提及 "LTD""LTD "LIMITED""HQ""LLP""TRUST""FOUNDATION TRUST"

有什么建议吗?

最佳答案

这里是使用 Stata 的类似策略。将来,请考虑并使用 dataex 生成您的数据示例。

* Example generated by -dataex-. To install: ssc install dataex
clear
input str68 Hosp
"RRK - UNIVERSITY HOSPITALS BIRMINGHAM NHS FOUNDATION TRUST"
"RLU - BIRMINGHAM WOMEN'S NHS FOUNDATION TRUST"
"5MX - HEART OF BIRMINGHAM TEACHING PCT"
"NO0 - HEALTHHARMONIE LIMITED"
"NLU - SK:N (LASERCARE CLINICS LTD)"
"NXX - SCRIVENS LTD"
"AGL - ADDITIONAL COMMUNITY MEDICAL SERVICES LTD"
"5M1 - SOUTH BIRMINGHAM PCT"
"NQR - PRIMECARE PRIMARY CARE"
"RXT - BIRMINGHAM AND SOLIHULL MENTAL HEALTH NHS FOUNDATION TRUST"
"RRJ - THE ROYAL ORTHOPAEDIC HOSPITAL NHS FOUNDATION TRUST"
"RXK - SANDWELL AND WEST BIRMINGHAM HOSPITALS NHS TRUST"
"RQ3 - BIRMINGHAM CHILDREN'S HOSPITAL NHS FOUNDATION TRUST"
"RYW - BIRMINGHAM COMMUNITY HEALTHCARE NHS TRUST"
"5PG - BIRMINGHAM EAST AND NORTH PCT"
"NIT - SOUTH DOC SERVICES LIMITED HQ"
"RR1 - HEART OF ENGLAND NHS FOUNDATION TRUST"
"NIS - COVENTRY AND WARWICKSHIRE DIAGNOSTIC SERVICES LIMITED"
"NDT - WEST MIDLANDS DIAGNOSTIC SERVICES LTD"
"5PF - SANDWELL PCT"
"TAJ - BLACK COUNTRY PARTNERSHIP NHS FOUNDATION TRUST"
"NEP - TICCS ULTRASOUND LIMITED"
"NL7 - ASSURA VERTIS URGENT CARE CENTRES (BIRMINGHAM)"
"NNT - ASSURA KINGSTANDING"
"5QW - SOLIHULL PCT"
"NR9 - JOHN TAYLOR HOSPICE COMMUNITY INTEREST COMPANY"
"RYK - DUDLEY AND WALSALL MENTAL HEALTH PARTNERSHIP NHS TRUST"
end

gen work = substr(Hosp, 7, .)
replace work = ustrregexra(work, " *(LTD|LIMITED|HQ|LLP|TRUST|FOUNDATION TRUST)", "")
leftalign // from SSC, to install, type: ssc install leftalign
list

关于r - 如何从 Stata 或 R 中的观察中删除某些特定单词?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36497024/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com