matrices with lowest difference between their sum

I have to find the difference between the sum of 4 sub-matrices, which I get after splitting the matrix A in any way, in order to get the lowest difference between the sum of sub-matrix. For example, for a matrix A, 3 0 2 -8 -8 5 3 2 2 3 2 5 2 1 4 3 4 -1 4 2 -3 6 2 4 3 I could split it like this: 3 | 0 2 -8 -8 5 | 3 2 2 3 2 | 5 2 1

矩阵的总和之间的差异最小

为了得到子矩阵之和的最小差值,我必须找出4个子矩阵的总和之间的差异,这是我以任何方式分割矩阵A后得到的。 例如,对于矩阵A, 3 0 2 -8 -8 5 3 2 2 3 2 5 2 1 4 3 4 -1 4 2 -3 6 2 4 3 我可以像这样拆分它: 3 | 0 2 -8 -8 5 | 3 2 2 3 2 | 5 2 1 4 ------------------- 3 4 -1 | 4 2 -3 6 2 | 4 3 每个子矩阵内的所有元素的总和给出以下结

converting seconds from the Epoch into localtime

Suppose I have a few timestamps given as integers (seconds) from the Unix Epoch (1970-01-01 00:00:00Z). How do I convert them into the proper date-time in the local timezone? I've been looking at the as.POSIXct help page as well as related questions on SO. It's easy to do in UTC, but for some reason I can't seem able to do it straightforwardly for the local timezone, or for anothe

将Epoch秒数转换为本地时间

