How to upgrade R in ubuntu? [closed]

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

How to generate a number of most distinctive colors in R?

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

Subset a matrix according to a columns vector

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

Split data.frame by value

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

Deleting reversed duplicates with R

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

Get indexes of a vector of numbers in another vector

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