[R] nchar(type = "chars") of "latin1" string in C locale

2017-02-24 Thread Mikko Korpela
\xa4" Encoding(foo2) <- "UTF-8" foo2 # [1] "" nchar(foo2) # [1] 1 nchar(foo2, type = "bytes") # [1] 2 nchar(foo2, type = "width") # [1] 1 But, confusingly, encodeString() does not agree with print(), contrary to the document '?encodeString

Re: [R] Functional programming?

2016-03-02 Thread Mikko Korpela
](x), type = "l") > for(i in 2:5) > lines(x, h[[i]](x), col = i) Here is my (ugly?) suggestion: f <- function(u) function(x) u * x^2 g <- function(u) function(x) u * log(x) set.seed(3) a <- runif(5) h <- f(a[1]) for (

Re: [R] How to parse xml with same key name ?

2012-11-01 Thread Mikko Korpela
html I'm not exactly sure of what you are trying to do, but here's a start: foo <- xmlInternalTreeParse("yourfile.xml") nodes <- getNodeSet(foo, "//node[@id]") sapply(nodes, xmlGetAttr, "id") sapply(nodes, xmlValue)

Re: [R] lm without intercept, false R-squared

2012-06-27 Thread Mikko Korpela
/FAQ/R-FAQ.html#Why-does-summary_0028_0029-report-strange-results-for-the-R_005e2-estimate-when-I-fit-a-linear-model-with-no-intercept_003f -- Mikko Korpela Aalto University School of Science Department of Information and Computer Science __ R-help@r-proj

Re: [R] Possible bug in is.na.data.frame(): input without columns

2012-06-25 Thread Mikko Korpela
On 06/20/2012 05:36 PM, Mikko Korpela wrote: > Hello list! > > Let's construct a matrix / data.frame with 0 columns, but > 0 rows, and > non-NULL rownames. Then, call is.na() on both the data.frame and the > matrix. We find that is.na.data.frame() gives an error. When

[R] Possible bug in is.na.data.frame(): input without columns

2012-06-20 Thread Mikko Korpela
LC_NUMERIC=C [3] LC_TIME=en_US.utf8LC_COLLATE=en_US.utf8 [5] LC_MONETARY=en_US.utf8 LC_MESSAGES=en_US.utf8 [7] LC_PAPER=CLC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C attached base packages: [1] stats grap

Re: [R] strftime - Dates from Excel files

2012-02-03 Thread Mikko Korpela
t, format="%d/%m/%Y") [1] "1978-02-01" > as.Date(dataset, format="%d/%m/%Y") [1] "1978-02-01" For converting "POSIXlt" or "Date" back to a character representation, use as.character() or, for a customizable style, format(). > format(s

Re: [R] Writing a function to return column position XXXX

2012-01-24 Thread Mikko Korpela
t; col.id<-function(x) any(grep("$",x)) > sapply(cand2,col.id) > > However, this returns TRUE for all columns (even those that do not contain > the $). > > Any assistance is appreciated. One option is to use fixed = TRUE in the call to grep(). See ?grep. BR, --

Re: [R] Max value of an integer

2012-01-11 Thread Mikko Korpela
rs are not exactly representable. > options(digits = 22) > print(max.num <- 2 ^ .Machine$double.digits) [1] 9007199254740992 > (max.num) - (max.num - 1) [1] 1 > (max.num + 1) - (max.num) [1] 0 > (max.num + 2) - (max.num + 1) [1] 2 > If I need to setup by myself what is the maximum

Re: [R] Error when using foreach package for parralelization

2012-01-10 Thread Mikko Korpela
ou actually accidentally iterate over some data structures. For example, 'pk' inside the %dopar% loop is a single element of the original 'pk' list (which may get overwritten, depending on whether the loop is actually run in parallel). This is probably not what you want. - M