Here is some toy data
x <- c("Bird","Bird","Tiger","Bird","Fish","grey","blue","orange","green","yellow","10","5","7","12","5","10","10","8","12","2","10","20","10","18","3")
m <- matrix(x,byrow = F,ncol = 5,nrow= 5)
m <- as.data.frame(m)
colnames(m) <- c("Animal","colour","length","height","weight")
y <- c("Tiger","Bird","Bird","colour","length","colour","orange","10","green","orange/black","12","light green")
new.m <- matrix(y,byrow=F,ncol=4,nrow = 3)
new.m <- as.data.frame(new.m)
colnames(new.m) <- c("Animal","attribute","value","new value")
How can I efficiently update the values in m
using the data frame new.m
. The final result should look like this:
z <- c("Bird","Bird","Tiger","Bird","Fish","grey","blue","orange/black"," light green","yellow","12","5","7","12","5","10","10","8","12","2","10","20","10","18","3")
update.m <- matrix(z,byrow = F,ncol = 5,nrow= 5)
update.m <- as.data.frame(update.m)
colnames(update.m) <- c("Animal","colour","length","height","weight")
For a fixed row in new.m I can achieve this easily. But can this be done in comprehensive not row based way?