小编Der*_*ran的帖子

用rjson在R中刮取NBA数据

我花了很长时间用R来试图抓取NBA数据,到目前为止我通过反复试验做了一点,但最后我发现了这个文档.前段时间我在抓镜头时遇到了一些问题,当我发现这个问题时我发现了问题

这有效

为此,这就是我所做的:

shotURLtotal <- paste0("http://stats.nba.com/stats/shotchartdetail?CFID=33&CFPARAMS=2016-17&ContextFilter=&ContextMeasure=FGA&DateFrom=&DateTo=&GameID=&GameSegment=&LastNGames=0&LeagueID=00&Location=&MeasureType=Base&Month=0&OpponentTeamID=0&Outcome=&PaceAdjust=N&PerMode=PerGame&Period=0&PlayerID=0&PlusMinus=N&Position=&Rank=N&RookieYear=&Season=2016-17&SeasonSegment=&SeasonType=Regular+Season&TeamID=0&VsConference=&VsDivision=&mode=Advanced&showDetails=0&showShots=1&showZones=0&PlayerPosition=")

Season <- rjson::fromJSON(file = shotURLtotal, method="C")
Names <- Season$resultSets[[1]][[2]]

Season <- data.frame(matrix(unlist(Season$resultSets[[1]][[3]]), ncol = length(Names), byrow = TRUE))

colnames(Season) <- Names
Run Code Online (Sandbox Code Playgroud)

但事实并非如此

但是当我尝试用shotchartlineupdetail做同样的事情,并且它不起作用时,我怀疑它与CFID有关,我不知道这意味着什么,这就是我尝试过的.

shoturl <- "http://stats.nba.com/stats/shotchartlineupdetail/?leagueId=00&season=2016-17&seasonType=Regular+Season&teamId=0&outcome=&location=&month=0&seasonSegment=&dateFrom=&dateTo=&opponentTeamId=0&vsConference=&vsDivision=&gameSegment=&period=0&lastNGames=0&gameId=&group_id=0&contextFilter=&contextMeasure=FGA"


Season <- rjson::fromJSON(file = shoturl, method="C")
Names <- Season$resultSets[[1]][[2]]

Season <- data.frame(matrix(unlist(Season$resultSets[[1]][[3]]), ncol = length(Names), byrow = TRUE))

colnames(Season) <- Names
Run Code Online (Sandbox Code Playgroud)

预期成绩

预期结果应该是包含以下列的数据框:

