On 14/03/17 14:56, Jinsong Zhao wrote:
Hi there,
I happened to find the following code can generate a data frame with
same column name.
x <- data.frame(a=c(1,2,3))
y <- data.frame(a=c(2,3,4))
z <- cbind(x,y)
However, in this case, one can not use the $ to extract the second
column, right?
Is it possible to prevent the cbind() produce a data frame with same
column name?
No.
Why not either:
(a) Just make sure the names in "x" and "y" differ?
Or:
(b) Change the names of "z", e.g. names(z) <- c("clyde","irving")?
Or maybe names(z) <- make.unique(names(z)).
You could probably write a wrapper function for cbind() to automate (b)
if you really want to.
cheers,
Rolf Turner
--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276
______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.