Re: [R] Recursive concatenation

2007-09-04 Thread Dimitris Rizopoulos
try this: paste(rep(LETTERS[1:3], each = 3), 1:3, sep = ) Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http

Re: [R] match help

2007-09-03 Thread Dimitris Rizopoulos
try this: x - c(NA, NA, 1, NA, NA, NA, NA, 2, NA, NA) na.ind - is.na(x) x[na.ind] - rnorm(sum(na.ind)) x I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven

Re: [R] substituting elements in vector according tosample(unique(vector))

2007-08-29 Thread Dimitris Rizopoulos
try the following: v - c(1, 2, 1, 2, 3, 3, 1) x - c(3, 2, 1) fv - factor(v, levels = x) as.vector(unclass(fv)) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35

Re: [R] Splitting strings

2007-08-23 Thread Dimitris Rizopoulos
one way is the following: data.frame(status = gsub([0-9], , surgery), time = gsub([a-z], , surgery)) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven

Re: [R] plot in for loop with i indexed variables does not work

2007-08-22 Thread Dimitris Rizopoulos
you need something like this: par(mfrow = c(5, 5)) for (i in 1:10) { nam - paste(Var., i, sep = ) plot(x = time, y = mat[, nam], xlab = Time, ylab = nam) } where `mat' is the matrix containing Var.1, Var.2, Var.3, etc. I hope it helps. Best, Dimitris Dimitris Rizopoulos

Re: [R] standardized cronbach's alpha?

2007-08-21 Thread Dimitris Rizopoulos
look at: help(cronbach.alpha, package = ltm) Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be

Re: [R] Select rows of matrix

2007-08-20 Thread Dimitris Rizopoulos
try this: mat - matrix(rnorm(20*10), 20, 10) mat[sample(200, 10)] - -Inf mat mat[apply(is.finite(mat), 1, all), ] I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35

Re: [R] values from a linear model

2007-07-24 Thread Dimitris Rizopoulos
try this: coef(summary(mod))[, Std. Error] I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http

Re: [R] extraction of vector elements to new list

2007-07-23 Thread Dimitris Rizopoulos
try this: new.list - lapply(my.list, [, i = 1:2) new.list I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015

Re: [R] Help on looping problem needed!

2007-07-23 Thread Dimitris Rizopoulos
Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm

Re: [R] create an array with rep

2007-07-22 Thread Dimitris Rizopoulos
try this: x - -3:3 as.matrix(expand.grid(x, x)) # or t(as.matrix(expand.grid(x, x))) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16

Re: [R] GEE code

2007-07-20 Thread Dimitris Rizopoulos
random-slopes (e.g., in lmer()) or an AR1 structure, as you did below. For the latter case, you probably want to use functions lme() and gls() from package `nlme'. I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic

Re: [R] EM unsupervised clustering

2007-07-18 Thread Dimitris Rizopoulos
you could also have a look at function lca() from package `e1071' that performs a latent class analysis, e.g., fit1 - lca(data, 2) fit1 fit2 - lca(data, 3) fit2 I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic

Re: [R] multiple rugs on a single plot

2007-07-17 Thread Dimitris Rizopoulos
, x1, 0) segments(x2, 0 + ds, x2, len) segments(x3, len + ds, x3, 2*len) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32

Re: [R] nearest correlation to polychoric

2007-07-13 Thread Dimitris Rizopoulos
you could also have a look at function posdefify() from package `sfsmisc'. I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax

Re: [R] counting occurances of matching rows in a matrix

2007-07-13 Thread Dimitris Rizopoulos
one way is the following (maybe there're better): pats - do.call(paste, c(as.data.frame(M), sep = \r)) pats - factor(pats, levels = unique(pats)) cbind(unique(M), Freq = as.vector(table(pats))) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School

Re: [R] how to get the p-values from an lm function ?

2007-07-12 Thread Dimitris Rizopoulos
try the following: tmp - by(projet, rating, function (x) Thursday, 12.July.2007{ fit - lm(defaults ~ CGDP + CSAVE + SP500, data = x) summary(fit)$coefficients }) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health

Re: [R] compare 2 vectors

2007-06-28 Thread Dimitris Rizopoulos
look at setdiff(), e.g., setdiff(b, a) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http

Re: [R] create matrix from comparing two vectors

2007-06-26 Thread Dimitris Rizopoulos
try this: test - 1:10 fac - c(3, 6, 9) outer(test, fac, ) * 1 I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16

Re: [R] how to ave this?

2007-06-23 Thread Dimitris Rizopoulos
+ lis[[i]] out } n - 6 p - 5 lis - list(matrix(rnorm(n * p), n, p), matrix(rnorm(n * p), n, p), matrix(rnorm(n * p), n, p), matrix(rnorm(n * p), n, p), matrix(rnorm(n * p), n, p)) matFun(lis, sum) matSums(lis) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D

Re: [R] generating a new variable based on results of a by command

2007-06-21 Thread Dimitris Rizopoulos
maybe you want to use ave(), e.g., f$sums - ave(f$b, f$e, FUN = sum) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32

Re: [R] Got Unexpected ELSE error

2007-06-20 Thread Dimitris Rizopoulos
the problem is that you start `else' on a new line; check the following two solutions: if ( a ) { cat(TRUE, \n) } else { cat(FALSE, \n) } # or { if ( a ) { cat(TRUE, \n) } else { cat(FALSE, \n) } } I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student

Re: [R] Gini coefficient in R

2007-06-11 Thread Dimitris Rizopoulos
- length(x) mu - mean(x) N - if (unbiased) n * (n - 1) else n * n ox - x[order(x)] dsum - drop(crossprod(2 * 1:n - n - 1, ox)) dsum / (mu * N) } gini(c(100,0,0,0)) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical

Re: [R] find position

2007-06-10 Thread Dimitris Rizopoulos
try this: which(a == 0.4)[1] I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be

Re: [R] Sorting dataframe by different columns

2007-06-08 Thread Dimitris Rizopoulos
probably the function sort.data.frame() posted in R-help some time ago can be useful; check: RSiteSearch(sort.data.frame) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address

Re: [R] logical 'or' on list of vectors

2007-06-08 Thread Dimitris Rizopoulos
try the following: as.logical(rowSums(is.na(Theoph))) ## or !complete.cases(Theoph) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16

Re: [R] How to obtain coefficient standard error from the result ofpolr?

2007-06-04 Thread Dimitris Rizopoulos
() in the `bootStepAIC' package, e.g., library(bootStepAIC) boot.stepAIC(result.plr, data = mydata) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel

Re: [R] Abstract plot

2007-06-04 Thread Dimitris Rizopoulos
maybe you're looking for curve(), e.g., curve(5*x + 2, -3, 4, ylab = expression(5*x + 2)) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0

Re: [R] how to extract the maximum from a matrix?

