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
1 answer
Concatenating matches in a merge with multiple matches
I have data as follows:
input_A <- data.frame(ID = c(1,2), some_var = c("bla","more bla"))
input_B <- structure(list(ID = c(1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,
2, 2), year = c(2001, 2002, 2003, 2001, 2002, 2003, 2001, 2002,
2003, 2001, 2002,…

Tom
- 2,173
- 1
- 17
- 44
1
vote
2 answers
Assigning multiple column names at once using cbind
How can I assign multiple column names at once using cbind?
# works fine
cbind(mtcars, 'new1' = apply(X = array(data = 1:64, dim = c(32, 1)),
MARGIN = c(1,2),
FUN = function(x)…

user1
- 404
- 1
- 5
- 18
1
vote
1 answer
Difficulty connecting data tables
I want to bind these two (df1,df2) datasets:
df1f <- mtcars %>% filter(am == 1)
df1 <- cbind(n = table(df1f$carb),
prop.table(with(df1f, table(carb, cyl)), margin = 1))
> df1
n 4 6 8
1 4 1 0.0000000 0.0000000
2 4 1…

Sascha
- 159
- 6
1
vote
1 answer
How can we remove rows between multiple dataframe that shared a commun words in R?
I have 36 dataframes (divided in two groups H and E; 18 for each). All my dataframes carry a column with multiple words called 'AA'. I would like to remove all the words in H that exists in E and keep only the words unshared between H or E.
Do you…

Asûra
- 15
- 3
1
vote
1 answer
How cbind data.frames in R using the IDs in a specific column
I have 2 dataframes:
df1
Taxa Env Correlation
1 C1161 pH -0.209916044
2 C1161 pH 0.101338976
3 C1161 Temp -0.228451375
4 C1161 Temp -0.218456646
5 C1161 TS 0.255112839
6 C26 NH4 …

abraham
- 661
- 8
- 14
1
vote
3 answers
How can I solve this if else statement and merge the data in to one one dataframe?
I want to make a table on Hazard level. if the risk level is less than 10 then it will be hazard level "I", risk level<100 = II, risk level<1000 = III and risk level > 1000 = IV. Now for this run the code below.
At first I made an empty…

Kazi
- 67
- 7
1
vote
0 answers
How to combine hundreds of columns into one data frame by matching to a specific column in R?
I currently have hundreds of files containing unique IDs and unnormalized read counts. I want to take the read counts from each file and match them all to the unique IDs in the first column. However, each files has a different amount of counts and…

Isabella2526
- 11
- 1
1
vote
0 answers
Using cbind for explanatory variables in glmer in R
I am trying to create a model in R where I want to estimate the variance of a particular ratio (in this example, nC:nT) of an individual that can be explained by the ratio of these values of its parents. In the model, I am using cbind for both the…

rschen
- 31
- 1
1
vote
2 answers
Can you use a loop to repeat a cbind function?
I have two dataframes (growth and investment) that I have split using the group_split() function into 40 dataframes (split per COROP region in the Netherlands). My aim is to merge the split dataframes for each COROP, which can be done using the…

seabasshartman
- 13
- 4
1
vote
1 answer
Why is R not recognizing the new column I added into my dataframe?
I am doing time series analysis on oil prices in R. In order to complete one of my modeling tasks, a MONTH column next to the closing price of oil each month was added:
df <- cbind(df, MONTH=1:nrow(df))
The output was successful and came out to…

davidd21
- 43
- 1
- 5
1
vote
3 answers
How can I force lapply to bind the output as apply does for variables with identical values?
apply(mtcars[,c('vs','am')],2,table)
produces
vs am
0 18 19
1 14 13
but
lapply(mtcars[,c('vs','am')],table)
produces
$vs
0 1
18 14
$am
0 1
19 13
Can I force lapply to do produce one table as apply does?
In the end I would like to…

Luitpold Wienerle
- 191
- 9
1
vote
1 answer
Formatting colnames to be read by cbind
Say I have a list called df such that colnames(df) yields:
"A" "B" "C" "D" "E" "F"
I would like aggregate data in the following way:
aggregate(cbind(`C`,`D`,`E`,`F`)~A+B, data = df, FUN…

Weierstraß Ramirez
- 251
- 2
- 14
1
vote
4 answers
Add new column with only odd numbers between 1:200
I want to create a new column in a data frame containing only odd numbers between 1:200. I'm using "cbind" to add the new column, but I'm not sure how to specify that I want only odd numbers. Right now my line of code looks like this
odd <-…

eak115
- 13
- 4
1
vote
0 answers
Simultaneously merge and paste in a loop in R
I'm trying to merge the four data frames with columns that overlap. However, the values within the columns are singular in some of the data frames and merged into one cell in another.
I simplified the dataset to only two data frames for the example.…

SP1
- 51
- 6
1
vote
0 answers
How to combine confusion matrices from the outputs of multiple algorithms?
I want to extract prediction confusion matrices of multiple prediction models in one table for easier comparison.
I collected confusion matrix tables from each model and combined them to created the following table.
Table1 <- rbind(confmat_nb$table,…

user115916
- 186
- 11