具有条件(针对每个变量)的按时间顺序排列的数据,并根据条件(针对每个变量)在数据帧中循环
我想按时间顺序将降雨时间序列数据组织到每个雨量计(按代码列)中。 雨量仪位于同一列中,与示例中的行相同,并且有一个月,年和降雨信息的专栏。
组织数据后,我需要进行统计测试,并且由于大量的雨量测量值,循环可以使其更容易。是否有一种方法可以通过在测试中重复的变量在Rain_gauge列中按代码指定每个雨量表?
rain_gauge = c(rep(1442032, 40), rep(1442035, 30), rep(1442036, 30),rep(1442039, 45),rep(1442049, 40),rep(1442032, 40),rep(1442045, 35))
year = runif(260, 1978,2020)
month = runif(260,1,12)
rainfall = runif(260, 50,202)
df = data.frame(rain_gauge, year, month, rainfall)#data frame to be organized in chronological order by "code" category
head(df)
#Examples of tests to apply to the series of each rain gauge in the rain_gauge column.
library(modifiedmk)
mmkh(as.vector(subset(df,rain_gauge=="1442032"))$rainfall)
pvalue_mk = mmkh(as.vector(subset(df,rain_gauge=="1442032"))$rainfall)[[2]]#Result to be save in a data frame results
library(tseries)
adf.test(subset(df,rain_gauge=="1442032")$rainfall)
pvalue_df = adf.test(subset(df,rain_gauge=="1442032")$rainfall)[[2]]#Result to be save in a data frame results
非常感谢!
I would like to organize the rainfall time series data into each rain gauge (by code column) chronologically.
The rain gauges are in the same column, specified in lines as in the example, and there are columns with the month, year and rainfall informations.
After organizing the data, I need to perform statistical tests and a loop can make it easier, due to the large number of rain gauges. Is there a way to loop specifying each rain gauge by code in the rain_gauge column, as the variable to be repeated in the tests?
rain_gauge = c(rep(1442032, 40), rep(1442035, 30), rep(1442036, 30),rep(1442039, 45),rep(1442049, 40),rep(1442032, 40),rep(1442045, 35))
year = runif(260, 1978,2020)
month = runif(260,1,12)
rainfall = runif(260, 50,202)
df = data.frame(rain_gauge, year, month, rainfall)#data frame to be organized in chronological order by "code" category
head(df)
#Examples of tests to apply to the series of each rain gauge in the rain_gauge column.
library(modifiedmk)
mmkh(as.vector(subset(df,rain_gauge=="1442032"))$rainfall)
pvalue_mk = mmkh(as.vector(subset(df,rain_gauge=="1442032"))$rainfall)[[2]]#Result to be save in a data frame results
library(tseries)
adf.test(subset(df,rain_gauge=="1442032")$rainfall)
pvalue_df = adf.test(subset(df,rain_gauge=="1442032")$rainfall)[[2]]#Result to be save in a data frame results
Many thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
考虑
by
,面向对象的包装器tapply
,它允许您按因子对数据帧进行切片并对子集运行进程以返回简化的对象(即、向量、矩阵)或任何输出的列表:Consider
by
, object-oriented wrapper totapply
, that allows you to slice a data frame by factor(s) and run processes on the subsets to return a simplified object (i.e., vector, matrix), or a list of any output: