numeric

PostgreSQL: IN A SINGLE SQL SYNTAX order by numeric value computed from a text column

女生的网名这么多〃 提交于 2019-12-20 02:59:28
问题 A column has a string values like "1/200", "3.5" or "6". How can I convert this String to numeric value in single SQL query? My actual SQL is more complicated, here is a simple example: SELECT number_value_in_string FROM table number_value_in_string's format will be one of: ## #.## #/### I need to sort by the numeric value of this column. But of course postgres doesn't agree with me that 1/200 is a proper number. 回答1: Seeing your name I cannot but post a simplification of your answer: SELECT

Numpy Array Slicing

非 Y 不嫁゛ 提交于 2019-12-20 01:34:18
问题 I have a 1D numpy array, and some offset/length values. I would like to extract from this array all entries which fall within offset, offset+length, which are then used to build up a new 'reduced' array from the original one, that only consists of those values picked by the offset/length pairs. For a single offset/length pair this is trivial with standard array slicing [offset:offset+length] . But how can I do this efficiently (i.e. without any loops) for many offset/length values? Thanks,

Data frame changes from numeric to character

人盡茶涼 提交于 2019-12-19 10:28:45
问题 I open my csv file and I control the class of each of my data: mydataP<-read.csv("Energy_protein2.csv", stringsAsFactors=F) apply(mydataP, 2, function(i) class(i)) #[1] "numeric" I add a column and check the class of the data: mydataP[ ,"ID"] <-rep(c("KOH1", "KOH2", "KOH3", "KON1", "KON2", "KON3", "WTH1", "WTH2", "WTH3","WTN1", "WTN2", "WTN3"), each=2) apply(mydataP, 2, function(i) class(i)) Here it changes to a "character" as.numeric(as.factor(mydataP)) #Error in sort.list(y) : 'x' must be

Data frame changes from numeric to character

为君一笑 提交于 2019-12-19 10:27:38
问题 I open my csv file and I control the class of each of my data: mydataP<-read.csv("Energy_protein2.csv", stringsAsFactors=F) apply(mydataP, 2, function(i) class(i)) #[1] "numeric" I add a column and check the class of the data: mydataP[ ,"ID"] <-rep(c("KOH1", "KOH2", "KOH3", "KON1", "KON2", "KON3", "WTH1", "WTH2", "WTH3","WTN1", "WTN2", "WTN3"), each=2) apply(mydataP, 2, function(i) class(i)) Here it changes to a "character" as.numeric(as.factor(mydataP)) #Error in sort.list(y) : 'x' must be

R floating point number precision being lost on coversion from character

天涯浪子 提交于 2019-12-19 08:54:13
问题 I have a large floating point number as a character like so x<-"5374761693.91823"; On doing as.numeric(x); I get the following output 5374761694 I would like to preserve the floating point nature of the number while casting. 回答1: use digits argument in print to see the actual number: > print(as.numeric(x), digits=15) [1] 5374761693.91823 options is another alternative: > options(digits=16) > as.numeric(x) [1] 5374761693.91823 > # assignments > options(digits=16) > y <- as.numeric(x) > y [1]

Performing math operations on very large numbers in Perl

我与影子孤独终老i 提交于 2019-12-19 04:04:22
问题 I have a case where some values in a data file have 64 bit wrap around which makes them very large, like, 18446744073709551608 . So I have to perform a subtraction from 2^64. I tried this using the simple 2^64 - 18446744073709551608 But I guess this number is too large and don't get the actual answer 8. What do I need to do to perform this substraction. 回答1: Check out the bignum pragma: use bignum; print 2**64 - 18446744073709551608; This should properly print 8 . 回答2: Note that bignum is

Scala: generic function multiplying Numerics of different types

假如想象 提交于 2019-12-19 02:31:49
问题 I am trying to write a generic weighted average function. I want to relax the requirements on the values and the weights being of the same type. ie, I want to support sequences of say: (value:Float,weight:Int) and (value:Int,weight:Float) arguments and not just: (value:Int,weight:Int) To do so, I first need to implement a function that takes two generic numerical values and returns their product. def times[A: Numeric, B: Numeric](x: B, y: A): (A, B) : ??? = {...} Writing the signature and

Scala: generic function multiplying Numerics of different types

时间秒杀一切 提交于 2019-12-19 02:31:34
问题 I am trying to write a generic weighted average function. I want to relax the requirements on the values and the weights being of the same type. ie, I want to support sequences of say: (value:Float,weight:Int) and (value:Int,weight:Float) arguments and not just: (value:Int,weight:Int) To do so, I first need to implement a function that takes two generic numerical values and returns their product. def times[A: Numeric, B: Numeric](x: B, y: A): (A, B) : ??? = {...} Writing the signature and

why (0+0i)^{0} == (nan, nan) in c++

五迷三道 提交于 2019-12-18 21:13:06
问题 take a look at the code blew: #include <complex> #include <iostream> int main() { std::cout << std::pow( std::complex<double>(0,0), std::complex<double>(0,0) ) << "\n"; std::cout << std::pow( std::complex<double>(0,0), double(0) ) << "\n"; return 0; } g++(4.8.1) gives an output of (nan,nan) (-nan,-nan) while clang++(3.3) gives an out put of (-nan,-nan) (-nan,-nan) But I am expecting (1.0, 0.0). Can anyone give an explanation? 回答1: According to std::pow documentation Return value base raised

How to remove NA values in vector in R [duplicate]

跟風遠走 提交于 2019-12-18 19:00:29
问题 This question already has answers here : Remove NA values from a vector (6 answers) Closed 5 years ago . I have a vector which stores over 1000 values. The first 50 values are NAs, how can I get rid of it? c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1.5741, 1.583, 1.605, 1.633, 1.6465, 1.6475, 1.6329, 1.6413, 1.685, 1.692, 1.7087, 1.7055