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
vote
3 answers

Manipulating a data frame to have all results in one row

Suppose I have a data table that looks like this: options(stringsAsFactors = F) letters <- list("A", "B", "C", "D") numbers <- list(2, 1, 1, 2) value <- list(.44, .54, .21, .102) test <- list(.001,.0005, .0004, .01) DF <- data.frame(cbind(numbers,…
Sheila
  • 2,438
  • 7
  • 28
  • 37
1
vote
2 answers

Merge specific columns from csv files and use the filenames as headers

I would like to merge specific columns from two csv files and use the filename as the column header.In this example, I want to merge the third column from each file into a single data frame. the csv files have the same number of rows and…
Lyndz
  • 347
  • 1
  • 13
  • 30
1
vote
1 answer

R memory allocation with cbind

I'm taking a large (dense) network matrix and converting it to an edgelist. Yet, when I do so, the memory allocated in R seems crazy. In my case, I have a 12MB matrix (1259 x 1259) that when converted to an edgelist (i, j, w) is taking up 71MB of…
Jesse Blocher
  • 523
  • 1
  • 4
  • 16
1
vote
1 answer

Bind data frames recursively

I have to data frames, same number of columns but different number of rows. I want to bind the columns of one data frame to the columns of the other data frame, but one to all the others, i.e., the first row of one data frame to all the other rows…
Andres
  • 281
  • 2
  • 13
1
vote
0 answers

Attaching a same dataframe for each row in the original dataframe

I have a dataframe that looks like this: First Last 1 Aamira Chaudhry 2 Abby Adams 3 Ada Sarmento structure(list(First = c("Aamira", "Abby", "Ada"), `Last ` = c("Chaudhry", "Adams", "Sarmento")), .Names = c("First", "Last "),…
jun.yoon77
  • 61
  • 1
  • 5
1
vote
1 answer

Create new column in data.frames within a list and populate it with specific repeating values

Here an example of my list (I actually have > 2,000 df in the real one): df1 = read.table(text = 'a b 1 66 1 999 23 89', header = TRUE) df2 = read.table(text = 'a b 99 61 32 99 83 19', header = TRUE) lst = list(df1, df2) I need to create a new…
aaaaa
  • 149
  • 2
  • 18
  • 44
1
vote
1 answer

Merge two data.frames where one of the data frame contain an extra row

I have two data frames where both data frame has one common column. One of the data frame has an extra row. > df1 type x y 1 A 10 417 2 B 2 …
add-semi-colons
  • 18,094
  • 55
  • 145
  • 232
1
vote
1 answer

How to combine dataframes by columns?

I have two dataframes and they look like: df <- data.frame( A = c(19, 79, 34), B = c(21, 21, 14), C = c(17, 14, 57) ) row.names(df) <- c("2016-10-31", "2016-09-30", "2016-08-31") df A B C 2016-10-31 19 21 17 2016-09-30 79 21…
T-T
  • 693
  • 1
  • 10
  • 24
1
vote
1 answer

I need to build new matrices by selecting alternate columns of the original matrix

I have a matrix where the first column is the ID of the samples, the columns 2 to 15 are the observed presences of 14 fish species, and the columns 16 to 29 are the predicted presences of the same 14 species. I need to build 14 matrices (1 per…
user2963185
  • 23
  • 1
  • 7
1
vote
2 answers

Merging multiple rows into single row

I've some problems with my data frame in R. My data frame looks something like this: ID TIME DAY URL_NAME VALUE TIME_SPEND 1 12:15 Monday HOME 4 30 1 13:15 Tuesday CUSTOMERS 5 21 1 …
1
vote
2 answers

consolidate columns that may or may not have overlapping data, using R

Let's say you have a data set that looks like this: Vietnam Gulf War Iraq War veteran1 1 0 0 veteran2 0 1 0 veteran3 0 0 1 veteran4 0 1 …
thanks_in_advance
  • 2,603
  • 6
  • 28
  • 44
1
vote
1 answer

rbind and cbind lists together

I have the code below in which I rbind the lists SampleDf and sampleDF2 together, and then cbind two character vectors on to it. What I would like to do is create a function where I could pass it another sampleDF3, Recipe3, and list of ingredients…
modLmakur
  • 531
  • 2
  • 8
  • 24
1
vote
1 answer

Combining for loop output

I want to write a loop that extracts a table from a three dimensional array and sequentially write it to a data frame as a column. The code I have so far is library(ncdf4) test <- nc_open("NorESM_TREFHT_cont_mem1-60_2006-2099.nc") temp <-…
Dylan
  • 37
  • 3
1
vote
1 answer

combine same column from various data frames into new dataframe

I have several dataframes that look like this: df1 Time Terrain 1 Land 2 Land 3 Land 4 Land I want to take the column "Terrain" from each dataframe and put them all in a new one, giving the columns of the new dataframe the name…
Bonono
  • 827
  • 1
  • 9
  • 18
1
vote
1 answer

Binding data to a dataframe in each 'for' run under different columns each time to compute average of each column finally

I am trying to do 10-fold-cross-validation in R. In each for run a new row with several columns will be generated, each column will have an appropriate name, I want the results of each 'for' to go under the appropriate column, so that at end I will…
moritf
  • 11
  • 2