【问题标题】:Filter rows in dataframe based on string value in column [duplicate]根据列中的字符串值过滤数据框中的行[重复]
【发布时间】:2020-02-06 19:17:49
【问题描述】:

我有以下几点:

Engine      HorsePower      Type
Model 1        500          V10
Model 2        230          A7
Model 3        330          IVTEC
Model 4        400          V8
Model 5        300          VX500

我想过滤上面数据框中的行,其中“类型”列以字母“V”开头

因此我会得到:

Engine      HorsePower      Type
Model 1        500          V10 
Model 4        400          V8
Model 5        300          VX500

上面每一列的数据类型都是“因子”类型。我尝试过类似的事情:

new_df <- new_df$AVC == "V"

但结果输出只是 FALSE 和 TRUE。希望能得到一些帮助。

【问题讨论】:

    标签: r


    【解决方案1】:
    new_df[grepl("^V", new_df$Type),]
    

    这将为您提供new_df$Type"V" 开头的所有行。

    【讨论】:

      猜你喜欢
      • 2019-12-27
      • 2023-01-15
      • 2019-03-04
      • 2015-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-08
      相关资源
      最近更新 更多