Tag: R

  • Array construction in R, Perl, and Python

    vous pouvez les essayer Array construction in R, Perl, and Python

    R:

    data

    Perl:

    @data = (1, 2, 3)
    @data[2..3]
    %hash = ('a' =>; 'b')
    $hash{a}
    

    Python:

    data = [1, 2, 3, 'a', 'b', 'c']
    data[2:3]
    tuple = (1, 2, 3, 'a', 'b', https://buycbdproducts.com  # immutable
    dict = {'a': 'America', 'c': 'Canada'}
    dict['a']
    
  • Debugging R scripts with command line arguments 1…

    Debugging R scripts with command line arguments.

    1. Break up the script into two parts: one for reading the arguments, another one for the analysis.
    2. Run R with *-args option. It enters the interactive R session.

    Example.

    R  --args -p ../../input/M00724-foxa1.mat -s ../../input/mouse_promoter_seqs_EPD.fasta -c 0.55 -o testing_
    

    3. Source the the file reading https://buycbdproducts.com arguments.
    The file can read the arguments with commandArgs() or by using the getopt package.

    4. Source the analysis script.

  • showMethods and selectMethod to find the functions and…

    showMethods() and selectMethod() to find the functions and sources of S3 object in R.
    http://tolstoy.newcastle.edu.au/R/help/05/09/12506.html

  • Shuffle sequences in DNASequenceSet lapply or sapply return…

    Shuffle sequences in DNASequenceSet.

    lapply() or sapply() return list.
    endoapply() returns the same data class, DNASequenceSet.
    It is way slower, though.

    shuffled.seqs <- endoapply(seqs, sample)
    

    For faster shuffling, look at the link.
    http://grokbase.com/t/r/bioconductor/133n8bw1f6/bioc-how-to-operate-on-a-dnastringset-object

  • Turn numeric into categorical data AdultUCI age…

    Turn numeric into categorical data.

    AdultUCI[["age"]] <- ordered(cut(AdultUCI[["age"]], c(15,25,45,65,100)), labels = c("Young", "Middle-aged", "Senior", "Old"))
    
  • Change the order of discrete axis Generate a…

    Change the order of discrete axis.

    Generate a factor with reversed levels or use a new ggplot2 option.

    Examples.

    df$X1 = with(df, factor(X1, levels = rev(levels(X1))))
    

    http://stackoverflow.com/questions/7418191/sorting-dotplot-factor-axis-in-ggplot

    1. Reverse the order of a discrete-valued axis
    2. Get the levels of the factor
    flevels <- levels(PlantGrowth$group)
    1. "ctrl" "trt1" "trt2"
    2. Reverse the order
    flevels <- rev(flevels)
    1. "trt2" "trt1" "ctrl"
    bp + scale_x_discrete(limits=flevels)

    http://www.cookbook-r.com/Graphs/Axes_(ggplot2)/#reversing-the-direction-of-an-axis

  • Nested Tmux command Screen vim + gnu screen…

    Nested Tmux command.

    Screen (vim + gnu screen/tmux) is a great tool for vim that split the pane and send vim buffer to
    another pane. (Link: http://www.vim.org/scripts/script.php?script_id=2711)

    However, when used the plugin in tmux session, the tmux sessions are nested then the command
    is not working properly. Then setting a send prefix in .tmuxrc will solve the nested problem.

    Command Sequence for Nested Tmux Sessions

    Often I’ll run a multiplexer inside another multiplexer and need a command sequence to send things to the inner session. In Screen, this could be accomplished using C-a a . This doesn’t work out of the box in tmux, but can be fixed with a little configuration.

    bind-key a send-prefix
    

    From https://mutelight.org/practical-tmux

  • Slopegraph in R Slopegraph shows the change of…

    slopegraph

    Slopegraph in R. Slopegraph shows the change of the quantity or rank.

    Beautiful slopegraph example. http://www.drewconway.com/zia/

    Theory of slopegraph. http://www.edwardtufte.com/bboard/q-and-a-fetch-msg?msg_id=0003nk

    An R and ggplot2 code example of slopegraph https://github.com/leondutoit/slopegraph/blob/master/slopegraph.

    R Example code.

    Generate sample data

    a <- data.frame(go = LETTERS[1:10], enrich = runif(10, 0, 10))
    b <- data.frame(go = LETTERS[1:10], enrich = runif(10, 0, 10))
    a <- cbind(a, status ='before')
    
    b <- cbind(b, status = 'after')
    ab.melt <- rbind(a, b)
    

    Add an offset column for label positioning

    ab.melt <- transform(ab.melt, offset = c(rep(2, times = 10), rep(-2, times = 10)))
    
    library(ggplot2)
    ggplot(data = ab.melt, aes(x = status, y = enrich)) + geom_line(aes(group = go, colour = go)) + geom_text(aes(label = go, hjust = offset, colour = factor(go)))
    
  • R function matching a function argument against candidate…

    R function matching a function argument against candidate values.

    match.arg(arg, choices, several.ok = FALSE)

    arg = match.arg(arg)
    
  • How to rank data in R rank a…

    How to rank data in R.

    rank(a)
    

    Then how to rank the data in reverse order?

    rand(-a)