Re: [R] Bug in R-Help Archives?

2023-01-26 Thread Jeff Newmiller
Every email thread (mailing list or not) gets a hidden identifier that is used 
to identify that thread. It is not that Outlook outsmarted John... any email 
program would have done the same.

John... please don't reply to existing posts with a new subject... many mailing 
list users may be using the threaded view in their email program and never see 
your question at all if they were not interested in the original thread.

On January 26, 2023 11:31:39 PM PST, Deepayan Sarkar 
 wrote:
>From looking at the headers in John Sorkin's mail, my guess is that he
>just replied to the other thread rather than starting a fresh email,
>and in his attempts to hide that, was outsmarted by Outlook.
>
>This is based on references to domains such as yahoo.com,
>dcn.davis.ca.us, and precheza.cz in the header, which were all
>involved in the certification thread.
>
>-Deepayan
>
>On Fri, Jan 27, 2023 at 12:26 PM Rui Barradas  wrote:
>>
>> Às 06:39 de 27/01/2023, Rui Barradas escreveu:
>> > Hello,
>> >
>> > When consulting the R-Help Archives today I've noticed that the thread
>> >
>> > Pipe operator
>> >
>> > started by John Sorkin, Tue Jan 3 17:48:30 CET 2023 is under another
>> > thread,
>> >
>> > R Certification
>> >
>> > started by Mukesh Ghanshyamdas Lekhrajani.
>> >
>> > Isn't this a bug in the filing system?
>> >
>> > Thanks to the list maintainer  Martin Maechler and ETH Zurich for
>> > organizing and hosting the list for all of us. It's an invaluable tool
>> > that has served so many R users along the years and that surely gives a
>> > lot of work organizing and eventual headaches. I hope this is not one of
>> > them.
>> >
>> > Rui Barradas
>> >
>> > __
>> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide
>> > http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>>
>> Maybe the attached screen capture makes it more clear.
>>
>> Rui Barradas
>>
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

-- 
Sent from my phone. Please excuse my brevity.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Bug in R-Help Archives?

2023-01-26 Thread Ivan Krylov
On Fri, 27 Jan 2023 13:01:39 +0530
Deepayan Sarkar  wrote:

> From looking at the headers in John Sorkin's mail, my guess is that he
> just replied to the other thread rather than starting a fresh email,
> and in his attempts to hide that, was outsmarted by Outlook.

That's 100% correct. The starting "Pipe operator" e-mail has
In-Reply-To: <047e01d91ed5$577e42a0$067ac7e0$@yahoo.com>, and the
message with this Message-ID is the one from Mukesh Ghanshyamdas
Lekhrajani with the subject "Re: [R] R Certification" that's
immediately above the message by John Sorkin.

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Bug in R-Help Archives?

2023-01-26 Thread Deepayan Sarkar
>From looking at the headers in John Sorkin's mail, my guess is that he
just replied to the other thread rather than starting a fresh email,
and in his attempts to hide that, was outsmarted by Outlook.

This is based on references to domains such as yahoo.com,
dcn.davis.ca.us, and precheza.cz in the header, which were all
involved in the certification thread.

-Deepayan

On Fri, Jan 27, 2023 at 12:26 PM Rui Barradas  wrote:
>
> Às 06:39 de 27/01/2023, Rui Barradas escreveu:
> > Hello,
> >
> > When consulting the R-Help Archives today I've noticed that the thread
> >
> > Pipe operator
> >
> > started by John Sorkin, Tue Jan 3 17:48:30 CET 2023 is under another
> > thread,
> >
> > R Certification
> >
> > started by Mukesh Ghanshyamdas Lekhrajani.
> >
> > Isn't this a bug in the filing system?
> >
> > Thanks to the list maintainer  Martin Maechler and ETH Zurich for
> > organizing and hosting the list for all of us. It's an invaluable tool
> > that has served so many R users along the years and that surely gives a
> > lot of work organizing and eventual headaches. I hope this is not one of
> > them.
> >
> > Rui Barradas
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> Maybe the attached screen capture makes it more clear.
>
> Rui Barradas
>
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Bug in R-Help Archives?

2023-01-26 Thread Rui Barradas

Às 06:39 de 27/01/2023, Rui Barradas escreveu:

Hello,

When consulting the R-Help Archives today I've noticed that the thread

Pipe operator

started by John Sorkin, Tue Jan 3 17:48:30 CET 2023 is under another 
thread,


R Certification

started by Mukesh Ghanshyamdas Lekhrajani.

Isn't this a bug in the filing system?

Thanks to the list maintainer  Martin Maechler and ETH Zurich for 
organizing and hosting the list for all of us. It's an invaluable tool 
that has served so many R users along the years and that surely gives a 
lot of work organizing and eventual headaches. I hope this is not one of 
them.


Rui Barradas

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.


Maybe the attached screen capture makes it more clear.

Rui Barradas


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Bug in R-Help Archives?

2023-01-26 Thread Rui Barradas

Hello,

When consulting the R-Help Archives today I've noticed that the thread

Pipe operator

started by John Sorkin, Tue Jan 3 17:48:30 CET 2023 is under another thread,

R Certification

started by Mukesh Ghanshyamdas Lekhrajani.

Isn't this a bug in the filing system?

Thanks to the list maintainer  Martin Maechler and ETH Zurich for 
organizing and hosting the list for all of us. It's an invaluable tool 
that has served so many R users along the years and that surely gives a 
lot of work organizing and eventual headaches. I hope this is not one of 
them.


Rui Barradas

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] implicit loop for nested list

2023-01-26 Thread Andrew Simmons
I would use replicate() to do an operation with random numbers repeatedly:

```
mysim <- replicate(10, {
two.mat <- matrix(rnorm(4), 2, 2)
four.mat <- matrix(rnorm(16), 4, 4)
list(two.mat = two.mat, four.mat = four.mat)
})
```

which should give you a matrix-list. You can slice this matrix-list
just like normal, then cbind it in one step:

```
two.mat <- do.call("cbind", mysim["two.mat", ])
four.mat <- do.call("cbind", mysim["four.mat", ])
```

