Re: [R] Another Real Basic Question

2019-11-03 Thread Linus Chen
A title like "Real basic question" is not quite informative... On Fri, 18 Oct 2019 at 17:45, John Kane wrote: > > Can you open in a text editor? > > On Wed, 16 Oct 2019 at 23:11, Phillip Heinrich wrote: > > > > In the Source window of RStudio (upper left) I save my code (File/Save) but > > can

Re: [R] how to use a matrix as an index to another matrix?

2019-10-28 Thread Linus Chen
Hi Jinsong, In such a case I think explicit loop IS the most elegant solution. for(i in 1:2) A[,i] <- A[,i][B[,i]] Linus On Fri, 11 Oct 2019 at 11:44, Jinsong Zhao wrote: > > Hi there, > > I have two matrices, A and B. The columns of B is the index of the > corresponding columns of A. I hope to

Re: [R] vectorizing the integrate function

2019-08-11 Thread Linus Chen
Dear ravi, In your example, the function "f" is linear to a, b, and c. Is this the general case in your task? If it is, you can save *lots* of computation taking advantage of the linearity. Lei On Sat, 10 Aug 2019 at 19:20, ravi via R-help wrote: > > Hi all,I am having some difficulties in v

Re: [R] Help with if else statement

2019-08-08 Thread Linus Chen
Bert's answer is great, but since there is only two columns to be used, why not simply pt$pheno <- pmax( p$phenoQ ,p$phenoH ) Cheers, Lei On Wed, 7 Aug 2019 at 21:23, Bert Gunter wrote: > > The ifelse() construction is fast, but after a couple of nested iterations, > it gets messy and error-pron

Re: [R] Printing vector

2019-07-23 Thread Linus Chen
Dear Steven, The function "write()" has a parameter "columns". And sprint() can do do some formatting in C style. x <- rnorm(100) s <- sprintf( fmt="%8.2f" ,x ) write(s, file="", ncolumns=7L) Cheers, Lei On Mon, 22 Jul 2019 at 07:37, Steven wrote: > > Is there a convenient way to print a vect

Re: [R] Nested structure data simulation

2019-05-21 Thread Linus Chen
The rows 21 to 40 with c2 with t1 with s1 > > The rows 41 to 60 with c3 with t2 with s1 > > The rows 61 to 80 with c4 with t2 with s1 > > The rows 81 to 100 with c5 with t3 with s1 > > The rows 101 to 120 with c6 with t3 with s1 > > The rows 121 to 140 with c7 with t

Re: [R] Nested structure data simulation

2019-05-21 Thread Linus Chen
Dear varin sacha, I think it will help us help you, if you give a clearer description of what exactly you want. I assume the situation is that you know what a data structure you want, but do not know how to conveniently create such structure. And that is where others can help you. So, please, des

Re: [R] Nested structure data simulation

2019-05-21 Thread Linus Chen
Dear varin sacha, Not very sure what you want, but will the following help a little? tmp <- rep(c("C1","C2","C3","C4","C5","C6"), 50) # make a character vector, with 50 "C1", 50 "C2", ... classroom <- tmp[sample(1:300)] # make a random permutation. Certainly you may also make it into one line: c