我導入了一些沒有列名的數據,所以現在我有超過一百萬行和一列(而不是5列)。在R中拆分一個字符串,不同的拆分參數元素
每一行的格式如下:
x <- "2012-10-19T16:59:01-07:00 192.101.136.140 <190>Oct 19 2012 23:59:01: %FWSM-6-305011: Built dynamic tcp translation from Inside:10.2.45.62/56455 to outside:192.101.136.224/9874"
strsplit(x , split = c(" ", " ", "%", " "))
,並得到
[[1]]
[1] "2012-10-19T16:59:01-07:00" "192.101.136.140"
[3] "<190>Oct" "19"
[5] "2012" "23:59:01:"
[7] "%FWSM-6-305011:" "Built"
[9] "dynamic" "tcp"
[11] "translation" "from"
[13] "Inside:10.2.45.62/56455" "to"
[15] "outside:192.101.136.224/9874"
我知道,它與循環分裂的說法做,但我似乎無法弄清楚如何獲得它是如何我想要的:
[[1]]
[1] "2012-10-19T16:59:01-07:00" "192.101.136.140"
[3] "<190>Oct 19 2012 23:59:01 "%FWSM-6-305011
[5] Built dynamic tcp translation from Inside:10.2.45.62/56455 to outside:192.101.136.224/9874"
每一行都有不同的消息作爲第五個元素,但在第四個元素我只想將其餘的字符串保存在一起。
任何幫助,將不勝感激。
你似乎認爲(誤)的拆分矢量項目按順序應用。 –
這是真的。謝謝你清理它 – camelarms