FAQ Database Discussion Community


Rbind in variable row size not giving NA's

r,rbind
The initial data frame mergedDf is PROD_CODE 1 PRD0900033,PRD0900135,PRD0900220,PRD0900709 2 PRD0900097,PRD0900550 3 PRD0900121 4 PRD0900353 5 PRD0900547,PRD0900614 After calling mergedDf<-data.frame(do.call('rbind', strsplit(as.character(mergedDf$PROD_CODE),',',fixed=TRUE))) Output becomes X1 X2 X3 X4 1 PRD0900033 PRD0900135 PRD0900220 PRD0900709 2 PRD0900097 PRD0900550 PRD0900097 PRD0900550 3 PRD0900121 PRD0900121 PRD0900121 PRD0900121 4 PRD0900353 PRD0900353 PRD0900353 PRD0900353 5 PRD0900547 PRD0900614...

How to add a row to dataframe without changing col classes?

r,rbind
I have a dataframe of 5 observations of 15 variables. Some of the classes are character, some numeric, some integer. I am trying to add a new row to my data frame. I did this by creating a new row: newrow= c('Chiyoda',600,.08,2,1500,1,3000,6500,10, .65, .1, 0,0,0,0) and then rbinding it to...

Empty rows in list as NA values in data.frame in R

r,list,lapply,na,rbind
I have a dataframe as follows: hospital <- c("PROVIDENCE ALASKA MEDICAL CENTER", "ALASKA REGIONAL HOSPITAL", "FAIRBANKS MEMORIAL HOSPITAL", "CRESTWOOD MEDICAL CENTER", "BAPTIST MEDICAL CENTER EAST", "ARKANSAS HEART HOSPITAL", "MEDICAL CENTER NORTH LITTLE ROCK", "CRITTENDEN MEMORIAL HOSPITAL") state <- c("AK", "AK", "AK", "AL", "AL", "AR", "AR", "AR") rank <- c(1,2,3,1,2,1,2,3) df...

`rbind` dataset by sequence in a directory

r,path,merge,dataset,rbind
I have a data set with identical row and row numbers. I want to rbind those data in a sequence of two. For example for data 5LSTT-test12_1.avgm and 5LSTT-test12_1_sum.avgm first I want to merge them by using rbind and save them with the new name let's say test12.avgm. This process...

How do I understand the warnings from rbind?

