cast

from absolute numbers to proportion in two level data (R! SAC? plyr?)

I have data nested in to levels: L1 L2 x1 x2 x3 x4 A This 20 14 12 15 A That 11 NA 8 16 A Bat Na 22 13 9 B This 10 9 11 6 B That 3 3 1 NA B Bat 4 10 2 8 Now I want something simply - and I feel I have been able to do this just last month. But something has gone missing in my head: I want percentages (ignoring NA), ...

Why won't Cast<double>() work on IEnumerable<int>?

Possible Duplicates: Enumerable.Cast<T> extension method fails to cast from int to long, why ? Puzzling Enumerable.Cast InvalidCastException Cast/Convert IEnumerable<T> to IEnumerable<U> ? I'm trying to convert an array of integers to an array of doubles (so I can pass it to a function that takes an array of doubles). The...

Cast Linq IEnumerable to Class that inherits Ienumerable

Hi, I have a resultset class: Public Class AResultSet Implements IEnumerable(Of ConcreteResult) Private _list As List(Of ConcreteResult) Public Sub New() _list = New List(Of ConcreteResult) End Sub Public Function GetEnumerator() As System.Collections.Generic.IEnumerator(Of ConcreteResult) Implements Syst...

T-SQL Format integer to 2-digit string

I can't find a simple way to do this in T-SQL. I have for example a column (SortExport_CSV) that returns an integer '2' thru 90. If the stored number is a single digit, I need it to convert to a 2 digit string that begins with a 0. I have tried to use CAST but I get stuck on how to display the style in the preferred format (0#) Of cour...

How is CAST(VARBINARY AS NVARCHAR) implemented in SQL Server?

I'm specifically referring to how stored procedure input parameters are handled. Does it just change how SQL Server interprets the data, or does it require SQL Server to make a copy of the data? Thanks! ...

Cast List<MyType> to Class that extends List<MyType>

Here's the problem I'm trying to cast form List to an object MyTypes which is defined as public class MyTypes : List<MyType> { ... } It won't cast directly with (MyTypes) - compiler error Or with as MyTypes - returns null I would think this would be possible, but clearly I have to overload some casting operation. Help! ...

Casting performance in Java

I've a Servlet filter which performs the following type cast: HttpServletRequest httpRequest = (HttpServletRequest) req; At present my filter is responsible for two tasks that would be better separated into two filters. If I'd split the logic into two filters I'd need two casts. What is the performance impact of such a cast? Is it wo...

Cast an IList to an IList<t> using dynamic instantiation

I am try to convert the following NHibernate query using dyanmic instantiation into an IList<t> rather than an IList. IList<AllName> allNames = (IList<AllName>)Session.CreateQuery( @"select new AllName( name.NameId, name.FirstName, origin.OriginId, origin.Description, name.Sex, name.Description, name.SoundEx ) from Name name j...

Why am I getting this ClassCastException?

I have two very simple classes, one extends the other: public class LocationType implements Parcelable { protected int locid = -1; protected String desc = ""; protected String dir = ""; protected double lat = -1000; protected double lng = -1000; public LocationType() {} public int getLocid() { ...

Executing machine code in memory

I'm trying to figure out how to execute machine code stored in memory. I have the following code: #include <stdio.h> #include <stdlib.h> int main(int argc, char* argv[]) { FILE* f = fopen(argv[1], "rb"); fseek(f, 0, SEEK_END); unsigned int len = ftell(f); fseek(f, 0, SEEK_SET); char* bin = (char*)malloc(len); ...

How can i remove an unckecked cast warning in java ?

i have this piece of code: import java.net.MalformedURLException; import java.rmi.Naming; import java.rmi.NotBoundException; import java.rmi.Remote; import java.rmi.RemoteException; public class ClientLookup<T extends Remote> { private T sharedObject; public void lookup(String adress) throws MalformedURLException, RemoteException, N...

How to cast array elements to strings in PHP?

If I have a array with objects: $a = array($objA, $objB); (each object has a __toString()-method) How can I cast all array elements to string so that array $a contains no more objects but their string representation? Is there a one-liner or do I have to manually loop through the array? ...

using group_concat in PHPMYADMIN will show the result as [BLOB - 3B]

I have a query which uses the GROUP_CONCAT of mysql on an integer field. I am using PHPMYADMIN to develop this query. My problem that instead of showing 1,2 which is the result of the concatenated field, I get [BLOB - 3B]. Query is SELECT rec_id,GROUP_CONCAT(user_id) FROM t1 GROUP BY rec_id (both fields are unsigned int, both are n...

How to cast an object to a list of generic type in F#

In the following snippet my intention is to convert a System.Object (which could be an FSharpList) to a list of whatever generic type it is holding. match o with | :? list<_> -> addChildList(o :?> list<_>) | _ -> addChild(o) Unfortunately only list<obj> is ever matched as a list. I would ...

HQL query throws ClassCastException when using count()devided by double value

I have a query looks like this @NamedQuery(name="WorkingDayLog.getExpectedWorkingHours",query="select ((count(o.id)-:approvedVacs)*(:shiftDuration/60.0)*:factor) from WorkingDayLog o where o.workingDayDate between :appraisalStart and :appraisalEnd")` it compiles fine but when executed it throws the following exception ClassCastExce...

How to Cast Objects in PHP

Ive some clases that share some attributes, and i would like to do something like: $dog = (Dog) $cat; is it posible or is there any generic work around? Its not a superclass, or a interface or related in any way. They are just 2 different clases i would like php map the attributes from a cat class to a dog and give me the new object. –...

unable to make out how ~ operator works in c

hello, I have this piece of code can you explain me the output unsigned int x=3; ~x; printf("%d",x); output is 10 I am not able to make it how. I have compiled the code on turbo c ...

Under what circumstances is it necessary to perform an explicit cast of a variable to a string in JavaScript?

Are there any scenarios where it is absolutely necessary to perform an explicit cast of a variable in JavaScript to a String In the following example it is not necessary: var n=1; var s = "Hello" + n; var s = "Hello"+String(n); //not necessary I've used a numeric value above, although this need not apply only to numerics. ...

Column fromate problem while reading Excel in c#

Hi, I am able to read the excel sheet from c# + asp.net application with MS interop Excel services (namespace). Data retrieving fine. But my excel sheet have a colummn whose formate type is of hh:mm:ss type. while retriving data i found value of this column fetching as General column getting some 0.45645646... like value. What should thi...

In C#, how to create an object given the name of its type?

I know the type of object (let's say IAnimal) I need to instantiate, and the name (lets say Tiger). How do I write the code to instantiate Tiger, given that the variable that knows the object name is a string. I'm likely missing something simple here, but am currently stuck on this. Update: I meant Class Tiger : IAnimal, changed abov...