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.
Questions tagged [cbind]
450 questions
1
vote
2 answers
How to do a parallel cbind
I have three tibbles a,b,c in a vector first=c(a,b,c). I have another three tibbles in another vector second=c(d,e,f). How do I do a parallel cbind? So a should be cbinded with d, b with e, and c with f. I started out with something…

user17144
- 428
- 3
- 18
1
vote
2 answers
cbind usage returns unexpected results
I have a tibble abc and a tibble def.
abc
# A tibble: 4 x 4
# Groups: Category, Measure [1]
Category Measure Date Value
1 Pickles Gross Sales 2016-01-03 6518758.
2 Pickles Gross Sales…

user17144
- 428
- 3
- 18
1
vote
3 answers
cbind with loop in R
I'm new with R and I've an issue
So my issue is :
I've multiples tables ex: 10 , also different list from kmeans results related to this tables (10). So I want use cbind in order to add each cluster to its table :
Ex:
NEW_table1<-…

Younes Allim
- 11
- 1
1
vote
1 answer
when using `cbind()`, 'identical' inputs trigger different behaviors: row names were found from a short variable and have been discarded
The following operation works fine :
df1 <- data.frame(a= 1, b = 2)
cbind(df1, c=3:4)
#> a b c
#> 1 1 2 3
#> 2 1 2 4
However if I subset df1, even keeping it identical, I get a warning :
df2 <- df1[1,]
identical(df1, df2)
#> [1] TRUE
cbind(df2,…

moodymudskipper
- 46,417
- 11
- 121
- 167
1
vote
1 answer
R how to make assignments and reference a variable name converted from a string
My question is embedded in the code below.
I have created variable names from character strings, and I can assign values to those variable names (in this case, a list), but I can't do any simple operations on the lists unless I use the created…

David Andow
- 25
- 6
1
vote
0 answers
Loop to create new groups of data by combining different columns in R (portfolio analysis)
I have a simple problem and would be grateful for anyone's advice.
I am working on an investment portfolio analysis problem and have created a time series object that includes daily returns data of 100 stocks. I am trying to create 100 portfolios…

vtang
- 11
- 2
1
vote
2 answers
How to cbind vectors of different length in R?
I need to combine some named numeric vectors in R into a data frame. I tried cbind.na as suggestet in another question, but it would not take names into account. Example:
v1 <- c(1,5,6,7)
names(v1) <- c("milk", "flour", "eggs", "sugar")
v2 <-…

Toby
- 177
- 6
1
vote
2 answers
cbind does not create dataset but character vector in R
My goal is to create a new dataframe with 3 columns using cbind.
However, each time I try it turns into a chr, not a data.frame.
L_bw_visit <- c(24.68130, 175.1266, 1.47421, 2.714970, 2.080063, 42.06174, 17.29546,
…

Andrea
- 41
- 8
1
vote
1 answer
How to add a column with the column-names of the value in the row?
My question may not be so well formulated and sounds complicated. But what I want is very simple.
From the given Data frame Df I have made a new Data frame Df1 which contains the max values from each individual column.
Now I want to add to my new…

Edin Mar
- 101
- 6
1
vote
1 answer
How to merge a data frame column with multiple data frames within a list?
I have a data frame df1 with three columns called x, y and z
df1
x y z
8 2 8
9 3 1
1 7 2
I also have a list that contains 30 data frames df2, df3, ... df31, that each have three columns a, b and c.
list1
df2 df3 ... df31
a b c …

Soph2010
- 563
- 3
- 13
1
vote
3 answers
Add columns to data frames with for loop
Variations of this question have been answered, but I am struggling to apply them to my dataset as someone relatively inexperienced with R/programming. I have several data frames and I am trying to use a for loop to create a new variable added to…

Hunter
- 43
- 1
- 5
1
vote
3 answers
Combine matrices of different length and keep column names
There is a similar question about combining vectors with different lengths here, but all answers (except @Ronak Shah`s answer) loose the names/colnames.
My problem is that I need to keep the column names, which seems to be possible using the rowr…

SeGa
- 9,454
- 3
- 31
- 70
1
vote
2 answers
Cbind columns from lists with other list
I have a list call Totalsamples, inside the list I have 9 data frames that look like this:
year total
2015 100
2016 115
2017 150
2018 155
I have other list call counts, inside the list I have 9 data frames that look like this:
year A B…

user195366
- 465
- 2
- 13
1
vote
0 answers
Behaviour of colnames with merging an xts object using cbind
If I use cbind to merge two matrices or data.frames that have the same colnames those colnames stay the same in the new matrix or data.frame:
df <- data.frame(test = c(1,2))
df.merge <- cbind(df,df)
df.merge
test test
1 1 1
2 2 …

smoff
- 592
- 5
- 21
1
vote
2 answers
Extract value from cell where one column/row value is equal to the column name
I've seen several threads on solutions to this, but I am struggling implementing them. I have a df with columns across the top with descriptions, and then I have a list of samples with data that are grouped by description. I need to extract the…

Steve
- 588
- 4
- 17