I have different 2 datasets like df1 and df2, with only difference in the row name. How can I print it efficiently? Many thanks in advance.
df1 <- mtcars[1:6, 1:3]; rownames(df1)
df2 <- df1; rownames(df2) <- c("Mazda RX4","Mazda RX4 Wag","Datsun 710","Hornet 4 Drive",
"Hornet Sportabout","NEW.NAME"); rownames(df2)
df3 <- cbind(df1,df2); df3
Expected outcome,
mpg cyl disp mpg cyl disp
Mazda RX4 21.0 6 160 21.0 6 160
Mazda RX4 Wag 21.0 6 160 21.0 6 160
Datsun 710 22.8 4 108 22.8 4 108
Hornet 4 Drive 21.4 6 258 21.4 6 258
Hornet Sportabout 18.7 8 360 18.7 8 360
Valiant 18.1 6 225 \\ \\ \\
New.NAME \\ \\ \\ 18.1 6 225
I’m not a massive fan of row names (I would even consider it bad practice or evil). There is an easy way to extract the row name information into a new column using
data.table
.In your case I'd go for:
If you want to keep the original sources identified, I'd do: