我正在使用R一些数据框。我的问题与如何检查第一个数据帧中的变量值是否与另一个数据帧中的值匹配有关。merge该匹配与或 之类的匹配非常不同join。我将介绍我的数据框(dput()最后):
我的第一个数据框是df1. name它包含我想与第二个数据帧中的其他变量进行对比的变量。它看起来像这样:
df1
name
1 JUAN GIRON
2 GINA OLEAS
3 JUAN FERNANDO ELIZAGA
4 MARCO TORRES
5 JUAN PABLO GONZALEZ
6 IRMA GOMEZ
Run Code Online (Sandbox Code Playgroud)
第二个数据框是df2. 它还包含一个变量name,用于与namefrom进行对比df1。它看起来像这样(在实际情况中df2可能非常大,超过 1000 行):
df2
name val
1 JUANA MARQUEZ 1
2 FERNANDO ELIZAGA 2
3 IRMA GOMEZ 3
4 PABLO GONZALEZ 4
5 GINA LUCIO 5
6 MARK TORRES 6
7 LETICIA …Run Code Online (Sandbox Code Playgroud) 我正在使用 Rselenium,今天遇到了一个奇怪的问题。它一直工作到上周五,但现在崩溃了。我已经更新了主包和 java,但它不起作用。这是我使用下一个代码时得到的结果:
library(wdman)
library(RSelenium)
library(xml2)
library(selectr)
library(httr)
library(jsonlite)
#start RSelenium
remDr <- rsDriver(
port = 4445L,
browser = "firefox"
)
#remDr$open()
remDr <- remoteDriver(port = 4445L,browser = "firefox")
Run Code Online (Sandbox Code Playgroud)
当为 rsDriver 运行第一个 remDr 时,我得到了这个:
checking Selenium Server versions:
BEGIN: PREDOWNLOAD
BEGIN: DOWNLOAD
BEGIN: POSTDOWNLOAD
checking chromedriver versions:
BEGIN: PREDOWNLOAD
BEGIN: DOWNLOAD
BEGIN: POSTDOWNLOAD
checking geckodriver versions:
BEGIN: PREDOWNLOAD
Error in (function (url, platform, history, appname, platformregex = platform, :
unused argument (fileregex = "\\.(gz|zip)$")
Run Code Online (Sandbox Code Playgroud)
对于第二个 remDr,它可以工作,但尝试使用 open 它会失败并显示下一条消息:
remDr$open()
[1] …Run Code Online (Sandbox Code Playgroud) 这是这个问题的后续问题:
这次我试图在谷歌搜索中获取标题后面的文本(用红色圈出):
由于我缺乏网页设计知识,我不知道如何制定 xpath 来提取标题下面的文本。
@AllanCameron 的答案非常有用,但我不知道如何修改它:
library(rvest)
library(tidyverse)
#Code
#url
url <- 'https://www.google.com/search?q=Mario+Torres+Mexico'
#Get data
first_page <- read_html(url)
titles <- html_nodes(first_page, xpath = "//div/div/div/a/h3") %>%
html_text()
Run Code Online (Sandbox Code Playgroud)
非常感谢您的帮助!
我正在使用 进行数据提取任务R。数据是在Power BI仪表板中分配的,所以获取起来非常麻烦。我在这里找到了解决方案:
但我不确定如何在页面中导航以获取组件并提取表格。我的代码如下:
library(wdman)
library(RSelenium)
library(xml2)
library(selectr)
library(tidyverse)
library(rvest)
# using wdman to start a selenium server
remDr <- rsDriver(
port = 4445L,
browser = "firefox"
)
#remDr$open()
remDr <- remoteDriver(port = 4445L,browser = "firefox")
# open a new Tab on Chrome
remDr$open()
# navigate to the site you wish to analyze
report_url <- "https://app.powerbi.com/view?r=eyJrIjoiOGI5Yzg2MGYtZmNkNy00ZjA5LTlhYTYtZTJjNjg2NTY2YTlmIiwidCI6ImI1NDE0YTdiLTcwYTYtNGUyYi05Yzc0LTM1Yjk0MDkyMjk3MCJ9"
remDr$navigate(report_url)
# fetch the data
data_table <- read_html(remDr$getPageSource()[[1]]) %>%
querySelector("div.pivotTable")
Run Code Online (Sandbox Code Playgroud)
虽然硒进程工作,但我不知道如何获取我的表:
蓝色箭头显示了我想要的表格,然后我需要移动到其他页面来提取剩余的表格。但我想如果第一页能做到的话,其他页面也会一样。
非常感谢!
我正在使用 中的数据框R。我需要扩展我的数据框df1:
#Code
df1 <- data.frame(v=paste0('P',1:3))
Run Code Online (Sandbox Code Playgroud)
这样每一行都用一个向量“扩展” val:
#Code vector
val <- c("cherry", "apple", "kiwi")
Run Code Online (Sandbox Code Playgroud)
最后我想得到这个输出:
df2
v val
1 P1 cherry
2 P1 apple
3 P1 kiwi
4 P2 cherry
5 P2 apple
6 P2 kiwi
7 P3 cherry
8 P3 apple
9 P3 kiwi
Run Code Online (Sandbox Code Playgroud)
非常感谢。如果可能的话,最好使用dplyr或解决方案。tidyr