[R] Efficient swapping

2017-07-06 Thread Gang Chen
Suppose that we have the following dataframe: set.seed(1) (tmp <- data.frame(x = 1:10, R1 = sample(LETTERS[1:5], 10, replace = TRUE), R2 = sample(LETTERS[1:5], 10, replace = TRUE))) x R1 R2 1 1 B B 2 2 B A 3 3 C D 4 4 E B 5 5 B D 6 6 E C 7 7 E D 8 8 D E 9 9

Re: [R] Efficient swapping

2017-07-06 Thread Gang Chen
swapme = (as.numeric(tmp$R1) - as.numeric(tmp$R2)) %% 2 != > 0), > { > tmp[swapme, "R1"] <- r2[swapme] > tmp[swapme, "R2"] <- r1[swapme] > tmp > }) > > Best, > Ista > > On Thu, Jul 6, 2017 at 4:06 PM, Gang Chen wrote: >>

[R] Subtraction with aggregate

2016-07-28 Thread Gang Chen
With the following data in data.frame: subject QMemotion yi s1 75.1017 neutral -75.928276 s2 -47.3512 neutral -178.295990 s3 -68.9016 neutral -134.753906 s1 17.2099 negative -104.168312 s2 -53.1114 negative -182.373474 s3 -33.0322 negative -137.420410 I can

Re: [R] Subtraction with aggregate

2016-07-28 Thread Gang Chen
s3 -50.9669 -136.08716 > > > > Jim Holtman > Data Munger Guru > > What is the problem that you are trying to solve? > Tell me what you want to do, not how you want to do it. > > On Thu, Jul 28, 2016 at 4:40 PM, Gang Chen wrote: >> >> With the follo

[R] aggregate

2016-08-23 Thread Gang Chen
This is a simple question: With a dataframe like the following myData <- data.frame(X=c(1, 2, 3, 4), Y=c(4, 3, 2, 1), Z=c('A', 'A', 'B', 'B')) how can I get the cross product between X and Y for each level of factor Z? My difficulty is that I don't know how to deal with the fact that crossprod()

Re: [R] aggregate

2016-08-24 Thread Gang Chen
ge Station, TX 77840-4352 > > > -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Jim Lemon > Sent: Tuesday, August 23, 2016 6:02 PM > To: Gang Chen; r-help mailing list > Subject: Re: [R] aggregate > > Hi Gang Chen, > I

Re: [R] aggregate

2016-08-24 Thread Gang Chen
], x[, 2]))) > Z CP > A A 10 > B B 10 > > David C > > > -Original Message- > From: Gang Chen [mailto:gangch...@gmail.com] > Sent: Wednesday, August 24, 2016 10:17 AM > To: David L Carlson > Cc: Jim Lemon; r-help mailing list > Subject: Re: [R] aggregate

Re: [R] aggregate

2016-08-24 Thread Gang Chen
cture(c(1L, > 1L, 2L, 2L, 1L, 1L, 2L, 2L), .Label = c("A", "B"), class = "factor")), .Names > = c("X", > "Y", "S", "Z"), row.names = c(NA, -8L), class = "data.frame") > > Combining two labels just requires the

Re: [R] aggregate

2016-08-24 Thread Gang Chen
38 3.2 S2 A > S2B 22 3.2 S2 B > > David C > > -Original Message- > From: Gang Chen [mailto:gangch...@gmail.com] > Sent: Wednesday, August 24, 2016 2:51 PM > To: David L Carlson > Cc: r-help mailing list > Subject: Re: [R] aggregate > > Thanks again for patiently o

[R] String manipulation

2014-12-08 Thread Gang Chen
I want to do the following: if a string does not contain a colon (:), no change is needed; if it contains one or more colons, break the string into multiple strings using the colon as a separator. For example, "happy:" becomes "happy" ":" ":sad" turns to ":" "sad" and "happy:sad" changes to "h

[R] Problem with Anova() in package "car"

2015-01-13 Thread Gang Chen
I'm having some trouble with Anova() in package "car". When the model formula is explicitly expressed: library('nlme') library('car') fm <- lme(distance ~ age + Sex, data = Orthodont, random = ~ 1) Anova() works fine: Anova(fm) However, if the model formula is scanned from an external source:

Re: [R] Problem with Anova() in package "car"

2015-01-13 Thread Gang Chen
fter the > package is next built on R-Forge, usually in a day or so. > > Best, > John > >> -Original Message- >> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Gang Chen >> Sent: January-13-15 1:48 PM >> To: r-help >> Subject: [R] Pro

[R] Issue with formula conversion

