1
我有兩個數據框具有相同的列名。我想在多個數據框的2列中替換某個表達式。所以我寫了下面的代碼:具有多個列和數據幀的函數gsub R
dat <- data.frame(n = 1:19, des = c("Some very long text", "Some very lang test", "Some vary long text", "Some veri long text", "Another very long text", "Anather very long text", "Another very long text", "Different text", "Diferent text", "More text", "More test", "Much more text", "Muh more text", "Some other long text", "Some otoher long text", "Some more text", "Same more text", "New text", "New texd"), x = c("other text", "bad text", "wrong text", "very bad text", "very nice text","text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text", "text"))
dat1 <- data.frame(n = 1:5, des = c("very Some long text", "text Some very long", "Some very long text", "long text Some very", "very long Some text"), x = c("crazy text", "very crazy text", "boring text", "very exciting text","ext"))
repla <- function(dat){
vari <- c(which(names(dat) == "x"),which(names(dat) == "des"))
for (i in vari){
dat[,i] <<- gsub("very", "0", dat[,i])
}
}
但是爲什麼重放功能不工作?