我有一个data.frame看起来像这样的.
x a 1
x b 2
x c 3
y a 3
y b 3
y c 2
Run Code Online (Sandbox Code Playgroud)
我想以矩阵形式这样做,所以我可以将它送到热图以制作情节.结果应该类似于:
a b c
x 1 2 3
y 3 3 2
Run Code Online (Sandbox Code Playgroud)
我已尝试cast从reshape包中尝试编写手动函数来执行此操作,但我似乎无法正确执行此操作.
网络可视化在实践中在科学中变得普遍.但随着网络规模的扩大,常见的可视化变得不那么有用.有太多的节点/顶点和链接/边缘.通常,可视化工作最终会产生"毛球".
已经提出了一些新方法来克服这个问题,例如:
我相信还有更多方法.因此,我的问题是: 如何克服毛球问题,即如何通过使用R来可视化大型网络?
以下是一些模拟示例网络的代码:
# Load packages
lapply(c("devtools", "sna", "intergraph", "igraph", "network"), install.packages)
library(devtools)
devtools::install_github(repo="ggally", username="ggobi")
lapply(c("sna", "intergraph", "GGally", "igraph", "network"),
require, character.only=T)
# Set up data
set.seed(123)
g <- barabasi.game(1000)
# Plot data
g.plot <- ggnet(g, mode = "fruchtermanreingold")
g.plot
Run Code Online (Sandbox Code Playgroud)

