我正在尝试生成一个条形图,其中R具有不同宽度的条形和它们之间的不同空格.例如,我有一个矩阵
data <- matrix(c(1,2,2,4,7,1,11,12,3), ncol = 3, byrow = T)
colnames(data) <- c("Start", "Stop", "Height")
Run Code Online (Sandbox Code Playgroud)
我想生成一个这样的数字(抱歉草图):
| __
| __ | |
| | | ________ | |
| | | | | | |
------------------- ------------------
0 1 2 3 4 5 6 7 8 9 10 11 12
Run Code Online (Sandbox Code Playgroud)
据我所知,barplot()允许您指定宽度,但条形之间的空间只能表示为平均条宽的一部分.但是,我想为条形之间的空格指定特定的(整数)数字.我会感谢任何提示/想法!
请解释此代码:
public static Func<TInput1, TOutput> Curry<TInput1, TOutput>(this Func<TInput1, TOutput> f)
{
return x => f(x);
}
Run Code Online (Sandbox Code Playgroud)
要么
Func<Int32, Int32> SubtractOne = x => x - 1;
Run Code Online (Sandbox Code Playgroud)
这些技术的名称是什么?
我在Linux上创建了一个R包(它正在Linux上工作),但我不能在Windows上使用相同的包.
我试图做的(可能有点愚蠢)是将tar.gz转换为Zip文件并从R GUI安装它.
但是,当我加载包库("myPackage")时,我收到以下消息:
Error in library("myPackage") :
there is no package called 'myPackage'
Run Code Online (Sandbox Code Playgroud)
我应该尝试使用R工具直接从Windows构建软件包吗?
我试图通过一些简单的方法来实现这一点.
比如,有一个售卖汽车的桌子,以及汽车模型的名称和汽车的售价
例如.,
CarName Price
AcuraLegend 30000
AcuraTSX 40000
HondaCivic 20000
HondaCivic 22000
HondaCivic 22000
ToyotaCamry 18000
Run Code Online (Sandbox Code Playgroud)
然后再增加2900个条目
我需要的是找到每辆车售出的最高价格以及最大售出的那种类型的汽车数量.因此,如果我们使用上述数据框架,假设在整个数据框架中为HondaCivic支付的最高价格是22000,并且只有2辆车以此价格出售,对于HondaCivic我会有,
CarName MaxPricePaidForCar NumberofCarsSoldforMaxPrice
HondaCivic 22000 2
Run Code Online (Sandbox Code Playgroud)
现在,我已经设法使用tapply和merge等等相当繁琐的方式将它们放在一起.
对更简单方法的任何建议都会非常有帮助,
我想转置类似于my.data下面的数据集,然后对行进行求和.
my.data <- "landuse units year county.a county.b county.c county.d
apple acres 2010 0 2 4 6
pear acres 2010 10 20 30 40
peach acres 2010 500 400 300 200"
my.data2 <- read.table(textConnection(my.data), header = T)
my.data2
Run Code Online (Sandbox Code Playgroud)
所需的输出是:
counties all.fruit
county.a 510
county.b 422
county.c 334
county.d 246
Run Code Online (Sandbox Code Playgroud)
我可以使用下面的代码执行此操作.但是,以下代码似乎必须是巨大的矫枉过正.我希望有一个更简单的解决方案.
# transpose the data set
tmy.data2 <- t(my.data2)
tmy.data2 <- as.data.frame(tmy.data2)
# assign row names to the data set
my.rows <- row.names(tmy.data2)
transposed.data <- cbind(my.rows, tmy.data2)
transposed.data
# …Run Code Online (Sandbox Code Playgroud) 我有一个数据框,其中包含有关驱动程序及其遵循的路径的数据.我想弄清楚旅行的总里程数.我正在使用该geosphere软件包,但无法弄清楚应用它的正确方法并以英里为单位获得答案.
> head(df1)
id routeDateTime driverId lat lon
1 1 2012-11-12 02:08:41 123 76.57169 -110.8070
2 2 2012-11-12 02:09:41 123 76.44325 -110.7525
3 3 2012-11-12 02:10:41 123 76.90897 -110.8613
4 4 2012-11-12 03:18:41 123 76.11152 -110.2037
5 5 2012-11-12 03:19:41 123 76.29013 -110.3838
6 6 2012-11-12 03:20:41 123 76.15544 -110.4506
Run Code Online (Sandbox Code Playgroud)
到目前为止我已经尝试过了
spDists(cbind(df1$lon,df1$lat))
Run Code Online (Sandbox Code Playgroud)
和其他几个功能似乎无法得到一个合理的答案.
有什么建议?
> dput(df1)
structure(list(id = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, …Run Code Online (Sandbox Code Playgroud) 我正在R中编写一个递归函数,我希望它能修改一个全局变量,以便知道调用了多少个函数实例.我不明白为什么以下不起作用:
i <- 1
testfun <- function( depth= 0 ) {
i <- i + 1
cat( sprintf( "i= %d, depth= %d\n", i, depth ) )
if( depth < 10 ) testfun( depth + 1 )
}
Run Code Online (Sandbox Code Playgroud)
这是输出:
i= 2, depth= 0
i= 2, depth= 1
i= 2, depth= 2
i= 2, depth= 3
i= 2, depth= 4
i= 2, depth= 5
i= 2, depth= 6
i= 2, depth= 7
i= 2, depth= 8
i= 2, depth= 9
i= 2, …Run Code Online (Sandbox Code Playgroud) `我想知道如何改变这个代码,以便两个向量的相应值不能相等.例如:如果x =(1,2,2,4,8,1,7,9,5,10)和y =(3,2,7,8,4,10,4,8,2, 1),两个向量的第二个值等于2.有没有什么方法可以告诉R在向量x中的第二个点重新采样,直到它在向量y中不是相同的值?
x <- c(1:10)
y <- c(1:10)
sample_x <- sample(x, length(10), replace = TRUE)
z <- sample_x > y`
Run Code Online (Sandbox Code Playgroud) library(quantmod)
getSymbols("GDPC1",src = "FRED")
Run Code Online (Sandbox Code Playgroud)
我试图提取FRED中的数字经济/金融数据,但也提取元数据.我试图绘制CPI并将元数据作为标签/脚注.有没有办法使用quantmod包提取这些数据?
Title: Real Gross Domestic Product
Series ID: GDPC1
Source: U.S. Department of Commerce: Bureau of Economic Analysis
Release: Gross Domestic Product
Seasonal Adjustment: Seasonally Adjusted Annual Rate
Frequency: Quarterly
Units: Billions of Chained 2009 Dollars
Date Range: 1947-01-01 to 2014-01-01
Last Updated: 2014-06-25 7:51 AM CDT
Notes: BEA Account Code: A191RX1
Real gross domestic product is the inflation adjusted value of the
goods and services produced by labor and property located in the
United States. …Run Code Online (Sandbox Code Playgroud)