cbind

Fast concatenation of thousands of files by columns

折月煮酒 提交于 2019-12-02 02:16:16
I am using R to cbind about ~11000 files using: dat <- do.call('bind_cols',lapply(lfiles,read.delim)) which is unbelievably slow. I am using R because my downstream processing like creating plots etc is in R. What are some fast alternatives to concatenating thousands of files by columns? I have three types of files for which I want this done. They look like this: [centos@ip data]$ head C021_0011_001786_tumor_RNASeq.abundance.tsv target_id length eff_length est_counts tpm ENST00000619216.1 68 26.6432 10.9074 5.69241 ENST00000473358.1 712 525.473 0 0 ENST00000469289.1 535 348.721 0 0

Cbind/Rbind With Ifelse Condition

非 Y 不嫁゛ 提交于 2019-12-01 23:09:30
问题 Here is the code that I am working with: x <- c("Yes","No","No","Yes","Maybe") y <- t(1:10) z <- t(11:20) rbind.data.frame(ifelse(x == "Yes",y,z)) This produces X1L X12L X13L X4L X15L 1 1 12 13 4 15 The desired outcome is: x 1 Yes 1 2 3 4 5 6 7 8 9 10 2 No 11 12 13 14 15 16 17 18 19 20 3 No 11 12 13 14 15 16 17 18 19 20 4 Yes 1 2 3 4 5 6 7 8 9 10 5 Maybe 11 12 13 14 15 16 17 18 19 20 I was thinking that I could use an ifelse statement with the rbind.data.frame() or cbind.data.frame() function

Cbind/Rbind With Ifelse Condition

落花浮王杯 提交于 2019-12-01 20:27:16
Here is the code that I am working with: x <- c("Yes","No","No","Yes","Maybe") y <- t(1:10) z <- t(11:20) rbind.data.frame(ifelse(x == "Yes",y,z)) This produces X1L X12L X13L X4L X15L 1 1 12 13 4 15 The desired outcome is: x 1 Yes 1 2 3 4 5 6 7 8 9 10 2 No 11 12 13 14 15 16 17 18 19 20 3 No 11 12 13 14 15 16 17 18 19 20 4 Yes 1 2 3 4 5 6 7 8 9 10 5 Maybe 11 12 13 14 15 16 17 18 19 20 I was thinking that I could use an ifelse statement with the rbind.data.frame() or cbind.data.frame() function. So if x == "Yes" then that would be combined with a vector "y". As shown in the first row of the

cbind converting factor to numeric

纵然是瞬间 提交于 2019-12-01 18:35:21
Not sure why this is happening. I have a dataframe df2 with the variables below: EVTYPE TOTAL_FATALITIES TOTAL_INJURIES (fctr) (dbl) (dbl) 1 TORNADO 5633 91346 2 EXCESSIVE HEAT 1903 6525 3 FLASH FLOOD 978 1777 4 HEAT 937 2100 5 LIGHTNING 816 5230 6 TSTM WIND 504 6957 > df2$TOTAL_FATALITIES [1] 5633 1903 978 937 816 504 470 368 248 224 206 204 172 160 133 127 103 101 101 > df2$EVTYPE [1] TORNADO EXCESSIVE HEAT FLASH FLOOD HEAT LIGHTNING [6] TSTM WIND FLOOD RIP CURRENT HIGH WIND AVALANCHE [11] WINTER STORM RIP CURRENTS HEAT WAVE EXTREME COLD THUNDERSTORM WIND [16] HEAVY SNOW STRONG WIND BLIZZARD

Using R, getting a “Can't bind data because some arguments have the same name” using dplyr:select

时光总嘲笑我的痴心妄想 提交于 2019-11-30 20:59:02
#use readtable to create data frames of following unzipped files below x.train <- read.table("UCI HAR Dataset/train/X_train.txt") subject.train <- read.table("UCI HAR Dataset/train/subject_train.txt") y.train <- read.table("UCI HAR Dataset/train/y_train.txt") x.test <- read.table("UCI HAR Dataset/test/X_test.txt") subject.test <- read.table("UCI HAR Dataset/test/subject_test.txt") y.test <- read.table("UCI HAR Dataset/test/y_test.txt") features <- read.table("UCI HAR Dataset/features.txt") activity.labels <- read.table("UCI HAR Dataset/activity_labels.txt") colnames(x.test) <- features[,2]

Combining lists of different lengths into data frame

非 Y 不嫁゛ 提交于 2019-11-29 13:03:09
I have data like the SampleData below, which has lists of different length that I'd like to combine in to a data frame like the Desired Result below. I've tried using lapply and cbind.na from the qpcR package like the example below, but for some reason it won't let me turn the result into a data frame. If I just used two of the lists and cbind.na it will combine them and add the NA to the end like I want, but when I try using it in lapply it just leaves them as a list of different length lists. Any tips are greatly appreciated. SampleData<-list(list(1,2,3),list(1,2),list(3,4,6,7)) Desired

cbind: is there a way to have missing values set to NA?

安稳与你 提交于 2019-11-27 14:23:13
Please forgive me if I missed an answer to such a simple question. I want to use cbind() to bind two columns. One of them is a single entry shorter in length. Can I have R supply an NA for the missing value? The documentation discusses a deparse.level argument but this doesn't seem to be my solution. Further, if I may be so bold, would there also be a quick way to prepend the shorter column with NA 's? Try this: x <- c(1:5) y <- c(4:1) length(y) = length(x) cbind(x,y) x y [1,] 1 4 [2,] 2 3 [3,] 3 2 [4,] 4 1 [5,] 5 NA or this: x <- c(4:1) y <- c(1:5) length(x) = length(y) cbind(x,y) x y [1,] 4

Combining lists of different lengths into data frame

纵然是瞬间 提交于 2019-11-27 07:21:20
问题 I have data like the SampleData below, which has lists of different length that I'd like to combine in to a data frame like the Desired Result below. I've tried using lapply and cbind.na from the qpcR package like the example below, but for some reason it won't let me turn the result into a data frame. If I just used two of the lists and cbind.na it will combine them and add the NA to the end like I want, but when I try using it in lapply it just leaves them as a list of different length

cbind 2 dataframes with different number of rows

风流意气都作罢 提交于 2019-11-26 23:15:03
问题 I have two lists named h and g . They each contain 244 dataframes and they look like the following: h[[1]] year avg hr sal 1 2010 0.300 31 2000 2 2011 0.290 30 4000 3 2012 0.275 14 600 4 2013 0.280 24 800 5 2014 0.295 18 1000 6 2015 0.330 26 7000 7 2016 0.315 40 9000 g[[1]] year pos fld 1 2010 A 0.990 2 2011 B 0.995 3 2013 C 0.970 4 2014 B 0.980 5 2015 D 0.990 I want to cbind these two dataframes. But as you see, they have different number of rows. I want to combine these dataframes so that

cbind: is there a way to have missing values set to NA?

a 夏天 提交于 2019-11-26 16:44:08
问题 Please forgive me if I missed an answer to such a simple question. I want to use cbind() to bind two columns. One of them is a single entry shorter in length. Can I have R supply an NA for the missing value? The documentation discusses a deparse.level argument but this doesn't seem to be my solution. Further, if I may be so bold, would there also be a quick way to prepend the shorter column with NA 's? 回答1: Try this: x <- c(1:5) y <- c(4:1) length(y) = length(x) cbind(x,y) x y [1,] 1 4 [2,] 2