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`.
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 …
4
votes
Accepted
Checking $R$ functions arguments
You could use something like formals() or args(), e.g. formals(glm) gives:
> formals(glm)
$formula
$family
gaussian
$data
$weights
$subset
$na.action
$start
NULL
$etastart
$mustart
$o …
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
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 …
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 …
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 …
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). …
2
votes
How to take many samples of 10 from a large list, without replacement overall
This should work:
x <- rnorm(20000)
x.copy <- x
samples <- list()
i <- 1
while (length(x) >= 10){
tmp <- sample(x, 10)
samples[[i]] <- tmp
i <- i+1
x <- x[-match(tmp, x)]
}
table(unl …
2
votes
Splitting a numeric column for a dataframe
The "trick" is to use do.call.
> a <- data.frame(x = c("1:1-15", "1:2-16", "1:3-17"))
> a
x
1 1:1-15
2 1:2-16
3 1:3-17
> a$x <- as.character(a$x)
> a.split <- strsplit(a$x, split = ":")
> tmp …
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. …
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 …
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 …
2
votes
Accepted
Test in R of whether three or more correlations from independent samples are equal
Most meta-analysis packages in R can do this test, for instance, meta or metafor. … I will provide an example for the meta package (differences are due to rounding errors):
library(meta)
library(psychometric)
dfr <- data.frame(r=c(0.2, 0.5, 0.6), n=c(200, 150, 75))
dfr$z <- r2z(dfr$r …
3
votes
Accepted
Getting started on BUGS, need help implementing a simple model
x[i] ~ dnorm(mu, prec)
}
## priors (will have strong impact on the parameter estimation)
prec ~ dgamma(0.1, 0.001)
mu ~ dnorm(2.0, 0.0001)
var <- 1/prec
}
## data vector (BUGS follows the S/R …
6
votes
Accepted
Using glmer to replicate result from lmer for mulitlevel modelling in R
Did you check the help page of lmer? It is pretty clear about the relationship between lmer and glmer:
The ‘lmer’ and ‘glmer’ functions are nearly interchangeable. If
‘lmer’ is called with a no …