On Thu, Jan 26, 2023 at 10:33 PM Naresh Gurbuxani
 wrote:
>
> >
> > I am looking for a more elegant way to write below code.
> >
> > #Simulation results have different dimensions
> > mysim <- lapply(1:10, function(y) {
> >two.mat <- matrix(rnorm(4), nrow = 2)
> >four.mat <- matrix(rnorm(16), nrow = 4)
> >list(two.mat = two.mat, four.mat = four.mat) #results with different 
> > dimensions
> > })
> >
> > #Collect different components of simulation results
> > #Is it possible to do this with implicit loops?
> > mat2 <- matrix(nrow = 2, ncol = 1)
> > mat4 <- matrix(nrow = 4, ncol = 1)
> > for (mat.list in mysim) {
> >mat2 <- cbind(mat2, mat.list[["two.mat"]])
> >mat4 <- cbind(mat4, mat.list[["four.mat"]])
> > }
> > mat2 <- mat2[,-1]
> > mat4 <- mat4[,-1]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] implicit loop for nested list

2023-01-26 Thread Jeff Newmiller
Elegance is in the eyes of the beholder...

extractor <- function( simlist, sim_name ) {
  do.call(
cbind
  , lapply(
  simlist
, function( r ) r[[ sim_name ]]
)
  )
}
extractor( mysim, "two.mat" )

... but using do.call will be much more memory efficient than successive cbind 
operations.


On January 26, 2023 7:33:25 PM PST, Naresh Gurbuxani 
 wrote:
>> 
>> I am looking for a more elegant way to write below code.
>> 
>> #Simulation results have different dimensions
>> mysim <- lapply(1:10, function(y) {
>>two.mat <- matrix(rnorm(4), nrow = 2)
>>four.mat <- matrix(rnorm(16), nrow = 4)
>>list(two.mat = two.mat, four.mat = four.mat) #results with different 
>> dimensions
>> })
>> 
>> #Collect different components of simulation results
>> #Is it possible to do this with implicit loops?
>> mat2 <- matrix(nrow = 2, ncol = 1)
>> mat4 <- matrix(nrow = 4, ncol = 1)
>> for (mat.list in mysim) {
>>mat2 <- cbind(mat2, mat.list[["two.mat"]])
>>mat4 <- cbind(mat4, mat.list[["four.mat"]])
>> }
>> mat2 <- mat2[,-1]
>> mat4 <- mat4[,-1]
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

-- 
Sent from my phone. Please excuse my brevity.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] implicit loop for nested list

2023-01-26 Thread Bert Gunter
Is this what you want:

## This cbinds all the 2 matrix components of mysim
## producing a 2 x 20 matrix
do.call(cbind,lapply(mysim,`[[`,1))

## Change the 1 to a 2 to cbind the other components.

Cheers,
Bert

Tha

On Thu, Jan 26, 2023 at 7:33 PM Naresh Gurbuxani <
naresh_gurbux...@hotmail.com> wrote:

> >
> > I am looking for a more elegant way to write below code.
> >
> > #Simulation results have different dimensions
> > mysim <- lapply(1:10, function(y) {
> >two.mat <- matrix(rnorm(4), nrow = 2)
> >four.mat <- matrix(rnorm(16), nrow = 4)
> >list(two.mat = two.mat, four.mat = four.mat) #results with different
> dimensions
> > })
> >
> > #Collect different components of simulation results
> > #Is it possible to do this with implicit loops?
> > mat2 <- matrix(nrow = 2, ncol = 1)
> > mat4 <- matrix(nrow = 4, ncol = 1)
> > for (mat.list in mysim) {
> >mat2 <- cbind(mat2, mat.list[["two.mat"]])
> >mat4 <- cbind(mat4, mat.list[["four.mat"]])
> > }
> > mat2 <- mat2[,-1]
> > mat4 <- mat4[,-1]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE 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]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] implicit loop for nested list

2023-01-26 Thread Naresh Gurbuxani
> 
> I am looking for a more elegant way to write below code.
> 
> #Simulation results have different dimensions
> mysim <- lapply(1:10, function(y) {
>two.mat <- matrix(rnorm(4), nrow = 2)
>four.mat <- matrix(rnorm(16), nrow = 4)
>list(two.mat = two.mat, four.mat = four.mat) #results with different 
> dimensions
> })
> 
> #Collect different components of simulation results
> #Is it possible to do this with implicit loops?
> mat2 <- matrix(nrow = 2, ncol = 1)
> mat4 <- matrix(nrow = 4, ncol = 1)
> for (mat.list in mysim) {
>mat2 <- cbind(mat2, mat.list[["two.mat"]])
>mat4 <- cbind(mat4, mat.list[["four.mat"]])
> }
> mat2 <- mat2[,-1]
> mat4 <- mat4[,-1]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] (no subject)

2023-01-26 Thread Hasan Diwan
Upananda.
On Mon, 16 Jan 2023 at 12:55, Upananda Pani  wrote:

> Greetings! I would like to know how to create the lag variable for my data.
>

Kindly provide a link to your data, on a publicly accessible page or a
means to generate fake data that illustrates your issue. -- H

-- 
OpenPGP: https://hasan.d8u.us/openpgp.asc
If you wish to request my time, please do so using
*bit.ly/hd1AppointmentRequest
*.
Si vous voudrais faire connnaisance, allez a *bit.ly/hd1AppointmentRequest
*.

Sent
from my mobile device
Envoye de mon portable

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Failing to install the rgl package

2023-01-26 Thread David Winsemius



On 1/26/23 11:04, Tunga Kantarcı wrote:

Hi,

I try to execute the seven lines of code below to plot a graph. But I
am failing as the messages below show. Where am I going wrong?


install.packages("rgl")
library(rgl)
y_hat = X%*%B_hat
open3d(windowRect = c(100,100,900,900),family = "serif")
color = rainbow(length(y_hat))[rank(y_hat)]
plot3d(educ,exper,wage,col = color,type = "s",size = 0.5,xlim =
c(0,20),ylim = c(0,60),zlim = c(-10,70),box = FALSE,axes = TRUE)
planes3d(B_hat[2],B_hat[3],-1,B_hat[1],alpha = 0.5,col = "azure")


  -

install.packages("rgl")

trying URL 'https://cran.rstudio.com/bin/macosx/contrib/4.1/rgl_1.0.1.tgz'
Content type 'application/x-gzip' length 9425401 bytes (9.0 MB)
==
downloaded 9.0 MB

The downloaded binary packages are in
/var/folders/fx/_msf5ycn14g59c3vlc4pc7b8gn/T//RtmpfaezHX/downloaded_packages

library(rgl)

Registered S3 methods overwritten by 'rgl':
   method   from
   knit_print.rglId
   knit_print.rglOpen3d
   sew.rglRecordedplot
Error in dyn.load(dynlib <- getDynlib(dir)) :
   unable to load shared object
'/Library/Frameworks/R.framework/Versions/4.1/Resources/library/rgl/libs/rgl.so':
   
dlopen(/Library/Frameworks/R.framework/Versions/4.1/Resources/library/rgl/libs/rgl.so,
0x0006): Library not loaded: /opt/X11/lib/libGLU.1.dylib
   Referenced from: <82C7D9AE-E1B2-39EA-A909-163B033CF7B1>



So It appears that X11, a.k.a. XQuartz on a Mac, is failing to load. You 
probably need to reinstall XQuartz with a current version that matches 
your version of R. You are also getting a message saying Java sdk cannot 
be found.



You also appear to be attempting to load the version for R 4.1 while the 
current version of R is 4.2. The R "ecosystem" needs consistency in 
versions of R, XQuartz, Java, and R packages. You will probably get 
better success if you first upgrade R, then reinstall XQuartz,  then 
reinstall or update Java, and finally update all your installed packages 
including rgl and then give it another go.


Finally, this is Rhelp. There is a SIG for R-Mac users. This question 
would have been more on-topic for  that help mailing list.


--

David


/Library/Frameworks/R.framework/Versions/4.1/Resources/library/rgl/libs/rgl.so
   Reason: tried: '/opt/X11/lib/libGLU.1.dylib' (no such file),
'/System/Volumes/Preboot/Cryptexes/OS/opt/X11/lib/libGLU.1.dylib' (no
such file), '/opt/X11/lib/libGLU.1.dylib' (no such file),
'/Library/Frameworks/R.framework/Resources/lib/libGLU.1.dylib' (no
such file), '/Users/tunga/lib/libGLU.1.dylib' (no such file),
'/usr/local/lib/libGLU.1.dylib' (no such file),
'/usr/lib/libGLU.1.dylib' (no such file, not in dyld cache),
'/lib/libGLU.1.dylib' (no such file),
'/Library/Java/JavaVirtualMachines/jdk1.8.0_241.jdk/Contents/Home/jre/lib/server/libGLU.1.dylib'
(no such file), '/var/folders/fx/_msf5ycn
In addition: Warning message:
package ‘rgl’ was built under R version 4.1.2
Error: package or namespace load failed for ‘rgl’:
  .onLoad failed in loadNamespace() for 'rgl', details:
   call: rgl.init(initValue, onlyNULL)
   error: OpenGL is not available in this build
In addition: Warning messages:
1: Loading rgl's DLL failed.
This build of rgl depends on XQuartz, which failed to load.
  See the discussion in https://stackoverflow.com/a/66127391/2554330
2: Trying without OpenGL...

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Failing to install the rgl package

2023-01-26 Thread Tunga Kantarcı
Hi,

I try to execute the seven lines of code below to plot a graph. But I
am failing as the messages below show. Where am I going wrong?


install.packages("rgl")
library(rgl)
y_hat = X%*%B_hat
open3d(windowRect = c(100,100,900,900),family = "serif")
color = rainbow(length(y_hat))[rank(y_hat)]
plot3d(educ,exper,wage,col = color,type = "s",size = 0.5,xlim =
c(0,20),ylim = c(0,60),zlim = c(-10,70),box = FALSE,axes = TRUE)
planes3d(B_hat[2],B_hat[3],-1,B_hat[1],alpha = 0.5,col = "azure")


 -
> install.packages("rgl")
trying URL 'https://cran.rstudio.com/bin/macosx/contrib/4.1/rgl_1.0.1.tgz'
Content type 'application/x-gzip' length 9425401 bytes (9.0 MB)
==
downloaded 9.0 MB

The downloaded binary packages are in
/var/folders/fx/_msf5ycn14g59c3vlc4pc7b8gn/T//RtmpfaezHX/downloaded_packages
> library(rgl)
Registered S3 methods overwritten by 'rgl':
  method   from
  knit_print.rglId
  knit_print.rglOpen3d
  sew.rglRecordedplot
Error in dyn.load(dynlib <- getDynlib(dir)) :
  unable to load shared object
'/Library/Frameworks/R.framework/Versions/4.1/Resources/library/rgl/libs/rgl.so':
  
dlopen(/Library/Frameworks/R.framework/Versions/4.1/Resources/library/rgl/libs/rgl.so,
0x0006): Library not loaded: /opt/X11/lib/libGLU.1.dylib
  Referenced from: <82C7D9AE-E1B2-39EA-A909-163B033CF7B1>
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/rgl/libs/rgl.so
  Reason: tried: '/opt/X11/lib/libGLU.1.dylib' (no such file),
'/System/Volumes/Preboot/Cryptexes/OS/opt/X11/lib/libGLU.1.dylib' (no
such file), '/opt/X11/lib/libGLU.1.dylib' (no such file),
'/Library/Frameworks/R.framework/Resources/lib/libGLU.1.dylib' (no
such file), '/Users/tunga/lib/libGLU.1.dylib' (no such file),
'/usr/local/lib/libGLU.1.dylib' (no such file),
'/usr/lib/libGLU.1.dylib' (no such file, not in dyld cache),
'/lib/libGLU.1.dylib' (no such file),
'/Library/Java/JavaVirtualMachines/jdk1.8.0_241.jdk/Contents/Home/jre/lib/server/libGLU.1.dylib'
(no such file), '/var/folders/fx/_msf5ycn
In addition: Warning message:
package ‘rgl’ was built under R version 4.1.2
Error: package or namespace load failed for ‘rgl’:
 .onLoad failed in loadNamespace() for 'rgl', details:
  call: rgl.init(initValue, onlyNULL)
  error: OpenGL is not available in this build
In addition: Warning messages:
1: Loading rgl's DLL failed.
This build of rgl depends on XQuartz, which failed to load.
 See the discussion in https://stackoverflow.com/a/66127391/2554330
2: Trying without OpenGL...

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R-es] Resumen de R-help-es, Vol 167, Envío 10

2023-01-26 Thread Griera-yandex
Hola:

Funciona a la perfección. Y los nombres de las nuevas variables tipo "V1c" 
"V2c"... ya me está bien.

Gracias por habertelo currado tanto! Me has ahorrado copiar, pegar y modificar 
un monton de linias. Y no
tenia conciencia de que podia ser tan complicado.

Gracias por la ayuda. Saludos.

On Thu, 26 Jan 2023 09:33:31 -0500
patricio fuenmayor  wrote:

> Hola esta es una solución
> 
> library(data.table)
> library(stringr)
> 
> 
> dt <- data.table( V1a = sample(c("1","0"), 10, TRUE)
> , V1b = sample(c("1","0"), 10, TRUE)
> , V2a = sample(c("1","0"), 10, TRUE)
> , V2b = sample(c("1","0"), 10, TRUE)
> , V3a = sample(c("1","0"), 10, TRUE)
> , V3b = sample(c("1","0"), 10, TRUE)
> , V4a = sample(c("1","0"), 10, TRUE)
> , V4b = sample(c("1","0"), 10, TRUE))
> dt[,":="(seq=.I)]
> setcolorder(dt,"seq")
> 
> dt1 <- melt(dt,id.vars=1,measure.vars=2:ncol(dt),variable.name="vrb",
> value.name="vl")
> dt1[,":="(vrb_nm=str_sub(vrb,end=2),vrb_tp=str_sub(vrb,start=-1))]
> dt2 <- dcast(dt1,seq+vrb_nm~vrb_tp,fun.aggregate=\(x)
> paste0(x,collapse="|"),value.var="vl")
> dt2[,":="(c=fifelse(a=="1"|b=="1","1","0"))]
> dt3 <-dcast(dt2,seq~vrb_nm,fun.aggregate=\(x)
> paste0(x,collapse="|"),value.var="c")
> setnames(dt3,paste0(colnames(dt3),"c"))
> dt <- dt[dt3,on=.(seq=seqc)]
> 
> Te crea un grupo de variables tipo c que es la lógica que necesitas .. pero
> le puedes reemplazar por el nombre de "a", qué es lo que muestras en el
> ejemplo
> 
> 
> Saludos
> 
> 
> 
> 
> El jue, 26 ene 2023 a la(s) 06:02, 
> escribió:
> 
> > Envíe los mensajes para la lista R-help-es a
> > r-help-es@r-project.org
> >
> > Para subscribirse o anular su subscripción a través de la WEB
> > https://stat.ethz.ch/mailman/listinfo/r-help-es
> >
> > O por correo electrónico, enviando un mensaje con el texto "help" en
> > el asunto (subject) o en el cuerpo a:
> > r-help-es-requ...@r-project.org
> >
> > Puede contactar con el responsable de la lista escribiendo a:
> > r-help-es-ow...@r-project.org
> >
> > Si responde a algún contenido de este mensaje, por favor, edite la
> > linea del asunto (subject) para que el texto sea mas especifico que:
> > "Re: Contents of R-help-es digest...". Además, por favor, incluya en
> > la respuesta sólo aquellas partes del mensaje a las que está
> > respondiendo.
> > Asuntos del día:
> >
> >1. Modificar una serie columnas de un dataframe (Griera)
> >
> >
> > -- Forwarded message --
> > From: Griera 
> > To: r-help-es@r-project.org, gri...@yandex.com
> > Cc:
> > Bcc:
> > Date: Thu, 26 Jan 2023 09:46:57 +0100
> > Subject: [R-es] Modificar una serie columnas de un dataframe
> > Hola:
> >
> > Lo vuelvo a enviar para ver si tengo más suerte:
> >
> > Tengo una tabla con pares de variables (V1a, V1b, V2a, V2b, ...) similar a
> > esta:
> >
> > df <- data.frame( V1a = sample(c("1","0"), 10, TRUE)
> > , V1b = sample(c("1","0"), 10, TRUE)
> > , V2a = sample(c("1","0"), 10, TRUE)
> > , V2b = sample(c("1","0"), 10, TRUE))
> >
> >V1a V1b V2a V2b
> > 10   1   0   0
> > 20   0   1   0
> > 30   1   0   0
> > ...
> >
> > y quiero que V1a valga "1" si V1a o V1b valen 1, V2a valga "1" si V2a o
> > V2b valen 1 y así sucesivamente. Lo hago mediante un transform con una
> > línia para cada pareja de variables:
> >
> > df <- transform (df
> > , V1a = ifelse (V1a == "1" | V1b == "1", "1, "0")
> > , V2a = ifelse (V2a == "1" | V2b == "1", "1, "0"))
> >
> >   )
> > ¿Habria forma de hacerlo (¿con un función?) de manera que no tenga que
> > escribir una línia para cada par de variables?
> >
> > Muchas gracias a todos y saludos.
> >
> >
> > ___
> > R-help-es mailing list
> > R-help-es@r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-help-es
> >

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R] R installation

2023-01-26 Thread Bert Gunter
What is the error, **exactly**?

Bert

On Thu, Jan 26, 2023 at 9:12 AM Vivian Jungels via R-help <
r-help@r-project.org> wrote:

> Hello!
>
> I am trying to install R and its says there is an error with the software.
> I am using the link for Mac OS the most recent version on the website
> because my Mac OS is M1 and 13.2 version. I am able to download it but then
> when I install it it says they’re an error with the software that caused
> the installation to fail. I was wondering what I need to do to install R?
>
> Vivian Jungels
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE 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]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R installation

2023-01-26 Thread Kevin Thorpe
If you used this link for R-4.2.2-arm64.pkg then I have no other ideas.

The r-sig-mac list can probably help you more, but there is the possibility you 
will get help here.


> On Jan 26, 2023, at 12:19 PM, Vivian Jungels  wrote:
> 
> I have an M1 Mac with OS 13.2 so I did the most recent version that said for 
> M1 Macs and higher. 
> 
> Vivian Jungels 
> 
>> On Jan 26, 2023, at 11:16 AM, Kevin Thorpe  wrote:
>> 
>> The most obvious question is did you download the correct package? There is 
>> a version for Intel-based MACs and for M1-based MACs.
>> 
>> 
>>> On Jan 25, 2023, at 11:22 AM, Vivian Jungels via R-help 
>>>  wrote:
>>> 
>>> Hello! 
>>> 
>>> I am trying to install R and its says there is an error with the software. 
>>> I am using the link for Mac OS the most recent version on the website 
>>> because my Mac OS is M1 and 13.2 version. I am able to download it but then 
>>> when I install it it says they’re an error with the software that caused 
>>> the installation to fail. I was wondering what I need to do to install R? 
>>> 
>>> Vivian Jungels 
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>> 


-- 
Kevin E. Thorpe
Head of Biostatistics,  Applied Health Research Centre (AHRC)
Li Ka Shing Knowledge Institute of St. Michael’s Hospital
Assistant Professor, Dalla Lana School of Public Health
University of Toronto
email: kevin.tho...@utoronto.ca  Tel: 416.864.5776  Fax: 416.864.3016


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R installation

2023-01-26 Thread Kevin Thorpe
The most obvious question is did you download the correct package? There is a 
version for Intel-based MACs and for M1-based MACs.


> On Jan 25, 2023, at 11:22 AM, Vivian Jungels via R-help 
>  wrote:
> 
> Hello! 
> 
> I am trying to install R and its says there is an error with the software. I 
> am using the link for Mac OS the most recent version on the website because 
> my Mac OS is M1 and 13.2 version. I am able to download it but then when I 
> install it it says they’re an error with the software that caused the 
> installation to fail. I was wondering what I need to do to install R? 
> 
> Vivian Jungels 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Kevin E. Thorpe
Head of Biostatistics,  Applied Health Research Centre (AHRC)
Li Ka Shing Knowledge Institute of St. Michael’s Hospital
Assistant Professor, Dalla Lana School of Public Health
University of Toronto
email: kevin.tho...@utoronto.ca  Tel: 416.864.5776  Fax: 416.864.3016


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] R installation

2023-01-26 Thread Vivian Jungels via R-help
Hello! 

I am trying to install R and its says there is an error with the software. I am 
using the link for Mac OS the most recent version on the website because my Mac 
OS is M1 and 13.2 version. I am able to download it but then when I install it 
it says they’re an error with the software that caused the installation to 
fail. I was wondering what I need to do to install R? 

Vivian Jungels 
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R-es] Resumen de R-help-es, Vol 167, Envío 10

2023-01-26 Thread Griera-yandex
Muchas gracias por responder!

Después lo hago.

Saludos.

On Thu, 26 Jan 2023 09:33:31 -0500
patricio fuenmayor  wrote:

> Hola esta es una solución
> 
> library(data.table)
> library(stringr)
> 
> 
> dt <- data.table( V1a = sample(c("1","0"), 10, TRUE)
> , V1b = sample(c("1","0"), 10, TRUE)
> , V2a = sample(c("1","0"), 10, TRUE)
> , V2b = sample(c("1","0"), 10, TRUE)
> , V3a = sample(c("1","0"), 10, TRUE)
> , V3b = sample(c("1","0"), 10, TRUE)
> , V4a = sample(c("1","0"), 10, TRUE)
> , V4b = sample(c("1","0"), 10, TRUE))
> dt[,":="(seq=.I)]
> setcolorder(dt,"seq")
> 
> dt1 <- melt(dt,id.vars=1,measure.vars=2:ncol(dt),variable.name="vrb",
> value.name="vl")
> dt1[,":="(vrb_nm=str_sub(vrb,end=2),vrb_tp=str_sub(vrb,start=-1))]
> dt2 <- dcast(dt1,seq+vrb_nm~vrb_tp,fun.aggregate=\(x)
> paste0(x,collapse="|"),value.var="vl")
> dt2[,":="(c=fifelse(a=="1"|b=="1","1","0"))]
> dt3 <-dcast(dt2,seq~vrb_nm,fun.aggregate=\(x)
> paste0(x,collapse="|"),value.var="c")
> setnames(dt3,paste0(colnames(dt3),"c"))
> dt <- dt[dt3,on=.(seq=seqc)]
> 
> Te crea un grupo de variables tipo c que es la lógica que necesitas .. pero
> le puedes reemplazar por el nombre de "a", qué es lo que muestras en el
> ejemplo
> 
> 
> Saludos
> 
> 
> 
> 
> El jue, 26 ene 2023 a la(s) 06:02, 
> escribió:
> 
> > Envíe los mensajes para la lista R-help-es a
> > r-help-es@r-project.org
> >
> > Para subscribirse o anular su subscripción a través de la WEB
> > https://stat.ethz.ch/mailman/listinfo/r-help-es
> >
> > O por correo electrónico, enviando un mensaje con el texto "help" en
> > el asunto (subject) o en el cuerpo a:
> > r-help-es-requ...@r-project.org
> >
> > Puede contactar con el responsable de la lista escribiendo a:
> > r-help-es-ow...@r-project.org
> >
> > Si responde a algún contenido de este mensaje, por favor, edite la
> > linea del asunto (subject) para que el texto sea mas especifico que:
> > "Re: Contents of R-help-es digest...". Además, por favor, incluya en
> > la respuesta sólo aquellas partes del mensaje a las que está
> > respondiendo.
> > Asuntos del día:
> >
> >1. Modificar una serie columnas de un dataframe (Griera)
> >
> >
> > -- Forwarded message --
> > From: Griera 
> > To: r-help-es@r-project.org, gri...@yandex.com
> > Cc:
> > Bcc:
> > Date: Thu, 26 Jan 2023 09:46:57 +0100
> > Subject: [R-es] Modificar una serie columnas de un dataframe
> > Hola:
> >
> > Lo vuelvo a enviar para ver si tengo más suerte:
> >
> > Tengo una tabla con pares de variables (V1a, V1b, V2a, V2b, ...) similar a
> > esta:
> >
> > df <- data.frame( V1a = sample(c("1","0"), 10, TRUE)
> > , V1b = sample(c("1","0"), 10, TRUE)
> > , V2a = sample(c("1","0"), 10, TRUE)
> > , V2b = sample(c("1","0"), 10, TRUE))
> >
> >V1a V1b V2a V2b
> > 10   1   0   0
> > 20   0   1   0
> > 30   1   0   0
> > ...
> >
> > y quiero que V1a valga "1" si V1a o V1b valen 1, V2a valga "1" si V2a o
> > V2b valen 1 y así sucesivamente. Lo hago mediante un transform con una
> > línia para cada pareja de variables:
> >
> > df <- transform (df
> > , V1a = ifelse (V1a == "1" | V1b == "1", "1, "0")
> > , V2a = ifelse (V2a == "1" | V2b == "1", "1, "0"))
> >
> >   )
> > ¿Habria forma de hacerlo (¿con un función?) de manera que no tenga que
> > escribir una línia para cada par de variables?
> >
> > Muchas gracias a todos y saludos.
> >
> >
> > ___
> > R-help-es mailing list
> > R-help-es@r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-help-es
> >

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R] Shadow Graphics Error in R Studio

2023-01-26 Thread Thomas Subia via R-help
Brinkley,

I am using R studio with
R version 4.2.0 (2022-04-22 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

I cannot reproduce your error messages.
That being said, you might want to look at:
 
https://github.com/rstudio/rstudio/issues/2214 
https://stackoverflow.com/questions/19513705/error-in-rstudiogd-shadow-graphics-device-error-r-error-4-r-code-execution

Hope this helps!

Thomas Subia

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] akima interp results to zero with less than 10 values

2023-01-26 Thread PIKAL Petr
Hallo Duncan

Thanks, I was not aware of this package.  I will try.

Petr

> -Original Message-
> From: Duncan Murdoch 
> Sent: Thursday, January 26, 2023 3:44 PM
> To: PIKAL Petr ; r-help@r-project.org
> Subject: Re: [R] akima interp results to zero with less than 10 values
>
> The akima package has a problematic license (it doesn't allow commercial 
> use),
> so it's been recommended that people use the interp package instead.  When I
> use interp::interp instead of akima::interp, I get reasonable output from 
> your
> example.
>
> So that's another reason to drop akima...
>
> Duncan Murdoch
>
> On 26/01/2023 9:35 a.m., PIKAL Petr wrote:
> > Dear all
> >
> > I have this table
> >> dput(mat)
> > mat <- structure(c(2, 16, 9, 2, 16, 1, 1, 4, 7, 7, 44.52, 42.8, 43.54,
> > 40.26, 40.09), dim = c(5L, 3L))
> >
> > And I want to calculate result for contour or image plots as I did few
> > years ago.
> >
> > However interp does not compute the z values and gives me zeros in z 
> > matrix.
> > library(akima)
> >
> >> interp(mat[,1], mat[,2], mat[, 3], nx=5, ny=5)
> > $x
> > [1]  2.0  5.5  9.0 12.5 16.0
> >
> > $y
> > [1] 1.0 2.5 4.0 5.5 7.0
> >
> > $z
> >   [,1] [,2] [,3] [,4] [,5]
> > [1,]00000
> > [2,]00000
> > [3,]00000
> > [4,]00000
> > [5,]00000
> >
> > With the example from help page if less than 10 values are used, the
> > result is also zero interp(akima$x[1:9], akima$y[1:9], akima$z[1:9],
> > nx=5, ny=5)
> >
> > but with 10 or more values the result is correctly calculated
> > interp(akima$x[1:10], akima$y[1:10], akima$z[1:10], nx=5, ny=5) $x [1]
> > 0.  6.1625 12.3250 18.4875 24.6500
> >
> > $y
> > [1]  1.24  5.93 10.62 15.31 20.00
> >
> > $z
> >   [,1] [,2] [,3] [,4] [,5]
> > [1,]   NA   NA   NA   NA 34.6
> > [2,]   NA   NA 27.29139 27.11807 26.60971
> > [3,]   NA 19.81371 19.63614 19.12778 18.61943
> > [4,]   NA 14.01443 10.66531 11.13750 10.62914
> > [5,]   NA   NA   NA   NA   NA
> >
> > Help page says
> > x, y, and z must be the same length (execpt if x is a
> > SpatialPointsDataFrame) and may contain no fewer than ***four*** points.
> >
> > So my understanding was that 5 poins could be used but I am obviously
> wrong.
> > Is it a bug in interp or in the documentation or is it my poor
> > understanding of the whole matter.
> >
> > Best regards
> > Petr
> >
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] akima interp results to zero with less than 10 values

2023-01-26 Thread Duncan Murdoch
The akima package has a problematic license (it doesn't allow commercial 
use), so it's been recommended that people use the interp package 
instead.  When I use interp::interp instead of akima::interp, I get 
reasonable output from your example.


So that's another reason to drop akima...

Duncan Murdoch

On 26/01/2023 9:35 a.m., PIKAL Petr wrote:

Dear all

I have this table

dput(mat)

mat <- structure(c(2, 16, 9, 2, 16, 1, 1, 4, 7, 7, 44.52, 42.8, 43.54,
40.26, 40.09), dim = c(5L, 3L))

And I want to calculate result for contour or image plots as I did few years
ago.

However interp does not compute the z values and gives me zeros in z matrix.
library(akima)


interp(mat[,1], mat[,2], mat[, 3], nx=5, ny=5)

$x
[1]  2.0  5.5  9.0 12.5 16.0

$y
[1] 1.0 2.5 4.0 5.5 7.0

$z
  [,1] [,2] [,3] [,4] [,5]
[1,]00000
[2,]00000
[3,]00000
[4,]00000
[5,]00000

With the example from help page if less than 10 values are used, the result
is also zero
interp(akima$x[1:9], akima$y[1:9], akima$z[1:9], nx=5, ny=5)

but with 10 or more values the result is correctly calculated
interp(akima$x[1:10], akima$y[1:10], akima$z[1:10], nx=5, ny=5)
$x
[1]  0.  6.1625 12.3250 18.4875 24.6500

$y
[1]  1.24  5.93 10.62 15.31 20.00

$z
  [,1] [,2] [,3] [,4] [,5]
[1,]   NA   NA   NA   NA 34.6
[2,]   NA   NA 27.29139 27.11807 26.60971
[3,]   NA 19.81371 19.63614 19.12778 18.61943
[4,]   NA 14.01443 10.66531 11.13750 10.62914
[5,]   NA   NA   NA   NA   NA

Help page says
x, y, and z must be the same length (execpt if x is a
SpatialPointsDataFrame) and may contain no fewer than ***four*** points.

So my understanding was that 5 poins could be used but I am obviously wrong.
Is it a bug in interp or in the documentation or is it my poor understanding
of the whole matter.

Best regards
Petr


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] akima interp results to zero with less than 10 values

2023-01-26 Thread PIKAL Petr
Dear all

I have this table 
> dput(mat)
mat <- structure(c(2, 16, 9, 2, 16, 1, 1, 4, 7, 7, 44.52, 42.8, 43.54, 
40.26, 40.09), dim = c(5L, 3L))

And I want to calculate result for contour or image plots as I did few years
ago.

However interp does not compute the z values and gives me zeros in z matrix.
library(akima)

> interp(mat[,1], mat[,2], mat[, 3], nx=5, ny=5)
$x
[1]  2.0  5.5  9.0 12.5 16.0

$y
[1] 1.0 2.5 4.0 5.5 7.0

$z
 [,1] [,2] [,3] [,4] [,5]
[1,]00000
[2,]00000
[3,]00000
[4,]00000
[5,]00000

With the example from help page if less than 10 values are used, the result
is also zero
interp(akima$x[1:9], akima$y[1:9], akima$z[1:9], nx=5, ny=5)

but with 10 or more values the result is correctly calculated
interp(akima$x[1:10], akima$y[1:10], akima$z[1:10], nx=5, ny=5)
$x
[1]  0.  6.1625 12.3250 18.4875 24.6500

$y
[1]  1.24  5.93 10.62 15.31 20.00

$z
 [,1] [,2] [,3] [,4] [,5]
[1,]   NA   NA   NA   NA 34.6
[2,]   NA   NA 27.29139 27.11807 26.60971
[3,]   NA 19.81371 19.63614 19.12778 18.61943
[4,]   NA 14.01443 10.66531 11.13750 10.62914
[5,]   NA   NA   NA   NA   NA

Help page says
x, y, and z must be the same length (execpt if x is a
SpatialPointsDataFrame) and may contain no fewer than ***four*** points.

So my understanding was that 5 poins could be used but I am obviously wrong.
Is it a bug in interp or in the documentation or is it my poor understanding
of the whole matter.

Best regards
Petr

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R-es] Resumen de R-help-es, Vol 167, Envío 10

2023-01-26 Thread patricio fuenmayor
Hola esta es una solución

library(data.table)
library(stringr)


dt <- data.table( V1a = sample(c("1","0"), 10, TRUE)
, V1b = sample(c("1","0"), 10, TRUE)
, V2a = sample(c("1","0"), 10, TRUE)
, V2b = sample(c("1","0"), 10, TRUE)
, V3a = sample(c("1","0"), 10, TRUE)
, V3b = sample(c("1","0"), 10, TRUE)
, V4a = sample(c("1","0"), 10, TRUE)
, V4b = sample(c("1","0"), 10, TRUE))
dt[,":="(seq=.I)]
setcolorder(dt,"seq")

dt1 <- melt(dt,id.vars=1,measure.vars=2:ncol(dt),variable.name="vrb",
value.name="vl")
dt1[,":="(vrb_nm=str_sub(vrb,end=2),vrb_tp=str_sub(vrb,start=-1))]
dt2 <- dcast(dt1,seq+vrb_nm~vrb_tp,fun.aggregate=\(x)
paste0(x,collapse="|"),value.var="vl")
dt2[,":="(c=fifelse(a=="1"|b=="1","1","0"))]
dt3 <-dcast(dt2,seq~vrb_nm,fun.aggregate=\(x)
paste0(x,collapse="|"),value.var="c")
setnames(dt3,paste0(colnames(dt3),"c"))
dt <- dt[dt3,on=.(seq=seqc)]

Te crea un grupo de variables tipo c que es la lógica que necesitas .. pero
le puedes reemplazar por el nombre de "a", qué es lo que muestras en el
ejemplo


Saludos




El jue, 26 ene 2023 a la(s) 06:02, 
escribió:

> Envíe los mensajes para la lista R-help-es a
> r-help-es@r-project.org
>
> Para subscribirse o anular su subscripción a través de la WEB
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>
> O por correo electrónico, enviando un mensaje con el texto "help" en
> el asunto (subject) o en el cuerpo a:
> r-help-es-requ...@r-project.org
>
> Puede contactar con el responsable de la lista escribiendo a:
> r-help-es-ow...@r-project.org
>
> Si responde a algún contenido de este mensaje, por favor, edite la
> linea del asunto (subject) para que el texto sea mas especifico que:
> "Re: Contents of R-help-es digest...". Además, por favor, incluya en
> la respuesta sólo aquellas partes del mensaje a las que está
> respondiendo.
> Asuntos del día:
>
>1. Modificar una serie columnas de un dataframe (Griera)
>
>
> -- Forwarded message --
> From: Griera 
> To: r-help-es@r-project.org, gri...@yandex.com
> Cc:
> Bcc:
> Date: Thu, 26 Jan 2023 09:46:57 +0100
> Subject: [R-es] Modificar una serie columnas de un dataframe
> Hola:
>
> Lo vuelvo a enviar para ver si tengo más suerte:
>
> Tengo una tabla con pares de variables (V1a, V1b, V2a, V2b, ...) similar a
> esta:
>
> df <- data.frame( V1a = sample(c("1","0"), 10, TRUE)
> , V1b = sample(c("1","0"), 10, TRUE)
> , V2a = sample(c("1","0"), 10, TRUE)
> , V2b = sample(c("1","0"), 10, TRUE))
>
>V1a V1b V2a V2b
> 10   1   0   0
> 20   0   1   0
> 30   1   0   0
> ...
>
> y quiero que V1a valga "1" si V1a o V1b valen 1, V2a valga "1" si V2a o
> V2b valen 1 y así sucesivamente. Lo hago mediante un transform con una
> línia para cada pareja de variables:
>
> df <- transform (df
> , V1a = ifelse (V1a == "1" | V1b == "1", "1, "0")
> , V2a = ifelse (V2a == "1" | V2b == "1", "1, "0"))
>
>   )
> ¿Habria forma de hacerlo (¿con un función?) de manera que no tenga que
> escribir una línia para cada par de variables?
>
> Muchas gracias a todos y saludos.
>
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>

[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R] Minimal match to regexp?

2023-01-26 Thread Duncan Murdoch

I'll submit a bug report.

On 25/01/2023 8:38 p.m., Andrew Simmons wrote:

It seems like a bug to me. Using perl = TRUE, I see the desired result:

```
x <- "\n```html\nblah blah \n```\n\n```r\nblah blah\n```\n"

pattern2 <- "\n([`]{3,})html\n.*?\n\\1\n"

cat(regmatches(x, regexpr(pattern2, x, perl = TRUE)))
```

If you change it to something like:

```
x <- c(
 "\n```html\nblah blah \n```\n\n```r\nblah blah\n```\n",
 "\n```html\nblah blah \n```\n"
)

pattern2 <- "\n([`]{3,})html\n.*?\n\\1\n"

print(regmatches(x, regexpr(pattern2, x)), width = 10)
```

you can see that it does find the match, so the combination of *? and
\\1 must be messing up regexpr(). They seem to work perfectly fine on
their own.

On Wed, Jan 25, 2023 at 7:57 PM Duncan Murdoch  wrote:


Thanks for pointing out my mistake.  I oversimplified the real problem.

I'll try to post a version of it that comes closer:  Suppose I have a
string like this:

x <- "\n```html\nblah blah \n```\n\n```r\nblah blah\n```\n"

If I cat() it, I see that it is really markdown source:

```html
blah blah
```

```r
blah blah
```

I want to find the part that includes the html block, but not the r
block.  So I want to match "```html", followed by a minimal number of
characters, then "```".  Then this pattern works:

pattern <- "\n```html\n.*?\n```\n"

and we get the right answer:

cat(regmatches(x, regexpr(pattern, x)))

```html
blah blah
```

Okay, but this flavour of markdown says there can be more backticks, not
just 3.  So the block might look like

html
blah blah


I need to have the same number of backticks in the opening and closing
marker.  So I make the pattern more complicated, and it doesn't work:

pattern2 <- "\n([`]{3,})html\n.*?\n\\1\n"

This matches all of x:

> pattern2 <- "\n([`]{3,})html\n.*?\n\\1\n"
> cat(regmatches(x, regexpr(pattern2, x)))

```html
blah blah
```

```r
blah blah
```


Is that a bug, or am I making a silly mistake again?

Duncan Murdoch



On 25/01/2023 7:34 p.m., Andrew Simmons wrote:

grep(value = TRUE) just returns the strings which match the pattern. You
have to use regexpr() or gregexpr() if you want to know where the
matches are:

```
x <- "abaca"

# extract only the first match with regexpr()
m <- regexpr("a.*?a", x)
regmatches(x, m)

# or

# extract every match with gregexpr()
m <- gregexpr("a.*?a", x)
regmatches(x, m)
```

You could also use sub() to remove the rest of the string:
`sub("^.*(a.*?a).*$", "\\1", x)`
keeping only the match within the parenthesis.


On Wed, Jan 25, 2023, 19:19 Duncan Murdoch mailto:murdoch.dun...@gmail.com>> wrote:

 The docs for ?regexp say this:  "By default repetition is greedy, so
 the
 maximal possible number of repeats is used. This can be changed to
 ‘minimal’ by appending ? to the quantifier. (There are further
 quantifiers that allow approximate matching: see the TRE
 documentation.)"

 I want the minimal match, but I don't seem to be getting it.  For
 example,

 x <- "abaca"
 grep("a.*?a", x, value = TRUE)
 #> [1] "abaca"

 Shouldn't I have gotten "aba", which is the first match to "a.*a"?  If
 not, what would be the regexp that would give me the first match to
 "a.*a", without greedy expansion of the .*?

 Duncan Murdoch

 __
 R-help@r-project.org  mailing list --
 To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/r-help
 
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 
 and provide commented, minimal, self-contained, reproducible code.





__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R-es] Modificar una serie columnas de un dataframe

2023-01-26 Thread Griera
Hola:

Lo vuelvo a enviar para ver si tengo más suerte:

Tengo una tabla con pares de variables (V1a, V1b, V2a, V2b, ...) similar a esta:

df <- data.frame( V1a = sample(c("1","0"), 10, TRUE)
, V1b = sample(c("1","0"), 10, TRUE)
, V2a = sample(c("1","0"), 10, TRUE)
, V2b = sample(c("1","0"), 10, TRUE))

   V1a V1b V2a V2b
10   1   0   0
20   0   1   0
30   1   0   0
...

y quiero que V1a valga "1" si V1a o V1b valen 1, V2a valga "1" si V2a o
V2b valen 1 y así sucesivamente. Lo hago mediante un transform con una línia 
para cada pareja de variables:

df <- transform (df
, V1a = ifelse (V1a == "1" | V1b == "1", "1, "0")
, V2a = ifelse (V2a == "1" | V2b == "1", "1, "0"))

)
¿Habria forma de hacerlo (¿con un función?) de manera que no tenga que escribir 
una línia para cada par de variables?

Muchas gracias a todos y saludos.

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es