我有一个如下所示的数据集:
我希望将Cloud列分成两列,一列用于字母,另一列只用于每个编码的编号,问题是在某些行中有两个或三个代码的组合(OVC32每行是一个代码)。 任何有关如何将其拆分为两列的帮助非常感谢
答案 0 :(得分:0)
您可以将数字和字母与" Cloud"像这样使用:
Cloud <- c("BKN130", "FEW090 SCT120 BKN150", "FEW200", "BKN140", "BKN120 BKN190")
Cloud_Letter <- gsub("[[:digit:]]","",Cloud)
Cloud_Letter
[1] "BKN" "FEW SCT BKN" "FEW" "BKN"
[5] "BKN BKN"
Cloud_Number <- str_extract_all(Cloud, "\\d+")
Cloud_Number
[[1]]
[1] "130"
[[2]]
[1] "090" "120" "150"
[[3]]
[1] "200"
[[4]]
[1] "140"
[[5]]
[1] "120" "190"