2014-08-27 Thread Gang Chen
A random effect formulation for R package nlme is read in as a string of characters from an input file: ranEff <- "pdCompSymm(~1+Age)" I need to convert 'ranEff' to a formula class. However, as shown below: > as.formula(ranEff) ~1 + Age the "pdCompSymm" is lost in the conversion. Any solutions?

Re: [R] Issue with formula conversion

2014-08-27 Thread Gang Chen
Thanks for the help! However, I just need to get pdCompSymm(~1 + Age) without a tilde (~) at the beginning. On Wed, Aug 27, 2014 at 3:34 PM, David Winsemius wrote: > > On Aug 27, 2014, at 11:19 AM, Gang Chen wrote: > >> A random effect formulation for R package nlme is read

Re: [R] Issue with formula conversion

2014-08-27 Thread Gang Chen
rocess automatic. On Wed, Aug 27, 2014 at 3:49 PM, David Winsemius wrote: > > On Aug 27, 2014, at 12:44 PM, Gang Chen wrote: > >> Thanks for the help! However, I just need to get >> >> pdCompSymm(~1 + Age) > > That's not a formula in the R sense of th

Re: [R] Issue with formula conversion

2014-08-27 Thread Gang Chen
Sorry for the misspelling! And more importantly, thanks a lot for the nice solution and for the quick help! On Wed, Aug 27, 2014 at 4:22 PM, David Winsemius wrote: > > On Aug 27, 2014, at 1:11 PM, Gang Chen wrote: > >> Good point! >> >> Here is an example: >> &g

[R] Failure with .Rprofile on Mac OS X

2014-09-18 Thread Gang Chen
When R starts in GUI (e.g., /Applications/R.app/Contents/MacOS/R) on my Mac OS X 10.7.5, the startup configuration in .Rprofile works fine. However, when R starts on the terminal (e.g., /Library/Frameworks/R.framework/Resources/bin/R), it does not work at all. What could be the reason for the failu

Re: [R] Failure with .Rprofile on Mac OS X

2014-09-19 Thread Gang Chen
at does R say is the user's home directory? Did you make > *any* changes to Rprofile.site, or Renviron? > > What is the output from Sys.getenv() in gui and cli, and do they differ? > > >> On Sep 18, 2014, at 11:18 AM, Gang Chen wrote: >> >> When R starts in GUI

[R] Problem running mvrnorm

2015-11-18 Thread Gang Chen
I’m running R 3.2.2 on a Linux server (Redhat 4.4.7-16), and having the following problem. It works fine with the following: require('MASS’) var(mvrnorm(n = 1000, rep(0, 2), Sigma=matrix(c(10,3,3,2),2,2))) However, when running the following in a loop with simulated data (Sigma): # Sigma defin

Re: [R] [FORGED] Problem running mvrnorm

2015-11-18 Thread Gang Chen
> > Doing anything in 190 dimensions is bound to be fraught with numeric > peril. > > cheers, > > Rolf Turner > > -- > Technical Editor ANZJS > Department of Statistics > University of Auckland > Phone: +64-9-373-7599 ext. 88276 > > > On 19/11/15 08:28,

[R] Mixed model with multiple response variables?

2008-08-05 Thread Gang Chen
Hi, I have a data set collected from 10 measurements (response variables) on two groups (healthy and patient) of subjects performing 4 different tasks. In other words there are two fixed factors (group and task), and 10 response variables. I could analyze the data with aov() or lme() in package nl

[R] Creating an array of lists

2008-08-07 Thread Gang Chen
Hi, I want to store some number of outputs from running a bunch of analyses such as lm() into an array. I know how to do this with a one-dimensional array (vector) by creating myArray <- vector(mode='list', length=10) and storing each lm() result into a component of myArray. My question is, how

Re: [R] Creating an array of lists

2008-08-07 Thread Gang Chen
MAIL PROTECTED] > +44 (0)20 8525 0696 > http://www.burns-stat.com > (home of S Poetry and "A Guide for the Unwilling S User") > > Gang Chen wrote: >> >> Hi, >> >> I want to store some number of outputs from running a bunch of >> analyses such as lm(

[R] Calculate variance/covariance with complex numbers

2010-03-27 Thread Gang Chen
Anybody knows what functions can be used to calculate variance/covariance with complex numbers? var and cov don't seem to work: > a 1 V1 0.00810014+0.00169366i V2 0.00813054+0.00158251i V3 0.00805489+0.00163295i V4 0.00809141+0.00159533i V5 0.00813976+0.00161850i > var(a)

Re: [R] Calculate variance/covariance with complex numbers

