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

Is there a trick to looping with cbind?

I have 87 vectors of length 4096. For example, > head(d[[1]]$x) [1] 1.676094 1.676323 1.676551 1.676780 1.677008 1.677237 I would like to concatenate these vectors into a matrix with each vector occupying a column. Because cbinding them…
-1
votes
1 answer

concatenate a specific cell from a number of files into one single row in R

I have a folder with several files. From each file I would like to select a cell (third row, 5th column) and bind them into one single column. Here's what I've got so far: fnames1 <- scan(file.choose(), what = "character", quiet = TRUE) …
-1
votes
1 answer

cbind multiple files having same number of columns still error "arguments imply differing number of rows"

I have a folder with 40 files (although I want to write the code so that it works with any number of files as this will come up all the time for me). All I want to do is obtain a new file that compiles all those files together as columns. Each…
-1
votes
1 answer

Using cbind to create a columnar .csv file but 'X' always appears in row one

I have a script that is working perfectly except that in my R cbind operation, adjacent to the numerical value that I require in the first row, is an 'X'. Here is my…
cohara
  • 111
  • 3
  • 19
-2
votes
1 answer

subtraction and division of row values in a data frame column

The details of the dataframe are ID Price Result 1 20 -0.1 2 18 0.1667 3 21 -0.2381 4 16 0.1875 5 19 -1 so i have to subtract the second row from first row then divide by the first row.…
Prad
  • 339
  • 1
  • 10
-2
votes
3 answers

Merging two data frames with different numbers of observations and matching them

The data frame below presents two data frames that I merged through cbindX(Period1, Period2). Both have the same columns but represent two time periods and have different observations for AEZ. Example for Abyei and Angola > dput(new_data2[1:6,…
Myr TH
  • 175
  • 1
  • 9
-2
votes
1 answer

Is there an R function that splits the columns of a data.frame and cbind them together?

I have a data frame and a column with over 1.000.0000 values. I know that I need to take values from 1:30.000 then, 30.000:60.000 and so on, and cbind this parts, to get multiple columns out of the original one. How do I do that?
-2
votes
3 answers

Combine matrices row by row

I have two matrices of arbitrary sizes, e.g. matrix 1 (n * m) and matrix 2 (k * l). Is there a (convenient) way in R to cbind them row-by-row, to form a (n * k) * (m + l) matrix where each row of matrix 1 has a chance to be cbinded to each row of…
Ken Chen
  • 7
  • 3
-2
votes
1 answer

R: cbind dataframes with common column names

Cbinding two dataframes (equal number of rows) with a few columns having common names normally results in a data.frame with the common names altered (e.g. NameA.1, NameB.1, etc) to avoid any issues. I noticed that even though the names have changed,…
IVy
  • 119
  • 3
  • 7
-2
votes
1 answer

cbind recycled rows to add to last row in R

I have a question about cbinding recycled items. I simplified my problem into the following code. I have two objects "a" and "b". "a" has 5 rows and "b" has 10 rows. When I cbind them, I get a data.frame with 10 rows, and my column "a" recycles…
NoVice
  • 43
  • 5
-3
votes
1 answer

Binding together the tables created in a loop

I managed to create a loop that opens the csv files that I have in a folder and adds the file name in the first column. However, I don’t know how to put together all the tables created so that the final output after the loop is one data.frame with…
Carlos
  • 47
  • 6
-3
votes
1 answer

combining variable columns with same values within the same dataset into a new variable

dataset being used is in this google sheets link https://docs.google.com/spreadsheets/d/1eV33Sgx_UVtk2vDtNBc4Yqs_kQoeffY0oj5gSCq9rCs/edit#gid=1959019385&vpid=A1 AMC.dataset$ExamMC.A<-surveySP15$Exams_A AMC.dataset$ExamMC.A<-factor(NA,…
-5
votes
3 answers

Combing two dataframes based on matching strings in multiple columns

Say I have two dataframes, df1 and df2, that look like this: student x y teacher value s.name1 4 5 t.name1 1 s.name2 3 3 t.name1 2 s.name2 2 1 t.name2 3 s.name3 5 5 t.name3 1 and that I…
soosus
  • 1,211
  • 4
  • 18
  • 27
-5
votes
2 answers

Could you please help me to understand an R code?

I'm completely new to R. Would you please explain me the following code? Thank you a lot in advance. patterns <- matrix(c(0,0,0,1,0,1,0,1,1,1,1,0),4,3, byrow = T) input <- unlist(lapply(1:100, function(i) { ps <-…
David
  • 3
  • 6
1 2 3
29
30