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

How to set axis range R

Without data, I tried to reproduce your plot error: Which gives the following plot: Changing your plot to: Might solve your problem. Edit It seems that the formula changes to factors and orders it from 1 to the number of items, so I’ll use your trick on the y axis to solve this.

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

Remove NA values from a vector

Trying ?max, you’ll see that it actually has a na.rm = argument, set by default to FALSE. (That’s the common default for many other R functions, including sum(), mean(), etc.) Setting na.rm=TRUE does just what you’re asking for: If you do want to remove all of the NAs, use this idiom instead: A final note: Other functions (e.g. table(), lm(), and sort()) have NA-related arguments that use different … Read more

Categories r