2010-03-27 Thread Gang Chen
e elegant modification than mine?): > crossprod(t(apply(xri, 1, '-', colMeans(xri/(nrow(xri)-1) Do you agree? Gang On Sat, Mar 27, 2010 at 7:07 PM, Charles C. Berry wrote: > On Sat, 27 Mar 2010, Gang Chen wrote: > >> Anybody knows what functions can be used to calculate &

[R] Puzzled by an error with apply()

2009-04-06 Thread Gang Chen
I've written a function, myFunc, that works fine with myFunc(data, ...), but when I use apply() to run it with an array of data apply(myArray, 1, myFunc, ...) I get a strange error: Error in match.fun(FUN) : '1' is not a function, character or symbol which really puzzles me because '1' is meant

[R] Convert bits to numbers in base 10

2009-04-09 Thread Gang Chen
I have some bits stored like the following variable nn (nn <- c(1, 0, 0, 1, 0, 1,0)) [1] 1 0 0 1 0 1 0 not in the format of 1001010 and I need to convert them to numbers in base 10. What's an easy way to do it? TIA, Gang __ R-help@r-project.org mail

Re: [R] Convert bits to numbers in base 10

2009-04-09 Thread Gang Chen
t;,collapse="") >> >> See ?paste for more information. >> >> HTH, >> >> Jorge >> >> >> On Thu, Apr 9, 2009 at 5:23 PM, Gang Chen wrote: >> >>> I have some bits stored like the following variable nn >>> >&g

[R] metafor package: effect sizes are not fully independent

2010-02-05 Thread Gang Chen
In a classical meta analysis model y_i = X_i * beta_i + e_i, data {y_i} are assumed to be independent effect sizes. However, I'm encountering the following two scenarios: (1) Each source has multiple effect sizes, thus {y_i} are not fully independent with each other. (2) Each source has multiple e

Re: [R] metafor package: effect sizes are not fully independent

2010-02-08 Thread Gang Chen
ngapore >  http://courses.nus.edu.sg/course/psycwlm/internet/ > - > > On Mon, Feb 8, 2010 at 6:48 AM, Gang Chen wrote: >> Dear Mike, >> >> Thanks a lot for the kind help! >> >> Actually a

[R] How to capture the printout on the screen?

2013-07-17 Thread Gang Chen
This is most likely a silly question. First I run the following: require(car) mod.ok <- lm(cbind(pre.1, pre.2, pre.3, pre.4, pre.5, post.1, post.2, post.3, post.4, post.5, fup.1, fup.2, fup.3, fup.4, fup.5) ~ treatment*gender, data=OBrienKaiser) phase <- factor(rep(c("pr

Re: [R] How to capture the printout on the screen?

2013-07-17 Thread Gang Chen
uld just call that function directly. If not, you can copy that > section of the code into your own function to call and have it return the > object rather than printing. > > > On Wed, Jul 17, 2013 at 3:38 PM, Gang Chen wrote: >> >> This is most likely a silly questi

[R] Package for comparing sensitivity, specificity, PPV, NPV, and accuracy?

2012-09-13 Thread Gang Chen
Hi, I have two sets of sensitivity, specificity, positive predictive value, and negative predictive value, and accuracy from two tests on the same subjects. Is there an R package that does such paired comparisons? Thanks, Gang Chen __ R-help@r

[R] Any refit function available for 'car' package?

2014-06-16 Thread Gang Chen
Suppose that I need to run a multivariate linear model Y = X B + E many times with the same model matrix X but each time with different response matrix Y. Is there a function available in 'car' package similar to refit() in lme4 package so that the model matrix X would not be reassembled each tim

[R] Display a dataframe

2014-07-03 Thread Gang Chen
I have a matrix 'dd' defined as below: dd <- t(matrix(c(153.0216306, 1, 7.578366e-35, 13.3696538, 1, 5.114571e-04, 0.8476713, 1, 7.144239e-01, 1.2196050, 1, 5.388764e-01, 2.6349405, 1, 2.090719e-01, 6.0507714, 1, 2.780045e-02), nrow=3, ncol=6)) dimnames(dd)[[2]] <- c('# Chisq', 'DF', 'Pr(>Ch

Re: [R] Display a dataframe

2014-07-04 Thread Gang Chen
; 2.6349405 1 2.090719e-01 # ISO > 6.0507714 1 2.780045e-02 # SEC > > >David Carlson > >-----Original Message- >From: r-help-boun...@r-project.org >[mailto:r-help-boun...@r-project.org] On Behalf Of Gang Chen >Sent: Thursday, July 3, 2014 2:56 PM >To: r-h

Re: [R] Display a dataframe

2014-07-04 Thread Gang Chen
8366e-35 # Sex      >#2  13.3696538  1 5.114571e-04 # Volume   >#3   0.8476713  1 7.144239e-01 # Weight   >#4   1.2196050  1 5.388764e-01 # Intensity >#5   2.6349405  1 2.090719e-01 # ISO      >#6   6.0507714  1 2.780045e-02 # SEC      > >A.K. &g

[R] Mapping from one vector to another

2014-07-17 Thread Gang Chen
Suppose I have the following dataframe: L4 <- LETTERS[1:4] fac <- sample(L4, 10, replace = TRUE) (d <- data.frame(x = 1, y = 1:10, fac = fac)) x y fac 1 1 1 B 2 1 2 B 3 1 3 D 4 1 4 A 5 1 5 C 6 1 6 D 7 1 7 C 8 1 8 B 9 1 9 B 10 1 10 B I'd like to add an

Re: [R] Mapping from one vector to another

2014-07-17 Thread Gang Chen
mple data and use dput() to include it in your > email. > > Sarah > > On Thu, Jul 17, 2014 at 11:00 AM, Gang Chen wrote: >> Suppose I have the following dataframe: >> >> L4 <- LETTERS[1:4] >> fac <- sample(L4, 10, replace = TRUE) >> (d <- data.f

Re: [R] Mapping from one vector to another

2014-07-17 Thread Gang Chen
range of values you have to work with then one of the other > more efficient methods may still be a better choice for this specific task. > > Hadley Wickham's "tidy data" [1] principles address this concern more > thoroughly than I have. > > [1] Google this phrase...

[R] Puzzling "Execution halted"

2012-11-20 Thread Gang Chen
I wrote an R program that does heavy computations with hundreds of lines of code. It's running fine both interactively and in batch mode on a Mac OS X computer. The program also has no problem running on a Linux system (Fedora 14) interactively. However, when I try it on the terminal in batch mode

Re: [R] Puzzling "Execution halted"

2012-11-20 Thread Gang Chen
à 12:54 -0500, Gang Chen a écrit : >> I wrote an R program that does heavy computations with hundreds of >> lines of code. It's running fine both interactively and in batch mode >> on a Mac OS X computer. The program also has no problem running on a >> Linux system (Fedo

[R] dataframe manipulation

2013-12-13 Thread Gang Chen
Suppose I have a dataframe defined as L3 <- LETTERS[1:3] (d <- data.frame(cbind(x = 1, y = 1:10), fac = sample(L3, 10, replace = TRUE))) x y fac 1 1 1 C 2 1 2 A 3 1 3 B 4 1 4 C 5 1 5 B 6 1 6 B 7 1 7 A 8 1 8 A 9 1 9 B 10 1 10 A I want to extract

Re: [R] dataframe manipulation

2013-12-13 Thread Gang Chen
Perfect! Thanks a lot, A.K! On Fri, Dec 13, 2013 at 4:21 PM, arun wrote: > > > Hi, > Try: > d[match(unique(d$fac),d$fac),] > A.K. > > > On Friday, December 13, 2013 4:17 PM, Gang Chen > wrote: > Suppose I have a dataframe defined as > > L3 <- LE

Re: [R] dataframe manipulation

2013-12-13 Thread Gang Chen
en everyone who tries it will get the same data > frame d. > > Sarah > > > On Fri, Dec 13, 2013 at 4:15 PM, Gang Chen wrote: > > Suppose I have a dataframe defined as > > > > L3 <- LETTERS[1:3] > > (d <- data.frame(cbind(x = 1, y = 1:10), fac

[R] Change factor levels

2013-12-14 Thread Gang Chen
Suppose I have a dataframe 'd' defined as L3 <- LETTERS[1:3] d0 <- data.frame(cbind(x = 1, y = 1:10), fac = sample(L3, 10, replace = TRUE)) (d <- d0[d0$fac %in% c('A', 'B'),]) x y fac 2 1 2 B 3 1 3 A 4 1 4 A 5 1 5 A 6 1 6 B 8 1 8 A Even though factor 'fac' in 'd' onl

Re: [R] Change factor levels

2013-12-14 Thread Gang Chen
gt; > > best > daniel > > Feladó: r-help-boun...@r-project.org [r-help-boun...@r-project.org] ; > meghatalmazó: Gang Chen [gangch...@gmail.com] > Küldve: 2013. december 14. 21:09 > To: r-help > Tárgy: [R] Change factor levels > > Suppose I have

[R] Trouble installing gsl wrapper

2010-10-29 Thread Gang Chen
Hi, I'm trying to install the gsl wrapper source code (http://cran.r-project.org/src/contrib/gsl_1.9-8.tar.gz) on a Linux system (OpenSuse 11.1), but encountering the following problem. I've already installed 'gsl' version 1.14 (ftp://ftp.gnu.org/gnu/gsl/gsl-1.14.tar.gz) on the system. What's miss

Re: [R] Trouble installing gsl wrapper

2010-10-30 Thread Gang Chen
You nailed it, Prof. Ripley! Thanks a lot... Gang On Sat, Oct 30, 2010 at 2:58 PM, Prof Brian Ripley wrote: > On Sat, 30 Oct 2010, Gang Chen wrote: > >> Hi, >> >> I'm trying to install the gsl wrapper source code >> (http://cran.r-project.org/src/contrib/gsl

[R] 3D scatter plot with projections

2011-01-08 Thread Gang Chen
I want to create some 3D scatter plot with a diagonal line. In addition, I'd like to have those points plus the diagonal line projected to those three planes (xy, yz and xz). Which package can I use to achieve this, scatterplot3d or something else? Thanks, Gang [[alternative HTML version

Re: [R] 3D scatter plot with projections

2011-01-08 Thread Gang Chen
Thanks a lot for the quick help! How to project the scatter plot with the diagonal line to the three planes with scatterplot3d? I could not find such an example demonstrating that in the vignette. Thanks, Gang 2011/1/8 Uwe Ligges > > > On 08.01.2011 16:38, Gang Chen wrote: >

Re: [R] 3D scatter plot with projections

2011-01-08 Thread Gang Chen
Yes, too bad I didn't realize that it's so simple like that! Thanks... On Sat, Jan 8, 2011 at 12:45 PM, David Winsemius wrote: > > On Jan 8, 2011, at 11:21 AM, Gang Chen wrote: > > Thanks a lot for the quick help! How to project the scatter plot with the >> diago

[R] Convert dataframe with two factors from wide to long format

2011-05-22 Thread Gang Chen
I know how to convert a simple dataframe from wide to long format with one varying factor. However, for a dataset with two factors like the following, Subj T1_Cond1 T1_Cond2 T2_Cond1 T2_Cond2 1 0.125869 4.108232 1.099392 5.556614 2 1.427940 2.170026 0.120748 1.176353 How to eleg

Re: [R] Convert dataframe with two factors from wide to long format

2011-05-22 Thread Gang Chen
, 4,8) ) > > ubj substr(variable, 1, 2)Cond1Cond2 > 1 1 T1 0.125869 4.108232 > 2 1 T2 1.099392 5.556614 > 3 2 T1 1.427940 2.170026 > 4 2 T2 0.120748 1.176353 > > The modifications to

[R] A question about data frame

2011-03-10 Thread Gang Chen
A very simple question. With a data frame like this: > n = c(2, 3, 5) > s = c("aa", "bb", "cc") > df = data.frame(n, s) I want df$s[1] or df[1,2], but how can I get rid of the extra line in the output about the factor levels: > df$s[1] [1] aa Levels: aa bb cc Thanks, Gang _

Re: [R] A question about data frame

2011-03-10 Thread Gang Chen
or. > -- > Robert Tirrell | r...@stanford.edu | (607) 437-6532 > Program in Biomedical Informatics | Butte Lab | Stanford University > > > On Thu, Mar 10, 2011 at 13:35, Gang Chen wrote: >> >> n = c(2, 3, 5) >> > s = c("aa", "bb", "cc

Re: [R] A question about data frame

2011-03-10 Thread Gang Chen
                    Statistical Computing Facility >                                         Department of Statistics >                                         UC Berkeley >                                         spec...@stat.berkeley.edu > > > > On Thu, 10 Mar 2011, Gang Chen w

[R] Saving a graph

2011-08-29 Thread Gang Chen
I read somewhere that vector graphics such as eps or dpf are more favorable than alternatives (jpeg, bmp or png) for publication because vector graphics scale properly when enlarged. However, my problem is that the file generated from a graph of fixed size is too large (in the order of 10MB) becaus

[R] non-recursive SVAR model with vars

2011-06-20 Thread Gang Chen
Hi, I have a question about SVAR modeling with the package vars. How does it handle the situation where the A (structural) matrix has a non-recursive structure in the SVAR model? In other words, what kind of algorithm does vars adopt to deal with the unidentifiable issue in a non-recursive model?

[R] Confused about a warning message

2011-07-07 Thread Gang Chen
I define the following function to convert a t-value with degrees of freedom DF to another t-value with different degrees of freedom fullDF: tConvert <- function(tval, DF, fullDF) ifelse(DF>=1, qt(pt(tval, DF), fullDF), 0) It works as expected with the following case: > tConvert(c(2,3), c(10,12)

Re: [R] Confused about a warning message

2011-07-07 Thread Gang Chen
c(0,12), 12) [1] 0 3 However, I feel my solution is a little kludged. Any better idea? Thanks, Gang On Thu, Jul 7, 2011 at 9:04 PM, David Winsemius wrote: > > On Jul 7, 2011, at 8:52 PM, David Winsemius wrote: > > >> On Jul 7, 2011, at 8:47 PM, Gang Chen wrote: >> >&

[R] Wide to long form conversion

2011-10-06 Thread Gang Chen
I have some data 'myData' in wide form (attached at the end), and would like to convert it to long form. I wish to have five variables in the result: 1) Subj: factor 2) Group: between-subjects factor (2 levels: s / w) 3) Reference: within-subject factor (2 levels: Me / She) 4) F: within-subject fa

Re: [R] Wide to long form conversion

2011-10-06 Thread Gang Chen
ndrew Miles wrote: > Take a look here. > http://stackoverflow.com/questions/2185252/reshaping-data-frame-from-wide-to-long-format > Andrew Miles > Department of Sociology > Duke University > On Oct 6, 2011, at 4:28 PM, Gang Chen wrote: > > I have some data 'myData'

Re: [R] Wide to long form conversion

2011-10-07 Thread Gang Chen
value_var = 'value') > head(mData4, 4) > >  Subj Group Ref Time  F  J > 1   S1     s  Me    1  4  5 > 2   S1     s  Me    2  3  6 > 3   S1     s She    1  6 10 > 4   S1     s She    2  6  9 > > mData5 <- cast(mData3, Subj + Group + Ref + Var ~ Time, value_var

Re: [R] Wide to long form conversion

2011-10-07 Thread Gang Chen
S1 s 6 She F1 6S1 s 6 She F2 7S1 s10 She J1 8S1 s 9 She J2 On Fri, Oct 7, 2011 at 7:16 AM, Jim Lemon wrote: > On 10/07/2011 07:28 AM, Gang Chen wrote: >> >> I have some data 'myData' in wide form (

Re: [R] Wide to long form conversion

2011-10-07 Thread Gang Chen
David, thanks a lot for the code! I've learned quite a bit from all the generous help... Gang On Fri, Oct 7, 2011 at 1:37 PM, David Winsemius wrote: > > On Oct 7, 2011, at 1:30 PM, David Winsemius wrote: > >> >> On Oct 7, 2011, at 7:40 AM, Gang Chen wrote: >> &

[R] Setting up infile for R CMD BATCH

2012-02-07 Thread Gang Chen
Suppose I create an R program called myTest.R with only one line like the following: type <- as.integer(readline("input type (1: type1; 2: type2)? ")) Then I'd like to run myTest.R in batch mode by constructing an input file called answers.R with the following: source("myTest.R") 1 When I ran t

Re: [R] Setting up infile for R CMD BATCH

2012-02-07 Thread Gang Chen
from a previous run in interactive mode, s/he may try out the batch mode the next time. > On Tue, Feb 7, 2012 at 4:05 PM, Gang Chen wrote: >> Suppose I create an R program called myTest.R with only one line like >> the following: >> >> type <- as.integer(readlin

Re: [R] Setting up infile for R CMD BATCH

2012-02-08 Thread Gang Chen
e "type<- readline(...)"  in your script so type > wouldn't be overwritten in subsequent runs. > > If your goal is to batch evaluate multiple answer files from users > (why else would you ask questions with readline?), then you should > have enough to go on with my ans

Re: [R] Setting up infile for R CMD BATCH

2012-02-09 Thread Gang Chen
7;Answers.R') > > # run again this time with answers available >> source('myTest.R') > [1] -1.088665   # skips prompt > [1] -1.088665   # -1.088^1 (type in Answer.R ==1) > > # Now you can also run as batch > $ R CMD BATCH myTest.R out.R > $ cat out.R &g

[R] Is there any package can be used to solve individual haplotyping problem?

2008-04-02 Thread Gang Chen
ve such problem? Thanks in advance for any information, Gang Chen [[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-proj

[R] Extract values from a named array

2008-04-07 Thread Gang Chen
Sorry for this dumb question. Suppose I have a named array ww defined as ww <- 1:5 names(ww) <- c("a", "b", "c", "d", "e") How can I extract the whole array of numbers without the names? ww[1:5] does not work while ww[[1]] can only extract one number at a time. Thanks, Gang

Re: [R] Extract values from a named array

2008-04-07 Thread Gang Chen
Thanks a lot for the suggestions! Gang On 4/7/08, Uwe Ligges <[EMAIL PROTECTED]> wrote: > > > Gang Chen wrote: > > > Sorry for this dumb question. Suppose I have a named array ww defined as > > > > ww <- 1:5 > > names(ww) <- c("a", &qu

[R] Formula with no intercept

2008-04-14 Thread Gang Chen
I'm trying to analyze a model with two variables, one is Group with two levels (male and female), and other is Time with four levels (T1, T2, T3 and T4). And for the convenience of post-hoc testing I wanted to consider a model with no intercept for factor Time, so I tried formula Group*(Time-1) H

[R] Post hoc tests with lme

2008-04-16 Thread Gang Chen
Using the "ergoStool" data cited in Mixed-Effects Models in S and S-PLUS by Pinheiro and Bates as an example, we have > library(nlme) > fm <- lme(effort~Type-1, data=ergoStool, random=~1|Subject) > summary(fm) Linear mixed-effects model fit by REML Data: ergoStool AIC BIC

Re: [R] [R-sig-ME] Post hoc tests with lme

2008-04-17 Thread Gang Chen
-10 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 (Adjusted p values reported -- single-step method) On 4/16/08, Simon Blomberg <[EMAIL PROTECTED]> wrote: > Try glht in package multcomp. > > Simon. > > > On

Re: [R] Formula with no intercept

2008-04-17 Thread Gang Chen
k the 'convenience' is largely lost, > and packages such as multcomp can post-hoc test any (coherent) set of > hypotheses you choose, irrespective of the model parametrization. > > > > > > > > -Original Message- > > > From: [EMAIL PROTECTED] > &g

[R] How to deal with character(0)?

2007-11-15 Thread Gang Chen
I want to identify whether a variable is character(0), but get lost. For example, if I have > dd<-character(0) the following doesn't seem to serve as a good identifier: > dd==character(0) logical(0) So how to detect character(0)? Thanks, Gang __

Re: [R] How to deal with character(0)?

2007-11-15 Thread Gang Chen
Thanks a lot for all who've provided suggestions! Gang On Nov 15, 2007, at 5:09 PM, Duncan Murdoch wrote: > On 11/15/2007 4:54 PM, Gang Chen wrote: >> I want to identify whether a variable is character(0), but get >> lost. For example, if I have >> > dd&l

[R] glm for nominal X ordinal

2008-01-04 Thread Gang Chen
Suppose I have a two-way table of nominal category (party affiliation) X ordinal category (political ideology): party affiliation X (3 levels) - democratic, independent, and republic political ideology Y (3 levels) - liberal, moderate, and conservative The dependent variable is the frequency (o

[R] Create a new dataframe from an existing dataframe

2008-01-07 Thread Gang Chen
I have a dataframe DF with 4 columns (variables) A, B, C, and D, and want to create a new dataframe DF2 by keeping B and C in DF but counting the frequency of D while collapsing A. I tried by(DF$D, list(DF$B, DF$C), FUN=summary) but this is not exactly what I want. What is a good way to do it

Re: [R] glm for nominal X ordinal

2008-01-07 Thread Gang Chen
Thanks a lot! This is exactly what I wanted. Gang On Jan 5, 2008, at 2:20 PM, David Winsemius wrote: > Gang Chen <[EMAIL PROTECTED]> wrote in > news:[EMAIL PROTECTED]: > >> Suppose I have a two-way table of nominal category (party >> affiliation) X ordinal c

Re: [R] Create a new dataframe from an existing dataframe

2008-01-07 Thread Gang Chen
C1 D243 B2 C2 D123 B2 C2 D243 Thanks, Gang On Jan 7, 2008, at 2:06 PM, Duncan Murdoch wrote: > On 1/7/2008 1:28 PM, Gang Chen wrote: >> I have a dataframe DF with 4 columns (variables) A, B, C, and D, >> and want to create a new dataframe DF2 by keeping B and C

Re: [R] Create a new dataframe from an existing dataframe

2008-01-07 Thread Gang Chen
Sorry the new column in DF2 should be called FreqD instead of FreqA. How can I get DF2 with aggregate? Gang On Jan 7, 2008, at 2:38 PM, Gang Chen wrote: > Yes, I misstated it when I said that I would keep B and C. I want to > collapse column A, but count the frequency of D as a new col

Re: [R] Create a new dataframe from an existing dataframe

2008-01-08 Thread Gang Chen
ts >> x.new <- x[, -1] # delete "A" >> x.new$FreqD <- counts # add new column >> # print out unique entries >> unique(x.new) >B C D FreqD > 1 B1 C1 D1 3 > 2 B2 C1 D1 3 > 4 B2 C2 D2 2 > 7 B1 C2 D2 2 >> > > > On

[R] Residual deviance in glm

2008-01-10 Thread Gang Chen
I'm running a categorical data analysis with a two-way design of nominal by ordinal structure like the Political Ideology Example (Table 9.5) in Agresti's book Categorical Data Analysis. The nominal variable is Method while the ordinal variable is Quality (Bad, Moderate, Good, Excellent). I

Re: [R] glht() and contrast() comparison

2008-01-11 Thread Gang Chen
With the example you provided, it seems both glht() and contrast() work fine. Based on my limited experience with contrast(), if you encounter such an error message you just mentioned, check > dat.lme$apVar You might see something like this [1] "Non-positive definite approximate variance

[R] Trouble receiving messages from the mailing list

2008-01-17 Thread Gang Chen
For some unknown reason I stopped receiving any messages from the R- help mailing list. See if this test gets through. Thanks, Gang __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http

[R] trouble with tkgetOpenFile

2008-09-17 Thread Gang Chen
I'm trying to use the following loop to open a window multiple times to select files, but only the last window shows up. What am I missing? library(tcltk) nWin <- 6 fn <- vector('list', nWin) for (ii in nWin) { fn[[ii]] <- tclvalue( tkgetOpenFile( filetypes = "{{Files} {.1D}} {{All files

Re: [R] trouble with tkgetOpenFile

2008-09-17 Thread Gang Chen
-- > John Fox, Professor > Department of Sociology > McMaster University > Hamilton, Ontario, Canada > web: socserv.mcmaster.ca/jfox > >> -Original Message- >> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > On >> Behalf Of Gang Chen >> Se

[R] Running source() on a file in another directory

2008-10-01 Thread Gang Chen
Suppose I have a file prog.R stored in a directory under ~/dirname, and ~/dirname is set in a shell script file (e.g. .cshrc) as one of the accessible paths on terminal. On a different directory I could run prog.R interactively by executing source("~/dirname/prog.R") It seems that source() does n

Re: [R] Running source() on a file in another directory

2008-10-02 Thread Gang Chen
> location: > > Find(file.exists, file.path(p, "prog.R")) > > so you can source that. > > On Wed, Oct 1, 2008 at 6:09 PM, Gang Chen <[EMAIL PROTECTED]> wrote: >> Suppose I have a file prog.R stored in a directory under ~/dirname, >> and ~/dirname i

[R] t.test() on a list

2008-10-02 Thread Gang Chen
I have a list, myList, with each of its 9 components being a 15X15 matrix. I want to run a t-test across the list for each component in the matrix. For example, the first t-test is on myList[[1]][1, 1], myList[[2]][1, 1], ..., myList[[9]][1, 1]; and there are totally 15X15 t-tests. How can I run th

[R] Load a program at the front end

2008-10-02 Thread Gang Chen
I want to run a R program, prog.R, interactively. My question is, is there a way I can start prog.R on the shell terminal when invoking R, instead of using source() inside R? TIA, Gang __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/l

Re: [R] t.test() on a list

2008-10-02 Thread Gang Chen
shouldn't be doing this. I suggest you consult with your local statistician. > > -- Bert Gunter > > -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On > Behalf Of Gang Chen > Sent: Thursday, October 02, 2008 11:24 AM > To: [EMAIL PROTECTED] >

Re: [R] Load a program at the front end

2008-10-07 Thread Gang Chen
t; and "R --interactive < prog.R", and they all failed. Any other suggestions? Thanks, Gang On Mon, Oct 6, 2008 at 10:12 PM, Bernardo Rangel Tura <[EMAIL PROTECTED]> wrote: > Em Qui, 2008-10-02 às 14:36 -0400, Gang Chen escreveu: >> I want to run a R program, prog.R, int

Re: [R] Load a program at the front end

2008-10-07 Thread Gang Chen
.First.sys at the beginning of > prog.R to get default packages loaded. > > luke > > On Tue, 7 Oct 2008, Gang Chen wrote: > >> Thanks a lot for the suggestion! >> >> Unfortunately " R --no-save < prog.R" does not work well with my >> situation b

Re: [R] t.test() on a list

2008-10-07 Thread Gang Chen
EMAIL PROTECTED]> > wrote: >> > I am sure you will get helpful answers. I am almost as sure that you >> > shouldn't be doing this. I suggest you consult with your local > statistician. >> > >> > -- Bert Gunter >> > >> > -O

[R] Confused with default device setup

2008-10-15 Thread Gang Chen
When invoking dev.new() on my Mac OS X 10.4.11, I get an X11 window instead of quartz which I feel more desirable. So I'd like to set the default device to quartz. However I'm confused because of the following: > Sys.getenv("R_DEFAULT_DEVICE") R_DEFAULT_DEVICE "quartz" > getOption("devi

[R] Parallel computing with snow

2009-01-02 Thread Gang Chen
I've been using parApply() in snow package for parallel computing with the following lines in R 2.8.1: library(snow) nNodes <- 4 cl <- makeCluster(nNodes, type = "SOCK") fm <- parApply(cl, myData, c(1,2), func1, ...) Since I have a Mac OS X (version 10.4.11) with two dual-core processors,

  1   2   >