rbind

Simplest way to get rbind to ignore column names

删除回忆录丶 提交于 2019-12-27 23:37:41
问题 This came up just in an answer to another question here. When you rbind two data frames, it matches columns by name rather than index, which can lead to unexpected behavior: > df<-data.frame(x=1:2,y=3:4) > df x y 1 1 3 2 2 4 > rbind(df,df[,2:1]) x y 1 1 3 2 2 4 3 1 3 4 2 4 Of course, there are workarounds. For example: rbind(df,rename(df[,2:1],names(df))) data.frame(rbind(as.matrix(df),as.matrix(df[,2:1]))) On edit: rename from the plyr package doesn't actually work this way (although I

Simplest way to get rbind to ignore column names

▼魔方 西西 提交于 2019-12-27 23:37:29
问题 This came up just in an answer to another question here. When you rbind two data frames, it matches columns by name rather than index, which can lead to unexpected behavior: > df<-data.frame(x=1:2,y=3:4) > df x y 1 1 3 2 2 4 > rbind(df,df[,2:1]) x y 1 1 3 2 2 4 3 1 3 4 2 4 Of course, there are workarounds. For example: rbind(df,rename(df[,2:1],names(df))) data.frame(rbind(as.matrix(df),as.matrix(df[,2:1]))) On edit: rename from the plyr package doesn't actually work this way (although I

rbind multiple data frames without typing out all the names of the data frames [duplicate]

不羁岁月 提交于 2019-12-25 06:13:36
问题 This question already has answers here : Rbind dataframes using wildcard (1 answer) R - use rbind on multiple variables with similar names (2 answers) Closed 3 years ago . Have 68 data frames with the same structure and columns. I started to use rbind and after typing in about 30 df names, I thought there might be an easier way to concatenate all the data frames without typing in each name. I mean, what if you have 100,000 data frames to concatenate? I looked at a dozen of online resources

Parsing data in R, alternative to rbind() which can be put in “for” loop to write rows to new data table?

╄→尐↘猪︶ㄣ 提交于 2019-12-25 05:52:07
问题 Let's say I have a data table called YC that looks like this: Categories: colsums: tillTF: ID: cat NA 0 MA NA 0 spayed NA 0 declawed NA 0 black NA 0 3 NA 0 no 57 1 claws NA 0 calico NA 0 4 NA 0 no 42 1 striped NA 0 0.5 NA 0 yes 84 1 not fixed NA 0 declawed NA 0 black NA 0 0.2 NA 0 yes 19 1 0.2 NA 0 yes 104 1 NH NA 0 spayed NA 0 claws NA 0 striped NA 0 12 NA 0 no 17 1 black NA 0 4 NA 0 yes 65 1 ID: DOG NA 0 MA NA 0 ... Only it's 1) not actually pivot table, it's inconsistently formatted to

rbind list of data frames with one column of characters and numerics

旧巷老猫 提交于 2019-12-24 16:17:40
问题 I have a list of two data frames with the same column names, but different number of rows, rbind.fill can help to put them together into a big data frame, but the problem is that the first column in df1 is numeric data, and df2 is character data, when they are merged, the character data all become 1, I've searched around, but didn't get the problem fixed, any help would be appreciated. A small example would be: station <- c(1:10) value <- c(101:110) df1 <- data.frame(cbind(station,value))

rbind all given columns within a list

▼魔方 西西 提交于 2019-12-24 11:51:10
问题 I am reading a variable number of .csv files, all contained in the present working directory, into a list, and would like to rbind the 2nd column of each of these .csv files. The files in the working directory look like this: 150601_0001.csv 150601_0002.csv 150601_0003.csv etc. I have the following code to read them all into a list for any given number of files in the directory: (code comes from here) myfiles <- dir(pattern = "\\.(csv|CSV)$", full.names = TRUE) # get filenames and paths

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

邮差的信 提交于 2019-12-24 11:33:54
问题 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 <- data.frame(hospital, state, rank) df hospital state rank 1 PROVIDENCE ALASKA MEDICAL CENTER AK 1 2 ALASKA

Extract then row.bind data.frames from nested lists

你。 提交于 2019-12-24 08:29:49
问题 I have a function that outputs a large matrix (Mat1) and a small dataframe (Smalldf1) I store them in a list called "Result". This function is run inside a loop so I create many versions of my "Result" list until my loop ends....each time I add them to a list called "FINAL". At the end of my loop I end up with a List called FINAL, that has many smaller "Result" lists inside...each containing a small dataframe and a large Matrix. I want to rbind all of the small dataframes together to form one

R rbind - unexpected symbol error when merging rows from two data frames

廉价感情. 提交于 2019-12-24 04:19:33
问题 I am trying to merge data vertically from two separate data frames as shown below. I believe I've met the criteria, namely both have the same column names. Does anyone see why I'm getting the error below? > str(rnorm.SR.df) 'data.frame': 20 obs. of 2 variables: $ criticalMeasureCount: num 3.37 1.77 1.29 1.79 2.09 ... $ projectType : chr "SR" "SR" "SR" "SR" ...` > str(rnorm.nonSR.df) 'data.frame': 30 obs. of 2 variables: $ criticalMeasureCount: num 3.635 1.057 0.836 3.722 5.887 ... $

R rbind while preserving order or rows in each data frame

情到浓时终转凉″ 提交于 2019-12-24 00:38:08
问题 I need to merge 2 data frames while preserving their order of appearance in each data frame : x = data.frame(a=1:3, b=2:4, c=3:5) y = data.frame(a=c(10, 20, 30), b=c(20, 30, 40), c=c(30, 40, 50)) What I want is : > z a b c 1 2 3 10 20 30 2 3 4 20 30 40 3 4 5 30 40 50 But what rbind does is it's adding the second dataframe under the first. 回答1: Try this one-liner do.call("rbind", Map("rbind", split(x, 1:nrow(x)), split(y, 1:nrow(y)))) which gives this data.frame if x and y are as in the