删除包含R中某个切割点以上值的行

时间:2014-09-28 16:01:33

标签: r graph time-series outliers

time-series plot

嗨,我已经为12小时内监控特定变量的一堆对象绘制了一个时间序列。我想删除上图中y轴上包含10以上值的所有对象。这甚至可能吗?任何指针都会对我有所帮助。感谢。

这是我的部分数据的输入:

test <- structure(list(hr3 = c(-0.448581004620338, 1.85091950824544, 
-0.388161362087543, -0.665380898414483, -0.277984366880682, -0.437918714761609, 
0.0418843288811726, -0.516108840392285, -0.76134150714304, -0.3348499127939, 
0.884205227720723, -0.014981217032046), hr4 = c(-0.428512239173087, 
1.95372170393779, -0.366683266603797, -0.646732142358816, -0.0320794150523447, 
-0.47943021658309, -0.315765289193793, -0.533985192379523, -0.537622190765952, 
0.0261125591305165, 0.935362155737723, -0.0138944231202006), 
hr5 = c(-0.556293173068285, 1.97570442413855, -0.393521898962132, 
-0.668424495230302, -0.219899206582235, -0.545441754794542, 
-0.527356057671636, -0.111385023844799, -0.581613149040354, 
1.05695101029493, 2.39890973681455, 0.0260662742892864), 
hr6 = c(0.141994463541292, 1.72026989695927, -0.433453508984239, 
-0.416627544875305, -0.181064047350234, -0.423357930518879, 
-0.48393140131104, -0.564696029033921, -0.749781634232192, 
0.52562644522498, 2.86107026354497, -0.0733778770530584), 
hr7 = c(-0.0818711569624052, 2.11985518432835, -0.373315076988859, 
-0.394510998445328, -0.375964567170917, -0.595872252281787, 
-0.577325821007376, -0.656810526469136, 0.180428371061403, 
0.143335508512581, 0.654687113649904, -0.285881900980923), 
hr8 = c(-0.474931311491395, 1.42292037404823, -0.37784044340877, 
-0.788186753795715, -0.526224600289764, -0.806505785509418, 
-0.766203915739272, -0.44012515123536, -0.474931311491395, 
-0.526224600289764, 0.0325058669781751, -0.471267505148655
), hr9 = c(-0.621770802068411, 0.401530426081227, -0.358586729853952, 
-0.304911030915477, -0.268550073570059, -0.654668811095218, 
-0.791455269680364, -0.822621804547866, -0.644279966139384, 
-0.491910240120487, -0.117911821710467, -0.384558842243537
), hr10 = c(-0.327619749398401, 0.462060915872808, 0.631788660670919, 
-0.611690395955239, -0.375858161077864, -0.77963153291337, 
-0.46518855307687, -0.78499135643331, -0.733179729073887, 
-0.427669788437288, 0.0118357401978198, 0.521018974592152
), hr11 = c(0.196841618716218, 0.58650231756246, -0.124164576047591, 
-0.562068980465273, -0.506403166344381, -0.756899329888394, 
-0.239207258564101, -0.756899329888394, -0.320850452608075, 
-0.189108025855298, 0.135609223183237, 0.126331587496421), 
hr12 = c(-0.336881803222796, 0.619313666511149, 3.66262655713023, 
-0.713215763198405, -0.177515891600472, -0.630652700550695, 
-0.254318740575086, -0.742016831563885, -0.44248572056289, 
-0.200556746292856, 0.212258566945695, 0.943805703428894), 
hr13 = c(-0.359473487083687, 0.577779602110567, -0.333386919988817, 
-0.771268581938419, 0.480886638615336, -0.707915490422307, 
-0.311027005336072, -0.761951950833109, -0.34456687731519, 
-0.56257604517946, 0.0821348273080387, 0.585232906994815), 
hr14 = c(-0.40294783799287, 0.573856351285527, -0.616102452351533, 
-0.758823368052551, 0.130865457096652, -0.773651515138371, 
-0.313978955477949, -0.771797996752644, -0.623516525894443, 
-0.562350419165435, 0.0696993503676446, -0.160136929462566
)), .Names = c("hr3", "hr4", "hr5", "hr6", "hr7", "hr8", 
"hr9", "hr10", "hr11", "hr12", "hr13", "hr14"), row.names = c("400", 
"401", "402", "403", "404", "405", "406", "407", "408", "409", 
"410", "411"), class = "data.frame")

和我用来制作情节的代码

library(ggplot2)
library(reshape2)
test$id = rownames(test)

mm = melt(test, id='id')

ggplot(mm)+geom_line(aes(x=variable, y=value, group=id, color=id))

感谢。

1 个答案:

答案 0 :(得分:0)

嗯,你的测试数据集中没有超过10的值,但是让我们将值放在上面,你可以用宽格式做

lt2 <- test[rowSums(test[, 1:12]>2)==0, ]

或者您可以使用

以高大的格式进行操作
mlt2 <- mm[with(mm, ave(value, id, FUN=max))<2, ]

对于具有任何值> 2的个人,所有这些观察都应该删除所有观察结果。