仅在特定行中替换一个df列的值

时间:2013-08-30 06:44:05

标签: r

我有vector index ,它对应于我想为一个特定列修改的df行

index <- c(1,3,6)

dm <- one  two three four
       x    y    z    k
       a    b    c    r 
       s    e    t    f
       e    d    f    a
       a    e    d    r
       q    t    j    i

现在我想修改第1,3和6行的“3”列,用“A”替换它中的任何值。

我应该使用 apply 吗?

1 个答案:

答案 0 :(得分:1)

不需要apply。您可以简单地使用以下内容:

dm$three[index] <- "A"