Questions tagged [coercion]

Coercion, type conversion and typecasting are different ways of, implicitly or explicitly, changing an entity of one data type into another.

Coercion, type conversion and typecasting are different ways of, implicitly or explicitly, changing an entity of one data type into another.

398 questions
0
votes
1 answer

Is np.random.choice supposed to coerce?

I just noticed that if np.random.choice is used on a list that contains both strings and integers, then when integers are returned, they are coerced to strings. Is this intended behavior?…
Acccumulation
  • 3,491
  • 1
  • 8
  • 12
0
votes
0 answers

Data.Matrix error - NAs introduced by coercion

I am required to build returns given Bob Shiller's updated data, which I have downloaded and imported in R to start working with it. Since my professor speaks at the speed of light and then keeps answering "wake up" when I try to ask him something…
Didokon
  • 1
  • 1
  • 1
0
votes
0 answers

Comparing a Date object to null, what happens?

I came across the fact, that when you compare dates in JavaScript, the following happens: $ new Date() > null > true $ new Date() > undefined > false I was wondering, what exactly happens under the hood, that leads to this behavior.
Finn Poppinga
  • 269
  • 4
  • 11
0
votes
2 answers

Unlisting nested lists and without loosing object classes

After a previous post regarding coercion of variables into their appropriate format, I realized that the problem is due to unlist():ing, which appears to kill off the object class of variables. Consider a nested list (myList) of the following…
Comfort Eagle
  • 2,112
  • 2
  • 22
  • 44
0
votes
2 answers

Coerce variables in data frame to appropriate format

I'm working a data frame which consists of multiple different data types (numerics, characters, timestamps), but unfortunately all of them are received as characters. Hence I need to coerce them into their "appropriate" format dynamically and as…
Comfort Eagle
  • 2,112
  • 2
  • 22
  • 44
0
votes
0 answers

Boolean coercion in Javascript 'if' guards

I noticed this behavior in Javascript today which has me thoroughly surprised and confused: if ("0") { console.log('first') } if ("0" == true) { console.log('second'); } output: first I would have expected either both or neither of the…
Mala
  • 14,178
  • 25
  • 88
  • 119
0
votes
2 answers

Flash Error #1034: Type Coercion failed when running with Flash Develop

I have compiled an SWC and am using it in a flashdevelop project. When I compile the project all is fine, but when I run/debug the project I get: [Fault] exception, information=TypeError: Error #1034: Type Coercion failed: cannot convert…
David
  • 8,340
  • 7
  • 49
  • 71
0
votes
0 answers

How to avoid implicit int coercion to string in JavaScript without sprintf?

Today I've had to take a break from debugging my code to debug my debug messages. Consider: let x = 1; console.log('x is ' + x + ' and x-1 is ' + x-1); // ^^^ // 'NaN' I get why this happens: by the time we…
Marek Jedliński
  • 7,088
  • 11
  • 47
  • 57
0
votes
0 answers

Coercion To Scalar In data.table Function Argument Accepting Scalar or Vector

I expect the code: datab <- data.table(Events = c(79,68,54), Duration = c(61,44,72)) datab[, .(Poisson.High=poisson.test(Events, T = Duration)$conf.int[2])] to produce: nrow Poisson.High 1: 1 1.6140585 2: 2 1.9592319 3: 3 …
user3673
  • 665
  • 5
  • 21
0
votes
1 answer

How to solve a linear interpolation data by time step in R : (list) object can not be coerced to type 'double'

I have data of instantaneous water discharge under a file data.txt (data below) (list) object can not be coerced to type 'double'   I think the problem is due to the format of the dates, please how to solve this problem? write.table(TAB4,…
tazrart
  • 167
  • 1
  • 15
0
votes
1 answer

Adding data labels to boxplot in R

Here's my code: iFacVector <- as.factor(c(1,1,1,1,10,1,1,1,12,9,9,1,10,12,1,9,5)) iTargetVector <- c(2,1,0,1,6,9,15,1,8,0,1,2,1,1,9,12,1) bp <-…
Pablo Boswell
  • 805
  • 3
  • 13
  • 30
0
votes
0 answers

Coerce superclass to subclass

I have a class, D, that contains a virtual class, A. I would like to coerce the pieces of D that comprise A into one of two subclasses for A. Is this possible with R's reference classes? The desired output is to have a new object of class D that…
Zelazny7
  • 39,946
  • 18
  • 70
  • 84
0
votes
1 answer

Javascript - Why isNaN(1 + null) returns false?

Well,I am going through Mozilla Javascript Reference and found that.. isNaN(1 + null) //false isNaN(1 + undefined) //true I am not able to understand reason behind this.
mukesh kudi
  • 719
  • 6
  • 20
0
votes
1 answer

Groovy coercion to interface not known at compile-time

Some time ago I asked how to make a class implement an interface that it doesn't implement by declaration. One possibility is as-coercion: interface MyInterface { def foo() } class MyClass { def foo() { "foo" } } def bar() { return new…
Erik Hofer
  • 2,296
  • 2
  • 18
  • 39
0
votes
1 answer

Why JavaScript behaves like that?

Let's look at those examples: var a = 1; var b = { toString:function() {return '1'} }; var c = 1; a + b + c === "111" // true It is pretty mind blowing. I know that JS interpreter performs ToPrimitive or ToString operations when we use +…
Hyphen Wrex
  • 645
  • 5
  • 9