LINQ’s Distinct() on a particular property

EDIT: This is now part of MoreLINQ. What you need is a “distinct-by” effectively. I don’t believe it’s part of LINQ as it stands, although it’s fairly easy to write: So to find the distinct values using just the Id property, you could use: And to use multiple properties, you can use anonymous types, which implement equality appropriately: … Read more

How can two strings be concatenated?

is the way to go. As the previous posters pointed out, paste can do two things: concatenate values into one “string”, e.g. where the argument sep specifies the character(s) to be used between the arguments to concatenate, or collapse character vectors where the argument collapse specifies the character(s) to be used between the elements of the vector to be … Read more

Categories R

Expected initializer before namespace

The error you offer, error: expected initializer before ‘namespace’ suggests that there is a structure or variable declaration that isn’t terminated. Something like: Here, the ‘struct foo’ declaration isn’t terminated with a semicolon. This should read: Getting the preprocessor involved (using #include) makes this type of thing a bit harder to track down. It may be that … Read more

How to fix ‘No match for operator[]’ error (c++)

Firstly, you use both ar and arr, while arr is an array and ar is a list. This is both confusing to the reader and (it turns out) to the code author. In C++, std::list doesn’t have random access. You cannot use ar[], since operator[] is not defined for lists. Further, largestOfArray expects an array, not a list. You probably intended to use arr there instead of ar.

How do I use valgrind to find memory leaks?

Try this: valgrind –leak-check=full -v ./your_program As long as valgrind is installed it will go through your program and tell you what’s wrong. It can give you pointers and approximate places where your leaks may be found. If you’re segfault’ing, try running it through gdb.

Update multiple columns in SQL

The “tiresome way” is standard SQL and how mainstream RDBMS do it. With a 100+ columns, you mostly likely have a design problem… also, there are mitigating methods in client tools (eg generation UPDATE statements) or by using ORMs