[R] Column names of model.matrix's output with contrast.arg

2024-06-13 Thread Christophe Dutang
Dear list, Changing the default contrasts used in glm() makes me aware how model.matrix() set column names. With default contrasts, model.matrix() use the level values to name the columns. However with other contrasts, model.matrix() use the level indexes. In the documentation, I don’t see any

Re: [R] Create a numeric series in an efficient way

2024-06-13 Thread avi.e.gross
Bert, I think you read my message differently than I expected. I approached the request as an exercise in evaluating various ways something can be done and maybe choosing a simple one or choosing a more general one as needed. I provided some solutions along the lines you mentioned and THEN also

Re: [R] Create a numeric series in an efficient way

2024-06-13 Thread Bert Gunter
"If you want a much more compact solution that handles arbitrary pairs of "what to copy", number_of_copies, you can write a function that evaluates two arguments at a time or takes two vectors as arguments like this one I wrote quickly and crudely:" Please! -- The "times" argument of rep can be a

Re: [R] Create a numeric series in an efficient way

2024-06-13 Thread avi.e.gross
For the particular example you asked for, consider the "each" you can use with rep() rep(1:13, each=84) This is what it does for a shorter version of 4 each: > rep(1:13, each=4) [1] 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5 6 6 6 6 7 7 7 7 8 8 8 8 9 9 9 9 10 10

Re: [R] Create a numeric series in an efficient way

2024-06-13 Thread Ebert,Timothy Aaron
Thank you. Using ‘each’ is shorter code, so better if the requested order was important versus being an initial solution. blocC <- c(rep(x=c(1:13), times=84)) #it makes 84 copies of the numbers 1:13 blocC <- arrange(.data = data.frame(blocC), blocC) #sort to get requested order. blocD <- c(rep(x

Re: [R] Create a numeric series in an efficient way

2024-06-13 Thread Bert Gunter
Nope. She would have wanted the 'each' argument = 84. See ?rep. -- Bert On Thu, Jun 13, 2024 at 3:54 PM Ebert,Timothy Aaron wrote: > Maybe this was your solution? > > blocC <- c(rep(x=c(1:13), times=84)) > blocC <- arrange(.data = data.frame(blocC), blocC) > > The second line sorts, but that

Re: [R] Create a numeric series in an efficient way

2024-06-13 Thread Ebert,Timothy Aaron
Maybe this was your solution? blocC <- c(rep(x=c(1:13), times=84)) blocC <- arrange(.data = data.frame(blocC), blocC) The second line sorts, but that may not be needed depending on application. The object class is also different in the sorted solution. Tim -Original Message- From: R-hel

Re: [R] Create a numeric series in an efficient way

2024-06-13 Thread Francesca PANCOTTO via R-help
I apologize, I solved the problem, sorry for that. f. Il giorno gio 13 giu 2024 alle ore 16:42 Francesca PANCOTTO < francesca.panco...@unimore.it> ha scritto: > Dear Contributors > I am trying to create a numeric series with repeated numbers, not > difficult task, but I do not seem to find an e

[R] Create a numeric series in an efficient way

2024-06-13 Thread Francesca PANCOTTO via R-help
Dear Contributors I am trying to create a numeric series with repeated numbers, not difficult task, but I do not seem to find an efficient way. This is my solution blocB <- c(rep(x = 1, times = 84), rep(x = 2, times = 84), rep(x = 3, times = 84), rep(x = 4, times = 84), rep(x = 5, times = 84), re

Re: [R] Integration of functions with a vector argument

2024-06-13 Thread Ivan Krylov via R-help
В Wed, 12 Jun 2024 23:42:18 + "Levine, Michael" пишет: > f.int1 <- function(x,y) {Vectorize (function(y) f(c(x,y),H=H,j=j))} Vectorize returns a callable function(y), so wrapping it in a function(x,y) will not work. Since you'd like to integrate over y, we can perform the same transformation

Re: [R] Integration of functions with a vector argument

2024-06-13 Thread Levine, Michael
Dear Ivan, Thank you very much for your suggestions. I understand what you are saying. I am afraid I didn't explain well enough what was needed, however. Let us again restrict ourselves to the case of two dimensions. Then, what I have is a bivariate density function f(x,y) and my intention is

Re: [R] Integration of functions with a vector argument

2024-06-13 Thread Jeff Newmiller via R-help
How do you integrate perpendicular to a plane if you don't have a concept of 3d? In that direction the plane is just a point. Vectors in R do not have any concept of "n by 1"... they are like a string of beads. When you take a column out of a matrix `a` using indexing b <- a[,j] the resulting v