小编phr*_*uin的帖子

如何将XTS更改为data.frame并保留索引?

我在R中有以下格式的XTS时间序列,并尝试在导出为CSV以便在另一个程序中工作之前进行一些处理,子集化和重新排列.

head(master_1)
                   S_1
2010-03-03 00:00:00 2.8520
2010-03-03 00:30:00 2.6945
2010-03-03 01:00:00 2.5685
2010-03-03 01:30:00 2.3800
2010-03-03 02:00:00 2.2225
2010-03-03 02:30:00 2.0650
Run Code Online (Sandbox Code Playgroud)

str(master_1)
An ‘xts’ object from 2010-03-03 to 2010-05-25 08:30:00 containing:
  Data: num [1:4000, 1] 2.85 2.69 2.57 2.38 2.22 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr "S_1"
  Indexed by objects of class: [POSIXt,POSIXct] TZ: 
  Original class: 'zoo'  
  xts Attributes:  
List of 1
 $ dateFormat: chr "Date"
Run Code Online (Sandbox Code Playgroud)

我想将其转换为data.frame,以便我可以更轻松地操作它,然后导出到另一个程序.但是,当我使用test1 <- as.data.frame(master_1)test1确实有可见的索引(即日期和时间)时,

head(test1)
                       S_1 …
Run Code Online (Sandbox Code Playgroud)

time r dataframe xts

29
推荐指数
4
解决办法
3万
查看次数

如何使用R在我的散点图上绘制我的R Squared值?

这似乎是一个简单的问题,所以我希望它是一个简单的答案.我正在绘制我的点并拟合线性模型,我可以做到.然后我想在图上绘制一些汇总统计数据,例如R Squared值.我似乎只能在命令行中获得R Squared值.任何建议; 我需要查看ggplot或其他什么吗?提前致谢.

#Does the plot
plot(df$VAR1, df$VAR2)
#Adds the line
abline(lm(df$VAR2~df$VAR1), col="red")
#Shows stats on command line
summary(lm(df$VAR2~df$VAR1))
Run Code Online (Sandbox Code Playgroud)

statistics plot r linear-regression

17
推荐指数
2
解决办法
6万
查看次数

如何更改R中的时间序列(XTS或ZOO)?

我是stackoverflow的新手,对R来说相当新,但搜索时间很长,很难找到以下问题的答案.

我有许多数据文件是温度与时间序列.我将CSV导入为ZOO对象,然后转换为XTS.正确的文件看起来像这样,有小时和半小时的读数:

>head(master1)
                       S_1
2010-03-03 00:00:00 2.8520
2010-03-03 00:30:00 2.6945
2010-03-03 01:00:00 2.5685
2010-03-03 01:30:00 2.3800
2010-03-03 02:00:00 2.2225
2010-03-03 02:30:00 2.0650
Run Code Online (Sandbox Code Playgroud)

但有些人的时间价值略有偏差 - 即23:59:00而不是00:00:00,或00:29:00而不是00:30:00.

>head(master21)
                       S_21
2010-03-04 23:59:00  -0.593
2010-03-05 00:29:00  -0.908
2010-03-05 00:59:00  -1.034
2010-03-05 01:29:00  -1.223
2010-03-05 01:59:00  -1.349
2010-03-05 02:29:00  -1.538
Run Code Online (Sandbox Code Playgroud)

我想纠正这些时间序列,因为微小差异对我的分析并不重要,我最终想要合并文件,因此每个时间序列需要具有相同的时间.

I want a command that can just say "shift the time series forward by 1 minute, but don't alter the data column (e.g. S_21). I have had some luck with gsub() on easier changes, …

r time-series zoo xts

9
推荐指数
1
解决办法
3197
查看次数

标签 统计

r ×3

xts ×2

dataframe ×1

linear-regression ×1

plot ×1

statistics ×1

time ×1

time-series ×1

zoo ×1