假设我在Unix Epoch(1970-01-01 00:00:00Z)中给出了几个时间戳(整数)(秒)。 我如何将它们转换为当地时区的适当日期时间? 我一直在寻找as.POSIXct帮助页面以及SO上的相关问题。 UTC很容易做到,但出于某种原因,我似乎无法直接为当地时区或另一个时区(顺便说一下,我恰好在“America / Los_Angeles”或“PST5PDT”中根据白天储蓄是否在指定时间生效,变成“PST或”PDT“;所以我通常指定基于位置的时区而不是”PST“或”PDT“,

How to add an additional single column heatmap at the side of main heatmap in R

I have the following scripts: library("gplots") mydata <- mtcars mydata.nr <- nrow(mydata) mydata.newval <- data.frame(row.names=rownames(mydata),new.val=-log(runif(mydata.nr))) # Functions hclustfunc <- function(x) hclust(x, method="complete") distfunc <- function(x) dist(x,method="euclidean") # Set colors hmcols <- rev(redgreen(256)); # Plot the scaled data heatmap.2(as.m

如何在R中的主热图一侧添加额外的单列热图

我有以下脚本: library("gplots") mydata <- mtcars mydata.nr <- nrow(mydata) mydata.newval <- data.frame(row.names=rownames(mydata),new.val=-log(runif(mydata.nr))) # Functions hclustfunc <- function(x) hclust(x, method="complete") distfunc <- function(x) dist(x,method="euclidean") # Set colors hmcols <- rev(redgreen(256)); # Plot the scaled data heatmap.2(as.matrix(mydata),d

Fast(er) way of indexing matrix in R

Foremost, I am looking for a fast(er) way of subsetting/indexing a matrix many, many times over: for (i in 1:99000) { subset.data <- data[index[, i], ] } Background: I'm implementing a sequential testing procedure involving the bootstrap in R. Wanting to replicate some simulation results, I came upon this bottleneck where lots of indexing needs to be done. For implementation of the

R中索引矩阵的快速(呃)方法

最重要的是,我正在寻找一种快速(呃)的方式来对一个矩阵进行子集化/索引化, for (i in 1:99000) { subset.data <- data[index[, i], ] } 背景: 我正在实施一个涉及R的引导程序的顺序测试程序。为了复制一些模拟结果,我遇到了需要完成大量索引的瓶颈。 为了实现block-bootstrap,我创建了一个索引矩阵,用它对原始数据矩阵进行子集化,以绘制数据的重采样。 # The basic setup B <- 1000 # no. of bootstrap r

How to catch warnings sent during S4 method selection

Warnings generated when evaluation arguments of S4 generic functions can not be caught using withCallingHandlers (). Illustration of the normal behaviour of withCallingHandlers: ### simple function that sends a warning send_warning <- function() { warning('send_warning') } send_warning() # Warning message: # In send_warning() : send_warning ### the warning can be caught by withCallingHan

如何捕捉S4方法选择期间发送的警告

使用withCallingHandlers ()无法捕获S4通用函数的评估参数时生成的警告 。 withCallingHandlers的正常行为的示例: ### simple function that sends a warning send_warning <- function() { warning('send_warning') } send_warning() # Warning message: # In send_warning() : send_warning ### the warning can be caught by withCallingHandlers withCallingHandlers(send_warning(), warning = function(w) {

Hmisc separate column headings with rowname = NULL

I'm trying to have column headings and the horizontal line underneath the headings separated by the groups. When I do the following it works, library(Hmisc) data(mtcars) latex(mtcars, file ='', cgroup = c("Group 1", "Group 2"), n.cgroup = c(5, 6)) but when I try to remove the rownames, the line under Group 1 & 2 merge into the same line library(Hmisc) data(mtcars) latex(mtcars, file =

Hmisc使用rowname = NULL分隔列标题

我正在尝试在由组分隔的标题下方添加列标题和水平线。 当我做下面的工作时, library(Hmisc) data(mtcars) latex(mtcars, file ='', cgroup = c("Group 1", "Group 2"), n.cgroup = c(5, 6)) 但是当我尝试删除rownames时,组1和2下的行合并到同一行中 library(Hmisc) data(mtcars) latex(mtcars, file ='', cgroup = c("Group 1", "Group 2"), n.cgroup = c(5, 6), rowname = NULL) 有谁知道一种方法来解决这个问题? 当l

readRDS() loads extra packages

Under what circumstances does the readRDS() function in R try to load packages/namespaces? I was surprised to see the following in a fresh R session: > loadedNamespaces() [1] "base" "datasets" "graphics" "grDevices" "methods" "stats" [7] "tools" "utils" > x <- readRDS('../../../../data/models/my_model.rds') There were 19 warnings (use warnings() to see them) > l

readRDS()加载额外的包

R中的readRDS()函数在什么情况下尝试加载包/名称空间? 我很惊讶在新的R会议上看到以下内容: > loadedNamespaces() [1] "base" "datasets" "graphics" "grDevices" "methods" "stats" [7] "tools" "utils" > x <- readRDS('../../../../data/models/my_model.rds') There were 19 warnings (use warnings() to see them) > loadedNamespaces() [1] "base" "class" "colorspa

How to draw a line with color in shiny application

This may be a simplest thing for lot of people, but I'm struggling with it. I'd like to draw a line with color using html tag "hr" This is what I have tried so far in ui.R file : HTML("<hr color='purple' >") HTML('<hr color="purple" >') hr( color="purple" ) None of them worked - any suggestions please? Shiny exposes a lot of control over the look and feel of the

如何在闪亮的应用程序中绘制颜色线

对许多人来说,这可能是最简单的事情,但我正在为此付出努力。 我想使用html标签“hr”绘制颜色线这是我迄今在ui.R文件中尝试过的: HTML("<hr color='purple' >") HTML('<hr color="purple" >') hr( color="purple" ) 他们都没有工作 - 有任何建议吗? Shiny暴露了对应用程序外观和感觉的很多控制,但碰巧hr的颜色不是其中之一。 所以你需要深入CSS来控制元素的外观。 您可以通过在Shiny中使用includeCSS来完

ggplot2 wind time series with arrows/vectors

From meteorological data (hourly values of temperature, wind and humidity) I managed to plot time series of wind speed and direction. Now I would like to add wind vectors on the time series plot. Here you can see the output I would like (arrows drawn over the actual plot). I am using ggplot2, been looking through stackoverflow, ggplot2 package docs (will continue) but no solution found. Any

带有箭头/矢量的ggplot2风时间系列

从气象数据(温度,风和湿度的小时值)我设法绘制风速和风向的时间序列。 现在我想在时间序列图上添加风向量。 在这里,您可以看到我想要的输出(箭头绘制在实际绘图上)。 我正在使用ggplot2,一直在寻找通过stackoverflow,ggplot2软件包文档(将继续),但没有找到解决方案。 任何想法或指示将看起来是一个起点。 提前致谢 编辑问题正如@slowlearner的评论中所建议的那样,我在此添加代码和数据以创建可重复的示例。

Data.table objects turn into data.frame after calling fix()

Every time I run the command fix(DT) on a data.table , after closing the fix window, DT turns into a data.frame object. Is this normal? library(data.table) DT <- data.table(a = 1:2, b = 2:3) > class(DT) [1] "data.table" "data.frame" fix(DT) # close the window > class(DT) [1] "data.frame" EDIT: some session info: R version 3.0.0 (2013-04-03) Platform: x86_64-w64-mingw32/x64 (64

调用fix()后,Data.table对象变为data.frame

每次我在data.table上运行命令fix(DT)时,在关闭修复窗口后, DT变成一个data.frame对象。 这是正常的吗? library(data.table) DT <- data.table(a = 1:2, b = 2:3) > class(DT) [1] "data.table" "data.frame" fix(DT) # close the window > class(DT) [1] "data.frame" 编辑: 一些会话信息: R version 3.0.0 (2013-04-03) Platform: x86_64-w64-mingw32/x64 (64-bit) fix调用edit 。 但是,没有data.