0
我想讀R中一個CSV文件並找到文件的列特定的模式,並計算出現了多少次gregexpr的額外信息。以下是代碼:刪除R中
dataframe <- read.csv("path-analysis-2003-a.csv", header = TRUE, stringsAsFactors=FALSE)
for(i in 1:nrow(dataframe))
{
counter <- gregexpr("-",dataframe$Path[i], fixed = TRUE, useBytes = TRUE)
print(length(counter))
}
但是,輸出顯示每行的長度爲1。當調試代碼我發現這個輸出:
[[1]]
[1] 10 19 28 41 43 44 45 46 50 60 67
attr(,"match.length")
[1] 1 1 1 1 1 1 1 1 1 1 1
attr(,"useBytes")
[1] TRUE
輸出(其中,位置是給定的)的第一行是有用,因爲我可以從那裏計算的發生。然而,問題是我不知道如何擺脫其他輸出信息。有什麼建議嗎?
'屬性(計數器[[1]])< - NULL',或更簡單地'C(計數器[[1]])' –
感謝您的。你能解釋它是如何工作的嗎? – user2293224
它在'help(gregexpr)'和'help(attributes)'中解釋過。 –