简体   繁体   中英

How are cbind and rbind implemented?

Suppose I have two data frames df1 and df2 , and I want to cbind them:

df1 <- data.frame(a=c(1,2), b=c(3,4))
df2 <- data.frame(c=c(3,4), d=c(5,7))
df1 <- cbind(df1,df2)

When I write the line 3 this way, would R create a new larger data frame and assign it to df1 or it would optimized to add the new columns of df2 into df1 in place to save memory? Are there any documents on this?

A data frame is a vector of columns. R will create a new vector for the new df1 result. Earlier versions would also duplicate the columns, but as of 3.1.0 R no longer does this and the columns will be shared between the new df1 and the old df1 and df2.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM