Apparently, folk have figured out how to make xkcd style graphs in Mathematica and in LaTeX. Can we do it in R? Ggplot2-ers? A geom_xkcd and/or theme_xkcd? I guess in base graphics, par(xkcd=TRUE)? How do I do it? As a first stab (and as much more elegantly shown below) in ggplot2, adding the jitter argument to a line makes for a great hand-drawn look. So - ggplot(mapping=aes(x=seq(1,10
显然,民间已经想出了如何在Mathematica和LaTeX中制作xkcd风格的图表。 我们可以在R中完成吗? GGPLOT2-ERS? geom_xkcd和/或theme_xkcd? 我猜在基础图形中,par(xkcd = TRUE)? 我该怎么做? 作为ggplot2中的第一个刺(以下更精美地显示),将jitter参数添加到一条线会使手绘效果非常好。 所以 - ggplot(mapping=aes(x=seq(1,10,.1), y=seq(1,10,.1))) + geom_line(position="jitter", color="red", size=2) +
I'd like to unload a package without having to restart R (mostly because restarting R as I try out different, conflicting packages is getting frustrating, but conceivably this could be used in a program to use one function and then another--although namespace referencing is probably a better idea for that use). ?library doesn't show any options that would unload a package. There is a
我想卸载一个软件包,而不必重新启动R(主要是因为重新启动R,因为我尝试了不同的,冲突的软件包令人沮丧,但可以想象,这可以在程序中使用一个函数,然后使用另一个函数 - 尽管命名空间引用可能是更好的主意)。 ?library不显示任何可以卸载程序包的选项。 有一个建议, detach可以卸载软件包,但以下都失败了: detach(vegan) detach(vegan)错误:无效的name参数 detach("vegan") detach("vegan")错误:无效
On general request, a community wiki on producing latex tables in R. In this post I'll give an overview of the most commonly used packages and blogs with code for producing latex tables from less straight-forward objects. Please feel free to add any I missed, and/or give tips, hints and little tricks on how to produce nicely formatted latex tables with R. Packages : xtable : for standard
在一般的要求下,一个关于在R中生产乳胶桌子的社区维基。在这篇文章中,我将概述最常用的软件包和博客,其中包含用于从不太直接的对象生产乳胶桌子的代码。 请随时添加我错过的任何内容,并且/或者提供有关如何使用R生成格式良好的乳胶表的技巧,提示和小技巧。 包装: xtable:用于最简单对象的标准表。 一个不错的画廊与例子可以在这里找到。 memisc:用于管理调查数据的工具,包含用于(基本)回归模型估计的乳胶表格
When I convert a factor to a numeric or integer, I get the underlying level codes, not the values as numbers. f <- factor(sample(runif(5), 20, replace = TRUE)) ## [1] 0.0248644019011408 0.0248644019011408 0.179684827337041 ## [4] 0.0284090070053935 0.363644931698218 0.363644931698218 ## [7] 0.179684827337041 0.249704354675487 0.249704354675487 ## [10] 0.0248644019011408 0.24970435467
当我将一个因子转换为数字或整数时,我会得到底层的代码,而不是数值。 f <- factor(sample(runif(5), 20, replace = TRUE)) ## [1] 0.0248644019011408 0.0248644019011408 0.179684827337041 ## [4] 0.0284090070053935 0.363644931698218 0.363644931698218 ## [7] 0.179684827337041 0.249704354675487 0.249704354675487 ## [10] 0.0248644019011408 0.249704354675487 0.0284090070053935 ## [13] 0.17968482
Given two data frames: df1 = data.frame(CustomerId = c(1:6), Product = c(rep("Toaster", 3), rep("Radio", 3))) df2 = data.frame(CustomerId = c(2, 4, 6), State = c(rep("Alabama", 2), rep("Ohio", 1))) df1 # CustomerId Product # 1 Toaster # 2 Toaster # 3 Toaster # 4 Radio # 5 Radio # 6 Radio df2 # CustomerId State # 2
给定两个数据帧: df1 = data.frame(CustomerId = c(1:6), Product = c(rep("Toaster", 3), rep("Radio", 3))) df2 = data.frame(CustomerId = c(2, 4, 6), State = c(rep("Alabama", 2), rep("Ohio", 1))) df1 # CustomerId Product # 1 Toaster # 2 Toaster # 3 Toaster # 4 Radio # 5 Radio # 6 Radio df2 # CustomerId State # 2 Alabam
I need to do a pretty simple task,but since im not versed in RI don't know exactly how to. I have to create a vector of 100 numbers with random values from 0 to 1 with 2 DECIMAL numbers. I've tried this: x2 <- runif(100, 0.0, 1.0) and it works great, but the numbers have 8 decimal numbers and I need them with only 2. 也许还有: (sample.int(101,size=100,replace=TRUE)-1)/100 So yo
我需要做一个非常简单的任务,但是因为我不熟悉RI,所以我不知道如何去做。 我必须创建一个包含100个数字的向量,其随机值从0到1以及2个DECIMAL数字。 我试过这个: x2 <- runif(100, 0.0, 1.0) 它工作得很好,但数字有8个十进制数,我只需要2个。 也许还有: (sample.int(101,size=100,replace=TRUE)-1)/100 所以你想从集合{0,1 / 100,2 / 100,...,1}中随机抽样数字? 然后在代码中完全写入: hundredths <- se
Tried to concatenate strings diagonally from this post how to alternatively concatenate 3 strings, but was not successful. My input is: a<-c("a1","a2","a3") b<-c("b1","b2","b3") c<-c("c1","c2","c3") My expected output would be "a1" "b2" "c3" "a2" "b3" "a3" How to get the above from c(rbind(a,b,c)) 在将较低对角线设置为丢失后,如何按行和列的派生值对向量排序mat <- rbind(a,b
试图从这个帖子对角串联字符串如何连接3个字符串,但没有成功。 我的意见是: a<-c("a1","a2","a3") b<-c("b1","b2","b3") c<-c("c1","c2","c3") 我的预期产出是 "a1" "b2" "c3" "a2" "b3" "a3" 如何从上面得到上述内容 c(rbind(a,b,c)) 在将较低对角线设置为丢失后,如何按行和列的派生值对向量排序mat <- rbind(a,b,c) mat[lower.tri(mat)] <- NA na.omit(mat[order(col(mat) - row(mat))]) 一
If you run: mod <- lm(mpg ~ factor(cyl), data=mtcars) It runs, because lm knows to look in mtcars to find both mpg and cyl. Yet mean(mpg) fails as it can't find mpg, so you do mean(mtcars$mpg) . How do you code a function so that it knows to look in 'data' for the variables? myfun <- function (a,b,data){ return(a+b) } This will work with: myfun(mtcars$mpg, mtcars$hp
如果你运行: mod <- lm(mpg ~ factor(cyl), data=mtcars) 它运行,因为他知道在mtcars中查找mpg和cyl。 然而, mean(mpg)因为找不到mpg而失败,所以你的mean(mtcars$mpg) 。 你如何编写一个函数,以便知道如何查找变量的“数据”? myfun <- function (a,b,data){ return(a+b) } 这将与: myfun(mtcars$mpg, mtcars$hp) 但会失败: myfun(mpg,hp, data=mtcars ) 干杯 以下是我将如何编码myfun() : myfun
One of the best ways to make a question reproducible is to use one of the built in data sets. Using data() , however, is frustrating because no information about the structure of the data set is provided. How can I quickly view the structure of available data sets? The following function may help: dataStr <- function(fun=function(x) TRUE) str( Filter( fun, Filter(
使问题可重现的最佳方法之一是使用内置数据集之一。 然而,使用data()令人沮丧,因为没有提供关于数据集结构的信息。 我如何快速查看可用数据集的结构? 以下功能可能有所帮助: dataStr <- function(fun=function(x) TRUE) str( Filter( fun, Filter( Negate(is.null), mget(data()$results[, "Item"], inh=T, ifn=list(NULL)) ) ) ) 它接受过滤功能,将其应用于所有数据集,并
Given a set of real numbers drawn from a unknown continuous univariate distribution (let's say is is one of beta, Cauchy, chi-square, exponential, F, gamma, Laplace, log-normal, normal, Pareto, Student's t, uniform and Weibull) .. x <- c(7.7495976,12.1007857,5.8663491,9.9137894,11.3822335,7.4406175,8.6997212,9.4456074,11.8370711,6.4251469,9.3597039,8.7625700,10.3171063,8.0983110,11.75
给定一组实数,从一个未知的连续单变量分布(假设是β,柯西,卡方,指数,F,伽马,拉普拉斯,对数正态,法线,帕累托,学生t,统一和威布尔中的一个).. x <- c(7.7495976,12.1007857,5.8663491,9.9137894,11.3822335,7.4406175,8.6997212,9.4456074,11.8370711,6.4251469,9.3597039,8.7625700,10.3171063,8.0983110,11.7564283,11.7583461,7.3760516,14.5713098,14.3289690,12.8436795,7.1834376,12.2530520,8.9362235,11.8