我有一個大資料框,并且想洗掉重復的列
為簡單起見,讓我們假設這是我的資料:
df <- data.frame(id1 = c("Aa","Aa","Ba","Ca","Da"), id2 = c(2,1,4,5,10), location=c(351,261,101,91,51), comment=c(35,26,10,9,5), comment=c(5,16,25,14,11), hight=c(15,21,5,19,18), check.names = FALSE)
我可以使用以下方法洗掉重復的列名“comment”:
df <- df[!duplicated(colnames(df))]
但是,當我在我的真實資料框中應用相同的代碼時,它會回傳一個錯誤:
Error in `[.data.table`(SNV_wild, !duplicated(colnames(SNV_wild))) :
i evaluates to a logical vector length 1883 but there are 60483 rows. Recycling of logical i is no longer allowed as it hides more bugs than is worth the rare convenience. Explicitly use rep(...,length=.N) if you really need to recycle.
抱歉,我無法發布真實資料,因為它非常大,您可能會看到錯誤。
我該如何解決這個問題 - 我已經瀏覽了所有列名并且有重復的列名。
先感謝您
uj5u.com熱心網友回復:
你真正的資料框是 class data.table,而你的小例子不是。你可以試試:
df[,!duplicated(colnames(df)), with=F]
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/468510.html
