How do you make a deep copy of an object?

A safe way is to serialize the object, then deserialize. This ensures everything is a brand new reference. Here’s an article about how to do this efficiently. Caveats: It’s possible for classes to override serialization such that new instances are not created, e.g. for singletons. Also this of course doesn’t work if your classes aren’t Serializable.

Open and write data to text file using Bash?

The short answer: However, echo doesn’t deal with end of line characters (EOFs) in an ideal way. So, if you’re gonna append more than one line, do it with printf: The >> and > operators are very useful for redirecting output of commands, they work with multiple other bash commands.

How to convert a factor to integer\numeric without loss of information?

See the Warning section of ?factor: In particular, as.numeric applied to a factor is meaningless, and may happen by implicit coercion. To transform a factor f to approximately its original numeric values, as.numeric(levels(f))[f] is recommended and slightly more efficient than as.numeric(as.character(f)). The FAQ on R has similar advice. Why is as.numeric(levels(f))[f] more efficent than as.numeric(as.character(f))? as.numeric(as.character(f)) is effectively as.numeric(levels(f)[f]), so you are performing the conversion to numeric on length(x) values, rather … Read more

Categories R

shifting a piece of text down using CSS

If I’m reading this correctly, then you’re trying to straddle the border between two table cells which won’t work. You’ll need to consolidate the first two cells in the right column and then rowspan=”2″ the new cell with the number in it. Then top or bottom vertically align the text in the cell and add … Read more