Re: [R] 'apply' for 0 or 1 element member.

2023-08-10 Thread Jeff Newmiller
Define

mean0na <- function(x) {
  x[ 0 == x ] <- NA
  mean( x, na.rm = TRUE )
}

and then use that instead of mean.

On August 10, 2023 7:25:08 PM PDT, ani jaya  wrote:
>Hello,
>
>I try to calculate the mean of an array with a condition. My array is
>B=c(181,101,420) in dimensions. And I want to find a specific member
>in 3rd dimension (time monthly) based on a condition of another data
>frame, A =c(420). My final array would be C=c(181,101,12) which 12 is
>a monthly mean based on the condition of A.
>
>what I tried is below but doesn't work.
>
>#find the index with a condition larger than 0.5
>index<-which(A>=0.5)
>#convert the index to monthly
>index1<-index%%12
>#change 0 to 12 (Jan=1, Feb=2, and so on..)
>index1[index1==0]<-12
>
>for (i in 1:12){
>dummy<-index[which(index1==i)]
>C[,,i]<-apply(B[,,dummy],c(1,2), mean,na.rm=T)
>}
>
>The problem is when there is a month that doesnt meet the condition,
>it will return 0 element.
>
>apply(B[,,1],c(1,2), mean,na.rm=T) also produce an error.
>
>Any solution and turnaround would be appreciated.
>
>Thank you
>
>Ani Jaya
>
>__
>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.


[R] 'apply' for 0 or 1 element member.

2023-08-10 Thread ani jaya
Hello,

I try to calculate the mean of an array with a condition. My array is
B=c(181,101,420) in dimensions. And I want to find a specific member
in 3rd dimension (time monthly) based on a condition of another data
frame, A =c(420). My final array would be C=c(181,101,12) which 12 is
a monthly mean based on the condition of A.

what I tried is below but doesn't work.

#find the index with a condition larger than 0.5
index<-which(A>=0.5)
#convert the index to monthly
index1<-index%%12
#change 0 to 12 (Jan=1, Feb=2, and so on..)
index1[index1==0]<-12

for (i in 1:12){
dummy<-index[which(index1==i)]
C[,,i]<-apply(B[,,dummy],c(1,2), mean,na.rm=T)
}

The problem is when there is a month that doesnt meet the condition,
it will return 0 element.

apply(B[,,1],c(1,2), mean,na.rm=T) also produce an error.

Any solution and turnaround would be appreciated.

Thank you

Ani Jaya

__
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] Expresión en un objeto

2023-08-10 Thread Griera
Hola a todos:

Se me ha planteado un problema que no está ligado a ningún problema
concreto. Es más teórico. 

Supongamos que tenemos tres variables:

V1  <- c (47, 71,  41,  23,  83, 152,  82,   8, 160,  18)
V2a <- c (NA, 36,  15,   5,  56,  18,  NA,   5,  NA,   5)
V2b <- c (37, NA,  15,  NA,  NA,  NA,  90,  NA,  161, NA)

Supongamos que tengo la expresión (que no puedo asignarlo a ninguna variable):

(ifelse (is.na (V2a) & ! is.na (V2b), V2b,  V2a))

Supongamos que tengo que utilizar esta expresión dos o más veces y no
puedo utilizar ni un xapply () ni un bucle. Por ejemplo:

V3 <- (((ifelse (is.na (V2a) & ! is.na (V2b), V2b,  V2a)) - V1)/V1)*100
V4 <-   ifelse (! is.na ifelse (is.na (V2a) & ! is.na (V2b),
V2b,  V2a))-V1)/V1)*100), ifelse ifelse (is.na (V2a) & ! is.na
(V2b), V2b,  V2a))-V1)/V1)*100 > 0, "1", "0"), NA)

Hay alguna forma de almacenar la expresión "(ifelse (is.na (V2a) & !
is.na (V2b), V2b,  V2a))" en un objeto y utilizar el nombre del objeto
en las ordenes (por ejemplo, con una hipotética función xfunc ()). Por
ejemplo:

ORD <- "(ifelse (is.na (V2a) & ! is.na (V2b), V2b,  V2a))"
V3 <- ((xfunc (ORD) - V1)/V1)*100
V4 <-   ifelse (! is.na (((xfunc (ORD)-V1)/V1)*100), ifelse
(((xfunc (ORD)-V1)/V1)*100 > 0, "1", "0"), NA)


El ejemnplo és absurdo, pero solo lo presento como un hipotético ejercicio.

Muchas gracias por la ayuda.

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


Re: [R] Technical Help Request for "Version Differences" (i.e., CYTOFKIT package)

2023-08-10 Thread Robert Baer
GIven that Cytofkit is removed from Bioconductor, and you seem new to 
everything, I would suggest like others already have that you install 
the most recent version of R for Windows 
https://cran.r-project.org/bin/windows/base/ and seek a more up-to-date 
package.


For flow cytometry, I would like to recommend the CytoExploreR package 
(https://dillonhammill.github.io/CytoExploreR/ which is built on top of 
the core flow cytometry packages produced by RGLab 
(https://cytoverse.org/) and available on Bioconductor 
https://bioconductor.org/packages/release/bioc/html/openCyto.html


God luck,

Rob

On 8/4/2023 2:10 AM, MURAT DELMAN via R-help wrote:



Dear Ms./Mr.,







If the email text and codes below are not properly displayed, you can download 
the attached Word file, which has exactly the same content.



I am a cytometrist and microscopist at Izmir Institute of Technology, 
Integrated Research Center. I operate a cytometer and fluorescence microscope 
to acquire data from our researchers’ samples and then give them analyzed data. 
I need to dive into bulk data to present all of the information in the sample. 
To do this, I have recently been trying to develop my skills in R, RStudio, and 
Cytofkit package for cytometry (flow, spectral, mass, imaging mass cytometry) 
data analysis. I am new in this area and must learn R for data analysis.





May I request help from you or one of your assistants who is competent in R, 
RStudio, and R packages with the installation issues caused by “ version 
differences ” between R itself, R packages, and their dependencies? I really 
had to send this email to you anymore, because I could not run the package 
“Cytofkit” and find a solution on the internet.


It has been nearly 2 weeks since I have been trying to solve the errors and 
warnings. I am in a vicious circle and cannot move forward anymore. This is why 
I needed help from an expert competent in R programming.



I tried to use the renv package, but I could not move forward because I am not 
competent in R.




I explained the errors that I faced during the installation below.



I have two computers, both operating Windows 10, 64-bit.



I installed R 3.5. 2 on the desktop (Windows in English) and R 3.5. 0 on the 
laptop (Windows in Turkish).



I know that you are very busy with your work, but may you (or your assistant) 
help me by informing me how to install consistent versions of R, RStudio, and 
packages/dependencies (for example, Cytofkit, ggplot2, Rtools, devtools, plyr, 
shiny, GUI)?





I guess I will need exact web page links " in an orderly manner" to download 
the correct versions of everything.



I would appreciate it if you could advise me or forward this email to one of 
your assistants or experts.






I really appreciate any help you can provide.






Kind Regards






Please find the technical details below;





I used the installation order listed below;



I downloaded R 3.5.0 and R 3.5.2 using the link and directory below.



Link: [ https://www.freestatistics.org/cran/ | 
https://www.freestatistics.org/cran/ ]



Directory: Download R for Windows > install R for the first time > Previous 
releases > R 3.5.2 (December, 2018) or R 3.5.0





I downloaded RStudio from the link below;



[ https://posit.co/download/rstudio-desktop/ | 
https://posit.co/download/rstudio-desktop/ ]






I downloaded packages via either [ 
https://cran.rstudio.com/bin/windows/contrib/r-devel/ | 
https://cran.rstudio.com/bin/windows/contrib/r-devel/ ] or the “install 
function” tab in RStudio.



Rtools : [ https://cran.r-project.org/bin/windows/Rtools/ | 
https://cran.r-project.org/bin/windows/Rtools/ ]



Devtools : [ https://cran.r-project.org/web/packages/devtools/index.html | 
https://cran.r-project.org/web/packages/devtools/index.html ]



ggplot2 : [ https://cran.r-project.org/web/packages/ggplot2/index.html | 
https://cran.r-project.org/web/packages/ggplot2/index.html ]



[ https://ggplot2.tidyverse.org/ | https://ggplot2.tidyverse.org/ ]



[ https://cran.r-project.org/web/packages/ggplot2/ggplot2.pdf | 
https://cran.r-project.org/web/packages/ggplot2/ggplot2.pdf ]





plyr : [ https://cran.r-project.org/web/packages/plyr/index.html | 
https://cran.r-project.org/web/packages/plyr/index.html ]



shiny : [ https://cran.r-project.org/web/packages/shiny/index.html | 
https://cran.r-project.org/web/packages/shiny/index.html ]



[ https://shiny.posit.co/r/getstarted/shiny-basics/lesson1/index.html | 
https://shiny.posit.co/r/getstarted/shiny-basics/lesson1/index.html ]



[ https://github.com/rstudio/shiny | https://github.com/rstudio/shiny ]



cytofkit : [ https://github.com/JinmiaoChenLab/cytofkit | 
https://github.com/JinmiaoChenLab/cytofkit ]



[ https://bioconductor.riken.jp/packages/3.3/bioc/html/cytofkit.html | 
https://bioconductor.riken.jp/packages/3.3/bioc/html/cytofkit.html ]



[ 
https://journals.plos.org/ploscompbiol/article/file?id=10.1371/journal.pcbi.1005112=printable
 |