Date: prev next · Thread: first prev next last
2016 Archives by date, by thread · List index


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: users+unsubscribe@global.libreoffice.org
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

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.