r

Format numbers to significant figures nicely in R

Hello, I want to format numbers in my reports to significant digits, but keep trailing significant zeroes and correctly format large numbers For instance the numbers c(10.00001,12345,1234.5,123.45,1.2345,0.12345) to 3 significant digits should be 10.0, 12300, 1230, 123, 1.23, 0.123 but I get differing results with different methods (a...

How to include a Percent Symbol in an xtable caption using Sweave in R

I'm trying to use Sweave to generate a statistical report, and am trying to put a caption on an xtable, however if I include the percent symbol this breaks things. Some example code <<label=Analyte2_Results, results=tex, echo=FALSE>>= print(xtable(result[[2]], caption=paste(levels(vardata$Analyte)[1], " ...

R statistics: problem with simple column vector

Hello, I have a problem using data from a tab delimited data file imported with read.delim. Most of the columns contain numerical data which I need to do a t.test for. Unfortunately I always get this error: Error in if (stderr < 10 * .Machine$double.eps * max(abs(mx), abs(my))) stop("data are essentiallyconstant") : missi...

RGoogleDocs authentication failure

Here's the deal: I've installed RGoogleDocs package from OmegaHat repository and everything worked fine during installation, but when I try to load specific document (spreadsheet) it states that I'm unauthorised! I did: # installation install.packages("RGoogleDocs", repos = "http://www.omegahat.org/R") library(RGoogleDocs) auth <- getG...

Sum up values for one column to a certain row in R

Hi all, first of all I am sorry for the bad description, but I really don't know how to explain it better, though what I want to do is really simple. Example: I have a matrix [,1] [1,] 0 [2,] 1 [3,] 1 [4,] 0 [5,] 1 [6,] 1 [7,] 0 [8,] 0 [9,] 1 [10,] 0 and i want to calculate for each row...

data.table and "by must evaluate to list" Error

I would like to use the data.table package in R to dynamically generate aggregations, but I am running into an error. Below, let my.dt be of type data.table. sex <- c("M","F","M","F") age <- c(19, 23, 26, 21) dependent.variable <- c(1400, 1500, 1250, 1100) my.dt <- data.table(sex, age, dependent.variable) grouping.vars <- c("sex", "age"...

how to change the order of a discrete x scale in ggplot?

I am making a dodged bar chart using ggplot with discrete x scale, the x axis are now arranged in alphabetical order, but I need to rearrange it so that it is ordered by the value of the y-axis (i.e., the tallest bar will be positioned on the left), I tried order or sort, but result in sort the x-axis, but not the bars respectively. What...

LU decomposition of rectangular matrices

Method lu of package Matrix works fine for square matrices. However, I can't see why there is that square restriction. How can I perform LU decomposition on a rectangular matrix? ...

Update Facebook status using R?

Is it possible to update my facebook status from an R session? EDIT 1: Reading the responses thus far, I would like to point out that I'm simply interested if a package already exists which provides this functionality, similar to how the lovely twitteR package does for twitter. Also, something doesn't have to be 'useful' in order to be ...

Geocoding in R with Google Maps

I've tried running the code to geocode locations in R via Google Maps and the XML package from this blog post: http://www.r-chart.com/2010/07/maps-geocoding-and-r-user-conference.html Here are his functions: getDocNodeVal=function(doc, path){ sapply(getNodeSet(doc, path), function(el) xmlValue(el)) } gGeoCode=function(str){ librar...

multicolor text on chart

Greetings, I need to display multicolor text on my chart for example early <- 30 ontime <- 70 late <- 25 txt <- paste(early, ontime, late, sep='/') plot(1:2, type='n') text(1.5, 1.5, txt) I need values for early, ontime, late in txt, be blue,green, and red respectively. I found following post on multicolor text in title, however ...

Allowing the user pick from a list of files rather than from inputting file path in R (or other means that can pass file to R)

I have a BATCH script (on a Windows machine, would like this to be generalised in time), that opens and runs the following code in the background: library(svDialogs) library(ggplot2) library (XML) sharesID <- display(guiDlg("SciViews-R", "Please Enter Shares ID:")) test.df <- xmlToDataFrame(sharesID) test.df sapply(test.df, class) test...

tools::texi2dvi - what happened to it?

I'm familiar with the fact that you can create LaTeX reports directly from R with tools package and texi2dvi function, but I was surprised to see that tools package is missing. It's just not in CRAN repositories. Does anyone know about an adequate replacement for texi2dvi? ...

Writing a Simple Triplet Matrix to a File?

Hi, I am using the tm package to compute term-document-matrix for a dataset, I now have to write the term-document-matrix to a file but when I use the write functions in R I am getting a error. Here is the code which I am using and the error I am getting: data("crude") tdm <- TermDocumentMatrix(crude, control = list(weighting = weig...

In R, how can I parse csv data from a character vector to extract a data frame?

The read.table and read.csv functions in R are used to parse a file or URL containing delimited data and produce an R data frame. However, I already have a character vector that contains the CSV delimited data (using comma and \n as column and record delimiters), so I don't need to read it from a file or URL. How can I pass this charac...

How do I remove empty data frames from a list?

I've got dozens of lists, each is a collection of 11 data frames. Some data frames are empty (another script did not output any data, not a bug). I need to push each list through a function but that chokes when it sees an empty data frame. So how do I write a function that will take a list, do a dim on each element (i.e. data frame) an...

replace 0's with 1's and vice versa for a diagonal matrix in R

Can anyone tell me how to replace 0's with 1's and vice versa for a diagonal matrix in R. ...

can I change the position of the strip label in ggplot from the top to the bottom?

I know this is not quite a data visualization issue, but the boss asked for it, so I need to figure out if it is possible. Thanks! ...

how to change the width of the gaps between the panels in facet in ggplot2?

as title, I have having quite a lot of panels when generating a chart by ggplot, and I think the gap is a bit too wide, can I adjust it? Thanks! ...

JIT of R code using Ra

I just discovered Ra from Ubuntu repositories. Has anyone used it in actual projects? Have you encountered any problems and are there any trade offs with using Ra instead of R or JIT in general? ...