0
我想根據一列中的值從數據中刪除某些行。我已經嘗試了幾種方法:根據列對子數據框進行子集
#reads in data
sbc016formants.df <- read.table("file path", sep="\t", header = F, strip.white = T)
# names columns
names(sbc016formants.df) <- c("fileName", "start", "end", "vowelLabel")
# list of values I want to remove
list16 <- c(615.162, 775.885)
# produces a subset of data - removes rows with values from list 16 in the start column
sbc016formants.df <- subset(sbc016formants.df, !start %in% list16)
產生此錯誤消息一些,但不是所有的我的數據文件:
Error in match(x, table, nomatch = 0L) :
'match' requires vector arguments
我也試過這樣的基礎上,第二個答案中this話題
sbc002formants.df <- sbc002formants.df[ apply(sbc002formants.df, 1 , function(x) any(unlist(x) %in% list2)) , ]
而這樣做會清除列表中的一些項目(list16
),但不是全部。我想使用第一個答案,但我不明白代碼(在示例中,我不確定bl
是什麼)。
這裏是做重複的例子代碼:
# creates dataframe
fileName <- c("sbc016", "sbc016", "sbc016", "sbc016")
start <- c(1.345, 2.345, 615.162, 775.885)
end <- c(100.345, 200.345, 715.162, 875.885)
sbc016formants.df <- data.frame(fileName, start, end)
# list of what I want to get rid of
list16 <- c(615.162, 775.885)
試試'sbc016formants.df [!(在%list16 sbc016formants.df $開頭%)]'? – aichao
我試圖重現錯誤,但我沒有收到錯誤消息 – Pieter
@aichao,這不會產生任何錯誤消息,但它也不會執行子集化。 – Lisa