Dear members, I have the following code:> FUN(OHLCDataEP[[63]])Error in (class(x) == "xts") || (class(x) == "zoo") : 'length = 2' in coercion to 'logical(1)'> traceback()2: ygix(x, "c") at <tmp>#9 1: FUN(OHLCDataEP[[63]])> class(OHLCDataEP[[63]])[1] "xts" "zoo" The following is in ygix() : if((class(x) == "xts") || (class(x) == "zoo") I think this would have been a warning (https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1) but I am on a ubuntu22.04 machine with R 4.3.0. What should I do? Change it to: if((class(x)[1] == "xts") || (class(x)[2] == "zoo")) {code}... or is there any workaround? THanking you, Yours sincerely, AKSHAY M KULKARNI [https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon at 2.png?v=73d79a89bded]<https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1> R Warning 'length(x) = 2 > 1' in coercion to 'logical(1)'<https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1> Using R 4.1.3 I observe: var <- 0 > if(is.data.frame(var) || is.vector(var)) var <- as.matrix(var) > is.null(var) || (!is.matrix(var) && var == 0) || (dim(var)==c(1,1) &&... stackoverflow.com ? [[alternative HTML version deleted]]
Dear members, AN update: I have changed the if clause to: if(class(x)[1] == "xts") || class(x)[2] == "zoo") {code} but am bootless..... PLease help... THanking you, Yours sincerely, AKSHAY M KULKARNI ________________________________ From: R-help <r-help-bounces at r-project.org> on behalf of akshay kulkarni <akshay_e4 at hotmail.com> Sent: Saturday, June 17, 2023 10:46 PM To: R help Mailing list <r-help at r-project.org> Subject: [R] warnng to an error.... Dear members, I have the following code:> FUN(OHLCDataEP[[63]])Error in (class(x) == "xts") || (class(x) == "zoo") : 'length = 2' in coercion to 'logical(1)'> traceback()2: ygix(x, "c") at <tmp>#9 1: FUN(OHLCDataEP[[63]])> class(OHLCDataEP[[63]])[1] "xts" "zoo" The following is in ygix() : if((class(x) == "xts") || (class(x) == "zoo") I think this would have been a warning (https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1) but I am on a ubuntu22.04 machine with R 4.3.0. What should I do? Change it to: if((class(x)[1] == "xts") || (class(x)[2] == "zoo")) {code}... or is there any workaround? THanking you, Yours sincerely, AKSHAY M KULKARNI [https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon at 2.png?v=73d79a89bded]<https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1> R Warning 'length(x) = 2 > 1' in coercion to 'logical(1)'<https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1> Using R 4.1.3 I observe: var <- 0 > if(is.data.frame(var) || is.vector(var)) var <- as.matrix(var) > is.null(var) || (!is.matrix(var) && var == 0) || (dim(var)==c(1,1) &&... stackoverflow.com ? [[alternative HTML version deleted]] ______________________________________________ R-help at 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]]
On 17/06/2023 1:16 p.m., akshay kulkarni wrote:> Dear members, > > I have the following code: > >> FUN(OHLCDataEP[[63]]) > Error in (class(x) == "xts") || (class(x) == "zoo") : > 'length = 2' in coercion to 'logical(1)' >> traceback() > 2: ygix(x, "c") at <tmp>#9 > 1: FUN(OHLCDataEP[[63]]) >> class(OHLCDataEP[[63]]) > [1] "xts" "zoo" > > The following is in ygix() : > > if((class(x) == "xts") || (class(x) == "zoo") > > I think this would have been a warning (https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1) but I am on a ubuntu22.04 machine with R 4.3.0. > > What should I do? Change it to: > if((class(x)[1] == "xts") || (class(x)[2] == "zoo")) {code}...Changing it to `if (inherits(x, c("xts", "zoo")))` should do the same. The vector of classes in the second argument is read as "any of these classes". Duncan Murdoch