【问题标题】:R data cleaningR 数据清理
【发布时间】:2017-11-24 22:46:50
【问题描述】:

我有一个数据框 (df1) 作为单列数据报废。

1
2  Amazon Pantry
3  Best Sellerin Soaps & Hand Wash
4
5  Palmolive Hygiene-Plus Sensitive Liquid Hand Wash, 300ml
6  Palmolive Hygiene-Plus Sensitive Liquid Hand Wash, 300ml
7   £0.90
8    ?
9
10  Palmolive Naturals Nourishing Liquid Hand Wash, 300ml
11  Palmolive Naturals Nourishing Liquid Hand Wash, 300ml
12  £0.90
13  ?
14
15  L'Oreal Men Expert Carbon Protect Deodorant 250ml
16  L'Oreal Men Expert Carbon Protect Deodorant 250ml
17  £1.50

为了清理数据,我尝试使用以下命令,以便在 2 个单独的列中获取产品和定价信息。有人可以让我知道是否有另一种方法。

install.packages("splitstackshape")
newdf <- cSplit(df1, "Amazon_Normal_Text2", direction = "long")

【问题讨论】:

    标签: r data-cleaning


    【解决方案1】:

    这只是一个思考过程......

    1. 每次有一个“ml”时,提取信息直到ml 向后退直到有一个空间并将其存储到体积变量中。 (substr)
    2. £ 中提取信息到字符串的末尾并将其存储到价格变量中。 (grep, regex, nchar)
    3. 从字符串的开头提取到体积出现的字符位置到产品变量中(substrnchar

    查看substrnchargrepregex

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-10
      • 1970-01-01
      • 2020-09-11
      • 2020-09-02
      • 2023-03-16
      • 1970-01-01
      相关资源
      最近更新 更多