r

Whitespace in R

I am having some troubles with leading and trailing whitespace in a data.frame. Eg I like to take a look at a specific row in a data.frame based on a certain condition: > myDummy[myDummy$country == c("Austria"),c(1,2,3:7,19)] [1] codeHelper country dummyLI dummyLMI dummyUMI [6] dummyHInonOECD dummyHIOECD ...

Psychology researcher wants to learn new language

I'm currently considering R, matlab, or python, but I'm open to other options. Could you help me pick the best language for my needs? Here are the criteria I have in mind (not in order): Simple to learn. I don't really have a lot of free time, so I'm looking for something that isn't extremely complicated and/or difficult to pick up. I ...

Where can I find useful R tutorials with various implementations?

I'm using R language and the manuals on the R site are really informative. However, I'd like to see some more examples and implementations with R which can help me develop my knowledge faster. Any suggestions? ...

How can I load my .RProfile using Textmate's R Bundle

This question is for those of you who happen to use R, on a Mac, in combination with Macromate's [Textmate](http://macromates.com/) text editor and the "R" Bundle. All of which are nifty, needless to say, but that's beside the point for now :-) I've got a .RProfile file sitting in my default "~" startup directory, and it's got a number ...

Handling NA values in apply and unique

I have a 114 row by 16 column data frame where the rows are individuals, and the columns are either their names or NA. For example, the first 3 rows looks like this: name name.1 name.2 name.3 name.4 name.5 name.6 name.7 name.8 name.9 name.10 name.11 name.12 name.13 name.14 name.15 1 ...

How to get geom_vline and facet_wrap from ggplot2 to work inside a function

I'm using ggplot2 to explore the effects of different military operations on murder rates. To show the effect I draw a vertical line when the operation occurred and a smoothed line of the murder rate before and after the operation. I've written a facet_wrap plot to show this for a whole bunch of counties. It works beautifully, but when...

What's the difference between `=` and `<-` in R?

I'm using R 2.8.1 and it is possible to use both = and <- as variable assignment operators. What's the difference between them? Which one should I use? ...

[R] plot line over last part of barplot

I have a barplot for which the second half should fit to this formula: y~a*x*exp(-b*x^2). Now I want to plot the entire barplot and display the fitted model over the last part of the barplot as it only holds for that part. However, I cannot find a way to display the line-graph only over the second half. If I just do something like subm...

What is the easiest way to install a R web application through RApache?

Hi all, I use windows XP and R for my desktop use. And a shared hosting account (at some company) for my web hosting needs. I wish to create an R web application and I understand that one such way is by using R with Apache through RApache , but since my current shared hosting plan doesn't allow me to install RApache I am a bit stuck. ...

Is R's apply family more than syntactic sugar

...regarding execution time and / or memory. If this is not true, prove it with a code snippet. Note that speedup by vectorization does not count. The speedup most come from *apply (tapply, sapply ...) itself. Thanks in advance ...

Saving dotplot to pdf in R

I am having trouble saving a dotplot to pdf when this command is done inside a function. It works fine when called normally: df <- data.frame(a = runif(10), b = runif(10), c = runif(10), x = 1:10) pdf("test.pdf") dotplot(a + b + c ~ x, data = df, type = "l", auto.key=TRUE) dev.off() But if this code is inside a function, it wil...

R only: Frequencies of all subsequences of size 3 in a given 0-1 sequnce?

Given data s<-c(1,0,0,0,1,0,0,0,0,0,1,1,1,0,0) I can count 1s and 0s with table or ftable ftable(s,row.vars =1:1) and the totals of 11s,01s,10s,00s occurred in s with table(s[-length(s)],s[-1]). What would be the clever way to count occurrences of 111s, 011s, ..., 100s, 000s? Ideally, I want a table of counts x like 0 ...

Vector vs. Data frame in R

What is the difference between a vector and a data frame in R? Under what circumstances vectors should be converted to data frames? ...

Upgrading Tinn-R

I'm using Tinn-R version 2.2.0.2 and I want to upgrade to the latest version 2.3.4.4. I couldn't find any upgrade options in the menus of Tinn-R. So my question is: Is it safe to download and just install the new version? Will it overwrite my current Tinn-R settings? ...

Row names & column names in R

Do the following function pairs generate exactly the same results? Pair 1) names() & colnames() Pair 2) rownames() & row.names() ...

Random sample from given bivariate discrete distribution

Suppose I have a bivariate discrete distribution, i.e. a table of probability values P(X=i,Y=j), for i=1,...n and j=1,...m. How do I generate a random sample (X_k,Y_k), k=1,...N from such distribution? Maybe there is a ready R function like: sample(100,prob=biprob) where biprob is 2 dimensional matrix? One intuitive way to sample is...

How can Notepad++ be extended as an IDE for R ?

Hi all, I am working with NppToR as an extension allowing the use of notepad++ to be an IDE for R. But there are a few features I didn't yet see implemented (I compiled the list from another IDE solution, which is not open source) : Object Browser - Allow users to see all the data and function objects that are available, including tho...

Organizing R Source Code

All, I am starting to write object-oriented R code for the first time and anticipate having multiple R files with dependencies in between. I'm new to R and have not yet wrote anything outside of a single massive script to test ideas. Are there resources online that give tips on how one ought to organize code? Short of descriptions on...

Plotting of multiple comparisons in R ?

Hi all, When one wishes to compare (test) multiple groups (as is the case, for example, when doing anova), one is confronted with the issue of multiple comparisons. The same applys if we wish to plot the comparisons. My question is thus, what tools (in R) do you know of that allow plotting that reflects multiple comparisons? Currently...

How do you combine "Revision Control" with "WorkFlow" for R?

Hello all, I remember coming across R users writing that they use "Revision control" (e.g: "Source control"), and I am curious to know: How do you combine "Revision control" with your statistical analysis WorkFlow? Two (very) interesting discussions talk about how to deal with the WorkFlow. But neither of them refer to the revision con...