考虑下表(快照):

我想编写一个查询来从表中选择行
知道怎么做吗?
考虑以下zoo对象:
x <- data.frame(Date = seq(as.Date("2013-02-01"), length=6, by="1 month") - 1, x = seq(6))
y <- data.frame(Date = seq(as.Date("2013-02-01"), length=4, by="1 month"), y = seq(4))
z <- data.frame(Date = seq(as.Date("2012-11-01"), length=9, by="1 month"), z = seq(9))
x.zoo = zoo(x[,-1], order.by = x[,1])
y.zoo = zoo(y[,-1], order.by = y[,1])
z.zoo = zoo(z[,-1], order.by = z[,1])
Run Code Online (Sandbox Code Playgroud)
请注意,3个动物园对象具有不同的长度.我想将所有对象与变量"x"的日期对齐:换句话说,我想创建一个包含Date列(对象x的索引)的新数据帧,并填充每个最接近的变量可用观察.
这是我要找的结果:
Date x y z
1 2013-01-31 1 1 4
2 2013-02-28 2 2 5
3 2013-03-31 3 3 6
4 2013-04-30 4 …Run Code Online (Sandbox Code Playgroud) 我想将数据帧打印到pdf文件.我尝试过以下方法:
pdf("myfile.pdf")
grid.table(df)
dev.off()
Run Code Online (Sandbox Code Playgroud)
这实际上是有效的,但绘制了一些单元格填充颜色的数据框,以及其他一些格式,以及行号.
我只想绘制一个没有特定格式的数据帧,尤其是没有行号.
我还需要提一下,我想绘制这个数据框和一个图.(在数据框上方绘图).我尝试过使用:
layout(matrix(c(1,2), nrow=2, byrow=TRUE), heights = c(2,1))
Run Code Online (Sandbox Code Playgroud)
但数据框显示在我的情节之上(请参见下文)......我不确定为什么?

这样做有简单的方法吗?
谢谢!
我想改进html我使用包在R中生成的表的外观xtable:
library(xtable)
html.table = xtable(<mydataframe>)
digits(html.table) = 2
Run Code Online (Sandbox Code Playgroud)
我打印表使用:
html.tab = print(html.table, type = "html", floating = FALSE)
cat(html.tab, file = <html link>)
Run Code Online (Sandbox Code Playgroud)
我希望能够证明表中的文本,修改标题列的颜色,更改字体,...
有什么方法可以在R中实现这一点吗?
谢谢!
考虑以下矩阵:
mat = rbind(c(".","2","3","4","5","6"),
c(".","2","3","7","8","1"),
c(".","2","3","7","9","2"))
Run Code Online (Sandbox Code Playgroud)
我想找到所有元素不同的第一列的索引.在这种情况下,结果应为5.如您所见,第五列是所有元素不同的第一列.
实际上,矩阵具有非常大的尺寸.
有没有一种简单的方法来检索所有元素不同的第一列的索引?
谢谢!
请耐心等待我,因为我是VBA的初学者.
我试图通过使用VBA的网站打开excel文件.文件的地址(路径)每月更改一次.例如:
7月,文件名为:http://www.clevelandfed.org/research/data/inflation_expectations/2014/July/excel1.xls
8月,文件名为:http://www.clevelandfed.org/research/data/inflation_expectations/2014/August/excel1.xls
问题是我从未预先知道本月的新文件何时发布.因此,我需要检查VBA代码是否存在当前月份文件,如果不存在,我只需打开上个月的文件.
这是我尝试过的:
Dim DirFile As String
Dim wbA As Workbook
DirFile = "http://www.clevelandfed.org/research/data/inflation_expectations/" & Format(Now, "YYYY") & "/" & Format(Now, "MMMM") & "/excel1.xls"
' Check if the file for current month does not exist, open previous month's file
If Len(Dir(DirFile)) = 0 Then
Set wbA = Workbooks.Open("http://www.clevelandfed.org/research/data/inflation_expectations/" & Format(Now, "YYYY") & "/" & Format(DateAdd("m", -1, Date), "MMMM") & "/excel1.xls", IgnoreReadOnlyRecommended:=True)
'If the current month file exists, open it
Else
Set …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 LASSO 进行变量选择,并尝试使用glmnet包在 R 中实现。这是我到目前为止编写的代码:
set.seed(1)
library(glmnet)
return = matrix(ret.ff.zoo[which(index(ret.ff.zoo) == beta.df$date[1]),])
data = matrix(unlist(beta.df[which(beta.df$date == beta.df$date[1]),][,-1]), ncol = num.factors)
dimnames(data)[[2]] <- names(beta.df)[-1]
model <- cv.glmnet(data, return, standardize = TRUE)
coef(model)
Run Code Online (Sandbox Code Playgroud)
这是我第一次运行时得到的:
> coef(model)
15 x 1 sparse Matrix of class "dgCMatrix"
1
(Intercept) 0.009159452
VAL .
EQ .
EFF .
SIZE 0.018479078
MOM .
FSCR .
MSCR .
SY .
URP .
UMP .
UNIF .
OIL .
DEI .
PROD .
Run Code Online (Sandbox Code Playgroud)
但是,这是我再次运行相同代码时获得的结果:
> coef(model)
15 x …Run Code Online (Sandbox Code Playgroud) 解决方案可能非常简单,但我似乎无法轻易搞清楚.我有以下号码:
a = 1000000
#> a
#[1] 1e+06
Run Code Online (Sandbox Code Playgroud)
我想将"a"转换为字符串,但是当我尝试使用时toString,它会提供以下内容:
#> toString(a)
#[1] "1e+06"
Run Code Online (Sandbox Code Playgroud)
我想得到:1,000,000而不是逗号分隔符.这容易实现吗?谢谢!
我想知道哪个函数可以让我绘制填充的矩形(或者用点或虚线/虚线等不同的其他填充)

我知道这个功能rect(),但该功能只允许填充颜色.
任何帮助,将不胜感激!谢谢!
请考虑以下字符串:
##snapshot
string s = "a,,,b,c,,,,d";
###
Run Code Online (Sandbox Code Playgroud)
我试图得到以下结果:
"a,null,null,b,c,null,null,null,d";
Run Code Online (Sandbox Code Playgroud)
换句话说,如果两个逗号之间没有任何内容,我想用"null"替换它.我尝试了以下方法:
using System.Text.RegularExpressions;
### snapshot
Regex r = new Regex("[\\,\\,]");
Console.WriteLine(r.Replace(s, ",null,"));
Run Code Online (Sandbox Code Playgroud)
我得到:

我对正则表达式了解不多,这是我能想到的最好的结果,但结果是错误的.有人可以帮忙吗?谢谢!
我是Perl的初学者,我正在尝试解码以下正则表达式:
$fname =~ /\/([^\/]+)\.txt$/
Run Code Online (Sandbox Code Playgroud)
谁能告诉我我们想要在这里匹配什么?
谢谢!