Search Results
Search type | Search syntax |
---|---|
Tags | [tag] |
Exact | "words here" |
Author |
user:1234 user:me (yours) |
Score |
score:3 (3+) score:0 (none) |
Answers |
answers:3 (3+) answers:0 (none) isaccepted:yes hasaccepted:no inquestion:1234 |
Views | views:250 |
Code | code:"if (foo != bar)" |
Sections |
title:apples body:"apples oranges" |
URL | url:"*.example.com" |
Saves | in:saves |
Status |
closed:yes duplicate:no migrated:no wiki:no |
Types |
is:question is:answer |
Exclude |
-[tag] -apples |
For more details on advanced search visit our help page |
Use this tag for any *on-topic* question that (a) involves `R` either as a critical part of the question or expected answer, & (b) is not *just* about how to use `R`.
51
votes
Removing duplicated rows data frame in R
You are looking for unique().
a <- c(rep("A", 3), rep("B", 3), rep("C",2))
b <- c(1,1,2,4,1,1,2,2)
df <-data.frame(a,b)
unique(df)
> unique(df)
a b
1 A 1
3 A 2
4 B 4
5 B 1
7 C 2
46
votes
Produce a list of variable name in a for loop, then assign values to them
in 1:3){
assign(paste("a", i, sep = ""), i)
}
gives
> ls()
[1] "a1" "a2" "a3"
and
> a1
[1] 1
> a2
[1] 2
> a3
[1] 3
Update
I agree that using loops is (very often) bad R …
23
votes
Accepted
What are efficient ways to organize R code and output?
Managing a statistical analysis project – guidelines and best practices
A workflow for R
R Workflow: Slides from a Talk at Melbourne R Users by Jeromy Anglim (including another much longer list of webpages … dedicated to R Workflow)
My own stuff: Dynamic documents with R and LATEX as an important part of reproducible research
More links to project organization: How to efficiently manage a statistical analysis …
23
votes
Accepted
Boxplot with respect to two factors using ggplot2 in R
I can think of two ways to accomplish this:
1. Create all combinations of f1 and f2 outside of the ggplot-function
library(ggplot2)
df <- data.frame(f1=factor(rbinom(100, 1, 0.45), label=c("m","w" …
21
votes
How to draw funnel plot using ggplot2 in R?
If you are looking for this (meta-analysis) type of funnel plot, then the following might be a starting point:
library(ggplot2)
set.seed(1)
p <- runif(100)
number <- sample(1:1000, 100, replace = TR …
20
votes
Accepted
R package for multilevel structural equation modeling?
It seems that OpenMx (based on Mx but it's now an R package) can do what you are looking for: "Multi Level Analysis" …
17
votes
Statistical methods to more efficiently plot data when millions of points are present?
For further references, see
Graphics of Large Datasets by Unwin/Theus/Hofmann
Quick-R on "High Density Scatterplots"
ggplot2's stat_hexbin …
16
votes
Accepted
Output of logistic model in R
Regarding your second question, you might want to check out the effects-package http://socserv.socsci.mcmaster.ca/jfox/Misc/effects/index.html by John Fox; see also his JSS article "Effect Displays in R …
14
votes
Are misses in my data distributed completely at random?
The second question is about (an) appropriate R package(s). … ]
(2) (Some) Missing data related R packages
Some of these packages also have functions to explore patterns of missingness (e.g., missing.pattern.plot() in the mi package). …
11
votes
Accepted
Meta-analysis in R using metafor package
Create a proper data.frame:
df <- structure(list(study = structure(c(1L, 5L, 3L, 4L, 2L), .Label = c("Foo2000",
"Pete2008", "Pric2005", "Rota2008", "Sun2003"), class = "factor"),
mean1 = c(0.78 …
10
votes
Accepted
Calculating proportions by age in R
Your approach seems way too complicated to me. Let's start with some data:
## make up some data
status <- factor(rbinom(1000, 1, 0.3), labels = c("single", "married"))
age <- sample(20:50, 1000, repl …
8
votes
Animating the effect of changing kernel width in R
The animation was created using the following R code:
library(animation)
density.ani <- function(){
i <- 1
d <- c(1,2,3,4)
while (i <= ani.options("nmax")) {
plot(density(d, kernel …
7
votes
Discrete-Time Event History (Survival) Model in R
For most book chapters there is R sample code (see chapters 11ff) available that demonstrates how your data has to be structured ("person-period format") and how to analyze that kind of data. …
7
votes
Accepted
Is it possible to construct a discrete-time multilevel hazard model in R?
Yes, you can use R and lme4 for fitting discrete-time multilevel hazard models. According to Hox (2010, p. 163) "[t]he discrete or grouped survival model extends readily to multilevel models [...]". … Please find below the table from Hox' book:
And here is the corresponding R code and the results based on lme4. …
7
votes
Accepted
Multilevel regression using lmer function in R and Stata
Fitting varying intercept/slope models in Stata and R
@Jens already has pointed out how to write Stata's xtmixed model in R. … to estimate simple MLMs in Stata and R. …