我需要创建一个包含1000到2000之间的任何dimnames(tmp)
的新数组。我知道dimnames(tmp)[1]
缺少1000到2000的值,这就是我收到错误的原因。但是,我仍然需要将1000到2000之间的所有dimnames(tmp)[1]
提取到名为tmp2
的新数组中。我一直在尝试
tmp2= tmp[c(seq(from=1000, to=2000))),,]
tmp
看起来像
attributes(tmp)
$dim
[1] 172 11688 13
$dimnames
$dimnames[[1]]
[1] "1257" "1206" "1175" "1223" "1303" "1379" "1345" "1322" "1376" "1443" "1435"
[12] "1483" "1496" "1474" "1435" "1377" "1244" "1149" "1273" "1362" "1429" "1527"
[23] "1470" "1462" "1361" "1380" "1490" "1490" "1577" "1466" "1511" "1545" "1536"
[34] "1592" "1620" "1698" "1722" "1712" "1689" "1805" "1780" "1829" "1952" "2106"
[45] "2203" "2187" "2199" "2136" "2098" "2052" "2053" "1952" "1977" "1965" "1894"
[56] "1843" "1803" "1782" "1770" "1770" "1770" "1748" "1728" "1722" "1615" "1483"
[67] "1458" "1431" "1425" "1410" "1425" "1410" "1410" "1403" "1402" "1383" "1415"
[78] "1489" "1393" "1384" "1379" "1364" "1346" "1327" "1357" "1357" "1454" "1480"
[89] "1316" "1273" "1239" "1383" "1531" "1531" "1587" "1634" "1736" "1640" "1682"
[100] "1797" "1996" "2067" "2001" "1970" "2169" "2198" "2361" "2328" "2253" "2239"
[111] "2173" "2333" "2275" "2269" "2276" "2411" "2566" "2673" "2673" "2702" "2597"
[122] "2568" "2638" "2786" "2805" "2839" "2788" "2700" "2669" "2599" "2568" "2546"
[133] "2536" "2521" "2498" "2476" "2503" "2428" "2404" "2418" "2431" "2471" "2476"
[144] "2505" "2484" "2547" "2668" "2731" "2716" "2553" "2437" "2437" "2367" "2355"
[155] "2382" "2439" "2455" "2399" "2338" "2267" "2192" "2169" "2223" "2255" "2277"
[166] "2250" "2192" "2206" "2199" "2212" "2166" "2161"
$dimnames[[2]]
NULL
$dimnames[[3]]
[1] "day" "month" "year" "snowpack" "pet" "precip" "snowfall"
[8] "wy" "yd" "wyd" "snowmelt" "rainfall" "recharge"
答案 0 :(得分:1)
您可以使用%in%
:
tmp2 <- tmp[dimnames(tmp)[[1]] %in% seq(from=1000, to=2000)), , ]