开发者

Can one add a data.frame to itself?

I want to append or add a data.frame to itself... Much in the same way the one adds:

n <- n + t  

I have a function that 开发者_如何学运维creates a data.frame.

I have been using:

g <- function(compareA,compareB) {
    for (i in 1:1000) {
        ttr <- t.test(compareA, compareA, var.equal = TRUE)
        tt_pvalues[i] <- ttr$p.value
    }
    name_tag <- paste(nameA, nameB, sep = "_Vs_")

    tt_titles <- data.frame(name_tag, tt_titles) 
    # character vector which I want to add to a list

    ALL_pvalues <- data.frame(tt_pvalues, ALL_pvalues) 
    # adding a numeric vector of values to a larger data.frame
}

Would cbind be better here?


There are two methods that would "add or append" data to a data.frame by columns and one that would append by rows. Assuming tag is the data.frame, and tt_titles is a vector of the same length that 'tag' has rows, then either of these would work:

 tag <- cbind(tag, tt_titles) 
# tt_titles could also be a data.frame with same number of rows

Or:

tag[["tt_titles"]] <- tt_titles

Now let's assume that we have instead two data.frames with the same column.names:

bigger.df <- rbind(tag, tag2)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