r,rbind
If I have two data.frames with the same column names, I can use rbind to make a single data frame. However, if I have one is a factor and the other is an int, I get a warning like this: Warning message: In [<-.factor(*tmp*, ri, value = c(1L, 1L, 0L,...

Combining and merging a sequence of data frames

r,loops,for-loop,dataframes,rbind
I have a sequence of n data frames, of the form: n<-10 k<-5 d1 <- data.frame() for(i in 1:(k)) {d1 <- rbind(d1,c(a="i+1",b="i-1",c="i/1"))} d2 <- data.frame() for(i in 1:(k+2)) {d2 <- rbind(d2,c(a="i+2",b="i-2",c="i/2"))} d3 <- data.frame() for(i in 1:(k+3)) {d3 <- rbind(d3,c(i+3, i-3, i/3))} ... d10 <- data.frame() for(i in 1:(k+10)) {d10...

How to rbind multiple matrices into one big matrix

r,matrix,rbind
I defined a function to process each csv file and it returns a matrix. I would like to use this function in a for loop to process all the files and combine all the data into one big matrix. But it seems this code does not work. filenames=dir() bigMatrix =...

R: rbind a list of data.frames with different columns in different data frames

r,lapply,rbind
I've a list of 11,383 data frames. I need to merge them into one big data frame, but the have different columns (2,3,4 columns) so when i use rbind_all from Dplyr i get not desired result. One way around would be to rbind data frames that have the same number...

How to rowbind two datasets with different number of columns using R

r,merge,rbind
I am trying to rowbind two xts datasets with different number of columns: dataset 1: one <- structure(c(0, 0.009009, 0.008929, -0.00885, 0, -0.017857, -0.027957, -0.00885, -0.013393, -0.024887, 0.00232, -0.009259, 0, 0, 0, 0, 0, 0, -0.017794, 0.028986, -0.007143, 0.007194, 0.021429, 0.017483, 0, 0, 0, 0, 0, 0, 0.007968, -0.011858, 0,...

R- rbind duplicated rows

r,list,rbind
I need to extract all numbers from a string and save them in one field as a list. My code is: library(stringr) d<-data.frame(dir='a', x=1) DIR<-"PJE INDEPENDENCIA 96 5" X <- str_extract_all(DIR,"\\(?[0-9]+\\)?")[[1]] d<-rbind(d, data.frame(dir=DIR , x=X)) But I get: > d dir x 1 a 1 2 PJE INDEPENDENCIA 96 5...

Convert data.frame with lists in it to nummerical vectors

r,list,data.frame,rbind
The data is a data.frame with 3199 rows and 30 columns. I have diffrent plots from diffrent locations and yearly data for specific years with many variables. I now want to calculate the mean of a specific variable by location and year. What the data looks like: year location variable1...

Add a row made of 0 for each identifier in a large database

r,merge,data.frame,rbind
I have a database where the first row of each of the unique identifiers is missing. Basically, I need to add for each unique id a new row made of 0. My database looks like that (I have more than a million rows, so loops are basically impossible). dt =...

Combining data frames with missing data frames with rbind

r,data.frame,rbind
I am using the following command for combining data from different dataframes.Some of the data frames are missing like data 4 etc., filings<- rbind.pages(list(data1,data2,data3,data4,data5)) Error in stopifnot(is.list(pages)) : object 'data4' not found I am getting the above error. I have about 1000 data frames and there are some missing dataframes...

Create a character vector column of predefined text and bind it to existing dataframe using rbind or bind_rows

r,data.frame,dplyr,rbind,cbind
Good day, I will present two [likely] very puny problems for your excellent review. Problem #1 I have a relatively tidy df (dat) with dim 10299 x 563. The 563 variables common to both datasets [that created] dat are 'subject' (numeric), 'label' (numeric), 3:563 (variable names from a text file)....

Row binding results in R while maintaining columns labels

r,data.frame,rbind
I have a technical question in R: how can I rowbind the following results (results1 and result2) into a data frame and keeping the columns labels for both: result1: meanAUC.SIM meanCmax.SIM meanTmax.SIM AUC.OBS Cmax.OBS Tmax.OBS PE.AUC PE.Cmax PE.Tmax 777.4444 74.64377 4.551254 820.7667 73.46508 3.089009 5.278274 1.604416 47.33703 result2: medianAUC.SIM medianCmax.SIM...

R: Combine list of data frames into single data frame, add column with list index

r,data.frame,rbind,do.call
The question is very similar to this one . It is for combining a list of data frames into a single longer data frame. However, I want to keep the information from which item of the list the data came from by adding an extra column with the index (id...

How to rbind vectors into different columns, leaving NAs in remaining cells

r,vector,data.frame,rbind,cbind
Let's say I have an unspecified number of vectors of different lengths, and I want to effectively rbind them together, with the caveat that they must each occupy a different column in the resulting data.frame. You may assume that the vectors are contained in a list, but you cannot depend...

How to split each of the columns in a data frame to two column?

r,loops,rbind,strsplit
I have a data frame which is like this(4 rows and 5 column): Marker ind1 ind2 ind3 ind4 mark1 CT TT CT TT mark2 AG AA AG AA mark3 AC AA AC AA mark4 CT TT CT TT what I want to do is to split each of the columns...

How to add rows to empty data frames in R based only if empty data frame generated?

r,if-statement,rbind
To build off of this question: How to add rows to empty data frames with header in R? If I happen to generate a data frame that is empty (I don't necessarily know which will be empty and which will contain data until I try to run the code) can...