简体   繁体   English

使用 tidyverse 中的“单独”function 时出现重音问题

[英]Issues with accent when using the "separate" function from tidyverse

I am using the separate function from tidyverse to split the first column of this tibble:我正在使用 tidyverse 中separatetidyverse来拆分此标题的第一列:

# A tibble: 6,951 x 9
   Row.names                    Number_of_analysis~ DL_Minimum DL_Mean DL_Maximum Number_of_measur~ Measure_Minimum Measure_Mean Measure_Maximum
   <I<chr>>                                   <dbl>      <dbl>   <dbl>      <dbl>             <dbl>           <dbl>        <dbl>           <dbl>
 1 2011.FACILITY.PONT-À-CELLES                  52       0.6    1.81        16                   0             0          0                 0  
 2 2011.FACILITY.PONT-À-CELLES                  52       0.07   0.177        1.3                 0             0          0                 0  
 3 2011.FACILITY.CHARLEROI                      52       0.07   0.212        1.9                 0             0          0                 0  
 4 2011.FACILITY.CHARLEROI                      52       0.08   0.209        2                   0             0          0                 0  
Merge_splitnames <- Merge %>% 
  separate(Row.names,sep = "\\.",into = c("Year", "Catchment", "Locality"), extra = "drop")

While everything seems correct, the output is a tibble without the first 2 columns (the ones which have a name comprising an accent in French):虽然一切看起来都是正确的,但 output 是一个没有前两列的小标题(名称包含法语重音的那些):

# A tibble: 6,951 x 9
   Year    Catchment    Locality                    Number_of_analysis~ DL_Minimum DL_Mean DL_Maximum Number_of_measur~ Measure_Minimum Measure_Mean Measure_Maximum
   <I<chr>>                                   <dbl>      <dbl>   <dbl>      <dbl>             <dbl>           <dbl>        <dbl>           <dbl>
 3 2011    FACILITY     CHARLEROI                      52       0.07   0.212        1.9                 0             0          0                 0  
 4 2011    FACILITY     CHARLEROI                      52       0.08   0.209        2                   0             0          0                 0  

Any idea how to deal with this issue?知道如何处理这个问题吗? I wish to keep the real name in French (with the accent).我希望保留法语的真实姓名(带有重音)。 This is quite surprising for me, I've never got any issue with all the other functions from tidyverse.这对我来说非常令人惊讶,我从来没有对 tidyverse 的所有其他功能有任何问题。

NB: this is a simple and reproducible example, my real tibble is about 100 times bigger注意:这是一个简单且可重现的示例,我真正的小标题大约大 100 倍

separate is retaining the accent for me: separate为我保留了口音:

library(tidyverse)

tribble(
  ~names,
  "2011.FACILITY.PONT-À-CELLES",
  "2011.FACILITY.PONT-À-CELLES",
  "2011.FACILITY.CHARLEROI",
  "2011.FACILITY.CHARLEROI"
)  %>%
  separate(names, sep = "\\.", into = c("Year", "Catchment", "Locality"))
#> # A tibble: 4 × 3
#>   Year  Catchment Locality     
#>   <chr> <chr>     <chr>        
#> 1 2011  FACILITY  PONT-À-CELLES
#> 2 2011  FACILITY  PONT-À-CELLES
#> 3 2011  FACILITY  CHARLEROI    
#> 4 2011  FACILITY  CHARLEROI

Created on 2022-05-06 by the reprex package (v2.0.1)reprex package (v2.0.1) 创建于 2022-05-06

Assuming DF shown reproducibly in the Note at the end, use extra = "merge" in separate .假设extra = "merge"在末尾的注释中可重复显示,请在separate的 . (It is possible that you may need to change your locale but I did not need to do that. Some things to try are shown in How to change the locale of R? or Using weekdays with any locale under Windows ) (您可能需要更改您的区域设置,但我不需要这样做。一些要尝试的事情显示在如何更改 R 的区域设置?使用 Windows 下的任何区域设置的工作日

library(tidyr)

DF  %>%
  separate(Row.names, c("Year", "Catchment", "Locality"), extra = "merge")

giving:给予:

  Year Catchment      Locality Number_of_analysis~ DL_Minimum DL_Mean
1 2011  FACILITY PONT-À-CELLES                  52       0.60   1.810
2 2011  FACILITY PONT-À-CELLES                  52       0.07   0.177
3 2011  FACILITY     CHARLEROI                  52       0.07   0.212
4 2011  FACILITY     CHARLEROI                  52       0.08   0.209
  DL_Maximum Number_of_measur~ Measure_Minimum Measure_Mean Measure_Maximum
1       16.0                 0               0            0               0
2        1.3                 0               0            0               0
3        1.9                 0               0            0               0
4        2.0                 0               0            0               0

Note笔记

DF <- 
structure(list(Row.names = c("2011.FACILITY.PONT-À-CELLES", "2011.FACILITY.PONT-À-CELLES", 
"2011.FACILITY.CHARLEROI", "2011.FACILITY.CHARLEROI"), `Number_of_analysis~` = c(52L, 
52L, 52L, 52L), DL_Minimum = c(0.6, 0.07, 0.07, 0.08), DL_Mean = c(1.81, 
0.177, 0.212, 0.209), DL_Maximum = c(16, 1.3, 1.9, 2), `Number_of_measur~` = c(0L, 
0L, 0L, 0L), Measure_Minimum = c(0L, 0L, 0L, 0L), Measure_Mean = c(0L, 
0L, 0L, 0L), Measure_Maximum = c(0L, 0L, 0L, 0L)), class = "data.frame", row.names = c("1", 
"2", "3", "4"))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM