将三维数据集读入R

将三维数据集读入R,r,statistics,dataset,gnuplot,R,Statistics,Dataset,Gnuplot,Gnuplot允许三维数据集,这是一组由空行分隔的表,例如: 54.32,16.17,7.42,4.28,3.09,2.11,1.66,1.22,0.99,0.82,7.9 54.63,15.50,8.53,5.31,3.75,1.66,1.14,0.83,0.94,0.52,7.18 56.49,16.67,6.38,3.69,2.80,1.45,1.12,0.89,1.12,0.89,8.50 56.35,16.26,7.76,3.57,2.62,1.89,1.05,1.15,0.63,1

Gnuplot允许三维数据集,这是一组由空行分隔的表,例如:

54.32,16.17,7.42,4.28,3.09,2.11,1.66,1.22,0.99,0.82,7.9

54.63,15.50,8.53,5.31,3.75,1.66,1.14,0.83,0.94,0.52,7.18
56.49,16.67,6.38,3.69,2.80,1.45,1.12,0.89,1.12,0.89,8.50
56.35,16.26,7.76,3.57,2.62,1.89,1.05,1.15,0.63,1.05,7.66

53.79,16.19,6.47,4.57,3.47,1.74,1.95,1.37,1.00,0.74,8.73
55.63,16.28,7.87,3.72,2.48,1.99,1.40,1.19,0.70,1.08,7.65
54.09,15.76,7.96,4.70,2.77,2.21,1.27,1.27,0.66,1.11,8.19
53.79,16.19,6.47,4.57,3.47,1.74,1.95,1.37,1.00,0.74,8.73

...
例如,这是为了显示一个数据集在时间上的演变。在Gnuplot中,您可以选择要用于给定绘图的数据集(使用其索引和关键字huh,indexIIRC)

我一直在使用R,到目前为止,我一直在使用scan/table函数一次手动输入一个it数据集。我没有一个包含所有数据集的大文件,而是每个数据集有一个文件,一次创建一个表

有没有一种(内置的,或者非常简单的)方法可以一次读取所有的聚合数据集,就像我想的那样

dataset <- neatInput("my-aggregate-data")
dataset[1]    # first data set
dataset[2]    # second data set
...

dataset我设法将代码合并成两行,FWIW:)


检查如果你的第三维度是时间,那么通常最好使用专门的时间/日期对象。R中最常用的通用时间序列包包括自定义函数,用于执行所需操作。例如,要以月到年为单位汇总某些数据,请执行以下操作:

> data(AirPassengers); AP = AirPassengers
> # import the package xts, which will 'auto-import' its sole dependency, 
> # the package 'zoo'
> library(xts)    

# AP is an R time series whose data points are in months
> class(AP)
[1] "ts"
> start(AP)
[1] 1949    1
> end(AP)
[1] 1960   12
> frequency(AP)
[1] 12
> AP[1:3]
[1] 112 118 132

> # step 1: convert ts object to an xts object
> X = as.xts(AP)
> class(X)
[1] "xts" "zoo"
> # step 2: create index of endpoints to pass to the aggregator function
> np = endpoints(X, on="years")
> # step 3: call the aggregator function
> X2 = period.apply(X, INDEX=np, FUN=sum)
> X2[1:3]
         [,1]
Dec 1949 1520
Dec 1950 1676
Dec 1951 2042
> # 'X2' is in years (each value is about 12X higher than the first three values for
> # AP above
> data(AirPassengers); AP = AirPassengers
> # import the package xts, which will 'auto-import' its sole dependency, 
> # the package 'zoo'
> library(xts)    

# AP is an R time series whose data points are in months
> class(AP)
[1] "ts"
> start(AP)
[1] 1949    1
> end(AP)
[1] 1960   12
> frequency(AP)
[1] 12
> AP[1:3]
[1] 112 118 132

> # step 1: convert ts object to an xts object
> X = as.xts(AP)
> class(X)
[1] "xts" "zoo"
> # step 2: create index of endpoints to pass to the aggregator function
> np = endpoints(X, on="years")
> # step 3: call the aggregator function
> X2 = period.apply(X, INDEX=np, FUN=sum)
> X2[1:3]
         [,1]
Dec 1949 1520
Dec 1950 1676
Dec 1951 2042
> # 'X2' is in years (each value is about 12X higher than the first three values for
> # AP above