Saturday, July 14, 2018

R: Replace a data frame in a list with a new data frame

For example, I have three data frames a1, a2, a3 in one list c



a1 <- data.frame(x=c(1,2), y=c(2,3))
a2 <- data.frame(x=c(3,4), y=c(4,5))
a3 <- data.frame(x=c(5,6), y=c(6,7))

c <- list(a1, a2, a3)


Now I have a new data frame b1. I want the a1 in c to be replaced by b1.



b1 <- data.frame(x=c(7,8,9), y=c(8,9,10))


I tried to use c[1] <- b1, which does not work.
c <- list(b1, a2, a3) will do what I want, but is there a better way to do it?

No comments:

Post a Comment

plot explanation - Why did Peaches&#39; mom hang on the tree? - Movies &amp; TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...