我有三个数据帧。
a)纬度:
20.08824 20.11288 20.13752 20.16218
20.09489 20.11954 20.14417 20.16882
20.11476 20.13941 20.16408 20.18874
20.12138 20.14604 20.17071 20.19536
b)经度:
-118.0981 -118.1052 -118.1123 -118.1194
-117.9931 -118.0002 -118.0072 -118.0143
-117.8092 -117.8162 -117.8232 -117.8302
-117.783 -117.7899 -117.7969 -117.8039
c)一个变量,比方说windspeed
2 2 3 4
2 4 3 3
4 4 5 9
6 4 2 5
我有一个Lat-Long坐标,用于我想要子集的边界框的边缘(c)
20.14417,-118.0002
20.14417,-118.0072
20.11954,-118.0002
20.11954,-118.0072
[Bounding Box][http://www.darrinward.com/lat-long/?id=634088]
我知道如何在一个数据帧中对列进行子集化,但我不知道如何在三个数据帧中进行。能帮忙吗?
注意:(a),(b)和(c)是具有完全相同尺寸的全局数据集。此处给出的数据仅供参考。
附录
我有大型Matrix,而不是数据帧,如果它有所作为。
答案 0 :(得分:1)
首先,我会将所有内容放入数据框中:
x<-data.frame(as.vector(lat),as.vector(long),as.vector(wind))
names(x)<-c("lat","long","wind")
dput(x)
,并提供:
structure(list(lat = c(20.08824, 20.09489, 20.11476,
20.12138, 20.11288, 20.11954, 20.13941, 20.14604, 20.13752, 20.14417,
20.16408, 20.17071, 20.16218, 20.16882, 20.18874, 20.19536),
long = c(-118.0981, -117.9931, -117.8092, -117.783,
-118.1052, -118.0002, -117.8162, -117.7899, -118.1123, -118.0072,
-117.8232, -117.7969, -118.1194, -118.0143, -117.8302, -117.8039
), wind = c(2L, 2L, 4L, 6L, 2L, 4L, 4L, 4L, 3L, 3L,
5L, 2L, 4L, 3L, 9L, 5L)), .Names = c("lat", "long",
"wind"), row.names = c("V11", "V12", "V13", "V14", "V21",
"V22", "V23", "V24", "V31", "V32", "V33", "V34", "V41", "V42",
"V43", "V44"), class = "data.frame")
然后它是一个简单的子集:
x[x$lat < 20.14417 & x$lat > 20.11954 & x$long < -118.0002 & x$long > -118.0072,]
答案 1 :(得分:0)
您可以通过将数据框放入其他其他子集表对象来进行数据集的子集化。数组和列表用于保存它们。
lst <- list(df1, df2, df3)
然后你可以用函数进行子集化。例如,每个数据框的第一列:
lapply(lst, `[`, 1)
[[1]]
V1
1 20.08824
2 20.09489
3 20.11476
4 20.12138
[[2]]
V1
1 -118.0981
2 -117.9931
3 -117.8092
4 -117.7830
[[3]]
V1
1 2
2 2
3 4
4 6
可以使用数组完成相同的第一列子集:
a <- simplify2array(c(df1, df2, df3))
dim(a) <- c(4,4,3)
a[,1,]