Re: [R] Counting enumerated items in each element of a character vector

2017-04-25 Thread Michael Hannon
Thanks, Ista. I thought there might be a "tidy" way to do this, but I hadn't use stringr. -- Mike On Tue, Apr 25, 2017 at 8:47 PM, Ista Zahn wrote: > stringr::str_count (and stringi::stri_count that it wraps) interpret > the pattern argument as a regular expression by default. > > Best, > Ista

Re: [R] Counting enumerated items in each element of a character vector

2017-04-25 Thread Ista Zahn
stringr::str_count (and stringi::stri_count that it wraps) interpret the pattern argument as a regular expression by default. Best, Ista On Tue, Apr 25, 2017 at 11:40 PM, Michael Hannon wrote: > I like Boris's "Hadley" solution. For the record, I've appended a > version that uses regular expres

Re: [R] Counting enumerated items in each element of a character vector

2017-04-25 Thread Michael Hannon
I like Boris's "Hadley" solution. For the record, I've appended a version that uses regular expressions, the only benefit of which is that it could be generalized to find more-complicated patterns. -- Mike counts <- sapply(text1, function(next_string) { loc_example <- length(gregexpr("Exampl

Re: [R] Counting enumerated items in each element of a character vector

2017-04-25 Thread Boris Steipe
I should add: there's a str_count() function in the stringr package. library(stringr) str_count(text1, "Example") # [1] 5 5 5 5 I guess that would be the neater solution. B. > On Apr 25, 2017, at 8:23 PM, Boris Steipe wrote: > > How about: > > unlist(lapply(strsplit(text1, "Example"), func

Re: [R] Counting enumerated items in each element of a character vector

2017-04-25 Thread Boris Steipe
How about: unlist(lapply(strsplit(text1, "Example"), function(x) { length(x) - 1 } )) Splitting your string on the five "Examples" in each gives six elements. length(x) - 1 is the number of matches. You can use any regex instead of "example" if you need to tweak what you are looking for. B.

[R] Counting enumerated items in each element of a character vector

2017-04-25 Thread Dan Abner
Hi all, I am looking for a streamlined way of counting the number of enumerated items are each element of a character vector. For example: text1<-c("This is an example. List 1 1) Example 1 2) Example 2 10) Example 10 List 2 1) Example 1 2) Example 2 These have been examples.","This is another ex

Re: [R] R Date Time

2017-04-25 Thread Dirk Eddelbuettel
On 25 April 2017 at 18:05, Duncan Murdoch wrote: | On 25/04/2017 5:41 PM, Dirk Eddelbuettel wrote: | > | > On 25 April 2017 at 16:04, Jeff Reichman wrote: | > | R Users | > | | > | Having problems converting the following DTG into an R recognized date/time | > | field | > | | > | 01-01-2016T14:02

Re: [R] R Date Time

2017-04-25 Thread Duncan Murdoch
On 25/04/2017 5:41 PM, Dirk Eddelbuettel wrote: On 25 April 2017 at 16:04, Jeff Reichman wrote: | R Users | | Having problems converting the following DTG into an R recognized date/time | field | | 01-01-2016T14:02:23.325 | | Would I separate it into a date field and time filed then put it back

Re: [R] R Date Time

2017-04-25 Thread Dirk Eddelbuettel
On 25 April 2017 at 16:04, Jeff Reichman wrote: | R Users | | Having problems converting the following DTG into an R recognized date/time | field | | 01-01-2016T14:02:23.325 | | Would I separate it into a date field and time filed then put it back | together??? The anytime package (on CRAN) do

Re: [R] R Date Time

2017-04-25 Thread William Dunlap via R-help
> z <- as.POSIXct("01-01-2016T14:02:23.325", format="%d-%m-%YT%H:%M:%OS") > dput(z) structure(1451685743.325, class = c("POSIXct", "POSIXt"), tzone = "") > z [1] "2016-01-01 14:02:23 PST" > format(z, "%H:%M:%OS3 on %b %d, %Y") [1] "14:02:23.325 on Jan 01, 2016" (Don't separate the date and time pa

Re: [R] R Date Time

2017-04-25 Thread Duncan Murdoch
On 25/04/2017 5:04 PM, Jeff Reichman wrote: R Users Having problems converting the following DTG into an R recognized date/time field 01-01-2016T14:02:23.325 Would I separate it into a date field and time filed then put it back together??? This appears to work (though I'm not sure whe

[R] R Date Time

2017-04-25 Thread Jeff Reichman
R Users Having problems converting the following DTG into an R recognized date/time field 01-01-2016T14:02:23.325 Would I separate it into a date field and time filed then put it back together??? Jeff [[alternative HTML version deleted]] __

Re: [R] Multiple-Response Analysis: Cleaning of Duplicate Codes

2017-04-25 Thread Boris Steipe
How about: d_sample_1 <- floor(d_sample/100) * 100 for (i in 1:nrow(d_sample_1)) { d_sample_1[i, duplicated(unlist(d_sample_1[i, ]))] <- NA } B. > On Apr 25, 2017, at 1:10 PM, Bert Gunter wrote: > > If I understand you correctly, one way is: > >> z <- rep(LETTERS[1:3],4) >> z > [1] "A

Re: [R] Multiple-Response Analysis: Cleaning of Duplicate Codes

2017-04-25 Thread Bert Gunter
If I understand you correctly, one way is: > z <- rep(LETTERS[1:3],4) > z [1] "A" "B" "C" "A" "B" "C" "A" "B" "C" "A" "B" "C" > z[!duplicated(z)] [1] "A" "B" "C" ?duplicated -- Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it

Re: [R] asking for help

2017-04-25 Thread Saifuddin, Miah Mohammad
Dear Altruist, Thank you so much. This does it. I shall keep connected. Regards, Miah From: Anthoni, Peter (IMK) Sent: Tuesday, April 25, 2017 8:38 AM To: Saifuddin, Miah Mohammad Cc: Thomas Mailund; r-help@r-project.org; PIKAL Petr Subject: Re: [R] aski

[R] R 3.4.0 on Windows 7 Home Premium installed apparently fine, but packages failing to load ...

2017-04-25 Thread Jan Galkowski
Hello! I welcome the new *R* 3.4.0. I installed it on my Windows 7 Home Premium [Service Pack 1, updated to latest, running on an HP AMD(Phenom) II 955 X4 Processor, 3.20 GHz, 16 GB RAM, 64-bit, with lots of free storage on disk and a solid state disk for virtual cache]. It was installed atop the

Re: [R] Delayed evaluation / lazy expression evaluation

2017-04-25 Thread Thomas Mailund
If anyone are interested, I found a solution for lazy lists. A simplified version of their construction and access looks like this: nil <- function() NULL cons <- function(car, cdr) {   force(car)   force(cdr)   function() list(car = car, cdr = cdr) } is_nil <- function(lst) is.null(lst()) car <

[R] Multiple-Response Analysis: Cleaning of Duplicate Codes

2017-04-25 Thread G . Maubach
Hi All, in my current project I am working with multiple-response questions (MRSets): -- Coding -- 100 Main Code 1 110 Sub Code 1.1 120 Sub Code 1.2 130 Sub Code 1.3 200 Main Code 2 210 Sub Code 2.1 220 Sub Code 2.2 230 Sub Code 2.3 300 Main Code 3 310 Sub Code 3.1 320 Sub Code 3.2 The coding

Re: [R] asking for help

2017-04-25 Thread Anthoni, Peter (IMK)
Hi, the cut function might be helpful. vec=1: 163863 fcut=cut(vec,seq(1, 163863+1,by= 6069),include.lowest = T,right=F) aggregate(vec,by=list(fcut),min) aggregate(vec,by=list(fcut),max) cheers Peter On 25. Apr 2017, at 14:33, PIKAL Petr mailto:petr.pi...@precheza.cz>> wrote: Hi -Origin

Re: [R] R-3.4.0 and survival_2.41-3 ..

2017-04-25 Thread Göran Broström
On 2017-04-25 10:34, Martin Maechler wrote: Göran Broström on Tue, 25 Apr 2017 10:22:48 +0200 writes: > I installed R-3.4.0 and got problems with the survival package, for instance > >> library(survival) >> mort <- data.frame(exit = 1:4, event = rep(1, 4), x

Re: [R] asking for help

2017-04-25 Thread PIKAL Petr
Hi > -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Thomas > Mailund > Sent: Tuesday, April 25, 2017 11:20 AM > To: r-help@r-project.org; Saifuddin, Miah Mohammad > > Subject: Re: [R] asking for help > > If you write something like > > indices <- rep(

Re: [R] R-3.4.0 and survival_2.41-3 ..

2017-04-25 Thread Göran Broström
Right, normally this is how it works for me when I install R from source. In this case, on this computer, I use the debian/ubuntu packaging, and then it is necessary to 'rebuild' packages, obviously. Thanks, Göran On 2017-04-25 12:20, Viechtbauer Wolfgang (SP) wrote: Sort of an obvious approa

Re: [R] Frequency of Combinations

2017-04-25 Thread Thierry Onkelinx
Dear Mustafa, Please keep the mailing list in cc. Since you claim to have written the code, you can share the code so we can review it. That makes more sense than having us to write code for you... Best regards, ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute fo

Re: [R] R-3.4.0 and survival_2.41-3 ..

2017-04-25 Thread Viechtbauer Wolfgang (SP)
Sort of an obvious approach, but after every upgrade (regardless if it is major/minor), I just delete my entire personal library and reinstall everything from scratch. For this, I have a script that includes just a bunch of install.packages() calls. Like: install.packages(c("lme4", "glmmML", "M

Re: [R] The effect of tolerance in all.equal()

2017-04-25 Thread Martin Maechler
> Ashim Kapoor > on Tue, 25 Apr 2017 14:02:18 +0530 writes: > Dear all, > I am not able to understand the interplay of absolute vs relative and > tolerance in the use of all.equal > If I want to find out if absolute differences between 2 numbers/vectors are > big

Re: [R] asking for help

2017-04-25 Thread Thomas Mailund
If you write something like indices <- rep(1:(163863/6069), each = 6069) you can get the i’th block of rows with table[indices == i,] It looks like a little more work than a loop would be since you have to run through all rows for each block, but the implicit loop in this approach is likely t

Re: [R] R-3.4.0 and survival_2.41-3 ..

2017-04-25 Thread Göran Broström
Thanks Martin, that helped! Göran On 2017-04-25 10:34, Martin Maechler wrote: Göran Broström on Tue, 25 Apr 2017 10:22:48 +0200 writes: > I installed R-3.4.0 and got problems with the survival package, for instance > >> library(survival) >> mort <- data.fra

Re: [R] R-3.4.0 and survival_2.41-3 ..

2017-04-25 Thread Martin Maechler
> Göran Broström > on Tue, 25 Apr 2017 10:22:48 +0200 writes: > I installed R-3.4.0 and got problems with the survival package, for instance > >> library(survival) >> mort <- data.frame(exit = 1:4, event = rep(1, 4), x = c(0, 1, 0, 1)) >> fit <- coxph

[R] The effect of tolerance in all.equal()

2017-04-25 Thread Ashim Kapoor
Dear all, I am not able to understand the interplay of absolute vs relative and tolerance in the use of all.equal If I want to find out if absolute differences between 2 numbers/vectors are bigger than a given tolerance I would do: all.equal(1,1.1,scale=1,tol= .1) If I want to find out if relat

[R] R-3.4.0 and survival_2.41-3

2017-04-25 Thread Göran Broström
I installed R-3.4.0 and got problems with the survival package, for instance > library(survival) > mort <- data.frame(exit = 1:4, event = rep(1, 4), x = c(0, 1, 0, 1)) > fit <- coxph(Surv(exit, event) ~ x, data = mort) Error in fitter(X, Y, strats, offset, init, control, weights = we