我正在尝试制作 somatoChart 的复制品来表征一些运动员的体型,我需要进行一些调整才能得到我期望的结果,图中左边是我的代码,右边是我希望的。
x <- c(0,-6,6,0,-4.5,4.5,0)
y <- c(12,-6,-6,0,4.5,4.5,-7.5)
par(mar = c(2,0,0,2), mgp = c(2,1,0))
plot(x,y,pch = 20,xlab = " ",ylab = " ",xlim = c(-8,8), ylim = c(-10,16),las = 1, col = "white",axes = F)
axis(4, las = 1, yaxp = c(-10,16,13),cex.axis=0.8)
axis(1, xaxp = c(-8, 8, 16),cex.axis=0.8)
# Segmentes
segments(x0 = 0, y0=-7.5, x1 = 0, y1 = 12, lty = 2)
segments(x0 = -6, y0=-6, x1 = 4.5, y1 = 4.5, lty = 2)
segments(x0 = 6, …Run Code Online (Sandbox Code Playgroud) 我正在使用神经网络包来训练神经网络。我正在使用 rmarkdown html 格式,但在打印时未显示绘图。
---
title: "neuralnet"
author: "RED"
date: "`r Sys.Date()`"
output:
html_document:
toc: yes
---
```{r}
library(neuralnet)
data(infert, package="datasets")
net.infert <- neuralnet(case~parity+induced+spontaneous, infert,
err.fct="ce", linear.output=FALSE, likelihood=TRUE)
```
```{r}
plot(net.infert)
```
Run Code Online (Sandbox Code Playgroud)
知道如何解决这个问题。
我有两列的数据框。我希望“ id”列是唯一的,并且非重复id的值应设置为相同的值,对于重复id的值应为NA。
library(data.table)
DT <- data.table(id = c(1,2,3,3,4,5,5), value = c(17,13,8,NA,9,NA,11))
DT
id value
1: 1 17
2: 2 13
3: 3 8
4: 3 NA
5: 4 9
6: 5 NA
7: 5 11
Run Code Online (Sandbox Code Playgroud)
预期产量
id value
1: 1 17
2: 2 13
3: 3 NA
4: 4 9
5: 5 NA
Run Code Online (Sandbox Code Playgroud) 我有尺寸的虚拟数据帧8×12,我想组变量x1j中x1,x2j中x2和x3j的x3.创建8x4维度的数据框.
set.seed(123)
df <- data.frame(replicate(4,as.factor(sample(1:3,8,rep=TRUE))))
library(dummies)
df.dummy <- dummy.data.frame(df)
Run Code Online (Sandbox Code Playgroud)
我的虚拟数据框
df.dummy
X11 X12 X13 X21 X22 X23 X31 X32 X33 X41 X42 X43
1 1 0 0 0 1 0 1 0 0 0 1 0
2 0 0 1 0 1 0 1 0 0 0 0 1
3 0 1 0 0 0 1 1 0 0 0 1 0
4 0 …Run Code Online (Sandbox Code Playgroud) 我正在使用osmdata包来查找哥伦比亚波哥大某个部门的银行。直接使用overpass网页时,找到如下对象,但是R API没有找到。问题是什么?
使用天桥
node[amenity=bank]
(4.6304414673187,-74.075607061386,4.6332058140013,-74.072549343109);
out;
Run Code Online (Sandbox Code Playgroud)
使用 R
library(osmdata)
library(mapview)
my_box <- c(4.6304414673187,-74.075607061386,4.6332058140013,-74.072549343109);
bank_pol <- opq(bbox = my_box, timeout = 25*100) %>%
add_osm_feature(key = "amenity", "bank") %>%
osmdata_sf()
bank_pol$osm_polygons
Simple feature collection with 0 features and 1 field
bbox: xmin: 1.797693e+308 ymin: 1.797693e+308 xmax: -1.797693e+308 ymax: -1.797693e+308
geographic CRS: WGS 84
[1] osm_id geometry
<0 rows> (or 0-length row.names)
mapview(bank_pol$osm_polygons)
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个函数,它使用Rcpp包创建一个大小为nxm的矩阵,其中包含均匀分布的条目.(我没有经验使用这个包.)
library(Rcpp)
cppFunction('NumericMatrix rngCpp(const int n,const int m) {
NumericMatrix X(n, m);
X(_,0) = runif(n);
return X;
}')
set.seed(1)
rngCpp(4,5)
[,1] [,2] [,3] [,4] [,5]
[1,] 0.2655087 0 0 0 0
[2,] 0.3721239 0 0 0 0
[3,] 0.5728534 0 0 0 0
[4,] 0.9082078 0 0 0 0
Run Code Online (Sandbox Code Playgroud)
预期产出
set.seed(1)
matrix(runif(4*5), nrow=4, ncol = 5)
[,1] [,2] [,3] [,4] [,5]
[1,] 0.2655087 0.2016819 0.62911404 0.6870228 0.7176185
[2,] 0.3721239 0.8983897 0.06178627 0.3841037 0.9919061
[3,] 0.5728534 0.9446753 0.20597457 0.7698414 0.3800352
[4,] …Run Code Online (Sandbox Code Playgroud) 我想用 rmarkdown 或 rsweave 写一份报告,但我需要一个西班牙语的自动拼写检查器。我正在写的文件有以下西班牙语句子:La niña ve películas de ciencia ficcion cuando llueve. 拼写检查器适用于英文文本。请参阅此链接
如何在 Rmarkdown 中使用拼写检查?. 有一些方法来使用拼写检查器,但在西班牙,因为西班牙正确的词是ficción与ó不是fiction,因为它通过点击ABC或使用出来F7
我怎么解决这个问题?
我需要对Portmanteau主要测试文章进行深入研究,为此,我必须在不同的场景,样本量和不同的ARMA模型(p,q)下评估它们,从而生成180个场景,这需要我花费6个小时。用R和Rcpp编程我的函数,但是我发现惊奇的是,在C ++中,它速度慢,我的问题是为什么?
我的R代码:
Portmanteau <- function(x,h=1,type = c("Box-Pierce","Ljun-Box","Monti"),fitdf = 0){
Ti <- length(x)
df <- h-fitdf
ri <- acf(x, lag.max = h, plot = FALSE, na.action = na.pass)
pi <- pacf(x, lag.max = h, plot = FALSE, na.action = na.pass)
if(type == "Monti"){d<-0} else{d<-1}
if(type == "Box-Pierce"){wi <- 1} else{wi <- (Ti+2)/seq(Ti-1,Ti-h)}
Q <- Ti*(d*sum(wi*identity(ri$acf[-1]^2))+(1-d)*sum(wi*identity(pi$acf^2)))
pv <- pchisq(Q,df,lower.tail = F)
result <- cbind(Statistic = Q, df,p.value = pv)
rownames(result) <- paste(type,"test")
return(result)
}
Run Code Online (Sandbox Code Playgroud)
我的Rcpp代码
#include <Rcpp.h>
using namespace …Run Code Online (Sandbox Code Playgroud)