【问题标题】:How to remove row from data frame based on particular format of cell with R [closed]如何使用 R [关闭] 基于特定格式的单元格从数据框中删除行
【发布时间】:2014-09-25 00:07:56
【问题描述】:

所以我正在尝试对来自 Twitter Analytics 的 .csv 文件执行一些基本分析。对于那些不知道的人,Twitter 分析导出包括有关您帐户的所有帖子和 @replies 的信息。但是,我只想查看我们实际帖子的信息。没有指定帖子是原始帖子还是回复帖子的列。帖子是回复的唯一信号是,在“推文文本”列中,它始终以用户名“@”开头。如何使用 R 从“推文文本”列中以 @ 开头的 .csv 中删除所有行?

【问题讨论】:

  • 对不起,我不够清楚,但我是编程新手,所以很难解释我需要什么......

标签: r csv twitter


【解决方案1】:

您可以使用grep() 来执行此操作。

# sample data frame
df <- data.frame(text = c("Here's a tweet", 
                          "@user this is a reply", 
                          "another tweet", 
                          "@another reply"),
                 stringsAsFactors = FALSE)

# remove rows beginning with @
df[grep("^@", df$text, invert = TRUE), ]
# [1] "Here's a tweet" "another tweet"

【讨论】:

    猜你喜欢
    • 2015-10-31
    • 2020-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-26
    • 2015-10-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多