Re: [R] Converting english words to numeric equivalents

2008-07-28 Thread Hans-Joerg Bibiko
On 28 Jul 2008, at 12:23, Hans-Joerg Bibiko wrote: How about this? unletter <- function(word) { gsub('-64',' ',paste(sprintf("%02d",utf8ToInt(tolower(word)) - 96),collapse='')) } unletter("abc") [1] "010203" unletter("

Re: [R] Converting english words to numeric equivalents

2008-07-28 Thread Hans-Joerg Bibiko
How about this? unletter <- function(word) { gsub('-64',' ',paste(sprintf("%02d",utf8ToInt(tolower(word)) - 96),collapse='')) } unletter("abc") [1] "010203" unletter("Aw") [1] "0123" unletter("I walk to school") [1] "09 23011211 2015 190308151512" --Hans

Re: [R] Similarity matching with probabilities

2008-06-27 Thread Hans-Joerg Bibiko
On 27 Jun 2008, at 14:30, francogrex wrote: Hello, It's just a strange coincidence that someone posted just very recently a question about matching. I know there are several match function in the base package (such as match, pmatch, charmatch, and the gsub etc) but I can't seem to use

Re: [R] matching problem

2008-06-27 Thread Hans-Joerg Bibiko
On 27 Jun 2008, at 13:56, Tom.O wrote: Well I have tried that and it's unfortuanally not the solution. This return all the characters in the string, but I dont want the characters after the ending non-character symbol. Only the starting characters ore of interest. gsub("\\W*","", myexst

Re: [R] matching problem

2008-06-27 Thread Hans-Joerg Bibiko
On 27 Jun 2008, at 12:23, Tom.O wrote: Hi R gurus I have a matching problem that I cant solve. I have tried multiple solutions and searched varius help-sites but I cant get it to work. This is the problem myexstrings = c("*AAA.AA","BBB BB","*.CCC.","**dd- d") what I want do do is to remov

Re: [R] avoid using Dingbats symbols for points()

2008-06-25 Thread Hans-Joerg Bibiko
On 25 Jun 2008, at 15:22, Prof Brian Ripley wrote: Please look at the NEWS for R-devel, which was an option to work around this known bug in Adobe Illustrator. Thanks a lot for the hint. (Of course, the R posting guide suggested this for before posting.) I looked at several mailing lists

[R] avoid using Dingbats symbols for points()

2008-06-25 Thread Hans-Joerg Bibiko
Hi, I came across with a tiny problem. E.g.: pdf() plot(1:5) points(2, 3, cex=10, pch=21, bg="grey", lwd=0.3) points(2, 4, cex=1, pch=21, bg="grey", lwd=0.3) dev.off() If I execute this I'll get a nice PDF. Fine. But I want to edit this PDF with let's say by using Adobe Illustrator. If I t

Re: [R] Create a new vector with filled with mean value of original vector

2008-06-23 Thread Hans-Joerg Bibiko
On 23 Jun 2008, at 10:47, Gundala Viswanath wrote: Hi, Given this vector: x <- c(30.9, 60.1 , 70.0 , 73.0 , 75.0 , 83.9 , 93.1 , 97.6 , 98.8 , 113.9) [1] 30.9 60.1 70.0 73.0 75.0 83.9 93.1 97.6 98.8 113.9 mean.x <- mean(x) [1] 79.63 I wish to: 1. Create a new vector (n

Re: [R] How to return multiple values in a function

2008-06-23 Thread Hans-Joerg Bibiko
On 23 Jun 2008, at 10:23, Gundala Viswanath wrote: I apologize for this newbie question. But I can't seem to find in R online manual. 1. How can I return two values in a function? 2. How can I capture the values again of this function? myfunc <- function (array) { # do something with array

Re: [R] paste data

2008-06-18 Thread Hans-Joerg Bibiko
On 18 Jun 2008, at 10:36, Sybille Wendel wrote: I need a command. I have a lot of data in different dataframes(auto.0a, auto.0b, auto. 0c, auto.5Na,...), that has similar names. I could print the names all at once wih a loop with the command paste(), see below: plot<- c("0a","0b","0c","5

Re: [R] exit function in R?

2008-06-02 Thread Hans-Joerg Bibiko
On 2 Jun 2008, at 15:18, Federico Abascal wrote: Hi, This is likely an stupid question, but I cannot find the solution. I am searching for an "exit" function, to end the execution of an R script if some condition is not filled. Any clue? f <- function() { ... if (1 == 1) return(WHATEVER)

Re: [R] Unicode characters (R 2.7.0 on Windows XP SP3 and Hardy Heron)

2008-05-30 Thread Hans-Joerg Bibiko
Quoting Duncan Murdoch <[EMAIL PROTECTED]>: On 5/30/2008 12:58 PM, Hans-Jörg Bibiko wrote: to put it simply. Windows cannot handle utf-8 data. There is no utf-8 locale available. Code page 65001 is utf-8. Most text editors (including Notepad) include an option to save in the UTF-8 encodin

Re: [R] Modify string-regular expression

2008-05-30 Thread Hans-Joerg Bibiko
On 30 May 2008, at 11:25, Romain wrote: ... SCAN <- scan("File.txt",sep="\n", what="raw",blank.lines.skip=F) For (i in 1:Nb_param) { sub('Param[i] = Value_i-1','Param[i] = Value_i-2', SCAN) } ... I Know how to modify a string with sub when it is a fixed string : sub("(K =)([0-9]*)",paste

Re: [R] Creating/Concatenate Strings into another String

2008-05-29 Thread Hans-Joerg Bibiko
On 29 May 2008, at 10:39, Gundala Viswanath wrote: Is there a way to do it? For example I tried this: args<-commandArgs() fname <- args[6]."-".args[9] This would work under Perl :) Look for details: ?paste Try this: fname <- paste(args[6], ".", args[9], sep="") --Hans

Re: [R] UTF-8 or Unicode on Windows PC

2008-04-22 Thread Hans-Joerg Bibiko
On 21 Apr 2008, at 12:33, Prof Brian Ripley wrote: >> Is it possible to download a compiled snapshot of 2.7.0 for Windows >> XP? > Yes, http://cran.r-project.org/bin/windows/base/rtest.html > And it is due for release tomorrow. I played with 2.7.0 on Windows XP. I can do things which couldn't

Re: [R] UTF-8 or Unicode on Windows PC

2008-04-21 Thread Hans-Joerg Bibiko
On 21 Apr 2008, at 12:33, Prof Brian Ripley wrote: >> Is it possible to download a compiled snapshot of 2.7.0 for Windows >> XP? > > Yes, http://cran.r-project.org/bin/windows/base/rtest.html > And it is due for release tomorrow. Many thanks! I can see the progress :) But please forgive my in

Re: [R] UTF-8 or Unicode on Windows PC

2008-04-21 Thread Hans-Joerg Bibiko
On 21 Apr 2008, at 11:33, Prof Brian Ripley wrote: > You didn't tell us your R version (or your locale). Windows has no > UTF-8 locales, so a lot of work has had to be done to allow Unicode > chars to be handled on Windows. It was more or less a general question on R running on Windows PCs. No

[R] UTF-8 or Unicode on Windows PC

2008-04-21 Thread Hans-Joerg Bibiko
Dear all, is it possible to set up RGUI or JGR on Windows PC to UTF-8 encoding? I looked for it in mailing lists and in the documentation, but I couldn't figure out it. My problem is e.g. to split a given string containing German and Russian words into characters. example: > a <- "asdШas"

Re: [R] X 11

2008-04-16 Thread Hans-Joerg Bibiko
On 16 Apr 2008, at 12:21, Tommi Viitanen wrote: > For example I have open x11 with device numbers 1 and 2. I want to > make > plot to the device 1 without doing anythin to the 2 and not making a > new > x11. Something like ?: Do you mean something like dev.set(DEVICENUMBER) ? Have a look at

Re: [R] a question of alphabetical order

2008-04-16 Thread Hans-Joerg Bibiko
Hi, as already mentioned, sorting could be a pain. My solution to that is to write my own "order" routine for a given language. The idea is to transform the UTF-8 string into ASCII in such a way that the built-in order routine outputs the desired result. But this could be a very stony way.

Re: [R] How to create a legend without plot, and to use scientific notation for axes label ?

2008-04-10 Thread Hans-Joerg Bibiko
On 10 Apr 2008, at 12:57, Hans-Joerg Bibiko wrote: > > On 10 Apr 2008, at 12:33, Stanley Ng wrote: >> How can I use formatC to convert 600 to 6e5 and not 6e+05 ? >> >>> formatC(60) >> [1] "6e+05" >>> formatC(60, format="e

Re: [R] How to create a legend without plot, and to use scientific notation for axes label ?

2008-04-10 Thread Hans-Joerg Bibiko
On 10 Apr 2008, at 12:33, Stanley Ng wrote: > How can I use formatC to convert 600 to 6e5 and not 6e+05 ? > >> formatC(60) > [1] "6e+05" >> formatC(60, format="e", digit=0) > [1] "6e+05" Try this: gsub("([eE])(\\+?)(\\-?)0+", "\\1\\3", formatC(60, format="e", digit=0)) --Hans

Re: [R] Number of words in a string

2008-04-09 Thread Hans-Joerg Bibiko
On 10 Apr 2008, at 07:43, Shubha Vishwanath Karanth wrote: > So powerful, the gsub... But I really don’t understand the how the > regular expressions like " *\\S+$", need to be used and how to make > best use of it... Any article/material/links that I can go through? A good starting point is:

Re: [R] Number of words in a string

2008-04-09 Thread Hans-Joerg Bibiko
On 9 Apr 2008, at 17:44, Shubha Vishwanath Karanth wrote: > Got all the answers using ?strsplit... Is there any way without > using string split?... More specifically... How can I just extract > the last word in all the strings without using ?strsplit ? Oops, sorry. gsub(" *\w+$", "", C) sh

Re: [R] Number of words in a string

2008-04-09 Thread Hans-Joerg Bibiko
Something like that? gsub(" {1,}\w+$", "", C) __ 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 provide commented, minimal, self-contained,

Re: [R] Number of words in a string

2008-04-09 Thread Hans-Joerg Bibiko
On 9 Apr 2008, at 17:29, Markus Gesmann wrote: > Would this: > > sapply(strsplit(C, " "), length) > > work for? or length(unlist(strsplit(C, " "))) --Hans __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do rea

Re: [R] Replace values according to conditions

2008-04-09 Thread Hans-Joerg Bibiko
On 9 Apr 2008, at 09:51, [EMAIL PROTECTED] wrote: >> I have the following data called mydata in a data.frame >> >> Col1 Col2 Col3 Col4 Col5 >> 1 2 46 7 >> 8 8 73 5 >> 4 4 56 7 >> >> I want to replace the data according to the following condit

Re: [R] distance matrix as text file - how to import?

2008-04-09 Thread Hans-Joerg Bibiko
> On Tue, Apr 8, 2008 at 1:50 PM, Hans-Jörg Bibiko <[EMAIL PROTECTED]> > wrote: >> I was sent a text file containing a distance matrix à la: >> >> 1 >> 2 3 >> 4 5 6 Thanks a lot for your hints. At the end all hints ends up more or less in my "stony" way to do it. Let me summarize it. The clea