2007-06-01 Thread Dimitris Rizopoulos
look at the `arr.ind' argument of ?which(), e.g., x - matrix(rnorm(9), 3, 3) x which(x == max(x), arr.ind = TRUE) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35

Re: [R] tapply

2007-06-01 Thread Dimitris Rizopoulos
try this: tapply(re, list(reg, ast), function(x) shapiro.test(x)$p.value) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax

Re: [R] about the unscaled covariances from a summary.lm object

2007-05-29 Thread Dimitris Rizopoulos
) all.equal(solve(crossprod(X)), summ.fit.lm$cov.unscaled) Sigma - summ.fit.lm$sigma^2 * solve(crossprod(X)) all.equal(sqrt(diag(Sigma)), summ.fit.lm$coefficients[, Std. Error]) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health

Re: [R] Number of NA's in every second column

2007-05-20 Thread Dimitris Rizopoulos
for data.frames try: rowSums(sapply(dfr, is.na)) whereas for matrices you could use: rowSums(is.na(mat)) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven

Re: [R] Number of NA's in every second column

2007-05-20 Thread Dimitris Rizopoulos
sorry but I misread the part about every second column of the data.frame; in this case you could use: rowSums(sapply(dfr[seq(1, length(dfr), 2)], is.na)) I hope it helps. Best, Dimitris -- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University

Re: [R] add info

2007-05-18 Thread Dimitris Rizopoulos
you could use attributes, e.g., dat - data.frame(x = 1:3, y = letters[1:3]) attr(dat, name) - my data.frame attr(dat, author) - John Smith attr(dat, date) - 2007-05-18 ## dat attributes(dat) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student

Re: [R] Simple programming question

2007-05-18 Thread Dimitris Rizopoulos
)) labs[match(x, sn)] })) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be

Re: [R] lapply not reading arguments from the correct environment

2007-05-18 Thread Dimitris Rizopoulos
. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be

Re: [R] more woes trying to convert a data.frame to a numerical matrix

2007-05-16 Thread Dimitris Rizopoulos
have a look at: ?as.numeric() and ?data.matrix(). I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web

Re: [R] Efficient computation of trimmed stats?

2007-05-15 Thread Dimitris Rizopoulos
, ])) all.equal(out1, out2) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http

Re: [R] Create an AR(1) covariance matrix

2007-05-11 Thread Dimitris Rizopoulos
one option is the following: times - 1:5 rho - 0.5 sigma - 2 ### H - abs(outer(times, times, -)) V - sigma * rho^H p - nrow(V) V[cbind(1:p, 1:p)] - V[cbind(1:p, 1:p)] * sigma V I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School

Re: [R] pvmnorm, error message

2007-05-09 Thread Dimitris Rizopoulos
A is not correlation matrix; try this instead: A - diag(rep(0.5, 3)) A[1, 2] - 0.5 A[1, 3] - 0.25 A[2, 3] - 0.5 A - A + t(A) pmvnorm(lower = rep(-Inf, 3), upper = rep(2, 3), corr = A) Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic

[R] [R-pkgs] package ltm -- version 0.8-0

2007-05-08 Thread Dimitris Rizopoulos
Dear R-users, I'd like to announce the release of the new version of package `ltm' (i.e., ltm_0.8-0 soon available from CRAN) for Item Response Theory analyses. This package provides a flexible framework for analyzing dichotomous and polytomous data under IRT, including the Rasch model, the

Re: [R] minimum from matrix

2007-05-08 Thread Dimitris Rizopoulos
try this: apply(a, 2, function(x) min(x[x 0])) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http

Re: [R] intersect of 2 data frames

2007-05-06 Thread Dimitris Rizopoulos
look at ?merge(), e.g., try something like the following: merge(pretestm, posttest, by = StuNum) check also the on-line help page for more info, especially for the 'all' argument. I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public

Re: [R] Get the difference between two matrices with different length

2007-05-04 Thread Dimitris Rizopoulos
try this: ind1 - do.call(paste, c(as.data.frame(mat1[, 1:2]), sep = \r)) ind2 - do.call(paste, c(as.data.frame(mat2[, 1:2]), sep = \r)) mat1[ind1 %in% ind2, 3] - mat2[ind2 %in% ind1, 3] I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School

Re: [R] logical or for two vectors or matrices

2007-05-04 Thread Dimitris Rizopoulos
you need: a | b Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http

Re: [R] searching for special variables

2007-05-03 Thread Dimitris Rizopoulos
one option is use something like the following: a - 1:10 b777 - rnorm(10) c777 - letters[1:6] fit - lm(b777 ~ a) a777d777 - 5 ## lis - ls() rm(list = c(lis[grep(777, lis)], lis)) ls() I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre

Re: [R] reference in article

2007-05-02 Thread Dimitris Rizopoulos
try citation() Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http

Re: [R] simulation

2007-05-01 Thread Dimitris Rizopoulos
maybe you're looking for something like this: x - rpois(999, 2000) y - numeric(length(x)) for (i in seq_along(x)) y[i] - sum(exp(rgamma(x[i], scale = 2, shape = 0.5))) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health

Re: [R] adding a column to a matrix

2007-04-26 Thread Dimitris Rizopoulos
just try: cbind(m, m[, censti] m[, survtime]) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http

Re: [R] problem in tapply command

2007-04-24 Thread Dimitris Rizopoulos
probably you're looking for tapply(slp_jeo2$slp, slp_jeo2$jeo, mean, na.rm = TRUE) Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16

Re: [R] intersect more than two sets

