【发布时间】:2020-12-21 12:38:22
【问题描述】:
我对数据进行了预处理,从许多 pcap 文件中“提取”了一些信息,结果如下:
device, command type, latency, device id
Nokia 3310, turn on, 22, 1
Nokia 3310, turn off, 12, 1
Nokia 3310, turn on, 20, 2
Nokia 3310, turn off, 14, 2
Nokia 3310, turn on, 21, 3
Nokia 3310, turn off, 19, 3
Nokia 3310, turn on, 2, 4
Nokia 3310, send sms, 12, 4
candle, turn on, 5, 1
candle, turn off, 1, 1
Nuclear power plant, turn on, 64, 1
Nuclear power plant, turn off, 32, 1
Car, turn on, 7, 1
Car, turn off, 2, 1
Car, fuel, 42, 1
我想做箱线图(我的意思是这样的https://www.statmethods.net/graphs/images/boxplot1.jpg),我会在哪里看到:
- X 轴,设备类型(设备列)
- Y 轴,延迟
- “开启”延迟应该是一种颜色”
- “关闭”延迟应该是一种颜色”
- 不应显示其他命令类型
- 请注意,并非所有设备都具有所有操作,有些设备有不止一个观察结果(即诺基亚 3310 有更多“开启”样本...
我认为我有更多的任务/问题。 IE。我可能需要先对数据进行分类。
我目前的做法是这样的:
> library(readr)
> stack <- read_csv("stack.csv")
── Column specification ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
cols(
device = col_character(),
`command type` = col_character(),
latency = col_double(),
`device id` = col_double()
)
> plot(stack$device, stack$latency)
Error in plot.window(...) : need finite 'xlim' values
In addition: Warning messages:
1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
2: In min(x) : no non-missing arguments to min; returning Inf
3: In max(x) : no non-missing arguments to max; returning -Inf
PS:我对 R-project 几乎一无所知(只是一些 10 多年前的其他工作)。
【问题讨论】:
-
也许你想要一个直方图...首先使用
aggregate(latency ~ device, FUN = mean, data = stack)计算频率。 -
@RomanLuštrik,您的命令有效并打印了所有操作的每个设备的平均延迟。我只需要将输入限制为两个特定操作并将其放入单个图表中。我已经尝试过
hist(stack$latency[startsWith(stack$device, 'Nokia 3310')]),但这样一来,我将需要每个设备两个(两个操作)直方图,并且我有大约 10 个设备。