R:从文本文件创建图形 #/垃圾箱/垃圾箱 skip.header是否尝试将两个占位符名称添加到col.names?您正在为每一行添加两个|,因此可能会创建两个额外的列,因此引发错误。@Mako212,感谢您的回答,如果您的意思是:col.names尝试向
R:从文本文件创建图形R:从文本文件创建图形 #/垃圾箱/垃圾箱 skip.header是否尝试将两个占位符名称添加到col.names?您正在为每一行添加两个|,因此可能会创建两个额外的列,因此引发错误。@Mako212,感谢您的回答,如果您的意思是:col.names尝试向,r,linux,tshark,R,Linux,Tshark,R:从文本文件创建图形 #/垃圾箱/垃圾箱 skip.header是否尝试将两个占位符名称添加到col.names?您正在为每一行添加两个|,因此可能会创建两个额外的列,因此引发错误。@Mako212,感谢您的回答,如果您的意思是:col.names尝试向col.names添加两个占位符名称?您正在为每一行添加两个|,因此可能会创建两个额外的列,因此引发错误。@Mako212,感谢您的响应,如果您是指:col.names #!/bin/Rsceipt skip.header <- 11
#/垃圾箱/垃圾箱
skip.header是否尝试将两个占位符名称添加到col.names
?您正在为每一行添加两个|
,因此可能会创建两个额外的列,因此引发错误。@Mako212,感谢您的回答,如果您的意思是:col.names尝试向col.names
添加两个占位符名称?您正在为每一行添加两个|
,因此可能会创建两个额外的列,因此引发错误。@Mako212,感谢您的响应,如果您是指:col.names
#!/bin/Rsceipt
skip.header <- 11 # how many lines to skip including the header row
comment.char <- "=" # skip lines with <char> in it
col.names <- c( "time", "frames", "bytes" )
args <- commandArgs( trailingOnly = TRUE )
number.graphs <- length( args )
for ( d in 1:length( args ) ) {
file <- args[[d]]
# get date and time from file name and convert to a time object
date.time <- as.POSIXlt(
gsub(
".*([0-9]{4}-[0-9]{2}-[0-9]{2})_([0-9]{2})-([0-9]{2}).*",
"\\1 \\2:\\3:00",
file,
perl=T
)
)
# read the data
traffic <- read.table( file=file,
header=F,
sep="|",
col.names=col.names,
skip=skip.header,
comment.char="="
)
# massage the data a bit
traffic$kbits <- ( traffic$bytes * 8 ) / 1024
traffic$frames <- NULL
traffic$bytes <- NULL
traffic$time <- as.numeric(
gsub(" <> .*", "", traffic$time, perl = T )
) + date.time
# calculate max and avg
traffic.max <- round( max( traffic$kbits ), digits = 2 )
traffic.avg <- round( mean( traffic$kbits ), digits = 2 )
# prepare the graph
sub.title <- paste( "Max:", traffic.max, "Kbit/s; Avg:", traffic.avg, "Kbit/s" )
names( traffic )
# output as pdf and png
pdf( paste( file, ".pdf", sep = "" ) )
plot( traffic, type="h", main=file, sub=sub.title, xlab="Time", ylab="Kbit/s" )
png( paste( file, ".png", sep = "" ) )
plot( traffic, type="h", main=file, sub=sub.title, xlab="Time", ylab="Kbit/s" )
}
=============================
| IO Statistics |
| |
| Duration: 4.643122 secs |
| Interval: 1 secs |
| |
| Col 1: Frames and bytes |
|---------------------------|
| |1 |
| Interval | Frames | Bytes |
|---------------------------|
0 <> 1 | 21 | 1918
1 <> 2 | 24 | 4894
2 <> 3 | 491 | 5042
3 <> 4 | 34 | 402
4 <> Dur| 52 | 747
=============================
=============================
| IO Statistics |
| |
| Duration: 4.643122 secs |
| Interval: 1 secs |
| |
| Col 1: Frames and bytes |
|---------------------------|
| |1 |
| Interval | Frames | Bytes |
|---------------------------|
| 0 <> 1 | 21 | 1918 |
| 1 <> 2 | 24 | 4894 |
| 2 <> 3 | 491 | 5042 |
| 3 <> 4 | 34 | 402 |
| 4 <> Dur| 52 | 747 |
=============================