这个问题与可视化GraphViz太大的无向图有关 吗?.但是,在这里我不是寻找一般的软件推荐,而是寻找具体的例子(使用上面提供的数据)哪些技术有助于通过使用R来实现对大型网络的良好可视化(与此线程中的示例相当:R:Scatterplot with太多分了).
Jekyll有很多主题,例如https://github.com/jekyll/jekyll/wiki/Themes.
在EXISTING Jekyll安装中切换到新主题的最简单方法是什么?
使用替代BLAS for R有几个优点,例如https://cran.r-project.org/web/packages/gcbd/vignettes/gcbd.pdf.
Microsoft R Open https://mran.revolutionanalytics.com/documents/rro/installation/#sysreq使用Intel的MKL而不是默认的Reference BLAS来加速计算.
我的问题是:
将英特尔的MKL库**手动链接到R**在Windows上的最新版本(https://cran.r-project.org/bin/windows/base/)的确切步骤是什么?
更新20-07-2016: 这里有关于如何为R≥3.3.0的Windows 64位R构建基于OpenBLAS的Rblas.dll的详细说明:http://www.avrahamadler.com/r-tips /集结openblas换窗户-R64 /
我有一个SpatialPolygonsDataFrame,包含11589个"polygons"类对象.这些对象中的10699个正好由1个多边形组成,但其余对象由多个多边形(2到22)组成.
如果一个对象由多个多边形组成,则可能有三种情况:
Stackoverflow帮助我正确地绘制了这样一个空间对象(绘制由多个多边形定义的空间区域).
但是,我仍然无法回答如何确定一个点(由经度/纬度定义)是否在多边形中.
以下是我的代码.我试图point.in.polygon在sp包中应用该函数,但是没有办法处理这样一个由多个多边形/孔组成的对象.
# Load packages
# ---------------------------------------------------------------------------
library(maptools)
library(rgdal)
library(rgeos)
library(ggplot2)
library(sp)
# Get data
# ---------------------------------------------------------------------------
# Download shape information from the internet
URL <- "http://www.geodatenzentrum.de/auftrag1/archiv/vektor/vg250_ebenen/2012/vg250_2012-01-01.utm32s.shape.ebenen.zip"
td <- tempdir()
setwd(td)
temp <- tempfile(fileext = ".zip")
download.file(URL, temp)
unzip(temp)
# Get shape file
shp <- file.path(tempdir(),"vg250_0101.utm32s.shape.ebenen/vg250_ebenen/vg250_gem.shp")
# Read in shape file
map <- readShapeSpatial(shp, proj4string = CRS("+init=epsg:25832"))
# Transform the geocoding from UTM to Longitude/Latitude
map <- …Run Code Online (Sandbox Code Playgroud) 有没有办法在R中创建这样的图表?

以下是图表中显示的数据摘录:
df <- structure(list(Animal = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("Buffalo",
"Goat", "Sheep"), class = "factor"), Texture = structure(c(4L,
4L, 4L, 4L, 4L, 3L, 3L, 3L, 2L, 1L, 1L, 4L, 3L, 4L, 2L, 2L, 2L,
2L, 1L, 1L, 1L, 1L), .Label = c("Hard", "Semi-Hard", "Semi-Soft",
"Soft"), class = "factor"), Name = structure(c(16L, 9L, 3L, 21L,
5L, 4L, 10L, 2L, 12L, …Run Code Online (Sandbox Code Playgroud) 我想计算大约之间的距离.100,000种不同的邮政编码.我知道包中的mapdist功能ggmap
mapdist 完美的工作:
library(ggmap)
mapdist('Washington', 'New York', mode = 'driving')
# from to m km miles seconds minutes hours
# 1 Washington New York 366284 366.284 227.6089 13997 233.2833 3.888056
mapdist('20001', '10001', mode = 'driving')
# from to m km miles seconds minutes hours
# 1 20001 10001 363119 363.119 225.6421 13713 228.55 3.809167
Run Code Online (Sandbox Code Playgroud)
但是,mapdist依赖于Google地理编码API,该API 每天的查询限制为2,500个地理定位请求.
您是否知道使用具有更高请求限制的其他服务(例如诺基亚地图或必应)来计算两点之间距离的替代r代码?
有没有办法使用RStudio删除R脚本中的所有注释?
我需要将文件缩小到可能的最小尺寸.但是,此文件的评论很多.
如果我是对的,那么支持REGEX的Rstudio中的搜索和替换功能可能对此有所帮助.
我感谢任何帮助.
有没有办法加快combn命令,以获得从矢量中取出的2个元素的所有独特组合?
通常这将设置如下:
# Get latest version of data.table
library(devtools)
install_github("Rdatatable/data.table", build_vignettes = FALSE)
library(data.table)
# Toy data
d <- data.table(id=as.character(paste0("A", 10001:15000)))
# Transform data
system.time({
d.1 <- as.data.table(t(combn(d$id, 2)))
})
Run Code Online (Sandbox Code Playgroud)
但是,combn使用data.table计算所有可能的组合要慢10倍(23秒对比我的计算机3秒).
system.time({
d.2 <- d[, list(neighbor=d$id[-which(d$id==id)]), by=c("id")]
})
Run Code Online (Sandbox Code Playgroud)
处理非常大的向量,我正在寻找一种通过仅计算唯一组合(如combn)来节省内存的方法,但是使用data.table的速度(参见第二个代码片段).
我感谢任何帮助.
我正在使用tm-package 在R中进行一些文本挖掘.一切都很顺利.但是,在词干之后会出现一个问题(http://en.wikipedia.org/wiki/Stemming).显然,有些词语具有相同的词干,但重要的是它们不会"被拼凑"(因为这些词语意思不同).
有关示例,请参阅下面的4个文本.在这里你不能使用"讲师"或"讲座"("协会"和"联系人")可互换.但是,这是在步骤4中完成的操作.
是否有任何优雅的解决方案如何手动实现某些案例/单词(例如,"讲师"和"讲座"是两个不同的东西)?
texts <- c("i am member of the XYZ association",
"apply for our open associate position",
"xyz memorial lecture takes place on wednesday",
"vote for the most popular lecturer")
# Step 1: Create corpus
corpus <- Corpus(DataframeSource(data.frame(texts)))
# Step 2: Keep a copy of corpus to use later as a dictionary for stem completion
corpus.copy <- corpus
# Step 3: Stem words in the corpus
corpus.temp <- tm_map(corpus, stemDocument, language = "english")
inspect(corpus.temp) …Run Code Online (Sandbox Code Playgroud)