Re: [R] return first index for each unique value in a vector

2012-08-28 Thread Noia Raindrops
Hi, Try this: order(A)[!duplicated(sort(A))] -- Noia Raindrops noia.raindr...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and

Re: [R] Turning of source echo

2012-08-25 Thread Noia Raindrops
Sorry, How about this? invisible(capture.output(source(...))) # or sink("/dev/null") source(...) sink() -- Noia Raindrops noia.raindr...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEA

Re: [R] sourcecode for the balloonplot function from the gplots package

2012-08-25 Thread Noia Raindrops
Use triple colon operator: gplots:::balloonplot.default -- Noia Raindrops noia.raindr...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting

Re: [R] extract vector elements of unknown range

2012-08-25 Thread Noia Raindrops
Hi, Yes you can. As William says, the 'seq_len' approach seems to be better. 'head' function is the wrapper for 'seq_len' approach and slower. I didn't know that '-length(x)' approach is slow for long vectors

Re: [R] extract vector elements of unknown range

2012-08-25 Thread Noia Raindrops
Hi, try below: x <- c(1:20) y <- c(1, 5, 10, 14) x[ c( (y[1]+2):(y[2]-1), (y[2]+2):(y[3]-1), (y[3]+2):(y[4]-1) ) ] x[unlist(lapply(1:(length(y) - 1), function (i) (y[i] + 2) : (y[i + 1] - 1)))] x[unlist(mapply(seq, y[-length(y)] + 2, y[-1] - 1, SIMPLIFY = FALSE))] -- Noia Rai

Re: [R] Turning of source echo

2012-08-25 Thread Noia Raindrops
Hi, ?cat Read item sep in argument section. And try: cat("X = ", B, sep = "") -- Noia Raindrops noia.raindr...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the postin

Re: [R] RJSONIO/rjson maximum depth?

2012-08-24 Thread Noia Raindrops
Hi, You missed a close bracket. node4:{ ... nodeDef:{ node4:{ ... # need a close bracket here } }, -- Noia Raindrops noia.raindr...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help

Re: [R] Branch and Bound

2012-08-24 Thread Noia Raindrops
Hi, Do you try 'RSiteSearch("Branch Bound")'? -- Noia Raindrops noia.raindr...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.or

Re: [R] updating elements of a vector sequentially - is there a faster way?

2012-08-24 Thread Noia Raindrops
tions elapsed relative ## 1 f1() 100 2.917 30.385417 ## 2 f2() 100 0.448 4.67 ## 3 f3() 100 32.439 337.906250 ## 4 f4() 100 3.635 37.864583 ## 5 f5() 100 0.096 1.00 -- Noia Raindrops noia.raindr...@gmail.com __

Re: [R] Regular expressions: stuck again...

2012-08-24 Thread Noia Raindrops
xx should become \"xxx\".\"xxx\"\".\"xxx\" x <- gsub("([[:alpha:]]+)_([[:alpha:]]+)\\.([[:alpha:]]+)", "\"\\1\".\"\\2\".\"\\3\"", x) -- Noia Raindrops noia.raindr...@gmail.com ___

Re: [R] load workspace by function

2012-08-23 Thread Noia Raindrops
Hello, Add 'envir' arugment: load(workspace_name, envir = globalenv()) # or load(workspace_name, envir = parent.frame()) -- Noia Raindrops noia.raindr...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listi

Re: [R] Plot label axis with expression

2012-08-22 Thread Noia Raindrops
(text = sprintf("e^%d", axTicks(2))), las = 1) -- Noia Raindrops noia.raindr...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guid

Re: [R] Loop for readLines(URL[i]) fails when URL returns Error 404

2012-08-22 Thread Noia Raindrops
cannot open the connection\n" ## attr(,"class") ## [1] "try-error" ## attr(,"condition") ## # or for (i in 1:length(url)) res[[i]] <- tryCatch(readLines(url[i]), error = function (e) conditionMessage(e)) res[[2]] ## [1] "cannot open the connection"

Re: [R] strange behaviour when sourcing inside function

2012-08-22 Thread Noia Raindrops
nt. test <- function () source("test.R", local = FALSE) # test.R is evaluated in global environment. test <- function () source("test.R", local = environment()) # environment() returns the envrionment of 'test' function. test <- function () source("test.R&q

Re: [R] Regular Expressions in grep

2012-08-21 Thread Noia Raindrops
;- regmatches(a, regexpr("[1-9][0-9]*\\.", a)) End <- regmatches(a, regexpr("\\.[0-9]*[1-9]", a)) Front ## [1] "1020." End ## [1] ".9092" -- Noia Raindrops noia.raindr...@gmail.com __ R-help@r-project.or

Re: [R] Entering a table

2012-08-21 Thread Noia Raindrops
Try this: table(nDeaths = rep(0:4, c(109, 65, 22, 3, 1))) ## or as.table(array(c(109L, 65L, 22L, 3L, 1L), dimnames = list(nDeaths = 0:4))) -- Noia Raindrops noia.raindr...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman

Re: [R] reexpr transform nonumeric values to numeric

2012-08-21 Thread Noia Raindrops
Use backreference: as.numeric(gsub("^(.*)-$", "-\\1", as.character(temp))) -- Noia Raindrops noia.raindr...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the postin

Re: [R] irregular splits in dataframe

2012-08-21 Thread Noia Raindrops
pland 12-16 PZ ## 5 Loamy Upland 16-20 PZ -- Noia Raindrops noia.raindr...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/

Re: [R] Error: level sets of factors are different?

2012-08-17 Thread Noia Raindrops
== as.character(dat$b) ## [1] TRUE FALSE TRUE dat <- cbind(data.frame(x = 1:3), a = c("a", "b", "c"), b = c("a", "a", "c"), stringsAsFactors = FALSE) str(dat) ## 'data.frame': 3 obs. of 3 variables: ## $ x: int 1 2 3 ## $ a: