Re: [R] rename and color a list of list of list of values

2015-06-05 Thread Sven E. Templer
Hi Karim, you should learn ?Map to iterate along the list and supply mutliple list arguments (there is also parallel:::mcMap for multicore). The magic of the color code generation you figure out yourself, I guess... Here 'i' intends to be the value, 'n' the name, e.g. # returns color by

Re: [R] generate a list as follows: 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, . . . . ., n, n, n, n

2015-04-20 Thread Sven E. Templer
In '?rep' find out about the 'each' argument. Also there is the function 'gl' which creates a factor and offers a shorter syntax for your problem. If n equals 5 use one of: rep(seq(5), each = 4) gl(5,4) On 19 April 2015 at 15:44, John Sorkin jsor...@grecc.umaryland.edu wrote: Windows 7 64-bit

Re: [R] regexpr - ignore all special characters and punctuation in a string

2015-04-20 Thread Sven E. Templer
Hi Dimitri, str_replace_all is not in the base libraries, you could use 'gsub' as well, for example: a = What a nice day today! - Story of happiness: Part 2. b = What a nice day today: Story of happiness (Part 2) sa = gsub([^A-Za-z0-9], , a) sb = gsub([^A-Za-z0-9], , b) a==b # [1] FALSE sa==sb #

Re: [R] idiom for constructing data frame

2015-03-31 Thread Sven E. Templer
If you don't mind an extra column, you could use something similar to: data.frame(r=seq(8),foo=NA,bar=NA) If you do, here is another approach (see function body): empty.frame - function (r = 1, n = 1, fill = NA_real_) { data.frame(setNames(lapply(rep(fill, length(n)), rep, times=r), n)) }

Re: [R] changing column labels for data frames inside a list

2015-03-30 Thread Sven E. Templer
On 30 March 2015 at 16:47, Sarah Goslee sarah.gos...@gmail.com wrote: colnames(e) - paste0('pop',1:12) isn't a function and doesn't return anything. But function(e){colnames(e) - paste0('pop', 1:2)} is a function and it returns something (the last evaluated expression! - here the paste0

Re: [R] changing column labels for data frames inside a list

2015-03-30 Thread Sven E. Templer
convention to always copy the reply to the last person who responded? I guess it depends on which answer you refer to. On Mon, Mar 30, 2015 at 10:56 AM, Sven E. Templer sven.temp...@gmail.com wrote: On 30 March 2015 at 16:47, Sarah Goslee sarah.gos...@gmail.com wrote: colnames(e) - paste0

Re: [R] changing column labels for data frames inside a list

2015-03-30 Thread Sven E. Templer
:56 AM, Sven E. Templer sven.temp...@gmail.com wrote: On 30 March 2015 at 16:47, Sarah Goslee sarah.gos...@gmail.com wrote: colnames(e) - paste0('pop',1:12) isn't a function and doesn't return anything. But function(e){colnames(e) - paste0('pop', 1:2)} is a function

Re: [R] changing column labels for data frames inside a list

2015-03-30 Thread Sven E. Templer
On 30 March 2015 at 17:50, Sarah Goslee sarah.gos...@gmail.com wrote: On Mon, Mar 30, 2015 at 11:43 AM, Sven E. Templer sven.temp...@gmail.com wrote: On 30 March 2015 at 17:31, Bert Gunter gunter.ber...@gene.com wrote: Sarah's statement is correct. So is yours

Re: [R] the making of _R_ eBooks

2015-03-23 Thread Sven E. Templer
Q3: any other recommendations? You might be interested in the very easy to use R markdown, see: http://rmarkdown.rstudio.com/ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see

Re: [R] Comparing each component of vector to each component of a Matrix.

2015-03-11 Thread Sven E. Templer
Hi, you didn't specify values in A, and you first wanted to compare bi with Aij, but then also which bi is less/equal to zero. For the first case, with A - matrix(0:3,2) b - seq(-1,5) and a comparison function for bi less/equal to Aij like f - function (bi) {as.integer(bi=A)} you can iterate

Re: [R] Raster Help

2015-02-19 Thread Sven E. Templer
Without (example) code it is hard to follow... use ?dput to present some data (subset). But if it is data.frames you are dealing with (for sure with read.csv, but not so sure at all with raster maps), give this a try: ?merge On 19 February 2015 at 17:44, Simon Tarr simon.t...@adtrak.co.uk wrote:

Re: [R] Extract data from Array to Table

2015-02-12 Thread Sven E. Templer
Make use of the plyr and reshape2 package (both on CRAN): library(plyr) d-adply(ArrayDiseaseCor, 1:2) # adply calls function identity by default d-melt(d) d-subset(d,value.5) head(d) You will have to rename columns, or adjust arguments in melt/adply. Note: use set.seed before sampling for

Re: [R] Extract data from Array to Table

2015-02-12 Thread Sven E. Templer
see inline On 12 February 2015 at 09:10, Sven E. Templer sven.temp...@gmail.com wrote: Make use of the plyr and reshape2 package (both on CRAN): I forgot: library(reshape2) library(plyr) d-adply(ArrayDiseaseCor, 1:2) # adply calls function identity by default d-melt(d) d-subset(d,value

Re: [R] Sum function and missing values --- need to mimic SAS sum function

2015-01-27 Thread Sven E. Templer
Maybe this is due to the usage of rep() in ifelse(): f.rep - function(ans){ans - rep(ans,1);return(ans)} f - function(ans){return(ans)} f(a - 123) # no print here f.rep(a - 123) # prints: # [1] 123 On 27 January 2015 at 11:54, Bert Gunter gunter.ber...@gene.com wrote: Huh?? ifelse(TRUE, a -

Re: [R] Sum function and missing values --- need to mimic SAS sum function

2015-01-26 Thread Sven E. Templer
you can also define 'na.rm' in sum() by 'NA state' of x (where x is your vector holding the data): sum(x, na.rm=!all(is.na(x))) On 26 January 2015 at 13:45, Martin Maechler maech...@lynne.stat.math.ethz.ch wrote: Jim Lemon drjimle...@gmail.com on Mon, 26 Jan 2015 11:21:03 +1100 writes:

Re: [R] Make 2nd col of 2-col df into header row of same df then adjust col1 data display

2014-12-19 Thread Sven E. Templer
Another solution: CaseID - c(1015285, 1005317, 1012281, 1015285, 1015285, 1007183, 1008833, 1015315, 1015322, 1015285) Primary.Viol.Type - c(AS.Age, HS.Hours, HS.Hours, HS.Hours, RK.Records_CL, OT.Overtime, OT.Overtime, OT.Overtime, V.Poster_Other, V.Poster_Other) library(reshape2)

Re: [R] Formula with dynamic number of variables

2014-11-22 Thread Sven E. Templer
# fixed formula part: f - dat ~ a0 * exp(-S*(x - 250)) + K # convert to character f - as.character(f) # component: C - (p0*exp(-0.5*((x-p1)/p2)^2)) # number of components (defined randomly): n - sample(1:3, 1) C - rep(C, n) # collapse: C - paste(C, collapse = +) # combine f - paste(f[2], f[1],

Re: [R] add text to the first line of an output file

2014-10-22 Thread Sven E. Templer
Hi. You can't. But using a second file where you first write your header and then append the original file is a solution. ?cat and ?write.table with a focus on the 'append' argument should help. you can then use ?unlink to delete the original file and ?file.rename to rename the second, if

Re: [R] add text to the first line of an output file

2014-10-22 Thread Sven E. Templer
, 2014 12:33 AM, Sven E. Templer sven.temp...@gmail.com wrote: Hi. You can't. But using a second file where you first write your header and then append the original file is a solution. ?cat and ?write.table with a focus on the 'append' argument should help. you can then use ?unlink

Re: [R] creating individual records from a frequency distribution

2014-10-22 Thread Sven E. Templer
With melt and rep you are close. If you combine them it works: library(reshape) # your data: df1 - data.frame(area=c(1,2),group1=c(2,3),group2=c(1,5),group3=c(4,0)) df2-data.frame(person_id=seq(1:15),area=c(rep(1,7),rep(2,8)),group_num=c(1,1,2,3,3,3,3,1,1,1,2,2,2,2,2)) # first melt d -

Re: [R] sort a data.frame in a different way

2014-10-22 Thread Sven E. Templer
seems like a transpose, so use ?t t(your.data.frame) On 22 October 2014 11:34, Matthias Weber matthias.we...@fntsoftware.com wrote: Hello together, i have a little problem. Maybe anyone can help me. I have a data. frame which look like this one: 1000 1001 10021003 15

Re: [R] package installation failure virtualisation environment

2014-10-15 Thread Sven E. Templer
. http://fsf.org/ [5] Everyone is permitted to copy and distribute verbatim copies [6] of this license document, but changing it is not allowed. On 15 October 2014 10:51, r...@openmailbox.org wrote: On 2014-10-14 15:40, Sven E. Templer wrote: Prevent graphic menues with: options(menu.graphics

Re: [R] evaluate NA to FALSE instead of NA?

2014-10-14 Thread Sven E. Templer
use: which(p=.05) this will not yield logical, but integer indices without NA On 14 October 2014 11:51, Rainer M Krug rai...@krugs.de wrote: Hi I want to evaluate NA and NaN to FALSE (for indexing) so I would like to have the result as indicated here: , | p - c(1:10/100, NA, NaN) |

Re: [R] package installation failure virtualisation environment

2014-10-14 Thread Sven E. Templer
Prevent graphic menues with: options(menu.graphics = FALSE) or and define repositories: options(repos = c(CRAN = http://cran.r-project.org;)) On 14 October 2014 17:00, r...@openmailbox.org wrote: Subscribers, A version of R is installed in a virtual machine, which has complete internet

Re: [R] (no subject)

2014-10-10 Thread Sven E. Templer
follow instructions on https://stat.ethz.ch/mailman/listinfo/r-help at To unsubscribe from R-help, get a password reminder, or change your subscription options enter your subscription email address: ... On 10 October 2014 16:16, Tasnuva Tabassum t.tasn...@gmail.com wrote: I want to get rid of

Re: [R] Function on an array

2014-10-08 Thread Sven E. Templer
Dear Barry, some thoughts: 1) e in your function status_fnc is a vector when applied on a matrix like object, but you index it as a matrix (e[,i] should be e[i]). 2) You can simplify the if statement by using the function any (replacing all the OR statements) on the vector, so use any(e=='Y')

[R] Obtain 00Index.html

2014-09-30 Thread Sven E. Templer
Hello, how can I open (by an R command) the index page in html mode, as obtained by: options(browser=firefox) # or any other options(help_type=html) ?help # and then following the html reference on the page bottom named Index In text mode I know library(help='utils') to open the utils package

Re: [R] how to get the rows that satisfy a specific condition

2014-09-28 Thread Sven E. Templer
in ?which read about arr.ind following jims assumption (column instead of row indices is what you want) this also works: m - matrix(1:20,4) unique(which(m11, arr.ind = T)[,col]) On 27 September 2014 12:23, Jim Lemon j...@bitwrit.com.au wrote: On Fri, 26 Sep 2014 10:15:14 PM Fix Ace wrote:

Re: [R] adding rows

2014-09-25 Thread Sven E. Templer
see inline for another vectorized example. On 25 September 2014 23:05, David L Carlson dcarl...@tamu.edu wrote: Another approach fun - function(i, dat=x) { grp - rep(1:(nrow(dat)/i), each=i) aggregate(dat[1:length(grp),]~grp, FUN=sum) } lapply(2:6, fun, dat=TT)

Re: [R] How to use multi paragraph comment like /* and */ in cpp?

2014-09-09 Thread Sven E. Templer
One way I know to do this is (in bash) to use a dummy variable and make the comment a multiline character string: dummy - c( This is my multiline comment or code block. ) or if printing does not disturb you, just use: ... Use ' if you have in the block. Other workarounds are here, which you