r

Assign group-level indices during or after melt

I have a data frame with gaps like this: Var1 Var2 Var3 1 NA NA NA 2 NA NA NA 3 NA NA NA 4 NA 0.06703 NA 5 NA 0.08639 NA 6 NA 0.19023 0.02322 7 NA 0.31764 0.08058 8 NA 0.44426 0.15081 9 ...

How can I draw a tree with igraph "bottom-up"?

It is very straight-forward to plot a tree using igraph in R library(igraph) plot(graph.tree(20, 2), layout=layout.reingold.tilford) Is it possible to "turn the graph around", so that the root (node 0) is at the top of the plot? Or, alternatively, is it possible to put the root to middle left? ...

Indexing data.frames using arrays of TRUEs and FALSEs

I'm having some trouble indexing data.frames in R. I'm an R beginner. I have a data.frame called d which has 35512 columns and 77 rows. I have a list called rd which contains 35512 elements. I'd like all the columns of d which correspond to the items in rd less than 100. Here's what I'm doing: # just to prove I'm not crazy > length(coln...

Reorder levels of a data frame without changing order of values

Hello, I have data frame with some numerical values and factors for groups, treatment etc. The order of levels for those factors is not the way I want them to be. numbers = 1:4 letters = factor(c("a", "b", "c", "d")) df <- data.frame(numbers, letters) numbers letters 1 1 a 2 2 b 3 3 c 4 4 ...

scatterplot: how to color points in a different color if a data attribute is not null

I have a scatter plot in R (with ggplot2). The data has a numeric column (let's call it "bin") which can contain various integer values or null. I would like to colour the points with non-null bin values differently from the others. I do not want to one colour per value of bin, that would be too noisy. Just simply, say, red for those wi...

Create qplots (with ggplot2) larger than the window?

I have a large chart with many data points. When I create the qplot in R, the chart is auto-fitted to the window. Even if I maximize the window, the chart is still too small and details are lost. I would like to save it as a large PNG and then look at certain areas at 1:1 resolution with an image viewer (as I cannot zoom in easily in R)....

Can you merge cells in an xtable in R

Hello, I've got some data (the output of a ddply function) that I want to present in an xtable for use somewhere else. calqc_table<-structure(list(RUNID = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), ANALYTEINDEX = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), ID = structure(1:11, .Label = c("Cal A", "Cal B", "Cal C", "Cal D", "C...

How to draw a chart with sorted horizontal error bars (sorted barcharts with error marks)?

I would like to plot means and standard errors as a horizontal barchart, and I want the mean sorted. I've found the way to plot horizontal sorted barcharts using lattice, but I do not know how to add error marks. The following are my data and the R code I came up with. data <- structure(c(0.67, 0.67, 0.76, 0.66, 0.71, 0.6, 0.52, 0.6, ...

using R to copy files

As part of a larger task performed in R run under windows, I would like to copy selected files between directories. Is it possible to give within R a command like "cp patha/filea*.csv pathb" (notice the wildcard, for extra spice)? ...

R slash - escape oder sanatize using regex?

Hi there I've just started analyzing some data using R - unfortunately I have encountered some problem... I'm reading in a (tab separted) csv file and want to process the data and there is one attribute I am particularly interested (which certainly exists within this csv). This is called: data_transfer.Jingle/TCP.total_size_kb Now when ...

How do I use cookies with RCurl?

I am trying to write an R package that accesses some data via a REST API. The API, however, doesn't use http authentication, but rather relies on cookies to keep credentials with the session. Essentially, I'd like to replace the following two lines from a bash script with two R functions: One to perform the login, and store the session ...

is the garbage collection in R effecient?

I use 32bit R on Windows machines and ran into out of memory problem from time to time. Can anyone comment on the garbage collection in R? I am not sure if the memory management issue would be a legit reason for me to switch to F# or python/numpy or something. ...

How can I get aov to show me the F-statistic and p-value?

The following script #!/usr/bin/Rscript --vanilla x <- c(4.5,6.4,7.2,6.7,8.8,7.8,9.6,7.0,5.9,6.8,5.7,5.2) fertilizer<- factor(c('A','A','A','A','B','B','B','B','C','C','C','C')) crop <- factor(c('I','II','III','IV','I','II','III','IV','I','II','III','IV')) av <- aov(x~fertilizer*crop) summary(av) yields Df Sum Sq Me...

converting multiple lines of text into a data frame

I'm trying to find a way to convert multiple lines of text into a data frame. I'm not sure if there's a way where you can use read.delim() to read in multiple lines of text and create the following data frame with something akin to rehape()?. The data is structured as follows: A: 1 B: 2 C: 10 A: 34 B: 20 C: 6.7 A: 2 B: 78 C: 35 I'd ...

How can I run a OSX terminal command from within R?

How can I run a OSX terminal command from within R? ...

SQLite or flat text file?

I process a lot of text/data that I exchange between Python, R, and sometimes Matlab. My go-to is the flat text file, but also use SQLite occasionally to store the data and access from each program (not Matlab yet though). I don't use GROUPBY, AVG, etc. in SQL as much as I do these operations in R, so I don't necessarily require the dat...

Why is as.factor returns a character when used inside apply ?

I tried doing this: a <- data.frame(x1 = rnorm(100), x2 = sample(c("a","b"), 100, replace = T), x3 = factor(c(rep("a",50) , rep("b",50)))) apply(a2, 2,class) # why is column 3 not a factor ? a a2 <- apply(a, 2,as.factor) apply(a2, 2,class) # why are all columns not factors ? But don't understand why it doesn't have factors... Thank...

Recombining a list of Data.frames into a single data frame.

Hello everyone I am sorry if this question has been answered already. Also, this is my first time on stackoverflow. I have a beginner R question concerning lists , data frames and merge and/or rbind. I started with a Panel that looks like this COUNTRY YEAR VAR A 1 A 2 B 1 B 2 For efficiency purpos...

Remove variable labels attached with foreign/Hmisc SPSS import functions

As usual, I got some SPSS file that I've imported into R with spss.get function from Hmisc package. I'm bothered with labelled class that Hmisc::spss.get adds to all variables in data.frame, hence want to remove it. labelled class gives me headaches when I try to run ggplot or even when I want to do some menial analysis! One solution wo...

How can a data ellipse be superimposed on a ggplot2 scatterplot?

Hi, I have an R function which produces 95% confidence ellipses for scatterplots. The output looks like this, having a default of 50 points for each ellipse (50 rows): [,1] [,2] [1,] 0.097733810 0.044957994 [2,] 0.084433494 0.050337990 [3,] 0.069746783 0.054891438 I would like to superimpose a number of suc...