numbers

R ifelse avoiding change in date format [duplicate]

柔情痞子 提交于 2019-12-17 17:22:09
问题 This question already has answers here : How to prevent ifelse() from turning Date objects into numeric objects (6 answers) Closed 4 years ago . I am trying to make ifesle for two dates. I have two columns- DateIn and DateOut. I need to add 3rd variable, which would show "DateOut" if there is date value, or DateIn if there is : DateIn DateOut Travel date 2010-11-24 <NA> 2010-11-24 2011-12-21 2012-01-21 2012-01-21 2010-10-25 2010-11-25 2010-11-25 2014-01-14 <NA> 2014-01-14 I tried to do that

Formatting scientific number representation in xsl

佐手、 提交于 2019-12-17 16:39:43
问题 I have the following value in my XML -1.8959581529998104E-4. I want to format this to the exact number it should be using XSL to give me -0.000189595815299981. format-number(-1.8959581529998104E-4,'0.000000;-0.000000') gives me NaN. Any ideas? Cheers Andez 回答1: XSLT 1.0 does not have support for scientific notation. This: number('-1.8959581529998104E-4') Result: NaN This: number('-0.000189595815299981') Result: -0.000189595815299981 XSLT 2.0 has support for scientific notation This: number('

PHP subtract array values

安稳与你 提交于 2019-12-17 16:36:01
问题 I have an array with keys and values. Each value is an integer. I have an other array with the same keys. How can I subtract all of the values for the matching keys? Also there might be keys that do not occur in the second array but both arrays have the same length. If there is a key in array 2 that is not present in array 1 its value should be unchanged. If there is a key in the first array that is not in the second it should be thrown away. How do I do it? Is there any built-in function for

range and xrange for 13-digit numbers in Python?

微笑、不失礼 提交于 2019-12-17 16:35:39
问题 range() and xrange() work for 10-digit-numbers. But how about 13-digit-numbers? I didn't find anything in the forum. 回答1: You could try this. Same semantics as range: import operator def lrange(num1, num2 = None, step = 1): op = operator.__lt__ if num2 is None: num1, num2 = 0, num1 if num2 < num1: if step > 0: num1 = num2 op = operator.__gt__ elif step < 0: num1 = num2 while op(num1, num2): yield num1 num1 += step >>> list(lrange(138264128374162347812634134, 138264128374162347812634140))

Scientific Notation with PrecisionEvaluate in Coldfusion

南笙酒味 提交于 2019-12-17 16:33:18
问题 I have problems working with large numbers and long decimal numbers, as others have mentioned or solved such issue using PrecisionEvaluate, I could not get consistent result with such function. Example with this code : <cfset n = 0.000000000009> <cfoutput>#precisionEvaluate(n)#</cfoutput> // this will produce "9E-12" <cfoutput>#precisionEvaluate("n")#</cfoutput> // this will produce "0.000000000009" According to Adobe Documentation, using Quote is not recommended (due to processing

Is there an efficient algorithm for integer partitioning with restricted number of parts?

爷,独闯天下 提交于 2019-12-17 16:09:47
问题 I have to create a method that takes two integers, let them be n and m , and returns how many ways there are to sum m positive numbers to get n . For example, a method call like this partition(6, 2) should return 3 because there are 3 ways possible. They are 5 + 1 , 4 + 2 , and 3 + 3 . By the way, 4 + 2 is the same as 2 + 4 , so the method should not count them as two distinct variations. Does anybody know a solution to the problem? Updated: n and m are not greater than 150. 回答1: recursive

Generate N random numbers whose sum is a constant K - Excel

心不动则不痛 提交于 2019-12-17 16:07:52
问题 How can I generate those numbers in Excel. I have to generate 8 random numbers whose sum is always 320. I need around 100 sets or so. http://en.wikipedia.org/wiki/User:Skinnerd/Simplex_Point_Picking. Two methods are explained here. Or any other way so I can do it in Excel. 回答1: You could use the RAND() function to generate N numbers (8 in your case) in column A. Then, in column B you could use the following formula B1=A1/SUM(A:A)*320 , B2=A2/SUM(A:A)*320 and so on (where 320 is the sum that

Adding space between numbers?

夙愿已清 提交于 2019-12-17 15:46:44
问题 I'm trying to make a number input. I've made so my textbox only accepts numbers via this code: function isNumber(evt) { evt = (evt) ? evt : window.event; var charCode = (evt.which) ? evt.which : evt.keyCode; if (charCode > 31 && (charCode < 48 || charCode > 57)) { return false; } return true; } But now the question comes to, how would I create spaces as the user is typing in their number, much like the iPhone's telephone spacing thing, but with numbers so for example if they type in: 1000 it

JavaScript adding a string to a number

泄露秘密 提交于 2019-12-17 15:35:42
问题 I was reading the re-introduction to JavaScript on MDN and in the section Numbers it said that you can convert a string to a number simply by adding a plus operator in front of it. For example: +"42" which would yield the number output of 42. But further along in the section about Operators it says that by adding a string "something" to any number you can convert that number to a string. They also provide the following example which confused me: "3" + 4 + 5 would presumably yield a string of

Negative numbers to binary string in JavaScript

早过忘川 提交于 2019-12-17 15:23:15
问题 Anyone knows why javascript Number.toString function does not represents negative numbers correctly? //If you try (-3).toString(2); //shows "-11" // but if you fake a bit shift operation it works as expected (-3 >>> 0).toString(2); // print "11111111111111111111111111111101" I am really curious why it doesn't work properly or what is the reason it works this way? I've searched it but didn't find anything that helps. 回答1: Short answer: The toString() function takes the decimal, converts it to