2007-04-24 Thread Dimitris Rizopoulos
you could try something like the following: t2 - lapply(1:11, function(i) c(a, sample(letters[1:5], sample(10, 1), TRUE), b)) unq.vals - unique(unlist(t2)) ind - rowSums(sapply(t2, %in%, x = unq.vals)) == length(t2) unq.vals[ind] I hope it helps. Best, Dimitris Dimitris

Re: [R] data recoding problem

2007-04-23 Thread Dimitris Rizopoulos
one option is the following: do.call(rbind, lapply(split(tox, tox$id), function (x) { if (any(ind - x$event == 1)) x[which(ind)[1], ] else x[nrow(x), ] })) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public

Re: [R] Problems in programming a simple likelihood

2007-04-19 Thread Dimitris Rizopoulos
= binomial(link = probit))$coefficients I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http

Re: [R] hello

2007-04-19 Thread Dimitris Rizopoulos
look at R FAQ 7.10 http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-do-I-convert-factors-to-numeric_003f I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven

Re: [R] Two sample t.test, order of comparions

2007-04-18 Thread Dimitris Rizopoulos
take a look at ?relevel() Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http

Re: [R] Matrix manipulation

2007-04-16 Thread Dimitris Rizopoulos
It would be helpful if you could be more specific of what exactly you'd like to compute. Have a look also at the posting guide available at: http://www.R-project.org/posting-guide.html Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health

Re: [R] Assignment from list

2007-04-12 Thread Dimitris Rizopoulos
try the following: z - matrix(1, ncol = 249, nrow = 240) zz - matrix(1, ncol = 249, nrow = 240) for (k in seq_along(x)) { z[rbind(x[[k]])] - 0 } zz[xx] - 0 all.equal(z, zz) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public

Re: [R] negative variances

2007-04-11 Thread Dimitris Rizopoulos
that the assumption of some common random-effects that the sample units share might not be valid. Alternatively, you could model directly the marginal covariance matrix V using the 'correlation' and 'weights' arguments of gls(). I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D

Re: [R] selection of character

2007-04-04 Thread Dimitris Rizopoulos
one way is the following: x - c(10_1, 1_1, 11_1, 2_1, 3_1, 4_1, 5_1, 6_1, 7_1, 8_1) # sapply(strsplit(x, _), [, 2) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address

Re: [R] argmax

2007-04-04 Thread Dimitris Rizopoulos
check ?which.max(), e.g., x - c(1,4,15,6,7) which.max(x) Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http

Re: [R] converting a list to a data.frame

2007-04-03 Thread Dimitris Rizopoulos
Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm

Re: [R] substitute values

2007-04-02 Thread Dimitris Rizopoulos
if your data set is a matrix try this new.data - cbind(data, New Column = is.na(data[, Years]) data[, Products] 20) whereas if your data set is a data.frame try this data$New.Column - as.numeric(is.na(data$Years) data$Products 20) I hope it helps. Best, Dimitris Dimitris

Re: [R] math-operations

2007-03-30 Thread Dimitris Rizopoulos
513 %/% 100 513 %% 100 check ?%/% for more info. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http

Re: [R] composed matrices

2007-03-29 Thread Dimitris Rizopoulos
try this: A1 - matrix(1:20, 5, 4) B1 - matrix(1:15, 5, 3) A2 - matrix(1:8, 2, 4) B2 - matrix(1:6, 2, 3) # rbind(cbind(A1, B1), cbind(A2, B2)) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic

Re: [R] Standardization Range

2007-03-28 Thread Dimitris Rizopoulos
, 2, function(x) (x - mean(x)) / diff(range(x)) ) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http

Re: [R] Replacement in an expression - can't use parse()

2007-03-27 Thread Dimitris Rizopoulos
you could try something like the following (untested): new.e - eval(substitute(expression(u1+u2+u3), list(u2 = x, u3 = 1))) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address

Re: [R] Listing function

2007-03-26 Thread Dimitris Rizopoulos
, new.info) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http

Re: [R] for loop in assigning column names

2007-03-21 Thread Dimitris Rizopoulos
try df.new - cbind(df, ObJeCt[1:10]) names(df.new) - c(names(df), paste(St, 1:10, sep = )) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32

Re: [R] abline within data range

2007-03-20 Thread Dimitris Rizopoulos
try this: x - rnorm(200, 35, 5) y - rnorm(200, 0.87, 0.12) ### lmObj - lm(y ~ x) xs - range(x) ys - predict(lmObj, newdata = data.frame(x = xs)) plot(x, y, pch = 17, bty = l) lines(xs, ys, col = red, lty = 2, lwd = 2) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D

Re: [R] Select the last two rows by id group

2007-03-20 Thread Dimitris Rizopoulos
[unlist(tapply(row.names(score), score$id, tail, n = 2)), ] look at ?tail() for more info. I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16

Re: [R] character to numeric conversion

2007-03-19 Thread Dimitris Rizopoulos
. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be

Re: [R] abs(U) 0 where U is a vector?

2007-03-14 Thread Dimitris Rizopoulos
try: all(U 0) Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http

Re: [R] selecting rows with more than x occurrences in a given column(data type is names)

2007-03-13 Thread Dimitris Rizopoulos
try this: set.seed(123) all.data - data.frame(name = sample(c(Joe, Elen, Jane, Mike), 8, TRUE), x = rnorm(8), y = runif(8)) ## tab.nams - table(all.data$name) nams - names(tab.nams[tab.nams = 2]) all.data[all.data$name %in% nams, ] I hope it helps. Best, Dimitris Dimitris

Re: [R] Removing duplicated rows within a matrix, with missing data as wildcards

2007-03-09 Thread Dimitris Rizopoulos
) if(any(x)) rep(TRUE, length(x)) else x) out - rbind(x[ind, ], matrix(rep(x[!ind, ], each = nwld), nc = nc)) unique(out[!keep.ind, ]) I hope it works ok. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address

Re: [R] Query about using setdiff

2007-03-07 Thread Dimitris Rizopoulos
try something along these lines (untested): DF1[DF1$id %in% DF2$id2, c(val1, val2)] DF1[!DF1$id %in% DF2$id2, c(val1, val2)] I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address

Re: [R] Passing command line parameters to a script

2007-03-06 Thread Dimitris Rizopoulos
probably you're looking for ?commandArgs(). I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http

Re: [R] count the # of appearances...

2007-03-01 Thread Dimitris Rizopoulos
?table Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http

Re: [R] Additional args to fun in integrate() not found?

2007-02-27 Thread Dimitris Rizopoulos
. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be

Re: [R] Test of Presence Matrix HOWTO?

2007-02-26 Thread Dimitris Rizopoulos
you can use something like the following: a - list(A,B,C,D) b - list(A,B,E,F) c - list(A,C,E,G) # abc - list(a, b, c) unq.abc - unique(unlist(abc)) out.lis - lapply(abc, %in%, x = unq.abc) out.lis lapply(out.lis, as.numeric) I hope it helps. Best, Dimitris Dimitris

Re: [R] Combining tapply() and cor.test()?

2007-02-22 Thread Dimitris Rizopoulos
- cor.test(x$Returns, x$MFR.Factor, method = spearman) c(estimate = cr$estimate, p.value = cr$p.value) })) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven

Re: [R] List filtration

2007-02-22 Thread Dimitris Rizopoulos
try this: lis. - lapply(lis, function(x) if (length(ind - grep(^IPI, x))) x[ind[1]] else NULL) lis.[!sapply(lis., is.null)] I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address

Re: [R] Cross-tabulations next to each other

2007-02-22 Thread Dimitris Rizopoulos
maybe cbind() is close to what you're looking for, e.g., tb1 - table(x, y) tb2 - table(x, z) cbind(tb1, tb2) Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32

Re: [R] Omiting repeated values

2007-02-21 Thread Dimitris Rizopoulos
x - sample(1:3, 20, TRUE) x # do you mean unique(x) # or rle(x)$values I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax

Re: [R] simple question on one-sided p-values for coef() on output of lm()

2007-02-21 Thread Dimitris Rizopoulos
Quoting Ranjan Maitra [EMAIL PROTECTED]: Yes, of course! Thank you. So, I guess the answer is that R itself can not be made to do so directly. Many thanks for confirming this. Sincerely, Ranjan On Wed, 21 Feb 2007 20:23:55 + (GMT) Prof Brian Ripley [EMAIL PROTECTED] wrote:

