Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/73.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_List_Dataframe_Text - Fatal编程技术网

R 如何从列表中删除特定字符并另存为数据帧?

R 如何从列表中删除特定字符并另存为数据帧?,r,list,dataframe,text,R,List,Dataframe,Text,我想 获得一个干净的数据集 没有特殊字符 只有用实际的话 没有数字 它来自一个JSON文件 library(rvest); library(XML); library(dplyr);library(tidyr); library(purrr); library(rjson) url <- "http://suggestqueries.google.com/complete/search?client=chrome&q=Nike" nike_autocomplete <

我想
  • 获得一个干净的数据集
  • 没有特殊字符
  • 只有用实际的话
  • 没有数字
  • 它来自一个JSON文件
  •  library(rvest); library(XML); library(dplyr);library(tidyr); library(purrr); library(rjson)
    
     url <- "http://suggestqueries.google.com/complete/search?client=chrome&q=Nike"
     nike_autocomplete <- read_html(url)
    

    因此,最后没有空的东西

    您试图提取的文本是JSON格式的,因此您最好使用JSON读取实用程序,而不是尝试使用正则表达式。我喜欢
    jsonlite::fromJSON

    library(rvest)
    library(jsonlite)
    library(purrr)
    
    url <- "http://suggestqueries.google.com/complete/search?client=chrome&q=Nike"
    read_html(url) %>%
      xml_text %>%
      fromJSON() %>%
      extract(1:2) %>%
      unlist
    #  [1] "Nike"                  "nike shox"             "nike shoes"            "nike air max"         
    #  [5] "nike outlet"           "nike air force 1"      "nike basketball shoes" "nike vapormax"        
    #  [9] "nike air max 97"       "nike id"               "nike store"            "nike stock"           
    # [13] "nike air max 270"      "nike promo code"       "nike windbreaker"      "nike sweatshirts"     
    # [17] "nike huarache"         "nike hoodie"           "nike cortez"           "nike sweatpants"      
    # [21] "nike slides"      
    
    库(rvest)
    图书馆(jsonlite)
    图书馆(purrr)
    url%
    xml_文本%>%
    fromJSON()%>%
    提取物(1:2)%>%
    非上市
    #[1]“Nike”“Nike shox”“Nike shoes”“Nike air max”
    #[5]“nike outlet”“nike air force 1”“nike basketball shoes”“nike vapormax”
    #[9]“nike air max 97”“nike id”“nike商店”“nike库存”
    #[13]“nike air max 270”“nike促销代码”“nike风衣”“nike运动衫”
    #[17]“nike huarache”“nike连帽衫”“nike cortez”“nike运动裤”
    #[21]“nike幻灯片”
    
    您想要的结果看起来不像数据帧。是一行两列吗?列名是什么?只有一列,重要的是删除第一个空列开头的值。将在第二个列中修改,您确定输入正确吗?当我运行您的
    列表时,这是来自JSON文件吗?您可能会更好地改进导入过程,而不是尝试清理导入不好的数据。
    
    library(rvest)
    library(jsonlite)
    library(purrr)
    
    url <- "http://suggestqueries.google.com/complete/search?client=chrome&q=Nike"
    read_html(url) %>%
      xml_text %>%
      fromJSON() %>%
      extract(1:2) %>%
      unlist
    #  [1] "Nike"                  "nike shox"             "nike shoes"            "nike air max"         
    #  [5] "nike outlet"           "nike air force 1"      "nike basketball shoes" "nike vapormax"        
    #  [9] "nike air max 97"       "nike id"               "nike store"            "nike stock"           
    # [13] "nike air max 270"      "nike promo code"       "nike windbreaker"      "nike sweatshirts"     
    # [17] "nike huarache"         "nike hoodie"           "nike cortez"           "nike sweatpants"      
    # [21] "nike slides"