# How to ask question related to the use of R?

Given the place of the R software in applied statistics, we expect that questions related to this statistical package will regularly come on this site, as has been done in the past. As a follow-up on an earlier discussion on this topic, How to answer R questions, here are some guidelines on how to ask good questions related to the use of R and what's the best place to ask such questions.

Our FAQ states that programming questions should be asked on Stack Overflow, but

If the language is statistically oriented (such as R, SAS, Stata, SPSS, etc.), then decide based on the nature of your question: if it needs statistical expertise to understand or answer, ask it here; if it's about an algorithm, routine data processing, or details of the language, then please refer to the collection of links to
resources
we maintain.

Usually, posts that are not related to a statistical question are migrated to Stack Overflow, through the close voting mechanism. However, Stack Overflow members also expect high quality questions, in accordance with rules of good practices on all Stack Exchange sites. For additional information, see this related thread: Please do not migrate low quality questions.

To sum up, in order to facilitate migration between the two sites, it is expected that R questions demonstrate some level of research effort and provide working illustrations or a reproducible example, whenever possible.

The following illustrations are prototypical examples of questions that would be considered off-topic on SO and CV, questions that are on-topic on SO but need to be improved, and questions that are ready to be migrated over Stack Overflow. For the first two cases, a post notice (moderators only) and/or a comment in the spirit of our Library of helpful responses are given to inform the original poster of the reasons why his post is not acceptable as is.

• Feel free to help with this thread, by providing samples of questions. Mark them CW so that anyone can contribute. – chl Aug 4 '12 at 11:30

### Question

(Cleaned up version from a real question: https://stackoverflow.com/q/11941178/892313)

I have a data.frame with numeric columns. How can I write it to a file, using write.table, such that R writes the full number 40000000 instead of 4e+07?

### Issues

No statistical issues, so Off Topic on CV. It does involve programming issues, so it is on topic for SO. It does not include a reproducible example but the description of the problem is clear enough that an answer can be given.

### Outcome

Migrate to SO. Once migrated to SO, it will be closed as an exact duplicate. On CV, those deciding to migrate to SO need not know that there is duplicate question; even if they were aware, it is not possible to close a question as a duplicate question on a different site. On SO, an appropriate duplicate (if any) can be found and it can be closed appropriately.

• When a question is a known duplicate on the target site and doesn't have any answers, there's no point migrating it: it should just be closed. – whuber Aug 14 '12 at 20:56
• With a comment that points to the answer (or duplicate question) on the target site, that seems reasonable. My point was that those migrating have no obligation to determine if it is a duplicate, and, therefore, a migrated question being closed as a duplicate does not indicate a failure in the migration process. – Brian Diggs Aug 14 '12 at 22:16
• If it is a real question, and there are no answers on the target site, simply closing the question is patently ridiculous. At worst the question should be migrated. – russellpierce Jan 20 '13 at 15:54
• @drknexus I'm not sure what you read about this example that indicated that the recommendation here was to close on the original site (CV). The first statement of Outcome is "Migrate to SO." This example was meant as a subtler example of meta.stats.stackexchange.com/a/1342/5880 where, after migrating, the question was closed on SO as a duplicate. The point was that despite the question being closed on SO (after migrating), it was a proper migration. We seem to be in agreement. – Brian Diggs Jan 21 '13 at 4:21
• Brian, I am in agreement with you, but in disagreement with @whuber's comment that 'there is no point in migrating it: it should just be closed'. Notably, the new question up for discussion below is an even subtler case. Yet the action taken was 'closed' not migration. So, although you an I seem to have some grounds for agreement, the actions at hand are not in line with the apparent consensus on meta. – russellpierce Jan 21 '13 at 6:30
• Moreover, I am still waiting to see where the community discussion was had regarding the 'if it's about an algorithm, routine data processing, or details of the language, then please refer to the collection of links to resources we maintain' line in the FAQ and the contemporary interpretation of that line. This entire meta post presupposes that line is a valid community decision and that it should guide the discussion we are having here. – russellpierce Jan 21 '13 at 6:33
• Even if the FAQ line has been legitimately vetted... its interpreation has not. Again, evidenced by the closure of the question I've introduced to this discussion, the judgement that questions such as the above should be migrated rather than closed appears to be less than unanimous. – russellpierce Jan 21 '13 at 6:34
• As an aside, let me say that I appreciate all of the moderation and effort involved on the part of the community members here, including those who I happen to disagree with. My goal here is to make sure we have this/these discussion/s. In my opinion, closing and migrating questions has a potentially chilling effect on new users - it makes the community less inviting. – russellpierce Jan 21 '13 at 6:37
• I imagine that this site has enjoyed some of the success it has had as a consequence of being inviting. I am distressed by the changes in tone and policy that have taken place during my period of inactivity. – russellpierce Jan 21 '13 at 6:38

### Question

I have hourly measurements of temperature collected in different sites over the past three years. How to plot my data with R?

Issues: Not enough context, no statistical question, no indication on the purpose of this graphical display.

Outcome: Not suitable [CV and SO].

This question is unclear. You need to say what you intend to do/show and what you have tried (or what is your level of expertise with R). A reproducible example would be helpful.

• Maybe qualifying such question as "not constructive" would help to signify they are also off-topic on SO? – chl Aug 4 '12 at 11:34
• I agree with chi. The close reason listed here is completely wrong. "Not constructive" or "not a real question" if the question asker fails to elaborate might be appropriate. But, the question itself is on-topic. – russellpierce Jan 20 '13 at 15:49
• I (now) disagree. Display of time series data has received attention from statisticians. The concept of banking for example where an aspect ratio is chosen such that small changes in slope are emphasised by being plotted at $45\degree$. In this case, the OP could be assisted to learn more than just get some figure of their data. – Gavin Simpson Sep 18 '13 at 15:49
• @Gavin Sure. But how to know if the OP just wants the R code or is interested in getting such useful recommendations? Anyway, this ought to be an example of short "how to do that in R." The SO R community often suggests to provide a reproductible example; depending on the data and the question at hand, we may provide helpful suggestions. – chl Sep 18 '13 at 21:19
• @ I agree it is a bad question as phrased. I guess this is where the approach of commenting to clarify the question, to tease out if there is a statistical aspect, would be useful. If nothing further forthcoming from the OP then we close. The fact that I up-voted this originally and now disagree with myself(!) is representative of the struggle being played out recently on Meta :-) – Gavin Simpson Sep 18 '13 at 21:30

