-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
uvoz #3
Comments
Stran dobi podatke s povezave http://www.ultimatetennisstatistics.com/seasonsTable?current=1&rowCount=20&sort%5Bseason%5D=desc&searchPhrase=&_=1512663744085 v obliki JSON. Vrstice so naštete v seznamu library(httr)
library(dplyr)
link <- paste0("http://www.ultimatetennisstatistics.com/seasonsTable?current=1&rowCount=20&sort[season]=desc&searchPhrase=&_=",
as.numeric(Sys.time()))
data <- content(GET(link))$rows %>% lapply(function(x) {
country <- x$bestPlayer$country$name
x$bestPlayer <- c(x$bestPlayer$country, x$bestPlayer)
x$bestPlayer$country <- country
x <- c(x, x$bestPlayer)
x$bestPlayer <- NULL
return(x)
}) %>% bind_rows() Svetujem, da uvoza knjižnic opraviš v V povezavi do podatkov sem zadnjo številko nadomestil s trenutnim časom (ne vem, če to kaj vpliva, a morda s tem poskrbiš, da dobiš vedno aktualne podatke). Potem se za vsako vrstico izvede podana funkcija. S Podatke bo treba še obdelati - stolpce s procenti bo treba pretvoriti v številke (uporabi funkcijo Kar se tiče zastav, jih lahko dobiš iz imen datotek z zastavami. Besedilne podatke lahko dobiš tako kot dosedaj, iz iste tabele pa dobiš še podatke o državah v razpredelnico, ki ima ustrezno državo na istem mestu kot tabela z igralci: html_tabela <- stran %>% html_nodes(xpath="//table[@class='wikitable']") %>% .[[1]]
tabela <- html_tabela %>% html_table(fill = TRUE)
drzave <- html_tabela %>% html_nodes(xpath=".//tr") %>% .[-1] %>%
sapply(. %>% html_nodes(xpath="./td") %>%
lapply(. %>% html_nodes(xpath="./a[@class='image']") %>% html_attr("href") %>%
sapply(. %>% { gsub("US_.*_Flag", "Flag_of_the_United_States", .) } %>%
strapplyc("Flag_of_(.*)\\.svg") %>%
{ gsub("_", " ", gsub("_\\(.*", "", gsub("^the_", "", .))) }) %>%
.[1]) %>% { ifelse(sapply(., is.list), NA, .) %>%
c(rep(NA, 5 - length(.)))} %>%
unlist()) %>% t() %>% data.frame()
colnames(drzave) <- colnames(tabela) V grobem torej to deluje tako, da greš čez vse vrstice (razen prve - prvi Vidim, da na svojem repozitoriju nimaš odprtega sledilca zadev - da ga odpreš, pojdi na svoj repozitorij, v zgornji vrstici klikni na Settings, nato pa obkljukaj Issues. V zgornji vrstici se bo pojavil zavihek Issues - če boš imeli kakršnokoli vprašanje, tam odpri zadevo (torej na svojem repozitoriju) in jo pusti odprto, dokler je ne razrešiš. |
Pozdravljeni,
zanima me za to tabelo s tega linka: http://www.ultimatetennisstatistics.com/seasons , če se jo da uvozit. Drugače pa sem razmišljala, če bi lahko podatke prepisala v excel tabelo, saj nimam nobene scv tabele?
Bi lahko pogledali še za to tabelo: https://sl.wikipedia.org/wiki/Seznam_zmagovalcev_turnirjev_za_Grand_Slam_-_mo%C5%A1ki_posami%C4%8Dno, kako bi lahko razbrala zastavice, da bi potem naredila tabelo (in graf), katera država je največkrat zmagala na turnirjih.
Hvala,
Špela Ognjanović
The text was updated successfully, but these errors were encountered: