search for: gangchen6

Displaying 20 results from an estimated 33 matches for "gangchen6".

2009 Jan 06
5
Using apply for two datasets
I can run one-sample t-test on an array, for example a matrix myData1, with the following apply(myData1, 2, t.test) Is there a similar fashion using apply() or something else to run 2-sample t-test with datasets from two groups, myData1 and myData2, without looping? TIA, Gang
2017 Jul 06
3
Efficient swapping
...; 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 <gangchen6 at gmail.com> wrote: >> 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...
2017 Jul 06
0
Efficient swapping
Untested, but I expect that setting the levels to be the same across the two factors levels(tmp$R1) <- levels(tmp$R2) <- LETTERS[1:6] and proceeding as before should be fine. Best, Ista On Jul 6, 2017 6:54 PM, "Gang Chen" <gangchen6 at gmail.com> wrote: Thanks a lot, Ista! I really appreciate it. How about a slightly different case as the following: set.seed(1) (tmp <- data.frame(x = 1:10, R1 = sample(LETTERS[1:5], 10, replace = TRUE), R2 = sample(LETTERS[2:6], 10, replace = TRUE))) x R1 R2 1 C B 2 B B...
2011 Mar 10
3
A question about data frame
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
2012 Feb 07
6
Setting up infile for R CMD BATCH
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 the following at the terminal: R CMD BATCH answer.R output.Rout it failed
2010 Mar 27
3
Calculate variance/covariance with complex numbers
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) 1 1 1.141556e-09 Warning message: In var(a) : imaginary parts discarded in
2017 Jul 06
0
Efficient swapping
...h(list(r1 = tmp$R1, r2 = tmp$R2, 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 <gangchen6 at gmail.com> wrote: > 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...
2013 Dec 14
2
Change factor levels
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' only has 2 levels, but it seems to bear the birthmark
2017 Jul 06
2
Efficient swapping
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 D B 10 10 A D I want to do the following: if the difference between the level index of factor
2010 Feb 05
3
metafor package: effect sizes are not fully independent
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 effect sizes, each of the effect size from a source can be categorized as one of a factor levels
2008 Mar 06
2
Array arithmetic
I have two arrays A and B with dimensions of (L, M, N, P) and (L, M, N), and I want to do for (i in 1:L) { for (j in 1:M) { for (k in 1:N) { if (abs(B[i, j, k]) > 10e-5) C[i, j, k,] <- A[i, j, k,]/B[i, j, k] else C[i, j, k,] <- 0 } } } How can I get C more efficiently than looping? Thanks, Gang
2008 Apr 07
3
Extract values from a named array
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
2011 May 22
2
Convert dataframe with two factors from wide to long format
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 elegantly convert to a long form as Subj Time Cond Value 1 1 1 0.125869 1
2009 Jan 23
1
Interpreting model matrix columns when using contr.sum
With the following example using contr.sum for both factors, > dd <- data.frame(a = gl(3,4), b = gl(4,1,12)) # balanced 2-way > model.matrix(~ a * b, dd, contrasts = list(a="contr.sum", b="contr.sum")) (Intercept) a1 a2 b1 b2 b3 a1:b1 a2:b1 a1:b2 a2:b2 a1:b3 a2:b3 1 1 1 0 1 0 0 1 0 0 0 0 0 2 1 1 0 0 1 0
2011 Oct 06
3
Wide to long form conversion
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 factor (2 levels: F1 / F2) 5) J: within-subject factor (2 levels: J1 / J2) As this is the
2010 Oct 31
1
R-help Digest, Vol 92, Issue 31
...do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] ------------------------------ Message: 93 Date: Sat, 30 Oct 2010 13:02:13 +0800 From: Gang Chen <gangchen6@gmail.com> To: R-help <r-help@stat.math.ethz.ch> Cc: hankin.robin@gmail.com Subject: [R] Trouble installing gsl wrapper Message-ID: <AANLkTikYJi+-pH1rdBbjyduVri6t2sVqBLrrzmB21uZB@mail.gmail.com> Content-Type: text/plain; charset=windows-1252 Hi, I'm trying to install the gs...
2008 Apr 14
1
Formula with no intercept
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) However this seems to give me the following terms in the model GroupMale, GroupFemale, TimeT2,
2008 Oct 02
1
t.test() on a list
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 these t-tests in a simple way? TIA, Gang
2008 Oct 15
1
Confused with default device setup
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("device") [1] "X11" What's going on? Also is
2011 Jan 08
1
3D scatter plot with projections
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 deleted]]