multiple use of ifelse function

classic Classic list List threaded Threaded
4 messages Options
message message
Reply | Threaded
Open this post in threaded view
|

multiple use of ifelse function

Readers,

Could someone please explain how to apply the function 'ifelse' to
change a vector, for various conditions?

testseq<-seq(1:20)
testchange<-ifelse(testseq<=4,'x',testseq)
testchange<-c(ifelse(testseq<=4,'x',testseq),ifelse(testseq>=5,'y',testseq))

The last instruction causes the vector 'testchange' to change
dimensions, when the result wanted is:

testchange
x x x x y y y y y y y y y y y y y y y y



--
To unsubscribe e-mail to: [hidden email]
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted

TomD TomD
Reply | Threaded
Open this post in threaded view
|

Re: multiple use of ifelse function

Hi :)
Aaaarrrgh.  Nope, no idea!

Is there a helpful chapter in the Published Guides?
https://wiki.documentfoundation.org/Documentation/Publications

or the Faq?
https://wiki.documentfoundation.org/Faq

Sorry!
Good luck and regards from
Tom :)




On 11 October 2016 at 07:56, message <[hidden email]> wrote:

> Readers,
>
> Could someone please explain how to apply the function 'ifelse' to change
> a vector, for various conditions?
>
> testseq<-seq(1:20)
> testchange<-ifelse(testseq<=4,'x',testseq)
> testchange<-c(ifelse(testseq<=4,'x',testseq),ifelse(testseq>
> =5,'y',testseq))
>
> The last instruction causes the vector 'testchange' to change dimensions,
> when the result wanted is:
>
> testchange
> x x x x y y y y y y y y y y y y y y y y
>
>
>
> --
> To unsubscribe e-mail to: [hidden email]
> Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-uns
> ubscribe/
> Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
> List archive: http://listarchives.libreoffice.org/global/users/
> All messages sent to this list will be publicly archived and cannot be
> deleted
>
>

--
To unsubscribe e-mail to: [hidden email]
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted
libreoffice-ml.mbourne libreoffice-ml.mbourne
Reply | Threaded
Open this post in threaded view
|

Re: multiple use of ifelse function

In reply to this post by message
message wrote:

> Readers,
>
> Could someone please explain how to apply the function 'ifelse' to
> change a vector, for various conditions?
>
> testseq<-seq(1:20)
> testchange<-ifelse(testseq<=4,'x',testseq)
> testchange<-c(ifelse(testseq<=4,'x',testseq),ifelse(testseq>=5,'y',testseq))
>
>
> The last instruction causes the vector 'testchange' to change
> dimensions, when the result wanted is:
>
> testchange
> x x x x y y y y y y y y y y y y y y y y

I'm not familiar with whatever language that is (presumably one of the
macro languages supported by LibreOffice?), but I would have thought
your second condition would need to be in what appears to be the "else"
block of the first condition, i.e.:
   testchange<-c(ifelse(testseq<=4,'x',ifelse(testseq>=5,'y',testseq)))
or maybe, if the 'c' indicates a condition:
  testchange<-c(ifelse(testseq<=4,'x',c(ifelse(testseq>=5,'y',testseq))))
or if 'c' indicates concatenation, you may not want it at all:
  testchange<-ifelse(testseq<=4,'x',ifelse(testseq>=5,'y',testseq))

Just guessing though, as I don't recognise the syntax of those lines...

--
Mark.


--
To unsubscribe e-mail to: [hidden email]
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted
som som
Reply | Threaded
Open this post in threaded view
|

Re: multiple use of ifelse function


On Saturday 15 October 2016 01:39 AM, [hidden email] wrote:
> message wrote:
> > Readers,
> >
> > Could someone please explain how to apply the function 'ifelse' to
> > change a vector, for various conditions?
> >
> > testseq<-seq(1:20)
> > testchange<-ifelse(testseq<=4,'x',testseq)
> > testchange<-c(ifelse(testseq<=4,'x',testseq),ifelse(testseq>=5,'y',testseq))

it is an example of R script.
> I'm not familiar with whatever language that is (presumably one of the
> macro languages supported by LibreOffice?),
i am not sure if R scripts are supported for macros in libreoffice. one extension was available for OO but it has been discontinued for a long time.
> but I would have thought
> your second condition would need to be in what appears to be the "else"
> block of the first condition, i.e.:
>   testchange<-c(ifelse(testseq<=4,'x',ifelse(testseq>=5,'y',testseq)))
> or maybe, if the 'c' indicates a condition:
>  testchange<-c(ifelse(testseq<=4,'x',c(ifelse(testseq>=5,'y',testseq))))
just posting the solution here for closing the thread:

testchange<-ifelse(testseq<=4,'x',"y")
Or
testchange <- cut(testseq, breaks=c(0,4,21), labels=c("x","y"))
(credit goes to Pikal for sharing the answer in R mailing list)

regards,

som

--
To unsubscribe e-mail to: [hidden email]
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted