> On 9. Aug 2024, at 10:45, CALUM POLWART wrote:
>
> Or use <<- assignment I think. (I usually return, but return can only
> return one object and I think you want two or more
>
One can return multiple objects by putting them in a list and returning the
list.
Martin
__
Oh I thought that was just my experience of it !! So didn't want to slate
it too much!!
Yes, I nearly said "without making it an object of objects". I guess it
depends what they want to do with those objects in the end.
Usually if I want a function to manipulate two things I create two
functions.
On 2024-08-09 6:21 a.m., Bert Gunter wrote:
"Or use <<- assignment I think. (I usually return, but return can only
return one object and I think you want two or more"
You can return any number of objects by putting them in a list and
returning the list.
Use of "<<-" is rarely a good idea in R.
Thanks. Hmm, I like the idea of returning a list. I occasionally use
“invisible” and am still trying to figure out its difference with return.
Where do I read about <<- assignment?
On 8/9/2024 6:21 PM, Bert Gunter wrote:
> "Or use <<- assignment I think. (I usually return, but return can only
>
"Or use <<- assignment I think. (I usually return, but return can only
return one object and I think you want two or more"
You can return any number of objects by putting them in a list and
returning the list.
Use of "<<-" is rarely a good idea in R.
-- Bert
On Fri, Aug 9, 2024 at 1:53 AM CALUM
OK. The fact it's in a function is making things clearer.
Are you trying to update the values of an object from within the function,
and have them available outside the function. I don't speak functional
programming articulately enough but basically
v <- 1
funA <- function() {
v <- v+1
}
funA()
Thanks. Hmm. The loop is doing what it is supposed to do.
> try1<-function(joint12=FALSE,marg1=FALSE,marg2=FALSE,
+ cond12=FALSE,cond21=FALSE){
+ # ***
+ # Testing if loop
+ # ***
+ if(j
Is something wrong in the initialisation part that we don't see?
joint12 <- marg1 <-F
marg1 <-T
if (joint12) {
print ("joint 12")
cat (joint12)
}
if (marg1) {
print("marg 1")
cat(marg1)
}
Would probably be my diagnostic approach
On Fri, 9 Aug 2024, 04:45 Steven Yen, wrote:
> Can som
Às 05:33 de 09/08/2024, Steven Yen escreveu:
The following (using if else) did not help. Seemed like joint12 always
kicked in.
me1<-me0<-NULL.
if(joint12){
{me1<-cbind(me1,v1$p12); me0<-cbind(me0,v0$p12)}
} else if(marg1) {
{me1<-cbind(me1,v1$p1); me0<-cbind(me0,
1. I think to get useful help you will have to provide a small
reproducible example. In any case, I was not able to figure out your
problem from what you provided (perhaps others may).
2. R is a (mostly) functional language. It does not have "subroutines" .
Cheers,
Bert
On Thu, Aug 8, 2024 at 8:
The following (using if else) did not help. Seemed like joint12 always
kicked in.
me1<-me0<-NULL.
if(joint12){
{me1<-cbind(me1,v1$p12); me0<-cbind(me0,v0$p12)}
} else if(marg1) {
{me1<-cbind(me1,v1$p1); me0<-cbind(me0,v0$p1)}
} else if(marg2) {
{me1<-cbind(me
Can someone help me with the if loop below? In the subroutine, I
initialize all of (joint12,marg1,marg2,cond12,cond21) as FALSE, and call
with only one of them being TRUE:
,...,joint12=FALSE,marg1=FALSE,marg2=FALSE,cond12=FALSE,cond21=FALSE
joint12 seems to always kick in, even though I ca
Hi Phillip,
I wanted to follow up with you regarding your earlier post. Below is a
different way to work up your data than I posted earlier.
I took the baseball data you posted, stripped out
leading-and-following blank lines, removed all trailing spaces on each
line, and removed the "R1", "R2" an
W. Michels, Ph.D.
On Wed, Oct 23, 2019 at 12:40 AM PIKAL Petr wrote:
>
> Hi
>
> ***do not think in if or if loops in R***.
>
> to elaborate Jim's solution further
>
> With simple function based on logical expression
> fff <- function(x) (x!="")+0
>
Behalf Of Jim Lemon
> Sent: Wednesday, October 23, 2019 12:26 AM
> To: Phillip Heinrich
> Cc: r-help
> Subject: Re: [R] If Loop I Think
>
> Hi Philip,
> Try this:
>
> phdf<-read.table(
> text="Row Outs RunnerFirst RunnerSecond RunnerThird R1 R2 R3
> 1 0
x27;ll know more once I'm done.
>
> Can you suggest any other sources?
>
> Thanks.
>
> -Original Message-
> From: Jim Lemon
> Sent: Tuesday, October 22, 2019 3:26 PM
> To: Phillip Heinrich
> Cc: r-help
> Subject: Re: [R] If Loop I Think
>
> Hi Philip,
>
On 10/22/19 1:54 PM, Phillip Heinrich wrote:
Row Outs RunnerFirst RunnerSecond RunnerThird R1 R2 R3
1 0
2 1
3 1
4 1 arenn001
5 2 arenn001
6 0
7 0 perad001
8 0 polla001 perad001
9 0 goldp001 polla001 perad001
10 0 lamb
Hi Philip,
Try this:
phdf<-read.table(
text="Row Outs RunnerFirst RunnerSecond RunnerThird R1 R2 R3
1 0
2 1
3 1
4 1 arenn001
5 2 arenn001
6 0
7 0 perad001
8 0 polla001 perad001
9 0 goldp001 polla001 perad001
10 0 lambj001 goldp001
11 1 lambj001 goldp001
12 2 lambj001
13 0
14 1 ",
header=
Row Outs RunnerFirst RunnerSecond RunnerThird R1 R2 R3
1 0
2 1
3 1
4 1 arenn001
5 2 arenn001
6 0
7 0 perad001
8 0 polla001 perad001
9 0 goldp001 polla001 perad001
10 0 lambj001
Hello,
The following might be a better solution.
I include a minimal data set as an example.
Date <- c(rep(as.Date("2018-03-29"), 4),
rep(as.Date("2018-03-30"), 4),
rep(as.Date("2018-04-01"), 4))
ari18.test3 <- data.frame(Date)
ari18.test3$GameNum <- 1
#---
d <- c(0, diff
Hello,
There was no attachment, R-Help allows only a limited number of file
types, see the posting guide and try reposting.
As for the question, try ifelse, the vectorized fom of if/else.
ifelse(ari18.test3$Date > lag(ari18.test3$Date), ari18.tesm3$GameNum +
1, ari18.test3$gameNum)
(Not t
Attached is every at bat for the Arizona Diamondback’s first three games of
2018 – BBdata1.rda. I added the Date and DHCode variables by parsing the first
variable labeled GameID.
BBdata2 is a reduced dataset with five variables as shown in the str() command.
data.frame':234 obs. of 5 var
22 matches
Mail list logo