which(is.na(t.zoo[,2]))
which row has an NA value in the second column of variable t.zoo
Remove NA values
A<-na.omit(A)
Conditional array indexing in R
July 23, 2010
ts1[ts1[,6]>0,]
selects all rows of matrix “ts1″ that in column 6 have a value greater than zero. Don’t forget the very last comma!
Type t = Type.GetType(outer_type);
if (t == null)
{
srt.LogClient.Log(Tools.LogLevel.Error, "Failed to instantiate type {0}", outer_type);
return;
}
if (t.IsGenericType == true)
{
Type[] innerTArr = t.GetGenericArguments();
if (innerTArr == null || innerTArr.Length == 0)
{
Log("inner Type was not found. Cannot instantiate a generic class");
return;
}
Type innerT = innerTArr[0];
Type genericType = t.GetGenericTypeDefinition();
Type[] typeArgs = { innerT };
Type constructed = genericType.MakeGenericType(typeArgs);
object o = Activator.CreateInstance(constructed);
mac = o as IMac;
}
Personal notes for performing this to install Windows 7 on a Toshiba R100, which has no DVD drive nor the ability to boot from USB. These notes apply ONLY to Server 2008 R2, I believe some extra steps are required for 2008 R1 (which I haven’t tried, sorry)
- Install WDS on a machine that is NOT hosting DHCP server. I used the DHCP on my router, which worked fine.
- Download and install Windows Automated Install Toolkit (Windows AIK) ISO
- Create a WinPE image using “copype x86 <dir>” for 32-bit, or “copype x64 <dir>” for 64-bit
- Install the resulting boot image in the WDS install.
- Boot your target machine, ensuring that it’s set to boot from PXE
- Should now boot in to Windows PE – from here you can map a drive to a copy of the Windows 7 ISO/DVD, shared on another machine:
net use Y: \\machine\share - CD to the Y: drive and run setup.exe
Group by date LINQ example
April 28, 2010
var q = from t in _Trades
let dt = t.TradeTime
group t by new DateTime(dt.Year, dt.Month, dt.Day) into g
select g;
var dictionary = q.ToDictionary(result => result.Key, result => result.ToList());
Reflection snippet:
Type t = Type.GetType(kid.Attributes["type"].Value);
...
object o = t.Assembly.CreateInstance(t.FullName);
How to convert a string in ISO date format to a C# DateTime:
DateTime dt = DateTime.ParseExact(dateString, “yyyyMMdd”, CultureInfo.InvariantCulture);
Convert an integer in ISO format to a C# date
November 19, 2008
Yet another DateTime conversion routine, this time using DateTime.ParseExact()
int integerDate = "20081113";
DateTime date = DateTime.ParseExact(integerDate.ToString(), "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture);
A lovely piece of code for dealing with parameters in C#
October 7, 2008
I can’t claim credit for this, as I saw it yesterday whilst receiving a demo of a (very good) messaging architecture written by another developer. It’s only a little scrap of code, but that makes it even better: its beauty is its simplicity. So, to get parameters out of some parameter holding class, but to not have to (a) make everything the same type or; (b) have N methods for retrieving N types, you can do this:
public class Params
{
Dictionary _values = new Dictionary();
public Params()
{
}
public T GetParam(string name, T defaultValue)
{
if (_values.ContainsKey(name) == false)
{
return defaultValue;
}
return (T)_values[name];
}
}
Which you then call like this:
Params p = new Params();
int key1 = p.GetParam("key1", 39);
string key2 = p.GetParam("key2", "defaultValue");
double key3 = p.GetParam("key3", 44.2);