[R] detect escape character

2014-06-03 Thread Adrian Dușa
Dear All, I should be knowing this, but not get it right... For a string like this: Man\Woman I would like to detect the escape character \ and replace it with /. Tried various ways using gsub(), but don't get it right yet. Any suggestion would be highly welcomed... Thank you, Adrian --

Re: [R] detect escape character

2014-06-05 Thread Adrian Dușa
On Tue, Jun 3, 2014 at 8:44 PM, David Winsemius dwinsem...@comcast.net wrote: On Jun 3, 2014, at 11:03 AM, Adrian Dușa wrote: Dear All, I should be knowing this, but not get it right... I'm a little surprised to see you ask this, too, but we each have lacunae in our R knowledge, so I

Re: [R] Save P values calculated with anova

2013-11-04 Thread Adrian Dușa
That would be: MyAnova$Pr(F) and since that is an Anova table, you actually only need the first value: MyAnova$Pr(F)[1] Hope this helps, Adrian On Mon, Nov 4, 2013 at 4:10 PM, Anders Tisell anders.tis...@liu.se wrote: Hi, I have created a mixed linear model with one fixed factor and two

Re: [R] regex find anything which is not a number

2015-03-11 Thread Adrian Dușa
period. I tried to escape this, but it failed [0-9]+ == followed by one or more digits $ == followed by the end of the string. so: optional minus, followed by one or more digits, optionally followed by (a period with one or more ending digits). On Wed, Mar 11, 2015 at 2:27 PM, Adrian Dușa

[R] regex find anything which is not a number

2015-03-11 Thread Adrian Dușa
Hi everyone, I need a regular expression to find those positions in a character vector which contain something which is not a number (either positive or negative, having decimals or not). myvector - c(a3, N.A, 1.2, -3, 3-2, 2.) In this vector, only positions 3 and 4 are numbers, the rest should

Re: [R] regex find anything which is not a number

2015-03-12 Thread Adrian Dușa
On Thu, Mar 12, 2015 at 9:52 PM, John McKown john.archie.mck...@gmail.com wrote: [...] One problem is that Adrian wanted, for some reason, to exclude numbers such as 2. but accept 2.0 . That is, no unnecessary trailing decimal point. as.numeric() will not fail on 2. since that is a number.

[R] open connection to system

2015-07-14 Thread Adrian Dușa
Dear list, Probably not the best subject line, but hopefully I can explain. I would like to use R and open a connection to a (system) command line base chess engine (for example, there is an open source one at stockfishchess.org) In the Terminal window (using MacOS), I can type two commands: $

Re: [R] fill the area outside a polygon

