C++ delete vector, objects, free memory

You can call clear, and that will destroy all the objects, but that will not free the memory. Looping through the individual elements will not help either (what action would you even propose to take on the objects?) What you can do is this: That will create an empty vector with no memory allocated and … Read more

R “Error: unexpected ‘}’ in “}”

Your code has a number of issues: The if statement would need enclosing {} symbols. The if also needs enclosing () symbols around the logical expression. The result of the recode function is not stored anywhere (the function does not change values-in-place). Loops are a poor solution to this problem. It would be much simpler to take advantage of R’s natural vectorization. Rather than an if inside … Read more

Categories r

Reshaping data.frame from wide to long format

Three alternative solutions: 1) With data.table: You can use the same melt function as in the reshape2 package (which is an extended & improved implementation). melt from data.table has also more parameters that the melt-function from reshape2. You can for example also specify the name of the variable-column: which gives: Some alternative notations: 2) With tidyr: Some alternative notations: 3) With reshape2: Some alternative notations that give the … Read more

Categories R

Proper Linq where clauses

EDIT: LINQ to Objects doesn’t behave how I’d expected it to. You may well be interested in the blog post I’ve just written about this… They’re different in terms of what will be called – the first is equivalent to: wheras the latter is equivalent to: Now what difference that actually makes depends on the implementation of Where being called. If … Read more