我正在读表,它包含描述时间戳的字符串.我只想将字符串转换为内置日期时间类型...
R> Q <- read.table(textConnection('
tsstring
1 "2009-09-30 10:00:00"
2 "2009-09-30 10:15:00"
3 "2009-09-30 10:35:00"
4 "2009-09-30 10:45:00"
5 "2009-09-30 11:00:00"
'), as.is=TRUE, header=TRUE)
R> ts <- strptime(Q$tsstring, "%Y-%m-%d %H:%M:%S", tz="UTC")
Run Code Online (Sandbox Code Playgroud)
如果我尝试将datetime列存储到data.frame中,我会收到一个奇怪的错误:
R> Q$ts <- ts
Error in `$<-.data.frame`(`*tmp*`, "ts", value = list(sec = c(0, 0, 0, :
replacement has 9 rows, data has 5
Run Code Online (Sandbox Code Playgroud)
但如果我通过data.frame中的数字表示,它可以工作......
R> EPOCH <- strptime("1970-01-01 00:00:00", "%Y-%m-%d %H:%M:%S", tz="UTC")
R> Q$minutes <- as.numeric(difftime(ts, EPOCH, tz="UTC"), units="mins")
R> Q$ts <- EPOCH + 60*Q$minutes
Run Code Online (Sandbox Code Playgroud)
了解情况有什么帮助?
我想将平均值和标准误差绘制为水平条形图,我希望平均值排序.
我找到了使用晶格绘制水平排序条形图的方法,但我不知道如何添加错误标记.以下是我的数据和我提出的R代码.
data <- structure(c(0.67, 0.67, 0.76, 0.66, 0.71, 0.6, 0.52, 0.6, 0.71, 0.76,
0.76, 0.71, 0.6, 0.61, 0.9, 0.5, 0.58, 0.84, 0.68, 0.88,
0.89, 0.96, 1, 0.95, 1, 1, 0.98, 0.78, 0.98, 1,
1, 0.99, 1, 1, 0.95, 0.92, 1, 0.91, 1, 0.87,
0.91, 0.72, 0.73, 0.55, 0.82, 0.87, 0.64, 0.75, 0.75, 1,
0.81, 0.79, 1, 0.74, 0.57, 0.84, 1, 0.95, 0.78, 0.95), .Dim = c(20L, 3L), .Dimnames = list(
c("1", "2", "3", "4", "5", "6", "7", "8", "9", …Run Code Online (Sandbox Code Playgroud) HTML5规范允许一次上传多个文件<input type="file", ..., multiple="multiple">.有没有办法利用Rook R包来利用这个?
这是我的尝试,但似乎只显示了一个选定的文件:
library(Rook)
app <- function(env) {
req <- Rook::Request$new(env)
res <- Rook::Response$new()
res$write(
'<html><body>
Select files:
<form method="POST" enctype="multipart/form-data">
<input type="file" name="data" multiple="multiple">
<input type="submit" name="Upload">
</form>
</body></html>')
if (!is.null(req$POST())){
data <- req$POST()[['data']]
res$write("<pre>")
res$write(paste(capture.output(req$POST(),file=NULL),collapse='\n'))
res$write("</pre>")
res$write("<pre>")
res$write(paste(capture.output(data$filename,file=NULL),collapse='\n'))
res$write("</pre>")
}
res$finish()
}
s <- Rhttpd$new()
s$add(app=RhttpdApp$new(name="app", app=app))
s$start(listen="127.0.0.1", quiet=FALSE)
s$browse(1)
#s$stop(); s$remove(all=TRUE); rm(s)
Run Code Online (Sandbox Code Playgroud) 是软件rpart自动修剪?
由rpart生成的决策树比具有自动修剪功能的Oracle Data Mining生成的决策树要高得多.
有没有人知道是否有可能从ggplot中的条形图中排除零值?
我有一个包含如下比例的数据集:
X5employf prop X5employff
1 increase 0.02272727
2 increase 0.59090909 1
3 increase 0.02272727 1 and 8
4 increase 0.02272727 2
5 increase 0.34090909 3
6 increase 0.00000000 4
7 increase 0.00000000 5
8 increase 0.00000000 6
9 increase 0.00000000 6 and 7
10 increase 0.00000000 6 and 7
11 increase 0.00000000 7
12 increase 0.00000000 8
13 decrease 0.00000000
14 decrease 0.00000000 1
15 decrease 0.00000000 1 and 8
16 decrease 0.00000000 2
17 decrease 0.00000000 3
18 …Run Code Online (Sandbox Code Playgroud) 我发现这篇文章让F#使用R.是否有人知道在F#中使用Matlab库的类似方法?付费以及免费
但似乎这还没有,我特别想使用Matlab图像处理工具箱.如果在.NET环境中使用Matlab图像处理库还有其他选择,我会很感激,因为我有一些用Matlab编写的软件包,我希望移植到.NET.
我正在努力实现下面所述的目标,但出现了很多错误。我花了很多时间尝试对规则进行排序并打印前十名。我知道如何打印整个列表。
使用 R 探索较大数据文件中的生成规则。考虑成人数据(在 R 中使用 >data(Adult)命令可用)。生成置信度阈值为 0.8 的关联规则
apriori
。打印按电梯排序的前 10 条规则。到目前为止,这是我的代码:
library(arules)
library(arulesViz)
data(Adult)
head(Adult)
rules <- apriori(Adult, parameter = list(supp = 0.5, conf = 0.8))
top.support <- sort(rules, decreasing = TRUE, na.last = NA, by = "support")
top.ten.support <- sort.list(top.support, partial=10)
inspect(top.ten.support)
top.confidence <- sort(rules, decreasing = TRUE, na.last = NA, by = "confidence")
top.ten.confidence <- sort.list(top.support,partial=10)
inspect(top.ten.confidence)
rules2 <- apriori(Adult, parameter=list(supp = 0.5, conf = 0.8), …Run Code Online (Sandbox Code Playgroud) 我试图用来levelplot绘制一个简单的数字高程模型(DEM).
这是我的代码:
r1 = raster("ned10dem.tif")
e = extent(460000,480000,4555000,4567500)
rr1 = crop(r1,e)
p = levelplot(rr1, scales=list(x=list(at=seq(450000,480000,4000))),
margin=F, cuts=200,
col.regions = terrain.colors(350,alpha=1),
colorkey=list(space="bottom"),
xlab="Easting(m)", ylab="Northing(m)")
plot(p)
Run Code Online (Sandbox Code Playgroud)
情节最终看起来像这样:

我无法弄清楚的是如何增加colorkey和x轴之间的空间,使得colorkey不会覆盖x轴标签.
我有以下数据:
mydf = read.table(text="
name a b
x 10 15
y 20 25
z 35 45
", header = T)
Run Code Online (Sandbox Code Playgroud)
我想创建一个如下图:

我无法在x = 50处从点到垂直线添加水平线.这些线(蓝色)已在上图中手动绘制.我尝试了下面的代码,但它不起作用:
ggplot(mydf, aes(a, b)) + geom_point()+
geom_vline(xintercept=50)+
geom_line(aes(x=50,y=b, group=name))
Run Code Online (Sandbox Code Playgroud)