Re: [R] testing slopes

2007-02-20 Thread Dimitris Rizopoulos
. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be

Re: [R] list of data frame objects

2007-02-18 Thread Dimitris Rizopoulos
try something like the following (untested): objs - ls() sapply(objs, function(obj) inherits(get(obj), data.frame)) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35

Re: [R] Generating MVN Data

2007-02-13 Thread Dimitris Rizopoulos
you probably want to use mvrnorm() from package MASS, e.g., library(MASS) mu - c(-3, 0, 3) Sigma - rbind(c(5,3,2), c(3,4,1), c(2,1,3)) x - mvrnorm(1000, mu, Sigma, empirical = TRUE) colMeans(x) var(x) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical

Re: [R] Near function?

2007-02-11 Thread Dimitris Rizopoulos
maybe you could try something along these lines: x - c(1, 3, 2, 5, 11) thr - 3 ### ind - t(combn(x, 2)) unique(c(ind[abs(ind[, 1] - ind[, 2]) = thr, ])) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University

Re: [R] Confidence intervals of quantiles

2007-02-05 Thread Dimitris Rizopoulos
careful with Bootstrap if you wish to obtain CIs for extreme quantiles in small samples. I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16

Re: [R] indexing

2007-02-01 Thread Dimitris Rizopoulos
one way is the following: assignation$value[match(x, assignation$class)] I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax

Re: [R] Index mapping on arrays

2007-02-01 Thread Dimitris Rizopoulos
probably you want something like the following: A[cbind(rep(1, length(x)), x, y)] I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16

Re: [R] Need help writing a faster code

2007-02-01 Thread Dimitris Rizopoulos
(); gc()}) system.time(for (i in 1:m) { W2[i, ] - g2(A[i, ]) }) ## or invisible({gc(); gc()}) system.time(W3 - t(apply(A, 1, g2))) all.equal(W1, W2) all.equal(W1, W3) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health

Re: [R] Canging the type of point points sizein plots..

2007-01-27 Thread Dimitris Rizopoulos
) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http

Re: [R] Conversion of column matrix into a vector without duplicates

2007-01-24 Thread Dimitris Rizopoulos
you need: unique(A[, 2]) Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http

Re: [R] Replace missing values in lapply

2007-01-24 Thread Dimitris Rizopoulos
you need to return x in the function within lapply(), e.g., something like lapply(TP, function(x) { x[is.na(x)] - 0; x }) I hope it works. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address

Re: [R] Vector to Matrix transformation

2007-01-23 Thread Dimitris Rizopoulos
check the help page for ?matrix(); you probably want either matrix(V1, nrow = 5) or matrix(V1, nrow = 5, byrow = TRUE) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer

Re: [R] Matrix operations in a list

2007-01-23 Thread Dimitris Rizopoulos
you need the 'SIMPLIFY' argument of mapply(), i.e., mapply(%*%, a, b, SIMPLIFY = FALSE) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0

Re: [R] Integration + Normal Distribution + Directory Browsing Processing Questions

2007-01-22 Thread Dimitris Rizopoulos
functions. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be

Re: [R] comparing two matrices

2007-01-21 Thread Dimitris Rizopoulos
based on Marc's approach, I think you can even use which((mat2 %in% mat1)[1:nrow(mat2)]) instead of which(apply(matrix(mat2 %in% mat1, dim(mat2)), 1, all)) I hope it helps. Best, Dimitris Quoting Marc Schwartz [EMAIL PROTECTED]: On Sun, 2007-01-21 at 00:14 +0200, Adrian Dusa wrote: Dear

Re: [R] comparing two matrices

2007-01-21 Thread Dimitris Rizopoulos
I think the following should work in your case: mat1 - data.matrix(expand.grid(0:2, 0:2, 0:2)) mat2 - mat1[c(19, 16, 13, 24, 8), ] ind1 - apply(mat1, 1, paste, collapse = /) ind2 - apply(mat2, 1, paste, collapse = /) match(ind2, ind1) I hope it helps. Best, Dimitris Quoting

  1   2   3   4   5   6   >