c("GRID_TYPE", "GAME_ID", "GAME_EVENT_ID", "GROUP_ID", "GROUP_NAME", "PLAYER_ID", "PLAYER_NAME", "TEAM_ID", "TEAM_NAME", "PERIOD", "MINUTES_REMAINING", "SECONDS_REMAINING", "EVENT_TYPE", …
Run Code Online (Sandbox Code Playgroud)

r web-scraping rjson

12
推荐指数
1
解决办法
956
查看次数

如何在R中使用外推栅格

我试图缩减使用的方法在气候条件文章使用R软件.我几乎在那里,但我错过了几个步骤

需要的包和数据

在本例中,我将一些数据上传到archive.org网站,以加载本例中使用的所需包和数据,使用以下代码:

library(raster)
library(rgdal)

download.file("https://archive.org/download/Downscaling/BatPatagonia.rds", "Bat.rds")
download.file("https://archive.org/download/Downscaling/TempMinPatNow.rds", "Tmin.rds")

BatPatagonia <- readRDS("Bat.rds")
TempMinPatNow <- readRDS("Tmin.rds")
Run Code Online (Sandbox Code Playgroud)

BatPatagonia是一个栅格文件,其中Bathymetry和从GEBCO数据集中提取和转换的区域的高度,而TempMinPatNow是从worldclim中提取的1月相同区域的最低温度.下面是数据集的图:

在此输入图像描述

这个问题的目标

为了从过去的冰川最大值下调过去的数据,我需要模拟当前的气候如果海平面与过去相同的情况.为了做到这一点,我使用GEBCO数据,并且或多或少地弄清楚海岸是什么.根据上面引用的文章中的方法,这是前面的三个步骤:

  1. 为海拔20米以上的土地创建DEM
  2. 在移动窗口中计算多元线性回归
  3. 将系数外推到海洋

第3点是我一直在努力做的事情,我将展示我如何做到前2点,并展示我一直在寻找的尝试解决第3点的问题

1.为海拔20米的土地建立DEM

为了做到这一点,我采用了BatPatagonia栅格,并使用以下代码将所有超过20米的值替换为NA值:

Elev20 <- BatPatagonia

values(Elev20) <- ifelse(values(Elev20) <= 20, NA, values(Elev20))
Run Code Online (Sandbox Code Playgroud)

生成的栅格如下图所示

在此输入图像描述

2.在移动窗口中计算多元线性回归

根据第2591页的手稿,下一步是在移动窗口中使用以下公式对超过20米的高度进行多元线性回归:

在此输入图像描述

我们已经有高程数据,但我们还需要纬度和经度的栅格,为此我们使用以下代码,首先创建纬度和经度栅格:

Latitud <- BatPatagonia
Longitud <- BatPatagonia

data_matrix <- raster::xyFromCell(BatPatagonia, 1:ncell(BatPatagonia))

values(Latitud) <- data_matrix[, 2]
values(Longitud) <- data_matrix[, 1]
Run Code Online (Sandbox Code Playgroud)

我们将乘以高度超过20米的区域的光栅掩模,这样我们只得到我们需要的值:

Elev20Mask <- BatPatagonia

values(Elev20Mask) <- ifelse(values(Elev20Mask) <= 20, NA, 1)

Longitud <- Elev20Mask*Longitud

Latitud <- Elev20Mask*Latitud
Run Code Online (Sandbox Code Playgroud)

现在我将使用响应变量和预测变量构建一个堆栈:

Preds <- …
Run Code Online (Sandbox Code Playgroud)

r pde r-raster

12
推荐指数
1
解决办法
397
查看次数

无法转换标题或转换时间取决于在新版本的 gganimate 中使用 transition_states 或 transition_times

我一直在玩 gganimate 的新版本,我在课堂上经常使用动画。我正在尝试构建一个图表,显示西班牙的一个站点中一氧化二氮如何随时间变化。我想要动画中的两个功能

  1. 每年停下来一段时间
  2. 每次都在标题中注明年份

我已经能够使用以下数据构建这两个图

Madrid3 <- structure(list(month = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 
                     1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 
                     9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 
                     4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, …
Run Code Online (Sandbox Code Playgroud)

r ggplot2 gganimate

9
推荐指数
1
解决办法
1049
查看次数

将Github中的RDS文件导入R Windows

我试图在Windows中将RDS文件导入RStudio,我尝试使用此示例,这是针对Rdata的,我尝试了两种方法:

方法1:

githubURL <- ("https://github.com/derek-corcoran-barrios/LastBat/blob/master/best2.My.Lu2.rds")
BestMyyu <- readRDS(url(githubURL))
Run Code Online (Sandbox Code Playgroud)

方法2:

githubURL <- ("https://github.com/derek-corcoran-barrios/LastBat/blob/master/best2.My.Lu2.rds")
download.file(githubURL,"best2.My.Lu2.rds")
BestMyyu <- readRDS("best2.My.Lu2.rds")
Run Code Online (Sandbox Code Playgroud)

我找了其他线程,我还没有找到任何其他的例子

import r

7
推荐指数
1
解决办法
957
查看次数

Amazon EC2 中的磁盘空间不足,无法找到我正在使用的存储空间

我正在使用美国东部的 T2.large 实例运行 AWS ami。我试图上传一些数据,但我在终端中运行:

df -h
Run Code Online (Sandbox Code Playgroud)

我得到了这个结果:

Filesystem      Size  Used Avail Use% Mounted on
udev            3.9G     0  3.9G   0% /dev
tmpfs           799M  8.6M  790M   2% /run
/dev/xvda1      9.7G  9.6G   32M 100% /
tmpfs           3.9G     0  3.9G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
tmpfs           799M     0  799M   0% /run/user/1000
Run Code Online (Sandbox Code Playgroud)

我知道我没有将 9.7 GB 的数据上传到实例,但我不知道是什么/dev/xvda1或如何访问它。

我还假设所有tmpfs都是临时文件,我该如何删除它们?

回答评论里的一些问题,我跑了

sudo du -sh /*
Run Code Online (Sandbox Code Playgroud)

我得到了:

16M /bin
124M    /boot
0   /dev
6.5M    /etc …
Run Code Online (Sandbox Code Playgroud)

amazon-ec2 amazon-web-services ubuntu-16.04 amazon-ami

7
推荐指数
2
解决办法
9793
查看次数

地图不会在带有传单和栅格的闪亮应用中呈现

我正在一个闪亮的应用程序工作,让你知道你可以愉快地生活的地方,这是正确的工作应用程序知道:

闪亮的应用

到目前为止我喜欢它,但我真的宁愿有一个传单地图,你可以放大而不是静态地图,但到目前为止,我一直有很多问题,由传单包呈现或更新光栅.如果您需要文件存储库,那么github存储库就是这个存储库

这是现在应用程序的代码服务器:

library(shiny)
library(raster)
library(rworldmap)
library(rgdal)
library(dplyr)
data("countriesCoarse")
uno <- readRDS("uno.rds")
World <- getData('worldclim', var='bio', res=10)
cities <- readRDS("cities.rds")
shinyServer(function(input, output) {

  output$distPlot <- renderPlot({
    uno[World[[10]] > ifelse(input$degrees == "Celcius", (input$MaxTempC*10), (((input$MaxTempF-32)*5/9)*10))] <- NA
    uno[World[[11]] < ifelse(input$degrees == "Celcius", (input$MinTempC*10), (((input$MinTempF-32)*5/9)*10))] <- NA
    uno[World[[1]] < ifelse(input$degrees == "Celcius", min(input$RangeTempC*10), min(((input$RangeTempF-32)*5/9)*10))] <- NA
    uno[World[[1]] > ifelse(input$degrees == "Celcius", max(input$RangeTempC*10), max(((input$RangeTempF-32)*5/9)*10))] <- NA
    uno[World[[12]] < ifelse(input$degrees == "Celcius", min(input$RangePPC), min(input$RangePPF*25.4))] <- NA
    uno[World[[12]] > ifelse(input$degrees == "Celcius", …
Run Code Online (Sandbox Code Playgroud)

r leaflet shiny

6
推荐指数
1
解决办法
330
查看次数

在闪亮的应用程序中生成模态中的进度条,自动关闭

我正在研究一个需要很长时间才能进行计算的闪亮应用程序,我希望有一个模态进度条,一旦所有计算工作就会自动关闭.

理想的解决方案有两个特点

  1. 覆盖大部分屏幕并阻止用户与应用程序进行交互
  2. 完成制作后立即自动关闭

我在以下问题中找到了这个解决方案:

library("shiny")
library("shinyWidgets")

ui <- fluidPage(
  actionButton(inputId = "go", label = "Launch long calculation"), #, onclick = "$('#my-modal').modal().focus();"

  # You can open the modal server-side, you have to put this in the ui :
  tags$script("Shiny.addCustomMessageHandler('launch-modal', function(d) {$('#' + d).modal().focus();})"),
  tags$script("Shiny.addCustomMessageHandler('remove-modal', function(d) {$('#' + d).modal('hide');})"),

  # Code for creating a modal
  tags$div(
id = "my-modal",
class="modal fade", tabindex="-1", `data-backdrop`="static", `data-keyboard`="false",
tags$div(
  class="modal-dialog",
  tags$div(
    class = "modal-content",
    tags$div(class="modal-header", tags$h4(class="modal-title", "Calculation in progress")),
    tags$div(
      class="modal-body",
      shinyWidgets::progressBar(id = "pb", value …
Run Code Online (Sandbox Code Playgroud)

r modal-dialog progress-bar shiny

6
推荐指数
1
解决办法
439
查看次数

当试图安装rgeos R时找不到-lgeos

我正在尝试rgeos在运行ubuntu 16.04的R 3.5.1中安装.我跑的时候

install.packages("rgeos")
Run Code Online (Sandbox Code Playgroud)

我收到以下消息:

* installing *source* package ‘rgeos’ ...
** package ‘rgeos’ successfully unpacked and MD5 sums checked
configure: CC: gcc -std=gnu99
configure: CXX: g++
configure: rgeos: 0.4-1
checking for /usr/bin/svnversion... yes
configure: svn revision: 579
checking for geos-config... /usr/bin/geos-config
checking geos-config usability... yes
configure: GEOS version: 3.5.1
checking geos version at least 3.2.0... yes
checking geos-config clibs... yes
checking geos_c.h  presence and usability... yes
checking geos: linking with libgeos_c... no
/usr/bin/ld: cannot find -lgeos
collect2: …
Run Code Online (Sandbox Code Playgroud)

r geospatial

6
推荐指数
1
解决办法
528
查看次数

将新版本的包发送到 cran 时请注意“检查 CRAN 传入可行性... Note_to_CRAN_maintainers”不会让我将其发送到 CRAN

我知道这个问题之前已得到解答,并且我应该忽略该消息,但是,当我将包裹发送到 cran 时,我收到 Uwe Ligges 的自动回复,说明:

亲爱的维护者,

包 NetworkExtinction_0.1.1.tar.gz 不会自动通过传入检查,请参阅以下预测试: Windows:< https://win-builder.r-project.org/incoming_pretest/NetworkExtinction_0.1.1_20191026_190159/Windows/ 00check.log > 状态:1 注意

如果您检查该链接,您会看到我收到的唯一注释是:

* checking CRAN incoming feasibility ... Note_to_CRAN_maintainers
Maintainer: 'Derek Corcoran <derek.corcoran.barrios@gmail.com>'
Run Code Online (Sandbox Code Playgroud)

知道如何传递这张纸条吗?我看到很多开发者都遇到过这个问题,我应该回复说我认为是误报吗?

非常感谢

r package cran

6
推荐指数
1
解决办法
516
查看次数

在 R 双自由或损坏中安装 SF 时出错

问题

我试图在我的 Ubuntu 18.04 机器上再次安装 SF,因为它给了我一些问题。由于我想开始一切清理,我尝试了以下操作:

remove.packages("sf")
install.packages("sf")
Run Code Online (Sandbox Code Playgroud)

然而,这导致了以下错误。

checking GDAL: checking whether PROJ is available fur running:... double free or corruption (out)
./configure: line 3625: 20789 Aborted                 (core dumped) ./gdal_proj
no
configure: error: OGRCoordinateTransformation() does not return a coord.trans: PROJ not available?
ERROR: configuration failed for package ‘sf’
* removing ‘/home/derek/R/x86_64-pc-linux-gnu-library/3.6/sf’
Run Code Online (Sandbox Code Playgroud)

当我看到消息double free or corruption (out) 时,我查看并意识到这是一个 c++ 问题,如此链接此链接所示。但即使我知道问题应该出在 PROJ 中,我什至不知道从哪里开始。

我尝试过的。

我尝试重新安装 rgdal 以查看是否像上面一样神奇地解决了问题

remove.packages("rgdal")
install.packages("rgdal")
Run Code Online (Sandbox Code Playgroud)

这导致了类似的结果

** testing if installed package …
Run Code Online (Sandbox Code Playgroud)

r rgdal r-sf ubuntu-18.04

6
推荐指数
0
解决办法
580
查看次数