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
2
votes
2 answers

Using cbind on XTS object changes the dash (-) character in previous column names to a dot (.)

I have some R code that creates an XTS object, and then performs various cbind operations in the lifetime of that object. Some of my columns have names such as "adx-1". That is fine until another cbind() operation is performed. At that point, any…
Patrick
  • 513
  • 4
  • 14
2
votes
2 answers

how to create a empty matrix in the using cbind a loop R

I want to cbind matrix generated for each step in R, how to create a initial empty matrix say result=[] in matlab then cbind for each iteration?
user3341953
  • 309
  • 1
  • 5
  • 14
2
votes
1 answer

Multiplying and combine two data frames in R

I have two data frames data frame 1 A B C 1 1 0 0 0 0 1 1 0 data frame 2 1 2 0 4 100 0 100 4 I need to multiply and combine the columns to obtain A1 A2 B1 B2 C1 C2 0 4 0 4 0 0 0 0 0 0 0 0 100 4 100 4 0 …
ulrich
  • 3,547
  • 5
  • 35
  • 49
2
votes
1 answer

Is there a way to use a variable without the need of defining it (in R)?

I use following code: tempdata <- rbind(tempdata,newdata) # bind rowwise as far as I know, tempdata (like all objects, variables, ...) needs to be defined. Because there are only numerical values, I define it as tempdata<-0. It's not a really big…
new_to_R_user
  • 49
  • 1
  • 7
2
votes
2 answers

reshape a dataframe R

I am facing a reshaping problem with a dataframe. It has many more rows and columns. Simplified, it structure looks like this: rownames year x1 x2 x3 a 2000 2 6 11 b 2000 0 4 2 c 2000 0 3 …
refroll
  • 131
  • 1
  • 9
2
votes
2 answers

How to bind multiple data sets with different number of rows by the first row using R

I am trying to bind multiple stocks by "TimeStamp" which is the 1st column on the dataset. The rest of the columns are Open, High, Low, Close, Volume. One of the problems is that they all contain different rows.The second problem is that the…
Jason
  • 311
  • 1
  • 4
  • 14
2
votes
1 answer

R aggregate multiple variables using cbind

I'm aggregating all of the variables in the TEF data frame by the variable TEF using the following code : TEF2<-aggregate(cbind(column2, column3)~TEF, data=TEF, sum, na.rm=TRUE) This works great for the variables in columns 2 and 3. However the…
user2568648
  • 3,001
  • 8
  • 35
  • 52
2
votes
1 answer

cbind function creates misaligned xts object

I am trying to run the code in a tutorial by rbresearch titled 'Low Volatility with R', however when trying to run the cbind function the time series seems to get totally misaligned. Here's the data-preparation section that works…
user1462733
2
votes
2 answers

Nested List to Single Table (Merge By Column Name?)

I have a nested list that looks like this: dput(head(tempList)) structure(list(Species = c("RandArcBo1", "RandArcBo1", "RandArcBo1", "RandArcBo1", "RandArcBo1", "RandArcBo1", "RandArcBo1", "RandArcBo1", "RandArcBo1", "RandArcBo1", "RandArcBo1",…
Hannah O.
  • 383
  • 2
  • 12
1
vote
1 answer

Extracting components and elements from a list, then merging them

I have made a list and want to pull out only certain components and elements of that list and save it as a data frame. However, when using the sapply function, it pulls the correct data for some elements, but for others it does not. Here is a…
Purrsia
  • 712
  • 5
  • 18
1
vote
0 answers

Combining dataframe columns of different lengths in R

I tried cbind and merge, but both did not work for me so far, merge didn't work because the column "realtime_period" has different dates and it merges the dates which I do not want. I'm looking for the new dataframe to have NAs where there is no…
gillyp
  • 25
  • 4
1
vote
1 answer

Loop for combining specific columns from dataframe

I'm looking to make a loop that adds to an already existing data frame. So far I've tried to use the cbind function, as each data frame has 2 columns, dates and observations for that variable on said date. I'm looking to add just the observation to…
gillyp
  • 25
  • 4
1
vote
2 answers

Combine two single rows of data horizontally in r

I'm new to R so this probably has a simple solution, but I can't find it. I have two datasets: Dataset 1: A B C 1 2 3 Dataset 2: X Y Z 4 5 6 and I want to get A B C X Y Z 1 2 3 4 5 6 The dataset is just one row…
1
vote
1 answer

Different behaviours between base::cbind and dplyr::bind_cols

When combining a data frame and a vector with different number of rows/lengths, bind_cols gives an error, whereas cbind repeats rows – why is this? (And is it really wise to have that as a default behavior of cbind?) See example data below. #…
John
  • 309
  • 3
  • 12
1
vote
1 answer

Binding time series data with different lengths from a list

I have time series data outputted from a lapply and would like to cbind them together starting from their respective start date. Here I set an example of 5 random generated time series starting from random generated dates. set.seed(123) d <-…