Questions tagged [cbind]

The functions cbind and rbind are S3 generic, with methods for data frames. The data frame method will be used if at least one argument is a data frame and the rest are vectors or matrices. There can be other methods; in particular, there is one for time series objects. See the section on ‘Dispatch’ for how the method to be used is selected.

450 questions
52
votes
10 answers

cbind a dataframe with an empty dataframe - cbind.fill?

I think I'm looking for an analog of rbind.fill (in Hadley's plyr package) for cbind. I looked, but there is no cbind.fill. What I want to do is the following: #set these just for this example one_option <- TRUE diff_option <- TRUE return_df <-…
Xu Wang
  • 10,199
  • 6
  • 44
  • 78
51
votes
2 answers

pandas equivalent of R's cbind (concatenate/stack vectors vertically)

suppose I have two dataframes: import pandas .... .... test1 = pandas.DataFrame([1,2,3,4,5]) .... .... test2 = pandas.DataFrame([4,2,1,3,7]) .... I tried test1.append(test2) but it is the equivalent of R's rbind. How can I combine the two as two…
uday
  • 6,453
  • 13
  • 56
  • 94
39
votes
1 answer

cbind warnings : row names were found from a short variable and have been discarded

I have below line of code for cbind, but I am getting a warning message everytime. Though the code still functions as it should be, is there any way to resolve the warning? dateset =…
Ianthe
  • 5,559
  • 21
  • 57
  • 74
23
votes
3 answers

cbind 2 dataframes with different number of rows

I have two lists named h and g. They each contain 244 dataframes and they look like the following: h[[1]] year avg hr sal 1 2010 0.300 31 2000 2 2011 0.290 30 4000 3 2012 0.275 14 600 4 2013 0.280 24 800 5 2014 …
min
  • 279
  • 1
  • 3
  • 5
17
votes
3 answers

Dispatch of `rbind` and `cbind` for a `data.frame`

Background The dispatch mechanism of the R functions rbind() and cbind() is non-standard. I explored some possibilities of writing rbind.myclass() or cbind.myclass() functions when one of the arguments is a data.frame, but so far I do not have a…
Stef van Buuren
  • 348
  • 1
  • 10
16
votes
5 answers

Is it possible to skip NA values in "+" operator?

I want to calculate an equation in R. I don't want to use the function sum because it's returning 1 value. I want the full vector of values. x = 1:10 y = c(21:29,NA) x+y [1] 22 24 26 28 30 32 34 36 38 NA x = 1:10 y = c(21:30) x+y [1] 22 24 26 28…
M. Beausoleil
  • 3,141
  • 6
  • 29
  • 61
15
votes
2 answers

cbind: is there a way to have missing values set to NA?

Please forgive me if I missed an answer to such a simple question. I want to use cbind() to bind two columns. One of them is a single entry shorter in length. Can I have R supply an NA for the missing value? The documentation discusses a…
tumultous_rooster
  • 12,150
  • 32
  • 92
  • 149
10
votes
1 answer

Merging data frames with different number of rows and different columns

I have two data frames with different number of columns and rows. I want to combine them into one data frame. > month.saf Name NCDC Year Month Day HrMn Temp Q 244 AP 99999 2014 2 1 0 12 1 245 AP 99999 …
rar
  • 894
  • 1
  • 9
  • 24
9
votes
4 answers

Using R, getting a "Can't bind data because some arguments have the same name" using dplyr:select

#use readtable to create data frames of following unzipped files below x.train <- read.table("UCI HAR Dataset/train/X_train.txt") subject.train <- read.table("UCI HAR Dataset/train/subject_train.txt") y.train <- read.table("UCI HAR…
Doptima
  • 171
  • 1
  • 1
  • 10
9
votes
1 answer

cbind named vectors in R by name

I have two named vectors similar to these ones: x <- c(1:5) names(x) <- c("a","b","c","d","e") t <- c(6:10) names(t) <- c("e","d","c","b","a") I would like to combine them so to get the following outcome: x t a 1 10 b 2 9 c 3 8 d 4 7 e 5 …
ltr
  • 332
  • 2
  • 9
9
votes
2 answers

cbind (R function) equivalent in numpy

Here's the behavior I want: import numpy as np x = np.array([[1,2],[3,4]]) y = np.array([5, 6]) cbind(x,y) # desired result: np.array([[1,2,5],[3,4,6]]) Seems like it should be easy, but the options I found on…
stackoverflax
  • 1,077
  • 3
  • 11
  • 25
9
votes
1 answer

R fast cbind matrix using Rcpp

cbind in R is relatively time consuming in repeated calls, but it also is powerful for various data types. I have written code that is 3X faster than cbind when binding two matrices. But bind_cols in dplyr package is merely 100X faster than cbind.…
Weve Wang
  • 93
  • 1
  • 4
8
votes
2 answers

cbind two lists of data.frames to a new list

I have two lists of data.frames. Both lists have the same length and contain fitting data.frames in their according list elements. So the scenario looks like this dfa = data.frame(a=1:3, b = letters[1:3]) dfb = data.frame(x=runif(3)) a =…
jakob-r
  • 6,824
  • 3
  • 29
  • 47
8
votes
4 answers

Interleave columns of two data frames

I have two identical data frames. Same column and row headings. One has correlations in it and one has p-values. I want to merge these two tables in an interleaved manner, so that the first column is the correlation, the next the p-value, the next…
user3801778
  • 97
  • 1
  • 4
7
votes
4 answers

Combine two data frames of the same size one column after each other

I have two datasets both of the same size [132,450000]. One with values and another with p-values corresponding to those values. Now I want to combine those two datasets so that I have 1 large dataframe [264,450000] with the column with values…
1
2 3
29 30