Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何从行中提取单词_R_String - Fatal编程技术网

R 如何从行中提取单词

R 如何从行中提取单词,r,string,R,String,我有一个46 MB的csv文件,其中包含数据。从本质上讲,我只想选择那些具有特定单词(如“PRODUCT”)的行。此数据有60万行。我使用了grep()来搜索匹配的字符串。下面是我的几行数据 head(test) Item.Description UQC Year 1 PHARMACEUTICALS PRODUCTS.(MEDICINE) D

我有一个46 MB的csv文件,其中包含数据。从本质上讲,我只想选择那些具有特定单词(如“PRODUCT”)的行。此数据有60万行。我使用了
grep()
来搜索匹配的字符串。下面是我的几行数据

head(test)
                                                            Item.Description UQC Year
1                   PHARMACEUTICALS PRODUCTS.(MEDICINE) DOLEYKA SYRUP 100 ML NOS 2015
2                           Multani mati hesh100gm x 160 (AyurvedicProducts) PAC 2015
3             Amla /Shikakai/ Aritha powder 100gm x 160 (Ayurvedic Products) PAC 2015
4                            Godrej h.dye blk 40ml x 36 (Ayurvedic Products) PAC 2015
5 DR. COOLERS HERBAL LOZENGES.(2) DR. COOLERS HERBAL LOZENGES (MINT FLAVOUR) PAC 2015
6                          Eno lemon/ regular 100gm x 48 (AyurvedicProducts) PAC 2015
  Identifier RITC.Code
30049099
30049011
30049011
30049011
30049011
30049011
我使用了
test[grep(“产品”,行名(test)),]
。这给了我一个错误

  • 使用ms excel打开csv文件
  • 转到菜单“数据”并单击“过滤器”
  • 在过滤器下拉列表中选择“文本过滤器”,然后选择“包含”
  • 然后键入“产品”一词
  • 将筛选包含“产品”一词的列表
  • 1) 试试grepl,效果更好。 2) 大写/小写在这里很重要,并且在文本中都有

    因此,请尝试:


    1) 测试$Item.Description您是否在
    rownames
    中有“产品”看起来像是在
    Item.Description
    列中。i、 e.试试
    test[grep(“PRODUCT”,test$Item.Description),]
    我想OP更喜欢R解决方案。但我想要所有列?