小编Tho*_*s K的帖子

使用purrr影响列表中每个数据帧的单个列

仍然习惯于purrr,我有一个我认为应该很容易的问题,但我不知道该怎么做.我想要做的就是将下面的日期时间转换为as.Date()的日期.这是一个数据帧列表.一直在玩,但还没有找到有用的东西...任何帮助赞赏.

df <- data.frame(Date = seq.POSIXt(Sys.time(), Sys.time() + hours(24), by = "hour"),
             useless = "ignore me")
df2 <- data.frame(Date = seq.POSIXt(Sys.time(), Sys.time() + hours(1), by = "min"),
                    useless = "ignore me")
mylist <- list(df,df2)
mylist %<>% map(?????)
Run Code Online (Sandbox Code Playgroud)

r purrr tidyverse

8
推荐指数
2
解决办法
1550
查看次数

在 bookdown 中使用 csl 文件进行 pdf 输出

我想使用.csl-file 使用 bookdown 来格式化引用。添加csl: some-style.cslindex.Rmd影响输出到gitbook,但不影响到pdf_book。我知道我可以指定biblio-style,但这仅接受一些标准样式而不接受 csl 文件。有适当的解决方法吗?

重现步骤:

  1. 使用 RStudio 创建新项目并选择“Book Project using bookdown”作为选项。
  2. .cslhttps://www.zotero.org/styles下载一些文件并复制到项目的根目录。
  3. 添加csl: my_csl_file.cslindex.Rmd.
  4. 将本书构建为pdf和html,并观察参考文献中的差异(在参考文献部分,或在介绍中)

标题index.Rmd

--- 
title: "A Minimal Book Example"
author: "Yihui Xie"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
documentclass: book
bibliography: [book.bib, packages.bib]
csl: american-sociological-review.csl
link-citations: yes
description: "This is a minimal example of using the bookdown package to write a book. The output …
Run Code Online (Sandbox Code Playgroud)

r r-markdown bookdown

8
推荐指数
1
解决办法
1200
查看次数

从R中的gam.check中提取p值

当我跑步时gam.check(my_spline_gam),我得到以下输出.

Method: GCV   Optimizer: magic
Smoothing parameter selection converged after 9 iterations.
The RMS GCV score gradiant at convergence was 4.785628e-06 .
The Hessian was positive definite.
The estimated model rank was 25 (maximum possible: 25)
Model rank =  25 / 25 

Basis dimension (k) checking results. Low p-value (k-index<1) may
indicate that k is too low, especially if edf is close to k'.

         k'    edf k-index p-value
s(x) 24.000 22.098   0.849    0.06
Run Code Online (Sandbox Code Playgroud)

我的问题是我是否可以将这个p值分别提取到表中.

r gam p-value

5
推荐指数
1
解决办法
418
查看次数

向记者提供论据

以下可能是 Netlogo 的基本编程问题。我想写一篇通用的记者,我可以为他们应该报道的内容提供论据。假设有以下程序:

turtles-own [
  houses
  cars
]

to setup
  clear-all
  create-turtles 10
  reset-ticks
end

to go
  ask turtles [
    set houses houses + random 2
    set cars cars + random 5
  ]
  
  tick
end
Run Code Online (Sandbox Code Playgroud)

我可以写一篇关于房屋平均数的记者:

to-report mean-houses
  report mean [ houses ] of turtles
end
Run Code Online (Sandbox Code Playgroud)

但我想要一个通用的报告器,我也可以用它来报告汽车的平均值,如下所示:

to-report means [ param ]
  report mean [ param ] of turtles
end
Run Code Online (Sandbox Code Playgroud)

然而,这并没有按预期工作:

setup
repeat 15 [go]
show means houses

> ERROR: You can't use HOUSES in an observer context, because HOUSES …
Run Code Online (Sandbox Code Playgroud)

netlogo

4
推荐指数
1
解决办法
275
查看次数

将重复的列集合收集到单个列中

这里已经解决了收集多组列的问题:收集多组列,但在我的情况下,列不是唯一的.

我有以下数据:

input <- data.frame(
  id = 1:2, 
  question = c("a", "b"),
  points = 0,
  max_points = c(3, 5),
  question = c("c", "d"),
  points = c(0, 20),
  max_points = c(5, 20),
  check.names = F,
  stringsAsFactors = F
)
input
#>   id question points max_points question points max_points
#> 1  1        a      0          3        c      0          5
#> 2  2        b      0          5        d     20         20
Run Code Online (Sandbox Code Playgroud)

第一列是id,然后我有很多重复的列(原始数据集有133列):

  1. 问题的标识符
  2. 给出的分数
  3. 最高分

我想结束这个结构:

expected <- data.frame(
  id = c(1, …
Run Code Online (Sandbox Code Playgroud)

r reshape reshape2 data.table tidyr

2
推荐指数
1
解决办法
303
查看次数

标签 统计

r ×4

bookdown ×1

data.table ×1

gam ×1

netlogo ×1

p-value ×1

purrr ×1

r-markdown ×1

reshape ×1

reshape2 ×1

tidyr ×1

tidyverse ×1