Tag: r

如何将R Markdown转换为HTML? 也就是说,Rstudio 0.96中“Knit HTML”是做什么的?

在Rstudio 0.96的R Markdown文件上按下“编织HTML”时将运行什么命令? 我的动机是,我可能想要在另一个文本编辑环境中运行相同的命令,或者我可能想将这个命令组合到一个更大的makefile 。

用ggplot2重现格型树状图

这是可能重现与ggplot2这个格子图吗? library(latticeExtra) data(mtcars) x <- t(as.matrix(scale(mtcars))) dd.row <- as.dendrogram(hclust(dist(x))) row.ord <- order.dendrogram(dd.row) dd.col <- as.dendrogram(hclust(dist(t(x)))) col.ord <- order.dendrogram(dd.col) library(lattice) levelplot(x[row.ord, col.ord], aspect = "fill", scales = list(x = list(rot = 90)), colorkey = list(space = "left"), legend = list(right = list(fun = dendrogramGrob, args = list(x = dd.col, ord = col.ord, side = "right", size […]

在read.csv中指定colClasses

我试图在R中的read.csv函数中指定colClasses选项。在我的数据中,第一列“time”基本上是一个字符vector,而其余的列是数字。 data <- read.csv("test.csv", comment.char="" , colClasses=c(time="character", "numeric"), strip.white=FALSE) 在上面的命令中,我希望R在“时间”列中读取“字符”,其余的为数字。 尽pipe“data”variables在命令完成后确实得到了正确的结果,但R返回了以下警告。 我想知道如何解决这些警告? Warning messages: 1: In read.table(file = file, header = header, sep = sep, quote = quote, : not all columns named in 'colClasses' exist 2: In tmp[i[i > 0L]] <- colClasses : number of items to replace is not a multiple of replacement […]

在geom_point中标记点

我正在玩的数据来自下面列出的互联网来源 nba <- read.csv("http://datasets.flowingdata.com/ppg2008.csv", sep=",") 我想要做的是创build一个2D点图,比较这个表中的两个度量,每个玩家在图上代表一个点。 我有以下代码: nbaplot <- ggplot(nba, aes(x= MIN, y= PTS, colour="green", label=Name)) +geom_point() 这给了我以下几点: 我想要的是点旁边的玩家名字标签。 我认为ggplot美学中的标签function会为我做到这一点,但事实并非如此。 我也尝试了text()函数和library(calibrate)的textxy()函数,这两个函数都不能与ggplot一起使用。 我如何添加名称标签到这些点?

在R中用“粘贴”创build一个variables名?

见下文: paste("perf.a", "1", sep="") [1] "perf.a1" 如果我想为perf.a1赋值,该perf.a1办? 我试图as.name , as.symbol等,没有用: as.name(paste("perf.a", "1", sep="")) = 5 Error in as.name(paste("perf.a", "1", sep = "")) = 5 : target of assignment expands to non-language object as.symbol(paste("perf.a", "1", sep="")) = 5 Error in as.symbol(paste("perf.a", "1", sep = "")) = 5 : target of assignment expands to non-language object noquote(paste("perf.a", […]

从颜色1和颜色2的n种颜色的渐变

我经常使用ggplot2 ,使渐变更好( 点击这里为例 )。 我需要在基地工作,我认为可以在那里使用scales来创build颜色渐变,但是我严重偏离了标准。 基本目标是生成从x颜色到y颜色的n种颜色的调色板。 解决scheme需要在基地工作。 这是一个起点,但是没有地方可以inputn。 scale_colour_gradientn(colours=c("red", "blue")) 我很清楚: brewer.pal(8, "Spectral") 来自RColorBrewer 。 我正在寻找更多类似于ggplot2处理渐变的方法, ggplot2渐变说我有这两种颜色,而且我需要15种颜色。 我怎样才能做到这一点?

R中的parent.frame()和parent.env()有什么不同? 他们如何在参考呼叫方面有所不同?

如果有人可以用一个简单的例子来说明这一点会有帮助吗? 另外,使用parent.frame()而不是parent.env() ,反之亦然。

R中的因素:多一个烦恼?

R中的基本数据types之一是因素。 在我的经验中,因素基本上是一种痛苦,我从不使用它们。 我总是转换成字符。 我觉得很奇怪,我错过了一些东西。 是否有一些重要的使用因子作为因子数据types变得必要的分组variables的函数示例? 我应该使用因素有什么具体情况?

从R中的一系列情节创build电影

有没有一种简单的方法来创build一个“电影”通过拼接在R几个地块?

将全部0个值全部replace为NA

我有一些数字列的数据框。 一些行有一个0值,在统计分析中应该被认为是无效的。 什么是最快的方式来取代R中的所有0值为NULL?