numeric

Select rows of a data.frame that contain only numbers in a certain column

若如初见. 提交于 2019-12-01 05:57:47
问题 How to select only the rows that contain a number in column b . a <- c(1,5,3,1,-8,6,-1) b <- c(4,-2,1,0,"c",2,"DX") df <- data.frame(a,b) df # a b # 1 1 4 # 2 5 -2 # 3 3 1 # 4 1 0 # 5 -8 c # 6 6 2 # 7 -1 DX The output should look like this: # a b # 1 1 4 # 2 5 -2 # 3 3 1 # 4 1 0 # 5 6 2 回答1: You could use grep : df[grep("[[:digit:]]", df$b), ] # a b #1 1 4 #2 5 -2 #3 3 1 #4 1 0 #6 6 2 回答2: This should be faster (it doesn't use regex) df[!is.na(as.numeric(df$b)), ] 来源: https://stackoverflow

Polymorphic Numerics on .Net and In C#

人盡茶涼 提交于 2019-12-01 05:46:08
问题 It's a real shame that in .Net there is no polymorphism for numbers, i.e. no INumeric interface that unifies the different kinds of numerical types such as bool, byte, uint, int, etc. In the extreme one would like a complete package of abstract algebra types. Joe Duffy has an article about the issue: http://www.bluebytesoftware.com/blog/CommentView,guid,14b37ade-3110-4596-9d6e-bacdcd75baa8.aspx How would you express this in C#, in order to retrofit it, without having influence over .Net or C#

as.numeric is rounding off values

时间秒杀一切 提交于 2019-12-01 05:15:26
问题 I am trying to convert a character column from a data frame to the numerics. However, what I am getting as a result are rounded up values. Whatever I have tried by researching other questions of the same nature on SO, hasn't worked for me. I have checked the class of the column vector I am trying to convert, and it is a character, not a factor. Here is my code snippet: some_data <- read.csv("file.csv", nrows = 100, colClasses = c("factor", "factor", "character", "character")) y <- Vectorize

Number values include comma — how do I make these numeric? [duplicate]

青春壹個敷衍的年華 提交于 2019-12-01 03:34:36
This question already has an answer here: How to read data when some numbers contain commas as thousand separator? 11 answers I have a whole column of numbers that include comma separators at the thousands. When I try to create a numeric column out of them, anything over 999 becomes NA. I used cbind: df <- cbind(df, var2 = as.numeric(as.character(df$var1))) and wound up with: var1 var2 1 2,518.50 NA 2 2,518.50 NA 3 5,018.50 NA 4 4,018.50 NA 5 10,018.50 NA 6 318.50 318.5 7 2,518.50 NA 8 3,518.50 NA 9 7,518.50 NA 10 1,018.50 NA Is there a way to strip the commas or tell as.numeric how to handle

ColdFusion 9: int and type=“numeric” nasty bug?

允我心安 提交于 2019-12-01 02:04:07
I've just experienced a behaviour that defies any logic and could potentially lead to serious issues and was wondering if it was a bug or if the behaviour was itended and what are the best practices to circumvent the issue? If it's a bug, is there a patch? Here's the two wierd behaviours that when put together are a threat to any system's data integrity. int('1 2') -> 41276 isValid('numeric', '1 2') -> true Why? Well let's see... <cffunction name="deleteSomething" access="public" returntype="void"> <cfargument name="somethingId" type="numeric" required="yes"> <cfquery datasource="#dsn()#">

Number values include comma — how do I make these numeric? [duplicate]

余生颓废 提交于 2019-12-01 00:15:34
问题 This question already has answers here : How to read data when some numbers contain commas as thousand separator? (11 answers) Closed 3 years ago . I have a whole column of numbers that include comma separators at the thousands. When I try to create a numeric column out of them, anything over 999 becomes NA. I used cbind: df <- cbind(df, var2 = as.numeric(as.character(df$var1))) and wound up with: var1 var2 1 2,518.50 NA 2 2,518.50 NA 3 5,018.50 NA 4 4,018.50 NA 5 10,018.50 NA 6 318.50 318.5

Fast implementation/approximation of pow() function in C/C++

半腔热情 提交于 2019-12-01 00:10:35
问题 I m looking for a faster implementation or good a approximation of functions provided by cmath . I need to speed up the following functions pow(x,y) exp(z*pow(x,y)) where z<0 . x is from (-1.0,1.0) and y is from (0.0, 5.0) 回答1: Here are some approxmiations: Optimized pow Approximation for Java and C / C++. This approximation is very inaccurate, you have to try for yourself if it is good enough. Optimized Exponential Functions for Java. Quite good! I use it for a neural net. If the above

How can I create an enum using numbers?

余生长醉 提交于 2019-11-30 23:20:53
问题 Is it possible to make an enum using just numbers in C#? In my program I have a variable, Gain, that can only be set to 1, 2, 4, and 8. I am using a propertygrid control to display and set this value. If I were to create an enum like this... private enum GainValues {One, Two, Four, Eight} and I made my gain variable of type GainValues then the drop-down list in the propertygrid would only show the available values for the gain variable. The problem is I want the gain values to read

How to compute an exponent in matlab without getting inf?

女生的网名这么多〃 提交于 2019-11-30 22:15:06
The title says it all: I want to calculate an exponent in matlab with big numbers, but I get overflow and it just returns infinity. >> 100^1000 ans = Inf Last time I checked, 100^1000 is decidedly smaller than infinity :) As Daniel has already pointed out, it's too big a number to be even outputted by MATLAB itself. This number is obtained with realmax for different datatypes. As an alternative to represent/use such huge numbers, you can use the corresponding mantissa and exponent with base-10 representation instead, which is the usual MATLAB representation. The function to get those two is

Iphone Development - How to display a numeric keyboard?

99封情书 提交于 2019-11-30 19:49:55
I'm working on a mobile website which is NOT a native iPhone app but rather a simple m.somedomain.com website which is developed in c# asp.net . Objective : On clicking one of the text boxes how do I display the numeric keyboard only ? Note : The website is NOT in HTML5 and is not part of a webview inside a Native app but rather a standalone regular website My textbox is a regular asp.net text box : <asp:TextBox runat="server" CssClass="reference_input" Text="1234567" /> mopsled EDIT : I found here that you can use <input type="text" pattern="[0-9]*" /> to tell mobile safari to set the numeric