这是一个数据帧as blow:
md <- data.frame(category=rep(LETTERS,3000000),
subcategory=rep(rev(LETTERS),3000000),
decategory=rep(rev(LETTERS),3000000),
amount=rnorm(26*3000000))目前,我使用以下代码更新值,我想知道是否有其他更有效的方法?(对于本例,代码非常快。但是,在我的工作中,有时并不是那么快。所以我想知道有没有其他有效的代码来解决这个问题)
md$amount[md$category=='B'&md$subcategory=='Y'&md$decategory=='Y'] <- 100发布于 2021-07-13 20:31:34
您可以使用data.table -
library(data.table)
setDT(md)[category=='B' & subcategory=='Y' & decategory=='Y', amount := 100]https://stackoverflow.com/questions/68362428
复制相似问题