R is a free, open source programming language and software environment for statistical computing, bioinformatics and graphics. It is advised to supplement your question with a reproducible example (http://stackoverflow.com/q/5963269); for statistical questions please use crossvalidated.com.

learn more… | top users | synonyms (1)

319
votes
11answers
17k views

How to make a great R reproducible example?

When discussing performance with colleagues, teaching, sending a bug report or searching for guidance on mailing lists and here on SO, a reproducible example is often asked and always helpful. What ...
102
votes
6answers
17k views

Quickly reading very large tables as dataframes in R

I have very large tables that I would like to load as a dataframes in R. read.table() has a lot of convenient features, but it seems like there is a lot of logic in the implementation that would slow ...
10
votes
2answers
816 views

Why are these numbers not equal?

The following code is obviously wrong. What's the problem? > i <- 0.1 > i <- i + 0.05 > i [1] 0.15 > if(i==0.15) cat("i equals 0.15") else cat("i does not equal 0.15") i does not ...
172
votes
4answers
40k views

R Grouping functions: sapply vs. lapply vs. apply. vs. tapply vs. by vs. aggregate vs

Whenever I want to do something "map"py in R, I usually try to use a function in the apply family. (Side question: I still haven't learned plyr or reshape -- would plyr or reshape replace all of these ...
175
votes
9answers
116k views

How to sort a dataframe by column(s) in R

I want to sort a data.frame by multiple columns in R. For example, with the data.frame below I would like to sort by column z (descending) then by column b (ascending): dd <- data.frame(b = ...
141
votes
12answers
20k views

Tricks to manage the available memory in an R session?

What tricks do people use to manage the available memory of an interactive R session? I use the functions below [based on postings by Petr Pikal and David Hinds to the r-help list in 2004] to list ...
33
votes
6answers
10k views

Speed up the loop operation in R

i have a big performance problem in R. I wrote a function that iterates over an data.frame object. It simply adds a new col to a data.frame and accumulate sth. (simple operation). The data.frame has ...
57
votes
5answers
6k views

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 must come from apply (tapply, sapply, ...
36
votes
1answer
35k views

How to convert a factor to an integer\numeric without a loss of information

When I convert a factor to a numeric, the values change to rank values. R> m$obs [1] 0 0 1 1 1 1 3 3 3 3 3 3 3 9 9 9 9 9 9 9 9 9 11 11 12 13 13 13 13 13 13 13 14 Levels: 0 ...
42
votes
3answers
14k views

Scraping html tables into R data frames using the XML package

How do I scrape html tables using the XML package? Take, for example, this wikipedia page on the Brazilian soccer team. I would like to read it in R and get the "list of all matches Brazil have ...
65
votes
1answer
4k views

In R, why is `[` better than `subset`?

When I need to filter a data.frame, i.e., extract rows that meet certain conditions, I prefer to use the subset function: subset(airquality, Month == 8 & Temp > 90) rather than the [ ...
114
votes
4answers
44k views

How to join data frames in R (inner, outer, left, right)?

Given two data frames df1 = data.frame(CustomerId=c(1:6),Product=c(rep("Toaster",3),rep("Radio",3))) df2 = data.frame(CustomerId=c(2,4,6),State=c(rep("Alabama",2),rep("Ohio",1))) > df1 ...
22
votes
3answers
11k views

Order Bars in ggplot2 bar graph

I am trying to make a bar graph where the largest bar would be nearest to the y axis and the shortest bar would be furthest. So this is kind of like theTable I have Name Position 1 James ...
22
votes
1answer
2k views

Cannot install R-forge package using install.packages

This, question, is, asked, over, and, over, and, over, on the R-sig-finance mailing list, but I do not think it has been asked on stackoverflow. It goes like this: Where can I obtain the latest ...
39
votes
10answers
8k views

General suggestions for debugging R?

I get an error from R when using a function that I wrote: Warning messages: 1: glm.fit: algorithm did not converge 2: glm.fit: algorithm did not converge What I have done step through the ...

1 2 3 4 5 298
15 30 50 per page