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
4
votes
1 answer

Calculate the distances between pairs of points in r

Lets say I have generated 10 random points x <- runif(10, min = -10, max = 10) y <- runif(10, min = -10, max = 10) and I want to calculate the distances between each pair of points. so I use d <- dist(cbind(x,y)) and I got a nice 9*9…
QwayneQ
  • 43
  • 1
  • 3
4
votes
2 answers

How to efficiently divide successor by predecessor in each column of a dataframe

I have a dataframe myDF created like this: a <- 1:4 b <- seq(3, 16, length=4) myDF <- data.frame(a=a, b=b) which looks like this: a b 1 1 3.000000 2 2 7.333333 3 3 11.666667 4 4 16.000000 Now I want to divide subsequently predecessor…
Cleb
  • 25,102
  • 20
  • 116
  • 151
4
votes
1 answer

Identify and cbind multiple vectors based on vector name

I have 100 numeric vectors named sim1 to sim100 in my workspace, all of the same length (18). I'm trying to find a way to identify them and cbind them to create a data frame of 18 rows and 100 columns. I can easily create a character vector of…
Ian Fisher
  • 43
  • 2
4
votes
4 answers

Bind two files by column in bash

when i have two files such as file A 012 658 458 895 235 and file B 1 2 3 4 5 how could they be joined in bash? The output shoudl just be 1012 2658 3458 4895 5235 really I just want to bind by column such as in R (cbind).
user3419669
  • 293
  • 2
  • 4
  • 11
3
votes
2 answers

How to column-bind frequency tables with different column numbers?

I have a frequency table that has different column numbers. I am using the following code but it is not resulting in accurate results. data_cbind <- cbind(table_45_1, table_45_3, table_45_6 table_45_12) head(table_45_1) 1 2 3 30 4 1…
Sana
  • 65
  • 6
3
votes
3 answers

Adding a new column to a list of data frames and then 'unlist' with names intact?

I have a number of dfs to which I want to add a column. For the sake of a mrp, these dfs are called df_1, df_2, df_3... for (i in 1:10) { assign(paste("df_",i,sep = ""),data.frame(x = rep(1,10), y = rep(2,10))) } I want to add another column z to…
NiGS
  • 96
  • 5
3
votes
2 answers

Combining 2 vectors in alternating way by step of 4 in R

I have two vector of same length: a = c(723, 680, 2392, 2063, 721, 746, 2053, 2129) b = c(1, 2, 3, 4, 5, 6, 7, 8) Now I want to merge them but with a step of 4 element, to be more precise I want as output: 723 680 2392 2063 1 2 3 4 721 746 2053…
Will
  • 1,619
  • 5
  • 23
3
votes
2 answers

Merging 2 dataframes with duplicate columns?

I have an empty dataframe as such: a <- data.frame(x = rep(NA,10)) which gives the following: x 1 NA 2 NA 3 NA 4 NA 5 NA 6 NA 7 NA 8 NA 9 NA 10 NA and I have another dataframe as such (the non-sequential row numbers are because this…
superasiantomtom95
  • 521
  • 1
  • 7
  • 25
3
votes
1 answer

Newly created data frame loses the labels for the categories of its vectors

I have a data frame like this: > str(dynamics) 'data.frame': 3517 obs. of 3 variables: $ id : int 1 2 3 4 5 6 7 8 9 10 ... $ y2015: int 245 129 301 162 123 125 115 47 46 135 ... $ y2016: int NA 385 420 205 215 295 130 NA NA 380 ... I…
Muneer
  • 209
  • 1
  • 3
  • 13
3
votes
4 answers

bind columns with different number of rows

I want to create iteration that takes a list (which is column of another dataframe) and add it to the current data frame as column. but the length of the columns are not equal. So, I want to generate NA as unmatched rows. seq_actions=as.data.frame(x…
Cina
  • 9,759
  • 4
  • 20
  • 36
3
votes
2 answers

cbind puts 1 instead of character

I'm about to throw R out of the window. R is lovely, but sometimes a little problem takes hours to get solved. Got this df: Product <- c("Basket", "Basket", "Basket", "Apple", "Apple", "Apple", "Corn", "Corn", "Corn", "Basket") Place <- c("America",…
David_Rowie
  • 127
  • 2
  • 10
3
votes
2 answers

cbind two dataframes where weekdays match

Before asking, I have searched and read many other questions on stackoverflow and tried the joins from dplyr package but none gives the result I want. I have two dfs and want to combine them that first values in df1$col1 which is Wed is matched with…
Zmnako Awrahman
  • 538
  • 7
  • 19
3
votes
1 answer

R Shiny: Creating New Columns Within a Reactive Data Frame

Say I have a data frame called summarized which includes the columns TY_COMP and LY_COMP (among others). I could write a function in R that performs a calculation on TY_COMP and LY_COMP and creates a new column called cac in the data frame like…
epiphius
  • 33
  • 4
3
votes
2 answers

How can I cbind() sets of data frames in a loop to generate multiple data sets

I have let say 4 data sets f1,f2,i1,i2. I want to cbind() f1 with i1 and f2 with i2. I can use v1<-cbind(f1,i1) v2<-cbind(f2,i2) but I want to do this in some sort of loop. I know the question is very basic. But after lots of searching I am…
humera
  • 31
  • 2
3
votes
3 answers

Combine rows of same size by cbind in R

I would like to rearrange the matrix b in the following way: > b <- matrix(1:24, 6, 4) > b [,1] [,2] [,3] [,4] [1,] 1 7 13 19 [2,] 2 8 14 20 [3,] 3 9 15 21 [4,] 4 10 16 22 [5,] 5 11 17 23 [6,] …
statsgrad1990
  • 89
  • 1
  • 3
1 2
3
29 30