我有一个矢量集' location'包含纬度/经度值的1000个位置。我想随机隐藏某些位置的百分比,并通过我的算法估计这些位置的纬度/经度值。假设我想要随机隐藏这1000个位置中的10%并使它们未知,如何隐藏R中我的数据集中的值。是否有任何可用的包可以帮助我实现这一点。
因此,如果这是一个完整的数据集location
:
print(location)
Longitude Latitude
74.858863999999997 31.327629000000002
74.224755999999999 31.309773000000000
74.216177999999999 31.463429000000001
74.321051999999995 31.575917000000000
74.349832000000006 31.582062000000001
74.319663000000006 31.573923000000001
74.349384000000001 31.527654999999999
74.410433999999995 31.521415999999999
74.349609000000001 31.527670000000001
74.426238999999995 31.522907000000000
74.309755999999993 31.561537999999999
74.426238999999995 31.522907000000000
74.282814000000002 31.456077000000001
74.224754000000004 31.309773000000000
74.426238999999995 31.522907000000000
74.365804999999995 31.470144000000001
74.311349000000007 31.483550999999999
74.312512999999996 31.472501999999999
74.426238999999995 31.522907000000000
74.319362999999996 31.484127000000001
74.370300000000000 31.537609000000000
74.879557000000005 32.104958000000003
74.426238999999995 31.522907000000000
73.463269999999994 30.815715999999998
74.412903999999997 31.470146000000000
74.319362999999996 31.484127999999998
74.412891999999999 31.470144999999999
74.313017000000002 31.484044999999998
74.412890000000004 31.470147999999998
74.328925999999996 31.536244000000000
74.336599000000007 31.528677999999999
我想只打印以下内容:
print(location)
Longitude Latitude
74.858863999999997 31.327629000000002
74.224755999999999 31.309773000000000
74.216177999999999 31.463429000000001
74.321051999999995 31.575917000000000
74.349832000000006 31.582062000000001
74.319663000000006 31.573923000000001
74.349384000000001 31.527654999999999
74.410433999999995 31.521415999999999
74.349609000000001 31.527670000000001
74.426238999999995 31.522907000000000
74.309755999999993 31.561537999999999
74.426238999999995 31.522907000000000
74.282814000000002 31.456077000000001
74.224754000000004 31.309773000000000
74.426238999999995 31.522907000000000
74.365804999999995 31.470144000000001
74.311349000000007 31.483550999999999
74.312512999999996 31.472501999999999
74.426238999999995 31.522907000000000
74.319362999999996 31.484127000000001
74.370300000000000 31.537609000000000
74.879557000000005 32.104958000000003
74.426238999999995 31.522907000000000
73.463269999999994 30.815715999999998
74.412903999999997 31.470146000000000
74.319362999999996 31.484127999999998
74.412891999999999 31.470144999999999
74.313017000000002 31.484044999999998
但是数据集仍然包含未打印的值,并且被隐藏了#34;
答案 0 :(得分:1)
我只是定义一个向量(可以是数据集的列或可以是单独的),指示每行是隐藏还是显示。例如:
# to hide about 20% of your data:
hide_row = which(rbinom(n = nrow(location), size = 1, prob = 0.2) == 1)
# to hide exactly 20% of your data:
hide_row = sample(1:nrow(location), size = 0.2 * nrow(location))
# print all but the hidden rows
location[-hide_row, ]
您似乎不希望这样(不确定您的用例),但更自然的方法是复制隐藏行的数据副本:
partial_location = location[-hide_row, ]