numeric

How can I determine if a string is numeric in SQL?

心不动则不痛 提交于 2019-12-17 12:47:53
问题 In a SQL query on Oracle 10g, I need to determine whether a string is numeric or not. How can I do this? 回答1: You can use REGEXP_LIKE: SELECT 1 FROM DUAL WHERE REGEXP_LIKE('23.9', '^\d+(\.\d+)?$', '') 回答2: You ca try this: SELECT LENGTH(TRIM(TRANSLATE(string1, ' +-.0123456789', ' '))) FROM DUAL where string1 is what you're evaluating. It will return null if numeric. Look here for further clarification 回答3: I don't have access to a 10G instance for testing, but this works in 9i: CREATE OR

Trait for numeric functionality in Rust

試著忘記壹切 提交于 2019-12-17 07:52:14
问题 Is there any trait that specifies some numeric functionality? I'd like to use it for bounding a generic type, like this hypothetical HasSQRT : fn some_generic_function<T>(input: &T) where T: HasSQRT { // ... input.sqrt() // ... } 回答1: You can use num or num-traits crates and bound your generic function type with num::Float, num::Integer or whatever relevant trait: extern crate num; use num::Float; fn main() { let f1: f32 = 2.0; let f2: f64 = 3.0; let i1: i32 = 3; println!("{:?}", sqrt(f1));

How to convert time (mm:ss) to decimal form in R

谁说我不能喝 提交于 2019-12-17 07:42:13
问题 I've imported a csv-file to R using RStudio where I am trying to plot points per game against minutes per game. However the minutes per game is in the format mm:ss and I'm having a hard time finding how to convert it to decimal form. Please help! 回答1: Given that you start with a character vector, this is relatively easy : minPerGame <- c("4:30","2:20","34:10") sapply(strsplit(minPerGame,":"), function(x) { x <- as.numeric(x) x[1]+x[2]/60 } ) gives [1] 4.500000 2.333333 34.166667 Make sure you

Numeric sort on two columns but in different order using Python

浪子不回头ぞ 提交于 2019-12-14 04:27:15
问题 I have to sort a multi-column file based on two columns. Both the columns have floating point numbers and first sort should from lower to higher and second on higher to lower. Here is sample file: A B C D AK 0.01 200.8 NY DK 0.90 50.5 PHL AB 0.0002 750.04 Port GA 0.076 340.00 NY So, I have to sort on column B first in order low to high and then on column C in order high to low. The code I have is taking a lot of time and make my laptop unresponsive which I believe should not be the case.

Convert time values to numeric while keeping time characteristics

筅森魡賤 提交于 2019-12-14 03:57:41
问题 I have a data set which contains interval times of different events occurring. What I want to do, is convert the data into a numeric vector, so its easier to manipulate and run summaries/make graphs etc, while keeping its time characteristics. Here is a snippet of my data: data <- c( "03:31", "12:17", "16:29", "09:52", "04:01", "09:00", "06:29", "04:17", "04:42") class(data) [1] character The obvious answer is : as.numeric(data) But I get this error: Warning message: NAs introduced by

Overloading comparison for double to allow for numerical error

倖福魔咒の 提交于 2019-12-14 03:53:05
问题 In my C++ project I frequently encounter inexact results due to numerical errors. Is it somehow possible to somehow redefine the standard comparison operators ( == , <= , >= , < , > ) so that they do not compare exactly but within an acceptable error (e.g. 1e-12 ) ? (If yes, is it a good idea to do this?) (Of course one could write comparison functions but people intuitively use the operators.) 回答1: To overload operators some argument must be user-defined type. The built-in ones are fixed and

R shiny numericInput step and min value interaction

我的梦境 提交于 2019-12-14 01:26:40
问题 Consider the following numeric widget in an R Shiny app: numericInput("val", "Enter value:", value = 50, min = 0, step = 5) If you click on the up/down arrows in the widget when the app is run, the value will increase or decrease by 5 (0, 5, 10, 15,...) as expected. Now consider changing the min value to 1: numericInput("val", "Enter value:", value = 50, min = 1, step = 5) If you now click on the up/down arrows, the value will still increase/decrease by 5, but start from 1, creating the

Numeric calculations using dplyr piping commands

时光总嘲笑我的痴心妄想 提交于 2019-12-13 20:22:58
问题 Is it possible to use piping from the dplyr package to do numeric calculations? A simple example is: 0.15 %>% 3.8416 * (.*(1-.))/(0.03^2) #does not work seq(1,10,1) %>% log(.) %>% .^2 #works Tying to understand more of how piping works and when it can and cannot be used. I really enjoy using the piping feature and want to find a way to use it for these types of numeric calculations. Many thanks 回答1: You have an operator precedence problem. It's trying to start by doing 0.15 %>% 3.8416 which

equivalent of using #include <Numeric/arrayobject.h> in Numpy

血红的双手。 提交于 2019-12-13 18:50:54
问题 I have an old piece of code and it uses Numeric and I wanted to swap that with numpy. There is some C code too that uses the following: #include <Numeric/arrayobject.h> I want to do the same using Numpy, is there a way to do this? 回答1: So if anyone is interested -to continue to use arrayobject.h like in the old Numeric system do the following: Replace <Numeric/arrayobject.h> with <numpy/arrayobject.h> But the new arrayobject.h is in a different location to Numeric so update the setup.py as

Difference between numeric and string value in PHP

北战南征 提交于 2019-12-13 16:03:11
问题 I am getting a difference when comparing two string which are 0 and '0' in PHP. Can I do anything to make them be compared equally in an if action? Thanks! 回答1: If you compare using: if ('0' == 0) // if '0' is equal to 0 it should return true as the values are compared with the string being converted to a number. If you do: if ('0' === 0) // if '0' is identical to 0 it will return false as they have to be of the same type too. Note the triple '=' 回答2: You can also force their type to be the