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 wrote: > Windows 7 64-bit > R 3.1.3 > RStudio 0.98.1

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] FAL

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 charact

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

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 wrote: >> Jim Lemon >> on Mon, 26 Jan 2015 11:21:03 +1100 writes: > > > Hi Allen, How about this: > >

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 wrote: > Huh?? > >> ifelse(TRUE, a <- 2L, a <- 3L)

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 rep

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 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&l

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 wrote: > Hello everyone, > > I

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 iter

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 https://st

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 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 return): > mylist2 <

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

2015-03-30 Thread Sven E. Templer
ct (the data.frames) with each rowSums output. So, use cbind within your first lapply. p.s. Is it a standard 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, S

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

2015-03-30 Thread Sven E. Templer
y not wisdom." > Clifford Stoll > > > > > On Mon, Mar 30, 2015 at 7:56 AM, Sven E. Templer > wrote: > > On 30 March 2015 at 16:47, Sarah Goslee wrote: > > > >> colnames(e) <- paste0('pop',1:12) > >> > >> isn't a fun

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 wrote: > On Mon, Mar 30, 2015 at 11:43 AM, Sven E. Templer > wrote: > > > > > > On 30 March 2015 at 17:31, Bert Gunter wrote: > >> > >> Sarah's statement is correct. > >> > >> So is yours.

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)) } emp

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, whic

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 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 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(m>11, arr.ind = T)[,"col"]) On 27 September 2014 12:23, Jim Lemon wrote: > On Fri, 26 Sep 2014 10:15:14 PM Fix Ace wrote: >> Hello, there, >>

[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 pack

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') her

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 wrote: > I want to get rid of this thread. what

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 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) > | > p

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, wrote: > Subscribers, > > A version of R is installed in a virtual machine, which has complete > internet access via the host.

Re: [R] package installation failure virtualisation environment

2014-10-15 Thread Sven E. Templer
; [4] " Copyright (C) 2007 Free Software Foundation, Inc. <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, wrote: > On 2014-10

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 desired

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

2014-10-22 Thread Sven E. Templer
> On Oct 22, 2014 12:33 AM, "Sven E. Templer" 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

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 <- melt(df1

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 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 6 12

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],