2015-12-02 Thread Adrian Dușa
On Wed, Dec 2, 2015 at 5:19 PM, David L Carlson wrote: > > Using only base graphics, one solution would be to embed the inner polygon in the outer one and turn off the border: > > par(mai=c(0, 0, 0, 0)) > plot(1:100, type="n") > polygon(c(0, 100, 100, 0, 0, 20, 80, 80, 20, 20,

Re: [R] fill the area outside a polygon

2015-12-03 Thread Adrian Dușa
On Wed, Dec 2, 2015 at 10:38 PM, Michael Sumner <mdsum...@gmail.com> wrote: > > On Wed, 2 Dec 2015 at 23:10 Adrian Dușa <dusa.adr...@unibuc.ro> wrote: > >> Dear All, >> >> I know how to fill a polygon, using a basic R graphics device: >> >

Re: [R] fill the area outside a polygon

2015-12-03 Thread Adrian Dușa
Hi Greg, On Wed, Dec 2, 2015 at 10:28 PM, Greg Snow <538...@gmail.com> wrote: > > Adrian, > > Draw the polygon once without the border and the whole in it, then go > back and draw the border around the outer polygon without any fill. I thought about it too, but this only works on a Windows

[R] fill the area outside a polygon

2015-12-02 Thread Adrian Dușa
Dear All, I know how to fill a polygon, using a basic R graphics device: par(mai=c(0, 0, 0, 0)) plot(1:100, type="n") polygon(c(20, 80, 80, 20), c(20, 20, 80, 80), col="lightblue") But let's say I have an outer polygon like this: polygon(c(0,100,100,0), c(0,0,100,100)) Is it possible to fill

Re: [R] regexp inside and outside brackets

2015-12-11 Thread Adrian Dușa
ular expressions... they are hardly R-specific. > > -- > Sent from my phone. Please excuse my brevity. > > On December 11, 2015 5:50:28 AM PST, "Adrian Dușa" <dusa.adr...@unibuc.ro> > wrote: >> >> For the regexp aficionados, out there: >> >> I need

[R] regexp inside and outside brackets

2015-12-11 Thread Adrian Dușa
For the regexp aficionados, out there: I need a regular expression to extract either everything within some brackets, or everything outside the brackets, in a string. This would be the test string: "A1{0}~B0{1} CO{a2}NN{12}" Everything outside the brackets would be: "A1 ~B0 CO NN" and

Re: [R] regexp inside and outside brackets

2015-12-11 Thread Adrian Dușa
> Also, I was a bit hypo-caffeinated ... ;-) > > Regards, > > Marc > > > > On Dec 11, 2015, at 9:12 AM, Adrian Dușa <dusa.adr...@unibuc.ro> wrote: > > > > Thanks very much, Marc and Jeff. > > Jeff's solutions seem to be simple one liners. I really need to l

Re: [R] Bezier to line segments

2016-01-06 Thread Adrian Dușa
I just found the package "bezier". Trying to find the needle, I missed the haystack... On Wed, Jan 6, 2016 at 9:56 AM, Adrian Dușa <dusa.adr...@unibuc.ro> wrote: > Dear All, > > I am interested into transforming Bezier curves (or general splines) to a > series of lin

[R] Bezier to line segments

2016-01-05 Thread Adrian Dușa
Dear All, I am interested into transforming Bezier curves (or general splines) to a series of line segments. For simplicity, the Bezier curves are either cubic (arches, no inflection points) or they have at most one inflection point. The entry parameters are exactly four points (with x and y

Re: [R] Bezier to line segments

2016-01-09 Thread Adrian Dușa
be made similar to Bezier curves > (but not exactly the same). The function returns a set of coordinates > (when draw=FALSE) that represent line segments for drawing the > approximate curve. > > On Wed, Jan 6, 2016 at 6:43 AM, Adrian Dușa <dusa.adr...@unibuc.ro> wrote:

Re: [R] detect computer drives

2015-11-27 Thread Adrian Dușa
On Fri, Nov 27, 2015 at 4:03 PM, Dirk Eddelbuettel wrote: > > On 27 November 2015 at 15:43, Adrian Duşa wrote: > | Is there a method to detect the computer's drives? > | That would include USB sticks, when they are recognised by the operating > | system. > > That is very

[R] detect computer drives

2015-11-27 Thread Adrian Dușa
Dear All, Is there a method to detect the computer's drives? That would include USB sticks, when they are recognised by the operating system. I believe to have read somewhere it's possible, but I am unable to find that message. Thank you for any hint, Adrian -- Adrian Dusa University of

Re: [R] Importing data from a text file with no separator

2016-06-08 Thread Adrian Dușa
See: ?read.fwf Example: > ff <- tempfile() > cat(file = ff, "10030614911608", "10030614911608", sep = "\n") > read.fwf(ff, widths = c(2,8,10), colClasses = "character") V1 V2 V3 1 10 03061490 000116 2 10 03061490 000116 > unlink(ff) Hth, Adrian On Thu,

[R] [R-pkgs] new package: venn

2016-01-11 Thread Adrian Dușa
Dear R users, I would like to announce a new package that has just the appeared on CRAN, called "venn" version 1.0: http://cran.r-project.org/web/packages/venn/ (binaries will appear in one or two days) Although there are quite a few packages that draw Venn diagrams, there are a number of

Re: [R] Split Strings

2016-01-17 Thread Adrian Dușa
Try this: mylist <- list("pc_m2_45_ssp3_wheat", "pc_m2_45_ssp3_wheat", "ssp3_maize", "m2_wheat") mylist <- lapply(mylist, function(x) unlist(strsplit(x, split="_"))) allstrings <- unique(unlist(mylist)) lapply(mylist, function(x) allstrings[match(allstrings, x)]) [[1]] [1] "pc""m2""45"

Re: [R] How to create an executable file from R GUI?

2016-02-22 Thread Adrian Dușa
Feb 21, 2016 at 11:37 AM, Adrian Dușa <dusa.adr...@unibuc.ro> > wrote: > >> Oh, thanks Peter, good example for Mac, but indeed not working on Windows. >> For a completely cross-platform solution (that is, including Windows which >> is what Zahra wants), I believe s

Re: [R] missing values in csv file

2016-02-17 Thread Adrian Dușa
On Wed, Feb 17, 2016 at 12:04 PM, Jan Kacaba wrote: > In my original data a csv file I have missing values. If I use read.table > the missing values are replaced by NAs. > That is the normal way of dealing with missing values, in R. Is it possible to get object where

Re: [R] How to create an executable file from R GUI?

2016-02-18 Thread Adrian Dușa
Simon, Greg, That is the very reason why I've given up on Tck/Tk, in favor of shiny. The user interface opens up in a webpage, without opening the normal R console (it only opens a Terminal window). To exemplify, package QCAGUI has a function called runGUI(), and on Windows it's a simple matter

Re: [R] How to create an executable file from R GUI?

2016-02-19 Thread Adrian Dușa
gt; you've written? > > ------ > * From: * Adrian Dușa <dusa.adr...@unibuc.ro>; > * To: * Greg Snow <538...@gmail.com>; > * Cc: * simon0...@yahoo.com <simon0...@yahoo.com>; r-help@r-project.org < > r-help@r-project.org>; > * Subject: * Re: [

Re: [R] How to create an executable file from R GUI?

2016-02-20 Thread Adrian Dușa
I don't know about RGtk2, never tried it, but I assume it is similar to Tcl/Tk situation: you need to open an R console to make it work. My approach works, only because I am using the package shiny, and R's web server can be started via a script in the terminal. I might be wrong of course, but I

Re: [R] How to create an executable file from R GUI?

2016-02-21 Thread Adrian Dușa
able("exit") > > Make it executable (chmod +x foo.app) and you can double-click it in the > Finder. (Notice that as written, there is nothing to shut down the tkwait > loop, so you'll have to force quit it.) > > Peter D. > > > On 19 Feb 2016, at 23:36 , Adrian Du

Re: [R] formula argument evaluation

2016-04-13 Thread Adrian Dușa
ring anyways (which is parsed by other functions). On Tue, Apr 12, 2016 at 6:20 PM, Richard M. Heiberger <r...@temple.edu> wrote: > Would making it regular function %=>%, using "%" instead of quotes, > work for you? > > On Tue, Apr 12, 2016 at 11:09 AM, Adrian Dușa &l

Re: [R] sorting of files using system

2016-04-09 Thread Adrian Dușa
I suspect it is a problem related to locales: R and the base Ubuntu might be using different locales, hence the source of the different sorting. Can't say if this is the problem in your case, but it might be. Adrian On Sat, Apr 9, 2016 at 12:18 AM, Maria Ninova wrote: >

[R] formula argument evaluation

2016-04-12 Thread Adrian Dușa
I have a simple function such as: foo <- function(x) { call <- lapply(match.call(), deparse) testit <- capture.output(tryCatch(eval(x), error = function(e) e)) if (grepl("Error", testit)) { return(call$x) } } and I would like to detect a formula when x is not an object:

Re: [R] formula argument evaluation

2016-04-12 Thread Adrian Dușa
On Tue, Apr 12, 2016 at 2:08 PM, Duncan Murdoch wrote: > [...] > > It never gets to evaluating it. It is not a legal R statement, so the parser signals an error. > If you want to pass arbitrary strings to a function, you need to put them in quotes. I see. I thought it

Re: [R] Problem with <= (less than or equal): not giving the expected result

2016-04-05 Thread Adrian Dușa
Yes, that does have to do with floating point representation. I use this function for these types of comparisons (works with values as well as with vectors): check.equal <- function(x, y) { check.vector <- as.logical(unlist(lapply(x, all.equal, y))) check.vector[is.na(check.vector)] <-

Re: [R] Bug in by() function which works for some FUN argument and does not work for others

2016-04-14 Thread Adrian Dușa
I think you are not using the best function for what your intentions are. Try: > by(data=mtcars, INDICES=list(as.factor(mtcars$am)), FUN=colMeans) : 0 mpg cyldisp hpdrat wt qsec vs 17.1473684 6.9473684 290.3789474 160.2631579

Re: [R] formula argument evaluation

2016-04-14 Thread Adrian Dușa
!is.environment(object)) { > object <- as.list(object) > names <- names(object) > for (i in seq_along(object)) { > str.language(object[[i]], ..., level = level + 1, > name = names[i]) > } > } > a$names &l

Re: [R] Beginner needs help with R

2017-02-06 Thread Adrian Dușa
Two methods, among others: seq1 <- paste("DQ", sprintf("%0*d", 6, seq(060054, 060060)), sep = "") or seq1 <- paste("DQ", formatC(seq(060054, 060060), dig = 5, flag = 0), sep = "") Hth, Adrian On Mon, Feb 6, 2017 at 3:50 AM, Nabila Arbi wrote: > Dear R-Help Team!

Re: [R] A strange arithmetic error in R (maybe a bug)

2017-02-18 Thread Adrian Dușa
There is no bug, of course, this is a common floating point arithmetic misunderstanding. > print(2.01, digits = 20) [1] 2.0097868 Please search for "What every scientist should know about floating-point arithmetic" and you'll hopefully understand what the "bug" is. Hth, Adrian On

Re: [R] evaluating expressions as R console

2016-09-05 Thread Adrian Dușa
On Mon, Sep 5, 2016 at 5:33 PM, Bert Gunter wrote: > > I'm sharing this with r-help, as your detailed response might help > others help you. Oh, my bad (thought I had replied to all). I wanted to add anyways the intended result seems to be possible. If pasting the code

Re: [R] evaluating expressions as R console

2016-09-05 Thread Adrian Dușa
;The trouble with having an open mind is that people keep coming along > and sticking things into it." > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) > > > On Sun, Sep 4, 2016 at 11:45 PM, Adrian Dușa <dusa.adr...@unibuc.ro> > wrote:

[R] evaluating expressions as R console

2016-09-04 Thread Adrian Dușa
Dear R users, I am trying to simulate a pseudo R console, evaluating commands. This is a simple example of a series of command lines which get evaluated: foo <- function(x) { print(x) } print)foo) foo(2) If I copied and pasted this example in an R console, this is the result to replicate

[R] separate commands by semicolon

2016-09-15 Thread Adrian Dușa
Dear R-helpers, When parsing a text, I would like to separate commands written on the same line, by a semicolon. Something like: x <- "foo <- '3;4'; bar <- \"don't ; use semicolons\"" Ideally, that would translate to these two commands in a character vector of length 2: foo <- '3;4' bar <-

Re: [R] separate commands by semicolon

2016-09-15 Thread Adrian Dușa
On Thu, Sep 15, 2016 at 10:28 PM, William Dunlap wrote: > The most reliable way to split such lines is with parse(text=x). > Regular expressions don't do well with context-free grammars. > Oh, that's right of course. > as.character(parse(text = x)) [1] "foo <- \"3;4\""

Re: [R] Loop to check for large dataset

2016-10-08 Thread Adrian Dușa
It would help to have a minimal, reproducible example. Unless revealing the structure of your FD object, it is difficult to understand how a column having 61327 values would be "consistent over an 1 to 157 interval": is this interval cyclic until it reaches 61327 values? >From your example using

Re: [R] separate commands by semicolon

2016-09-19 Thread Adrian Dușa
On Sun, Sep 18, 2016 at 12:34 AM, Peter Langfelder < peter.langfel...@gmail.com> wrote: > On Sat, Sep 17, 2016 at 2:12 PM, David Winsemius > wrote: > > Not entirely clear. If you were intending to just get character output > then you could just use: > > > > strsplit(txt,

Re: [R] separate commands by semicolon

2016-09-19 Thread Adrian Dușa
n't ; use semicolons\"" [3] " foo <- '3;4'" " ls(" Excellent, thanks very much, Adrian On Mon, Sep 19, 2016 at 3:19 PM, Duncan Murdoch <murdoch.dun...@gmail.com> wrote: > On 19/09/2016 7:59 AM, Adrian Dușa wrote: > >> On Sun

Re: [R] separate commands by semicolon

2016-09-17 Thread Adrian Dușa
: [1] "print(2)" "ls(" I hope this explains the situation, Adrian On Thu, Sep 15, 2016 at 11:02 PM, Adrian Dușa <dusa.adr...@unibuc.ro> wrote: > On Thu, Sep 15, 2016 at 10:28 PM, William Dunlap <wdun...@tibco.com> > wrote: > >> The most reliable way t

Re: [R] Loop to check for large dataset

2016-10-10 Thread Adrian Dușa
Granted,, there are better solutions than my "KISS" (keep it simple and stupid) example. Hopefully, Christoph will have learned from both. Best, Adrian On 10 Oct 2016 13:44, "PIKAL Petr" wrote: > Hi > > > > Given this example data, you can get same answer with less

Re: [R] Loop to check for large dataset

2016-10-10 Thread Adrian Dușa
This is an example of how a reproducible code looks like, assuming you have three columns in your dataset named S (store), P (product) and W (week), and also assuming they have integer values from 1 to 19, 1 to 22 and 1 to 157 respectively: # mydata <- expand.grid(seq(19), seq(22),

Re: [R] Help

2017-06-20 Thread Adrian Dușa
One solution, among many, involving recoding. There is a function in package QCA called recode() (similar, but in my opinion more flexible than the same function recode() in package car) > library(QCA) > ind.davis$Ageclass <- recode(ind.davis$Ageclass, "adult = Adult; Juvanile = Juvenile;

Re: [R] problems in converting numeric to character

2018-06-07 Thread Adrian Dușa
Does this helps? > formatC(x, digits = 1, format = "f") [1] "1.0" "2.0" "2.0" "2.1" On Thu, Jun 7, 2018 at 10:08 PM 刘瑞阳 wrote: > Hi, > I am having trouble converting numeric to characters in the format I > desire. To be more specific, I have a number of numeric as follows: > >

[R] [R-pkgs] CRAN has a new package: declared

2021-06-18 Thread Adrian Dușa
Dear All, A new package called 'declared' has made it to CRAN (platform specific binaries in due course). This might be useful for social scientists, where multiple (types of) missing values are declared for any given variable. The package has a similar functionality to packages 'haven' and

Re: [R] .Rdata not loading

2021-12-24 Thread Adrian Dușa
On Fri, 24 Dec 2021 at 17:35, Rich Shepard wrote: > On Fri, 24 Dec 2021, Rasmus Liland wrote: > > > If you want to look at Rdata-files in a quick way in the > > terminal, use this little gem in your .zshrc.local: > > > > readrdata() { Rscript -e "options(width=$COLUMNS); load('$1'); >

Re: [R] Creating NA equivalent

2021-12-26 Thread Adrian Dușa
and season's greetings, Adrian On Tue, 21 Dec 2021 at 21:45, Avi Gross wrote: > I wonder if the package Adrian Dușa created might be helpful or point you > along the way. > > It was eventually named "declared" > > https://cran.r-project.org/web/packages/declared/index.h

[R] [R-pkgs] new version of package declared

2022-03-17 Thread Adrian Dușa
Dear community, Version 0.12 of the package declared has just made it on CRAN. Apart from the usual functions to declare labels for regular and missing values, this version has a suite of new functions to calculate various weighted frequencies and summaries. The weighted versions are heavily

[R] [R-pkgs] new version of package declared

2022-09-29 Thread Adrian Dușa
Dear R-list, It gives me great pleasure to announce the release of version 0.18 of package declared, that makes a difference between empty missing values (the current NAs in R) and declared missing values (NAs with a reason). Besides an automatic detection of such values by most base R

Re: [R] Variable and value labels

2023-07-13 Thread Adrian Dușa
Anupam, This is very general, and it also depends on the scientific domain. Factors do solve the value labels, but they drop the (original) values. They also lose the connection to the different types of missing values (an important topic in the social sciences). Base R provides as much as it

[R] replacing unicode characters

2023-06-28 Thread Adrian Dușa
Dear list, Building on the example from ?iconv: x <- "fa\xE7ile" xx <- iconv(x, "latin1", "UTF-8") # "façile" and: iconv(xx, "UTF-8", "ASCII", "Unicode") # "faile" This is the type of result I sometimes get from an R script that I cannot reproduce here, because it depends on a terminal process

Re: [R] replacing unicode characters

2023-06-30 Thread Adrian Dușa
quot;fa\xE7ile" > > xx <- iconv(x, "latin1", "UTF-8") > > iconv(xx, "UTF-8", "ASCII", "c99") > [1] "fa\\u00e7ile" > > > ``` > > For future reference, you can find this in section Examples of the > help page ?