Question

I have a dataset with foreign characters that I would like to read into SAS, work with, and then read it out. When I currently try to do this, the foreign characters come up as question marks.

Issues

No statistical issues, so Off Topic on CV. On SO would be Not A Real Question as it is currently posed. The asker has not provided minimal information needed: code, a small portion of the data itself, nor the locale+character encoding information for their OS.

Outcome

Suitable on SO only if edited to include the additional information described above. Otherwise, should be closed as Not A Real Question.

Question

Is it possible to write values of different datatypes to a file in R? Currently, I am using a simple vector as follows:

> vect = c (1,2, "string")
> vect
[1] "1"     "2"     "string"
> write.table(vect, file="/home/sampleuser/sample.txt",
append= FALSE, sep= "|")


However, since vect is a vector of string now, opening the file has following contents being in quoted form as:

"x"
"1"|"1"
"2"|"2"
"3"|"string"


Is it not possible to restore the data types of entries 1 and 2 being treated as numeric value instead of string. So my expected result is:

"x"
"1"|1
"2"|2
"3"|"string"


also, I am assuming the left side values "1", "2" and "3" are vector indexes? I did not understand how the first line is "x"?

Issues

No statistical issues, so Off Topic on CV. On topic on SO, and a good candidate for migration, as the OP has provided a clear explanation of the problem, and simple example code that is easily runnable by others that demonstrates their problem.

Outcome

Migrate to SO.

Question

Consider the following example long data.frame with two dependent measures, "Score" and "NewVariable", 1 between subjects variable "Prep" (3 levels), 2 within subjects variables "Day" (3 levels) and "Experiment" (2 levels), and a subject identifier "SID".

example <- (proper example here)

My best attempt so far would involve creating the two corresponding wide datasets, e.g.

library(reshape2) dcast(example,SID+Prep~Day+Experiment,value.var="Score") dcast(example,SID+Prep~Day+Experiment,value.var="NewVariable") ... then manually gluing them back together.

Is there a better way?

Issues

None.

Background This meta post was recently cited for closing a question I posed despite a long and consistent history on meta of allowing and even encouraging such questions on CV. Moreover, (as far as I can find) the quoted section of the FAQ "if it needs statistical expertise to understand or answer, ask it here; if it's about an algorithm, routine data processing, or details of the language, then please refer to the collection of links to resources we maintain" has never been a community moderated phrase in the FAQ. At worst, this may indicate that by fiat someone (or group of people) have been by fiat changing what is acceptable in the community without appropriate discussion. Regardless of the validity of the statement in the FAQ, the FAQ should (at the very least) be considered in light of the determinations made on meta. See the citations below. As such, the question listed above is appropriate for CV.

Outcome (Under Debate)

Should not be closed. Discussion continues about whether the question is suitable for CV or if migration is a suitable response.

