给定一个二维平面,其中有n个点.我需要生成一个划分平面的线的方程,使得一侧有n/2个点,另一侧有n/2个点.(顺便说一句,这不是家庭工作,我只是想解决问题)
我创建了一个生成矩阵的函数,但是我无法弄清楚如何在函数环境之外使这个函数的输出可用,所以我可以将它保存在csv文件中.
我的功能代码如下:
getTitle <- function(url) {
webpage <- readLines(url)
first.row <- webpage[1]
start <- regexpr("<title>", first.row)
end <- regexpr("</title>", first.row)
title <- substr(first.row,start+7,end-1)
return(title)
}
Run Code Online (Sandbox Code Playgroud)
getTitles <- function(pages) {
my.matrix <- matrix(NA, ncol=2, nrow=nrow(pages))
for (i in seq_along(1:nrow(pages))) {
my.matrix[i,1] <- as.character(pages[i,])
my.matrix[i,2] <- getTitle(as.character(pages[i,])) }
return(my.matrix)
print(my.matrix)}
Run Code Online (Sandbox Code Playgroud)
在http://goo.gl/D9lLZ上的示例文件上运行此函数后,我使用read.csv函数导入并命名为"mypages",我得到以下输出:
getTitles(mypages)
[,1] [,2]
[1,] "http://support.google.com/adwords/answer/1704395" "Create your first ad campaign - AdWords Help"
[2,] "http://support.google.com/adwords/answer/1704424" "How costs are calculated in AdWords - AdWords Help"
[3,] "http://support.google.com/adwords/answer/2375470" "Organizing …Run Code Online (Sandbox Code Playgroud) 我目前正在研究一种贝叶斯方法,该方法需要在每次迭代中对多项式 logit 模型进行多个优化步骤。我正在使用 optim() 来执行这些优化,并使用 R 编写的目标函数。分析显示 optim() 是主要瓶颈。
在挖掘之后,我发现了这个问题,他们建议重新编码目标函数Rcpp可以加快进程。我遵循了建议并用 重新编码了我的目标函数Rcpp,但它最终变慢了(大约慢了两倍!)。
这是我第一次使用Rcpp(或任何与 C++ 相关的东西),我无法找到一种对代码进行矢量化的方法。知道如何使它更快吗?
Tl; dr:当前 Rcpp 中函数的实现不如矢量化 R 快;如何让它更快?
一个可重现的例子:
Rand 中定义目标函数Rcpp:仅截取多项式模型的对数似然library(Rcpp)
library(microbenchmark)
llmnl_int <- function(beta, Obs, n_cat) {
n_Obs <- length(Obs)
Xint <- matrix(c(0, beta), byrow = T, ncol = n_cat, nrow = n_Obs)
ind <- cbind(c(1:n_Obs), Obs)
Xby <- Xint[ind]
Xint <- exp(Xint)
iota <- c(rep(1, (n_cat)))
denom <- log(Xint %*% iota)
return(sum(Xby …Run Code Online (Sandbox Code Playgroud) 当我尝试xampp在Mac OS X Yosemeti 10.10上启动(manager-osx)时,
我收到此错误:
此应用程序需要管理员权限
它不会像以前那样询问任何密码.
是否有一种直接的方法将多边形SpatVector类对象(来自terra库)转换为简单特征或SpatialPolygonsDataFrames?
每次我尝试安装RMySQL时都会出现以下错误:
Installing package into ‘/home/ehsan/R/x86_64-pc-linux-gnu-library/3.0’
(as ‘lib’ is unspecified)
* installing *source* package ‘RMySQL’ ...
** package ‘RMySQL’ successfully unpacked and MD5 sums checked
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking …Run Code Online (Sandbox Code Playgroud) 我正在使用在线练习教程中的数据集,代码可以在第 4 页的底部找到(https://tomhouslay.files.wordpress.com/2017/02/indivvar_mv_tutorial_asreml.pdf)
在本教程中,他们使用下面列出的代码使该函数正常工作,但在我的 R 会话中,我收到一条错误消息:
Run Code Online (Sandbox Code Playgroud)No tidy method for objects of class lmerMod.
我尝试过使用“parsnip”包并重新启动我的 R 会话,并且我尝试过按照类似问题的其他答案中的建议要求扫帚。
哈吉斯练习 csv 文件可以从这里下载:https://figshare.com/articles/Haggis_data_behavioural_syndromes/4702540
library(asreml)
library(nadiv)
library(tidytext)
library(tidyverse)
library(broom)
require(broom)
library(lme4)
library(data.table)
library(parsnip)
HData<- read_csv("haggis practice.csv")
lmer_b <- lmer(boldness ~ scale(assay_rep, scale=FALSE) +
scale(body_size) +
(1|ID),
data = HData)
plot(lmer_b)
qqnorm(residuals(lmer_b))
hist(residuals(lmer_b))
summary(lmer_b)
rep_bold <- tidy(lmer_b, effects = "ran_pars", scales = "vcov") %>%
select(group, estimate) %>%
spread(group, estimate) %>%
mutate(repeatability = ID/(ID + Residual))
Run Code Online (Sandbox Code Playgroud) 我有一个Access窗体的以下代码.当我打开和关闭表单时,似乎SendKeys是NumLock在打开和关闭它时弄乱了我的键.
出于完全正确的原因,我不想进入,我真的不想完全隐藏功能区(我希望下拉菜单仍然可访问)所以DoCmd.ShowToolbar命令不是我喜欢的方式.
有没有人有任何建议,我如何修改下面的代码,以完成我想要的SendKeys命令使用?
使用Access 2007这样的命令
CommandBars.ExecuteMso "MinimizeRibbon"
Run Code Online (Sandbox Code Playgroud)
不适合我.
顺便说一句,数据库将被分发,因此解决方案必须包含在数据库中.
Private Sub Form_Close()
' Unhide navigation pane
DoCmd.NavigateTo "acNavigationCategoryObjectType"
DoCmd.Maximize
' Maximize the ribbon
RibbonState = (CommandBars("Ribbon").Controls(1).Height < 75)
Select Case RibbonState
Case True
SendKeys "^{F1}", True
Case False
'Do nothing, already maximized
End Select
End Sub
Private Sub Form_Load()
' Hide navigation pane
DoCmd.NavigateTo "acNavigationCategoryObjectType"
DoCmd.Minimize
Debug.Print Application.CommandBars.Item("Ribbon").Height
' Minimize ribbon
RibbonState = (CommandBars("Ribbon").Controls(1).Height < 100)
Select Case RibbonState
Case True
'Do …Run Code Online (Sandbox Code Playgroud) 我想在R中计算一个等式.我不想使用该函数,sum因为它返回1个值.我想要完整的值向量.
x = 1:10
y = c(21:29,NA)
x+y
[1] 22 24 26 28 30 32 34 36 38 NA
x = 1:10
y = c(21:30)
x+y
[1] 22 24 26 28 30 32 34 36 38 40
Run Code Online (Sandbox Code Playgroud)
我不想要:
sum(x,y, na.rm = TRUE)
[1] 280
Run Code Online (Sandbox Code Playgroud)
哪个不返回矢量.
这是一个玩具示例,但我有一个更复杂的等式,使用长度为84647个元素的多个向量.
这是我的另一个例子:
x = 1:10
y = c(21:29,NA)
z = 11:20
a = c(NA,NA,NA,30:36)
5 +2*(x+y-50)/(x+y+z+a)
[1] NA NA NA 4.388889 4.473684 4.550000 4.619048 4.681818 4.739130 NA
Run Code Online (Sandbox Code Playgroud) 我有一个list()数据帧.我想申请dplyr的filter()于所有的人.
到目前为止我尝试过的示例代码...
require(dplyr)
list.DFs <- list(df1,df2)
lapply(
X = list.DFS,
FUN = filter(Gold.fish.count=="Total")
)
Run Code Online (Sandbox Code Playgroud)
但是这给出了一个错误:Object 'Gold.fish.count' not found.