David
David

Reputation: 91

Dynamically updating a data frame from a subset in R

So, here's what I'd like to do:

df <- data.frame(a=1:6, b=1:6)
ss <- magicSubset(df, a <= 3)

ss$b <- 100

df$b # should be c(100,100,100,4,5,6)

Is there something like this in R, or in a package? I guess it would not be too hard to implement... are there reasons it's a bad idea?

Upvotes: 1

Views: 1375

Answers (1)

Christopher Louden
Christopher Louden

Reputation: 7592

You can subset df$b and assign it a value:

df$b[df$a <= 3] <- 100

Upvotes: 3

Related Questions