cbind

Multiple Variable Values to Function and Cbind Results

╄→尐↘猪︶ㄣ 提交于 2019-12-11 12:05:42
问题 This is a continuation of this question here: For-Loop By Columns with existing For-loop by Rows I have a dataset in which I am using 3 variables: adstock_rate , diminishing_rate , and lag_number . These are currently set to only 1 number each. Currently I am using the following numbers: adstock_rate<-0.5 lag_number<-1 diminishing_rate<-0.6 The final output is a dataset with new columns attached to the existing dataset using the function below. foo1 <- function(dot, lag_val = 1) { tmp <- dot

Change all R columns names using a reference file

此生再无相见时 提交于 2019-12-11 06:05:47
问题 I am trying to rename columns in a dataframe in R . However, the renaming has circular referencing. I would like a solution to this problem, the circular referencing cannot be avoided. One way to think was to rename a column and move it to a new dataframe , hence, avoiding the circular referencing. However, I am unable to do so. The renaming reference is as follows: The current function I am using is as follows: standard_mapping <- function(mapping.col, current_name, standard_name, data){ for

R: How can I cbind specific columns of all data frames of a nested loop within the loop?

无人久伴 提交于 2019-12-11 05:38:22
问题 I am trying to combine the third column of several data frames, which are called and renamed in a nested for loop, within the same looping process. # Sample Data ecvec_msa6_1998=matrix( round(rnorm(200, 5,15)), ncol=4) ecvec_msa6_1999=matrix( round(rnorm(200, 4,16)), ncol=4) ecvec_msa6_2000=matrix( round(rnorm(200, 3,17)), ncol=4) datasets=c("msa") num_industrys=c(6) years=c(1998, 1999, 2000) alist=list() for (d in 1:length(datasets)) { dataset=datasets[d] for (n in 1:length(num_industrys)){

R: rBind from Matrix package does not work for sparse matrices

北战南征 提交于 2019-12-08 09:12:19
问题 I have the following code: concept_vectors <- foreach(j = 1:2, .combine=rBind, .packages="Matrix") %do% { Matrix::colMeans(sparseX[1:10,],sparseResult=TRUE) } which results in the following error message: Error in { : no method for coercing this S4 class to a vector However, if I either remove 'sparseResult=TRUE' option, or do not use colMeans at all, the code works, even if without colMeans, sparseX is still an S4 object . If I replace rBind with rbind2 directly, then I still see the

In R, when using named rows, can a sparse matrix column be added (concatenated) to another sparse matrix?

≯℡__Kan透↙ 提交于 2019-12-06 02:44:22
问题 I have two sparse matrices, m1 and m2 : > m1 <- Matrix(data=0,nrow=2, ncol=1, sparse=TRUE, dimnames=list(c("b","d"),NULL)) > m2 <- Matrix(data=0,nrow=2, ncol=1, sparse=TRUE, dimnames=list(c("a","b"),NULL)) > m1["b",1]<- 4 > m2["a",1]<- 5 > m1 2 x 1 sparse Matrix of class "dgCMatrix" b 4 d . > m2 2 x 1 sparse Matrix of class "dgCMatrix" a 5 b . > and I want to cbind() them to make a sparse matrix like: [,1] [,2] a . 5 b 4 . d . . however cbind() ignores the named rows: > cbind(m1[,1],m2[,1]) [

R fast cbind matrix using Rcpp

一曲冷凌霜 提交于 2019-12-05 20:16:12
问题 cbind in R is relatively time consuming in repeated calls, but it also is powerful for various data types. I have written code that is 3X faster than cbind when binding two matrices. But bind_cols in dplyr package is merely 100X faster than cbind . It is only a pity that it cannot take matrix as input. Can someone make the code below more fast. Also, how do I fast bind sparse matrix? Here is the code I used: require( Rcpp ) func <- 'NumericMatrix mmult(NumericMatrix a,NumericMatrix b) { //the

cbind items from multiple lists recursively

ぃ、小莉子 提交于 2019-12-05 11:14:09
Given three (or n lists): one <- list(a=1:2,b="one") two <- list(a=2:3,b="two") three <- list(a=3:4,b="three") What would be a more efficient way of cbind ind each list item across the n lists, to get this result? mapply(cbind,mapply(cbind,one,two,SIMPLIFY=FALSE),three,SIMPLIFY=FALSE) $a [,1] [,2] [,3] [1,] 1 2 3 [2,] 2 3 4 $b [,1] [,2] [,3] [1,] "one" "two" "three" This works okay when n is 2 or 3 but is quickly going to become ludicrously complex. Is there a more efficient variation on this? I have seen similar questions on S.O. but have struggled to adapt them. Or like this: mapply(cbind,

In R, when using named rows, can a sparse matrix column be added (concatenated) to another sparse matrix?

无人久伴 提交于 2019-12-04 09:33:30
I have two sparse matrices, m1 and m2 : > m1 <- Matrix(data=0,nrow=2, ncol=1, sparse=TRUE, dimnames=list(c("b","d"),NULL)) > m2 <- Matrix(data=0,nrow=2, ncol=1, sparse=TRUE, dimnames=list(c("a","b"),NULL)) > m1["b",1]<- 4 > m2["a",1]<- 5 > m1 2 x 1 sparse Matrix of class "dgCMatrix" b 4 d . > m2 2 x 1 sparse Matrix of class "dgCMatrix" a 5 b . > and I want to cbind() them to make a sparse matrix like: [,1] [,2] a . 5 b 4 . d . . however cbind() ignores the named rows: > cbind(m1[,1],m2[,1]) [,1] [,2] b 4 5 d 0 0 is there some way to do this without a brute force loop? You should send the

R fast cbind matrix using Rcpp

和自甴很熟 提交于 2019-12-04 02:47:34
cbind in R is relatively time consuming in repeated calls, but it also is powerful for various data types. I have written code that is 3X faster than cbind when binding two matrices. But bind_cols in dplyr package is merely 100X faster than cbind . It is only a pity that it cannot take matrix as input. Can someone make the code below more fast. Also, how do I fast bind sparse matrix? Here is the code I used: require( Rcpp ) func <- 'NumericMatrix mmult(NumericMatrix a,NumericMatrix b) { //the colnumber of first matrix int acoln=a.ncol(); //the colnumber of second matrix int bcoln=b.ncol(); /

Fast concatenation of thousands of files by columns

我与影子孤独终老i 提交于 2019-12-02 04:28:51
问题 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