casting

Data frame typecasting entire column to character from numeric

孤人 提交于 2019-12-20 04:21:01
问题 Suppose I have a data.frame that's completely numeric . If I make one entry of the first column a character (for example), then the entire first column will become character . Question : How do I reverse this. That is, how do I make it such that any character objects inside the data.frame that are "obviously" numeric objects are forced to be numeric ? MWE: test <- data.frame(matrix(rnorm(50),10)) is(test[3,1]) test[1,1] <- "TEST" is(test[3,1]) print(test) So my goal here would be to go FROM

Error passing 2D char* array into a function

て烟熏妆下的殇ゞ 提交于 2019-12-20 04:16:52
问题 I'm trying to pass a 2D array of char* into a function. I am getting this error: "cannot convert 'char* (*)[2]' to 'char***' for argument '1' to 'int foo(char***)'" Code: int foo(char*** hi) { ... } int main() { char* bar[10][10]; return foo(bar); } 回答1: Your array is an array of 10 char* arrays, each storing 10 char* pointers. This means that when passing it to a function whose parameter is not a reference, it is converted to a pointer to an array of 10 char* . The correct function parameter

What's the use of _ATL_PACKING constant when computing distance from the start of object?

旧巷老猫 提交于 2019-12-20 04:16:50
问题 ATL features a set of macros for so-called COM maps. COM map is a table that associates an interface GUID with an offset that is to be added to this pointer to get to the corresponding subobject - the whole stuff works as replacement to explicit static_cast for the upcast inside IUnknown::QueryInterface(). The map entries are built by using offsetofclass macro: #define _ATL_PACKING 8 #define offsetofclass(base, derived)\ ((DWORD_PTR)(static_cast<base*>((derived*)_ATL_PACKING))-_ATL_PACKING)

Templatized Storing Multiple Different Types In std::vector

懵懂的女人 提交于 2019-12-20 04:12:50
问题 thank you all for your time I really appreciate it. There exists a need to store multiple variables of different types in a std::vector using a templatized fashion. To use the following functions the programmer must be aware of which order they stored the variables and how many variables were stored. class _NetVar {}; A sub class is created to hold the actual variable: template <class VARTYPE> class NetVar : public _NetVar { private: VARTYPE Var; NetVar(VARTYPE Value) { Var = Value; } }; A

Finding the specific type held in an ArrayList<Object> (ie. Object = String, etc.)

微笑、不失礼 提交于 2019-12-20 03:57:12
问题 Say I have an ArrayList that I have cast to an ArrayList of objects. I know that all the objects that were in the ArrayList I cast were of the same type, but not what the type was. Now, if the ArrayList is not empty, I could take one of the objects in it and use the instanceof operator to learn what the actual type is. But what of the case where the ArrayList is empty? How do I determine what type Object actually is then? Is it possible? Edit: In retrospect, I suppose it doesn't strictly

Can't parse String from stdin to floating-point - Rust

久未见 提交于 2019-12-20 03:53:11
问题 When parsing a String type value to a floating-point type value in Rust, everything works fine with "let pi: f64 = 3.14".parse().unwrap(); . However, when parsing a String type value that comes from standard input, even if it's the exact same value, the program panics and throws: thread 'main' panicked at 'called Result::unwrap() on an Err value: ParseFloatError { kind: Invalid }', src/libcore/result.rs:999:5 note: run with RUST_BACKTRACE=1 environment variable to display a backtrace. I

Nested Interfaces: Cast IDictionary<TKey, IList<TValue>> to IDictionary<TKey, IEnumerable<TValue>>?

最后都变了- 提交于 2019-12-20 03:23:08
问题 I would think it's fairly straightforward to cast an IDictionary<TKey, IList<TValue>> object to an IDictionary<TKey, IEnumerable<TValue>> , but var val = (IDictionary<TKey, IEnumerable<TValue>>)Value; throws a System.InvalidCastException , and var val = Value as IDictionary<TKey, IEnumerable<TValue>>; makes val null. What is the proper way to cast this? 回答1: I would think it's fairly straightforward to cast an IDictionary<TKey, IList<TValue>> object to an IDictionary<TKey, IEnumerable<TValue>

Long int too large to convert to float

浪子不回头ぞ 提交于 2019-12-20 03:21:59
问题 Assuming I have a program with the function def fakultaet(x): if x>1: return(x* fakultaet(x-1)) else: return(1) that returns the factorial of a given number, I need to calculate 1.0/fakultaet(200) but I get an overflow error: long int too large to convert to float . How can I solve this problem? 回答1: You could try this: from decimal import Decimal def fakultaet(x): # as you have it currently if x>1: return(x * fakultaet(x-1)) else: return(1) print Decimal(1.0) / fakultaet(200) Output: 1

C What happens when casting floating point types to unsigned integer types when the value would overflow

本秂侑毒 提交于 2019-12-20 03:18:17
问题 I'm wondering what happens when casting from a floating point type to an unsigned integer type in C when the value can't be accurately represented by the integer type in question. Take for instance func (void) { float a = 1E10; unsigned b = a; } The value of b I get on my system (with unsigned on my system being able to represent values from 0 to 2^32-1) is 1410065408 . This seems sensible to me because it's simply the lowest order bits of the result of the cast. I believe the behavior of

C# performance analysis- how to count CPU cycles?

帅比萌擦擦* 提交于 2019-12-20 03:09:17
问题 Is this a valid way to do performance analysis? I want to get nanosecond accuracy and determine the performance of typecasting: class PerformanceTest { static double last = 0.0; static List<object> numericGenericData = new List<object>(); static List<double> numericTypedData = new List<double>(); static void Main(string[] args) { double totalWithCasting = 0.0; double totalWithoutCasting = 0.0; for (double d = 0.0; d < 1000000.0; ++d) { numericGenericData.Add(d); numericTypedData.Add(d); }