Removing punctuations from text using R

Here’s how I take your question, and an answer that is very close to @David Arenburg’s in the comment above. The extra space after [:punct:] is to add spaces to the string and the + matches one or more sequential items in the regular expression. This has the side effect, desirable in some cases, of … Read more

Categories r Tags

env=baseenv() in R

I’ve been playing around with the Life Analytics trading with R tutorial (http://lifeanalytics.blogspot.com/2011/01/forex-trading-with-r-part-1.html) and keep getting stuck on a problem related to building the data model. So I start with a bunch of functions: Then try to build a model passing the data to the functions: And keep getting the following error: Error in formula.default(object, … Read more

Categories r Tags

“no function to return from, jumping to top level”

CheckForMersennePrimes has extra {} on line 2 and line 4 (inside for loop) of this function, like vec<-MarsenneNumber(x){if()…} I removed those extra braces. I think, your intention is to get values of vec in which factorlist(vec[i]) is equal to 1. If this is true, then you have to initiate vec outside the for loop and check for this condition. Then finally return a1 which contains all vec values passing … Read more

Categories r Tags

How to catch integer(0)?

That is R’s way of printing a zero length vector (an integer one), so you could test for a being of length 0: It might be worth rethinking the strategy you are using to identify which elements you want, but without further specific details it is difficult to suggest an alternative strategy.

Categories r Tags

How do I flip rows and columns in R

Assuming you have this data frame df, see data below. First you have to transpose all data frame except the first column. The result being a matrix that we need to convert to a data frame. Finally, we assign as column names of df2the first column of the original data frame df. Output: Data:

Categories r Tags

What does ‘length of ‘dimnames’ [1] not equal to array extent’ mean?

OK, I can reproduce this from scratch, with reshape (but not with reshape2). Something is indeed getting mangled by head(). The specific problem is an interaction between utils::head.data.frame, which drops pieces of the object without keeping a completely consistent internal structure, and as.matrix.cast_df (called by matplot), which assumes that structure is there. Adding the following method seems to fix the problem. It might … Read more

Categories r Tags