首页 > 解决方案 > 忽略逗号作为 csv 文件中的千位分隔符

问题描述

我有一些具有多行的数据集,如下面的 data.fraedf所示。

最终,我真的需要字符串末尾的整数,在双引号之外的逗号之后。但是逗号作为千位分隔符似乎确实使事情复杂化。

保存每个计数的行标签会很有用(即 5,000 美元 - 9,999 美元),但我可以不这样做。

下面的代码返回同一列中的行标签和计数。

谢谢

library(tidyverse)
text<-'"Text / some other text / some other text / $5,000-$9,999", 10,000.00'
df<-data.frame(text=text)
df %>% 
  separate(., text, into=c('a', 'b', 'c', 'd'), sep='/')

标签: rcsvtidyverse

解决方案


像这样一秒钟怎么separate样?

df %>% 
  separate(., text, into=c('a', 'b', 'c', 'd'), sep='/') %>%
  separate(d, into = c("d", "e"), sep = "\", ")

推荐阅读