【发布时间】:2020-09-12 08:14:21
【问题描述】:
我有一个如下所示的数据框:
df<-structure(list(string = c(" Thermionic, cold and photo-cathode valves, tubes, and parts .................................. E ....................... 16.3",
" Automatic data processing machines and units thereof ............................................ E ....................... 15.0",
" Parts of and accessories suitable for 751, 752 .......................................................... E ....................... 14.6",
" Optical instruments and apparatus .............................................................................. E ....................... 14.1",
" Perfumery, cosmetics and toilet preparations ............................................................. E ....................... 13.3",
" Silk .................................................................................................................................. A ....................... 13.2",
" Undergarments, knitted or crocheted .......................................................................... B ....................... 13.1",
" Articles of materials described in division 58 ............................................................. D ....................... 13.1"
), id = c("1 ", "2 ", "3 ", "4 ", "5 ", "6 ", "7 ", "8 "), SH3 = c("776 ",
"752 ", "759 ", "871 ", "553 ", "261 ", "846 ", "893 ")), row.names = c(NA,
-8L), class = c("tbl_df", "tbl", "data.frame"))
# that looks like this
string id SH3
<chr> <chr> <chr>
1 " Thermionic, cold and photo-cathode valves, tubes, and parts .................................. E ....................... 16.3" "1 " "776 "
2 " Automatic data processing machines and units thereof ............................................ E ....................... 15.0" "2 " "752 "
3 " Parts of and accessories suitable for 751, 752 .......................................................... E ....................... 14.6" "3 " "759 "
4 " Optical instruments and apparatus .............................................................................. E ....................... 14.1" "4 " "871 "
5 " Perfumery, cosmetics and toilet preparations ............................................................. E ....................... 13.3" "5 " "553 "
6 " Silk .................................................................................................................................. A ....................... 13.2" "6 " "261 "
7 " Undergarments, knitted or crocheted .......................................................................... B ....................... 13.1" "7 " "846 "
8 " Articles of materials described in division 58 ............................................................. D ....................... 13.1" "8 " "893 "
我想将string 变量拆分为三个单独的变量。 string 有 3 个部分,由一系列点 (...) 隔开
1) 第一部分由一些文本组成: 例如。在第 1 行“热离子、冷阴极和光阴极阀、管和零件”
2) 第二部分是大写字母: 例如。在第 1 行:“E”
3) 最后一部分是一个数字: 例如第 1 行是“16.3”。
我想拆分我的字符串并从中创建三个变量。 问题是每行的点数不同。 有谁知道如何有效地做到这一点?
隔离大写字母(第 2 部分)的有效方式就足够了。
非常感谢您的帮助
【问题讨论】:
标签: r string split data-manipulation