• I wasn't one of the people who voted to migrate, but I would have. I agree w/ @whuber's comment that standards have evolved. You are right that to answer this programming question deftly, the answerer would have to know what a DV is & understand the data structure involved. However, you will find that the users on SO who answer R Q's are statistically savvy. Moreover, users who can answer purely R Q's here tend to also do so on SO (eg, caracal has an SO account). – gung - Reinstate Monica Jan 20 '13 at 19:36
• I would agree with migrating this. There are two questions here, one of which is unasked. First (the unasked one), how to specify a model with two dependent variable, one between subjects variable, and two within subjects variables. That question would be appropriate for CV. Second (the one that was asked), how to transform the data to a format suitable for the aforementioned model. That is a purely programming question suitable for SO. You need to know the answer to the first to know what the second should do, but you only asked the second. The assumption is you have (but not said) the first. – Brian Diggs Jan 21 '13 at 4:36
• Even if I grant the argument that the example question is 'off-topic', the question remains whether it should be migrated or closed. The question at issue here was not migrated. It was closed. – russellpierce Jan 21 '13 at 6:07
• @gung: Moreover, see the above argument. If standards have evolved, I ask for people to cite the relevant discussions on meta. Otherwise, they have evolved silently and without community consensus. – russellpierce Jan 21 '13 at 6:08
• @gung: You seem to grant my premise that to answer this question deftly requires statistical understanding. If you are granting that, then the question meets the criteria in the FAQ. Therefore, you ought not vote to migrate much less close the question. – russellpierce Jan 21 '13 at 6:12
• @BrianDiggs: The question isn't about model specification despite reshape2 using formula notation. The question is fundamentally about transforming data within a framework that is relevant to statistical analysis. I don't know what line in the sand should be drawn between 'purely programming' and statistical analysis. Statistical analysis is largely algorithmic. One can easily reduce most statistical analyses to programming problems. – russellpierce Jan 21 '13 at 6:16
• The only proposed standard I've seen in this discussion so far that would draw a line in the sand is @whuber's. He now states back in the original question that "one solid test (although not the only possible one) of whether a question has statistical interest would be if it could be asked in a software-independent way". Is that really a reasonable test at all? If so, what has happened is not an 'evolution' in the standards of CV so much as a qualitative change. – russellpierce Jan 21 '13 at 6:17
• Along similar lines to the above question, consider: stats.stackexchange.com/questions/14101/…. Is it now the community standard to migrate the above question? – russellpierce Jan 21 '13 at 14:18
• In fact, visualization as in the previous comment, is a great counter-example. Per @chi in this discussion (meta.stats.stackexchange.com/questions/1305/…): "When the question has to do with statistical analysis or related techniques (including visualization when the purpose is to answer a statistical question)--as per our FAQ--it belongs here". Is there a line somewhere between language specific data visualization and language specific data transformation that the community wants to draw? – russellpierce Jan 21 '13 at 14:28
• If you're looking for a meta discussion about the current standards for SO vs CV, it might be better to ask a new meta Q; comments are only so-so for hashing this out. Re: another of your points, I fully agree that this should have been migrated, not closed. If I had voted, it would have been to migrate. – gung - Reinstate Monica Jan 21 '13 at 15:59
• At any rate, I see a fairly clear distinction: Consider a question about how to compute a mean in C++, this requires an answerer to know what a mean is (a good CV Q), but is a programming Q. Your Q also requires an answerer to know some stats, but only to know what code to show / explain to you. The answerer doesn't need to explain what a DV or wide vs long data setups are--you don't need help w/ the statistical aspects of this issue. Moreover, most any R Q on SO will require answerers to know some stats, b/c that's what R is for. – gung - Reinstate Monica Jan 21 '13 at 15:59
• I have added meta.stats.stackexchange.com/questions/1514/… to further pursue the issue of hashing out the relevant criteria. – russellpierce Jan 21 '13 at 16:08
• @gung: I don't quite see the clear distinction you are making. The answerer has to know some stats not only to know how to generate the answer, but also to understand the question in the first place. – russellpierce Jan 21 '13 at 16:12
• I think the distinction you were trying to make was that the answer itself needs to involve statistical aspects. One of whuber's earlier comments had a similar tone. However, that criteria would eliminate questions like how to find specific values in given program's statistical output, e.g. 'how can I find the AIC in the output from lm in R' – russellpierce Jan 21 '13 at 16:13
• Notably @whuber's recent point (stats.stackexchange.com/questions/48155/…) seems to be that it is more appropriate to judge a question based on the content of the question being asked rather than the nature of the possible (as yet ungenerated) answers. – russellpierce Jan 21 '13 at 16:28