Load multiple packages at once
Several permutations of your proposed functions do work — but only if you specify the character.only argument to be TRUE. Quick example: lapply(x, require, character.only = TRUE)
Several permutations of your proposed functions do work — but only if you specify the character.only argument to be TRUE. Quick example: lapply(x, require, character.only = TRUE)
Since R is already installed, you should be able to upgrade it with this method. First of all, you may want to have the packages you installed in the previous version in the new one,so it is convenient to check this post. Then, follow the instructions from here Open the sources.list file: sudo nano /etc/apt/sources.list … Read more
I joined all qualitative palettes from RColorBrewer package. Qualitative palettes are supposed to provide X most distinctive colours each. Of course, mixing them joins into one palette also similar colours, but that’s the best I can get (74 colors). library(RColorBrewer) n <- 60 qual_col_pals = brewer.pal.info[brewer.pal.info$category == ‘qual’,] col_vector = unlist(mapply(brewer.pal, qual_col_pals$maxcolors, rownames(qual_col_pals))) pie(rep(1,n), col=sample(col_vector, … Read more
Try H[cbind(seq_len(nrow(H)), P)] ## [1] 0.6733731 0.7396847 0.5953580 Here we are indexing by consecutive rows and columns indicated in P Regarding your question, so the reason H[, P] returns a matrix is because you are telling R: select all rows in columns: 2, 1, 2 from matrix “H” thus the result that you are getting … Read more
You could find which values of the indexing vector equal “a”, then create a grouping variable based on that and then use split. df[,1] == “a” # [1] TRUE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE TRUE #[13] FALSE FALSE cumsum(df[,1] == “a”) # [1] 1 1 1 1 2 2 2 … Read more
mydf <- read.table(text=”gene_x gene_y AT1 AT2 AT3 AT4 AT1 AT2 AT1 AT3 AT2 AT1″, header=TRUE, stringsAsFactors=FALSE) Here’s one strategy using apply, sort, paste, and duplicated: mydf[!duplicated(apply(mydf,1,function(x) paste(sort(x),collapse=””))),] gene_x gene_y 1 AT1 AT2 2 AT3 AT4 4 AT1 AT3 And here’s a slightly different solution: mydf[!duplicated(lapply(as.data.frame(t(mydf), stringsAsFactors=FALSE), sort)),] gene_x gene_y 1 AT1 AT2 2 AT3 AT4 … Read more
Try gregexpr with perl=TRUE and use perl regular expressions with look-ahead assertions (see ?regex): gregexpr(“(?=CC)”,”CCCGTGCC”,perl=TRUE) [[1]] [1] 1 2 7 attr(,”match.length”) [1] 0 0 0
Use stats::reorder() to reference the version in stats.
Using base R you could do the following: v <- c(2,2,3,5,8,0,32,1,3,12,5,2,3,5,8,33,1) x <- c(2,3,5,8) idx <- which(v == x[1]) idx[sapply(idx, function(i) all(v[i:(i+(length(x)-1))] == x))] # [1] 2 12 This tells you that the exact sequence appears twice, starting at positions 2 and 12 of your vector v. It first checks the possible starting positions, i.e. … Read more
You can try: iris %>% head %>% mutate(sum = .[[1]] + .[[2]]) Sepal.Length Sepal.Width Petal.Length Petal.Width Species sum 1 5.1 3.5 1.4 0.2 setosa 8.6 2 4.9 3.0 1.4 0.2 setosa 7.9 3 4.7 3.2 1.3 0.2 setosa 7.9 4 4.6 3.1 1.5 0.2 setosa 7.7 5 5.0 3.6 1.4 0.2 setosa 8.6 6 5.4 … Read more