Look below to see what happens to your formatting when you use html. Don't use 
html.

Why do you use x='df' in defining the function

df is a data frame with 5 observations and 4 variables.
'df' is a character vector of length 1. Your function is looking for a data 
frame (or matrix) with at least 4 columns.

-------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352


-----Original Message-----
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Marie-Eve St-Onge
Sent: Thursday, September 11, 2014 10:53 AM
To: r-help@r-project.org
Subject: [R] incorrect number of dimensions

Dear all, I'm trying the following experiment simulation, but I'm receiving 
this error:
> probs()Error in x[j, 4] : incorrect number of dimensions
however, the simulation works fine outside the function statement{}. What am I 
doing wrong?
# Create some fake data and call the function: df <- data.frame(y1 = rpois(5, 
9),y2 = rpois(5, 7), y3 = rpois(5, 8), n = rpois(5, 100)) 
probs = function(x='df', j=5, export=1){  p=gtools::rdirichlet(100000, x[j,4] * 
c(x[j,1],x[j,2],x[j,3], 1-x[j,1]-x[j,2]-x[j,3])/100+1 )if(export==1){  
mean(p[,1] > p[,3])} else {  return(p)} }

Eve

                                          
        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to