[R] Function returning multiple objects but printing only one

2015-07-13 Thread Daniel Caro
Hello, Sorry if this has already been addressed before but I could not find any helpful references. I would like to create a function that outputs a single element of a list but stores all elements, similar to 'lm' and many other functions. There are several answers on how to return multiple obj

[R] lm weights argument within function

2014-08-01 Thread Daniel Caro
Hi all, I need to loop over "lm" within a function using "weights". For example: mydata = data.frame(y=rnorm(100, 500, 100), x= rnorm(100), group=rep(c(0,1), 50), myweight=1/runif(100)) reg.by.wt <- function(formula, wt, by, data) { if(missing(by)) { summary(lm(formula=formula, data=data,

[R] change specific factor level values to NA in data frame

2013-09-30 Thread Daniel Caro
Dear R-users I am trying to replace specific factor level values in a data frame with NAs. The data frame includes different kind of variables (e.g, characters, numbers, and factors). I'd like to replace all 'Not applicable', 'Invalid', 'and Missing' for NA. For example: f.level <- c('Yes', 'No'

[R] quotes in cat() within function

2013-04-09 Thread Daniel Caro
Hello all, Sorry if this question has been answered in the past, but I could not find an answer. I am trying to print quotes within a cat output. The arguments are: file= "Data labels" directory= "/home/mylaptop/" The function returns: cat("The file", file, "is located in directory", directory,

[R] lmer - BLUP prediction intervals

2013-02-05 Thread Daniel Caro
Dear all I have a model that looks like this: m1 <- lmer(Difference ~ 1+ (1|Examiner) + (1|Item), data=englisho.data) I know it is not possible to estimate random effects but one can obtain BLUPs of the conditional modes with re1 <- ranef(m1, postVar=T) And then dotplot(re1) for the examiner

Re: [R] looping through numbered variables

2012-08-27 Thread Daniel Caro
f not, please do so before > osting and pay particular attention to the section on indexing. If so, > re-read the sections on indexing. > > For a terser exposition, ?"[" > > -- Bert > > On Mon, Aug 27, 2012 at 7:11 AM, Daniel Caro wrote: >> Hello, >&g

[R] looping through numbered variables

2012-08-27 Thread Daniel Caro
Hello, This is a beginner question. I am trying to loop through numbered variables with "apply" to calculate weighted means. My data is "data", the variables are "var1" to "var100", the weight is "weight". The command works using sapply(paste('data$var', 1:100, sep=''), function(x) weighted.mean(

Re: [R] sem by variable x

2010-07-21 Thread Daniel Caro
you could do something like > > library(sem) > library(plyr) > > cfa_func<-function(a.df){ > >        cfa<-sem(ses.model, cov(a.df[,2:7], nrow(a.df))) >        print(summary(cfa)) > } > d_ply(data, "idcntry", cfa_func) > > -Jarrett > > On Jul 20, 201

[R] sem by variable x

2010-07-20 Thread Daniel Caro
Hi R users, I am new in R. I would like to perform confirmatory factor analysis for a data set of countries. My data are: data <- read.csv("ses.raw", header = TRUE) attach(data) names(data) [1] "idcntry" "momed" "daded" "dadocu" "momocu" "hompos" "finan" The country id is "idcntry", my

[R] loop through files and create object

2010-07-20 Thread Daniel Caro
Hi R users, I am a newbie and therefore the naive question. Sorry but I was unable to find an answer online. I would like to read 47 data sets (country1.raw, country2.raw, ... country47.raw) and save into a matrix each time (data1, data2, data47). for (i in 1:47){ data(?) <- read.csv(file.pat