[R] Multi-Level classification

2013-06-15 Thread Deb Midya
Hi,
 
Thanks in advance.
 
I am using R-3.0.1 on Windows XP.
 
May I request you to assist me for the following please.
 
I have a data set where each instance has two or more levels. As for example, 
level 1 (binary): 0, 1; level 2 (binary): 0, 1 and so on. These levels are 
target variables. The predictor variables may be numeric / factor /... / mixed.
 
I am looking for models to analyse the data.
 
Is there any R-package(s) / R-code(s) / any others to solve Multi-Level 
classification problems?
 
I am looking for some literature also.
 
Once again, thank you very much for the time you have given.
 
Regards,
 
Deb
[[alternative HTML version deleted]]

__
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, reproducible code.


[R] Reading shape files in R

2013-06-15 Thread jickngea alexand
Hi everyone,
   I am new with spatial data analysis in R and I'm not 
able to read a shape because of this error message but the shapefile is in my 
work directory.  Here are my commands; ogrListLayers(border.shp), 
border=readOGR(border.shp,border). What does it mean?. Any help?
Error in file(paste(dsn, .Platform$file.sep, layer, .dbf, sep = ),  :  
cannot open the connection In addition: Warning message: In file(paste(dsn, 
.Platform$file.sep, layer, .dbf, sep = ),  : cannot open file 
'border.shp/border.dbf': No such file or directory



Alexand
Msc.agriScs

[[alternative HTML version deleted]]

__
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, reproducible code.


[R] passing of arguments to R CMD BATCH in bash script that is submitted to torque (Linux platform)

2013-06-15 Thread Franckx Laurent
Dear all

I want to call R repeatedly in batch mode from a bash script that is then 
submitted to torque.

My calls to R depend on optional arguments.

When I introduce these arguments as literals, the calls work fine, for instance:

R CMD BATCH  --no-save --args PERIOD='08' YEAR='2008' SC='BAU'  
preparecostvectors.R

However, the arguments PERIOD, YEAR and SC are really variables over which I 
'loop'.

When these variables are defined in the same script as the call to R CMD BATCH, 
this still works, for instance:

year=2008
sc=BAU
R CMD BATCH  --no-save --args PERIOD='08' YEAR=\$year\ SC=\$sc\   
preparecostvectors.R

Things go wrong when the script is called from another script, for instanced 
with:

qsub -v year=2008,sc=BAU  ATLAS_assign.sh

echo $sc and echo $year in ATLAS_assign.sh yield BAU and 2008 
respectively.

Thus, as far as I can see, nothing goes wrong in the passing of the optional 
arguments in qsub.

However,

R CMD BATCH  --no-save --args PERIOD='08' YEAR=\$year\ SC=\$sc\   
preparecostvectors.R

is not executed. I do not get even an Rout file, so I suppose the R script is 
not even called.

I suppose there is something wrong in the format in which I submit year and sc, 
but I do not see what.


Laurent Franckx, PhD
VITO NV
Boeretang 200, 2400 MOL, Belgium
Tel. + 32 14 33 58 22
Skype: laurent.franckx
laurent.fran...@vito.be
Visit our website: www.vito.be/english and http://www.vito.be/transport











[http://www.vito.be/e-maildisclaimer/vito.png]


Ontdek hoe VITO de transitie naar een duurzame maatschappij op gang trekt: 
www.vito.be/duurzaamheidsverslag2012http://www.vito.be/duurzaamheidsverslag2012
Discover how VITO initiates the transition towards a sustainable society: 
www.vito.be/sustainabilityreport2012http://www.vito.be/sustainabilityreport2012


VITO Disclaimer: http://www.vito.be/e-maildisclaimer

__
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, reproducible code.


[R] Trouble sorting the matrix

2013-06-15 Thread Ola Cabaj
I would like to sort matrix3, so that every column in output matrix is
sorted. Also I have to unsort it later on.

matrix1-matrix(rnorm(100,354,78),ncol=10)
matrix2-matrix(rnorm(100,225,102),ncol=10)
matrix3-cbind(matrix1,matrix2)
nrCol-length(matrix3[1,])
class1-1:10
  for(i in 1:nrCol)
  {
sorted.matrix-matrix3[order(matrix3[class1,i]),]
  }
 for(i in 1:liczbaKolumn)
  {
   output-sorted.matrix[order(matrix3[class1,i]),]
  }

-- 
Aleksandra Cabaj

[[alternative HTML version deleted]]

__
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, reproducible code.


Re: [R] Trouble sorting the matrix

2013-06-15 Thread andrija djurovic
Hi. Here is an example of sorting matrix columns:

 mat - matrix(10:1, ncol=2, byrow=TRUE)
 mat
 [,1] [,2]
[1,]   109
[2,]87
[3,]65
[4,]43
[5,]21
 apply(mat, 2, function(x) x[order(x)])
 [,1] [,2]
[1,]21
[2,]43
[3,]65
[4,]87
[5,]   109

You should read help page  [, apply and order (?[, ?apply, ?order)

Hope this helps

Andrija


On Sat, Jun 15, 2013 at 12:36 PM, Ola Cabaj olaca...@gmail.com wrote:

 I would like to sort matrix3, so that every column in output matrix is
 sorted. Also I have to unsort it later on.

 matrix1-matrix(rnorm(100,354,78),ncol=10)
 matrix2-matrix(rnorm(100,225,102),ncol=10)
 matrix3-cbind(matrix1,matrix2)
 nrCol-length(matrix3[1,])
 class1-1:10
   for(i in 1:nrCol)
   {
 sorted.matrix-matrix3[order(matrix3[class1,i]),]
   }
  for(i in 1:liczbaKolumn)
   {
output-sorted.matrix[order(matrix3[class1,i]),]
   }

 --
 Aleksandra Cabaj

 [[alternative HTML version deleted]]

 __
 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, reproducible code.


[[alternative HTML version deleted]]

__
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, reproducible code.


Re: [R] Error: cannot allocate vector of size 1.9 Gb when loading xtable help

2013-06-15 Thread Duncan Murdoch

On 13-06-14 7:02 PM, Dan Keshet wrote:

I am using xtable version 1.7-1 built for R 3.0.1 on:

R version 3.0.1 (2013-05-16)
Platform: i686-pc-linux-gnu (32-bit)

Sometimes, not every time, when I load xtable or attempt to load the
help, I get an error such as this Error: cannot allocate vector of
size 1.9 Gb (Stacktrace from recover() below).

Other times, when loading packages that depend on xtable, I get an
error such as this:

Loading required namespace: xtable
Error in assign(identifier, list(name, description, identifier, help,  :
   lazy-load database 'P' is corrupt

I have attempted to reinstall the package using
install.packages(xtable, type=source), but the error persists (and
the xtable.rdb file is identical).

I have also tried this on macs and gotten the same error.

Thank you for any help.

-

?xtable

Error: cannot allocate vector of size 1.9 Gb


I would guess this is not related to the xtable help page, but is a sign 
of something being corrupted (e.g. an out of range write in memory), and 
this is just a symptom of the corruption.


If we could make this reliably reproducible, we could track it down, but 
without that, it is nearly impossible.


Could try starting an empty R session (nothing reloaded from .Rdata),
run until you trigger the error, then save the session history?  See if 
replaying that history triggers the error again in the same place.  If 
so, see if you can shrink it to a minimal script that others can try, 
and post that.


Duncan Murdoch



Enter a frame number, or 0 to exit

1: print(/usr/local/analytics/rlibs/xtable/help/xtable)
2: print.help_files_with_topic(/usr/local/analytics/rlibs/xtable/help/xtable
3: tools::Rd2txt(.getHelpFile(file), out = tempfile(Rtxt), package = pkgname
4: prepare_Rd(Rd, defines = defines, stages = stages, fragment = fragment, ...
5: .getHelpFile(file)
6: tools:::fetchRdDB(RdDB, basename(file))
7: lazyLoadDBexec(filebase, fun)
8: fun(environment())
9: fetch(key)

__
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, reproducible code.



__
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, reproducible code.


Re: [R] R session freezes when I try to save a new script

2013-06-15 Thread Duncan Murdoch

On 13-06-14 10:52 AM, anferg...@aol.com wrote:

All:


Recently my R session freezes when I try to open a file or save a new script after I have 
run existing scripts.  The session freezes so that I can no longer click on any windows 
within the R session -- including other scripts that are open or the R console.  (I hear 
the ding sound when I try to click on anything.)  I have looked at the Task 
Manager on the computer and R is still running (and is still responsive according to the 
Task Manager), but I cannot do anything within R.  I have tried pressing Esc and that 
does not help.


Any suggestions would be greatly appreciated!  I am using a 32 bit Windows 7 
computer with 4gb ram and 250gb hard drive.


Thanks in advance for any suggestions!


I have sometimes seen symptoms like that when an open file dialog gets 
hidden behind another window.  R is waiting for the dialog to complete, 
but since it is hidden, it never does.  Generally it pops up eventually; 
I'm not sure why it is allowed to be hidden at all.


Duncan Murdoch

__
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, reproducible code.


Re: [R] Trouble sorting the matrix

2013-06-15 Thread Rui Barradas

Hello,

If I understand it correctly, the following should sort all columns of 
matrix3 and then unsort the sorted matrix.



ord - apply(matrix3, 2, order)

# sort matrix3
mat4 - sapply(seq_len(ncol(ord)), function(i) matrix3[ord[,i], i])
mat4

# unsort mat4
mat5 - sapply(seq_len(ncol(ord)), function(i) mat4[order(ord[,i]), i])

identical(matrix3, mat5)  # TRUE


Hope this helps,

Rui Barradas

Em 15-06-2013 11:36, Ola Cabaj escreveu:

I would like to sort matrix3, so that every column in output matrix is
sorted. Also I have to unsort it later on.

matrix1-matrix(rnorm(100,354,78),ncol=10)
matrix2-matrix(rnorm(100,225,102),ncol=10)
matrix3-cbind(matrix1,matrix2)
nrCol-length(matrix3[1,])
class1-1:10
   for(i in 1:nrCol)
   {
 sorted.matrix-matrix3[order(matrix3[class1,i]),]
   }
  for(i in 1:liczbaKolumn)
   {
output-sorted.matrix[order(matrix3[class1,i]),]
   }



__
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, reproducible code.


Re: [R] Trouble sorting the matrix

2013-06-15 Thread Rui Barradas

Hello,

Yes, you can do it like you say. Or you can unsort first and multiply later.

mat5.1 - sapply(seq_len(ncol(ord)), function(i) mat4[order(ord[,i]), i])

multip-mat4*2
mat5.2 - sapply(seq_len(ncol(ord)), function(i) multip[order(ord[,i]), i])

identical(mat5.1*2, mat5.2)  #TRUE


Also, it's better if you Cc the list, for others to read and eventually 
find it of some use.


Rui Barradas

Em 15-06-2013 12:48, Ola Cabaj escreveu:

Thanks, that helps a lot! I got another question, if you don't mind.
If I would like to multiply mat4 by a number/vector
multip-mat4*2

so to unsort this multiplied matrix I have to change mat4 to multip?
mat5 - sapply(seq_len(ncol(ord)), function(i) multip[order(ord[,i]), i])


2013/6/15 Rui Barradas ruipbarra...@sapo.pt mailto:ruipbarra...@sapo.pt

Hello,

If I understand it correctly, the following should sort all columns
of matrix3 and then unsort the sorted matrix.


ord - apply(matrix3, 2, order)

# sort matrix3
mat4 - sapply(seq_len(ncol(ord)), function(i) matrix3[ord[,i], i])
mat4

# unsort mat4
mat5 - sapply(seq_len(ncol(ord)), function(i) mat4[order(ord[,i]), i])

identical(matrix3, mat5)  # TRUE


Hope this helps,

Rui Barradas

Em 15-06-2013 11:36, Ola Cabaj escreveu:

I would like to sort matrix3, so that every column in output
matrix is
sorted. Also I have to unsort it later on.

matrix1-matrix(rnorm(100,354,__78),ncol=10)
matrix2-matrix(rnorm(100,225,__102),ncol=10)
matrix3-cbind(matrix1,__matrix2)
nrCol-length(matrix3[1,])
class1-1:10
for(i in 1:nrCol)
{
  sorted.matrix-matrix3[order(__matrix3[class1,i]),]
}
   for(i in 1:liczbaKolumn)
{
 output-sorted.matrix[order(__matrix3[class1,i]),]
}




--
Aleksandra Cabaj


__
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, reproducible code.


[R] Plotting two y-axis vs non-numeric x-axis

2013-06-15 Thread Birdada Simret
Hi dear all, the following code is correct. but I want to use non-numeric
x-axis, for example
if I replace   time - seq(0,72,6)  by
month -
c(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec,Pag)

Ofcourse I use factor(month)  instead of time; but I didn't get similar
plot as the example shown. any help is greatful ;)

month -
c(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec,Pag)
music - c(0.05,0.18,0.25,0.31,0.32,0.34,0.35,
0.36,0.37,0.38,0.39,0.40,0.41)
actor - c(0,1000,2000,3000,4000,5000,6000,7000,8000,9000,1,11000,12000)
par(mar=c(5, 4, 4, 4) + 0.1)
plot(factor(month), music, pch=16, axes=F, ylim=c(0,1), xlab=, ylab=,
 type=b,col=black, main=Enjoy)
 axis(2, ylim=c(0,1),col=black)
mtext(Music,side=2,line=2.5)
 box()
par(new=T)
 plot(factor(month), actor, pch=15,  xlab=, ylab=, ylim=c(0,13000),
axes=F,  type=b, col=red)
 mtext(Actor,side=4,col=red,line=2.5)
axis(4, ylim=c(0,13000), col=red,col.axis=red)
 axis(1,pretty(range(month),10))
mtext(Month,side=1,col=black,line=2.5)
legend(5,13000,legend=c(Music,Actor),text.col=c(black,red),pch=c(16,15),col=c(black,red))

[[alternative HTML version deleted]]

__
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, reproducible code.


Re: [R] GGally installation problems

2013-06-15 Thread Uwe Ligges



On 12.06.2013 15:08, Tim Smith wrote:

Hi,

I was trying to install the GGally package, but was getting errors. Here is 
what I get:


install.packages(GGally)

Installing package(s) into ‘/Users/ts2w/Library/R/2.15/library’
(as ‘lib’ is unspecified)
Warning in install.packages :
  package ‘GGally’ is not available (for R version 2.15.2)


install.packages(GGally,repos=http://cran-r.project.org;)



Wrong repository: http://cran-r.project.org; - 
http://cran.r-project.org; ?


uwe ligges



Installing package(s) into ‘/Users/ts2w/Library/R/2.15/library’
(as ‘lib’ is unspecified)
Warning in install.packages :
  cannot open: HTTP status was '404 Not Found'
Warning in install.packages :
  cannot open: HTTP status was '404 Not Found'
Warning in install.packages :
  unable to access index for repository http://cran-r.project.org/src/contrib
Warning in install.packages :
  package ‘GGally’ is not available (for R version 2.15.2)
Warning in install.packages :
  cannot open: HTTP status was '404 Not Found'
Warning in install.packages :
  cannot open: HTTP status was '404 Not Found'
Warning in install.packages :
  unable to access index for repository 
http://cran-r.project.org/bin/macosx/leopard/contrib/2.15

thanks.

[[alternative HTML version deleted]]



__
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, reproducible code.



__
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, reproducible code.


[R] Widows 8

2013-06-15 Thread Chet Seligman
Can anyone confirm that R runs on Widows 8?

Thanks,
Chet Seligman

[[alternative HTML version deleted]]

__
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, reproducible code.


Re: [R] Widows 8

2013-06-15 Thread John Kane
Seems unlikely but it runs on Windows 8

John Kane
Kingston ON Canada


 -Original Message-
 From: chet.selig...@gmail.com
 Sent: Sat, 15 Jun 2013 07:50:45 -0700
 To: r-help@r-project.org
 Subject: [R] Widows 8
 
 Can anyone confirm that R runs on Widows 8?
 
 Thanks,
 Chet Seligman
 
   [[alternative HTML version deleted]]
 
 __
 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, reproducible code.


FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks  orcas on your 
desktop!

__
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, reproducible code.


Re: [R] Widows 8

2013-06-15 Thread Jeff Newmiller

On Sat, 15 Jun 2013, Chet Seligman wrote:


Can anyone confirm that R runs on Widows 8?


You can : http://lmgtfy.com/?q=site%3Astat.ethz.ch+%22windows+8%22


Thanks,
Chet Seligman



[[alternative HTML version deleted]]


Please read the Posting Guide, and asi it requests post in plain text.


__
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, reproducible code.



---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k

__
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, reproducible code.


Re: [R] Widows 8

2013-06-15 Thread Wensui Liu
confirmed.


On Sat, Jun 15, 2013 at 10:50 AM, Chet Seligman chet.selig...@gmail.comwrote:

 Can anyone confirm that R runs on Widows 8?

 Thanks,
 Chet Seligman

 [[alternative HTML version deleted]]

 __
 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, reproducible code.




-- 
==
WenSui Liu
Credit Risk Manager, 53 Bancorp
wensui@53.com
513-295-4370
==

[[alternative HTML version deleted]]

__
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, reproducible code.


[R] A strange issue with GSub

2013-06-15 Thread Ali Arslan Kazmi
Greetings, 

Apologies if this turns out to be a very silly question, but because I am the 
only person learning/using R at my workplace, I have no choice but to ask folks 
here.
I have been using Gsub to change some expressions in my Corpus object. After 
applying the gsub function, say
newCorpus- gsub(game,war,newCorpus, fixed=TRUE)
an object of class character is returned by the gsub function, as is 
understandable, like so:
[1] this is the text of the 1st document[1000] this is the text of the 
1000th document.
However, all such text is enclosed as such:
[1] c(\this is the text of the 1st document.\, \\\a\) ...[1000] c(\this 
is the text of the 1000th document.\, \\\a\) 
The worst part is that I tried recreating the problem with another example to 
post here, but I face no such problem with the example. So, after banging my 
head against the computer for two days now, I still remain clueless as to why 
this is happening. I was wondering if somebody had an explanation to why this 
happens? That will be very helpful.
The only thing I can think of is that I had initially converted MS word 
documents into txt files, and then imported them using R's plain text reader. 
Could this be the issue?

Thanks.   
[[alternative HTML version deleted]]

__
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, reproducible code.


Re: [R] Plotting two y-axis vs non-numeric x-axis

2013-06-15 Thread David Winsemius

On Jun 15, 2013, at 5:18 AM, Birdada Simret wrote:

 Hi dear all, the following code is correct. but I want to use non-numeric
 x-axis, for example
 if I replace   time - seq(0,72,6)  by
 month -
 c(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec,Pag)
 
 Ofcourse I use factor(month)  instead of time; but I didn't get similar
 plot as the example shown. any help is greatful ;)

We are not seeing any example. Please read the documentation for the Rhelp 
mailing list more carefully. The information about attachments may not be in 
the PostingGuide but instead in the listinfo page.  (I for one do not 
understand what you are requesting.)
 
 month -
 c(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec,Pag)
 music - c(0.05,0.18,0.25,0.31,0.32,0.34,0.35,
 0.36,0.37,0.38,0.39,0.40,0.41)
 actor - c(0,1000,2000,3000,4000,5000,6000,7000,8000,9000,1,11000,12000)
 par(mar=c(5, 4, 4, 4) + 0.1)
 plot(factor(month), music, pch=16, axes=F, ylim=c(0,1), xlab=, ylab=,
 type=b,col=black, main=Enjoy)
 axis(2, ylim=c(0,1),col=black)
 mtext(Music,side=2,line=2.5)
 box()
 par(new=T)
 plot(factor(month), actor, pch=15,  xlab=, ylab=, ylim=c(0,13000),
 axes=F,  type=b, col=red)
 mtext(Actor,side=4,col=red,line=2.5)
 axis(4, ylim=c(0,13000), col=red,col.axis=red)
 axis(1,pretty(range(month),10))
 mtext(Month,side=1,col=black,line=2.5)
 legend(5,13000,legend=c(Music,Actor),text.col=c(black,red),pch=c(16,15),col=c(black,red))
 
   [[alternative HTML version deleted]]

-- 

David Winsemius
Alameda, CA, USA

__
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, reproducible code.


Re: [R] A strange issue with GSub

2013-06-15 Thread David Winsemius

On Jun 15, 2013, at 7:46 AM, Ali Arslan Kazmi wrote:

 Greetings, 
 
 Apologies if this turns out to be a very silly question, but because I am the 
 only person learning/using R at my workplace, I have no choice but to ask 
 folks here.
 I have been using Gsub to change some expressions in my Corpus object. After 
 applying the gsub function, say
 newCorpus- gsub(game,war,newCorpus, fixed=TRUE)
 an object of class character is returned by the gsub function, as is 
 understandable, like so:
 [1] this is the text of the 1st document[1000] this is the text of the 
 1000th document.
 However, all such text is enclosed as such:
 [1] c(\this is the text of the 1st document.\, \\\a\) ...[1000] 
 c(\this is the text of the 1000th document.\, \\\a\) 
 The worst part is that I tried recreating the problem with another example to 
 post here, but I face no such problem with the example. So, after banging my 
 head against the computer for two days now, I still remain clueless as to why 
 this is happening. I was wondering if somebody had an explanation to why this 
 happens? That will be very helpful.
 The only thing I can think of is that I had initially converted MS word 
 documents into txt files, and then imported them using R's plain text reader. 
 Could this be the issue?
 
 Thanks. 
   [[alternative HTML version deleted]]

You are misspelling the gsub function name. You are not describing your process 
with enough detail to replicate it. You are using packages that you are not 
naming. I suspect you are using gsub with an item of a class for which it was 
never intended. Consider this:

 mydf - data.frame(a=c(this is a test, another test), b=c(athird, a 
 fourth))
 gsub(test,tester, mydf)
[1] c(2, 1) c(2, 1)

Please read the Posting Guide. Please make your example reproducible.

-- 

David Winsemius
Alameda, CA, USA

__
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, reproducible code.


Re: [R] Plotting two y-axis vs non-numeric x-axis

2013-06-15 Thread arun


Hi,

You could use ?twoord.plot() from library(plotrix):
library(plotrix)
dat2- data.frame(month,music,actor)
dat2$month- factor(month,labels=c(month.abb,Pag))
dat2New-dat2[order(dat2$month),]

 with(dat2New,twoord.plot(month,music,actor,
    lylim=c(0,1),rylim=c(0,13000),
    ylab=Music,
    rylab=Actor,main=Enjoy,
    
type=c(p,b),lcol=1,rcol=red,xtickpos=month,xticklab=month))
 
legend(5,13000,legend=c(Music,Actor),text.col=c(black,red),col=c(black,red))
   

#I tried to change the plotting symbol using pch inside the twoord.plot(), 
but it seems to be not working. 
 with(dat2New,twoord.plot(month,music,actor,
 lylim=c(0,1),rylim=c(0,13000),
 ylab=Music,
 rylab=Actor,main=Enjoy,
 
type=c(p,b),pch=c(1,4),lcol=1,rcol=red,xtickpos=month,xticklab=month))
#Error in localWindow(xlim, ylim, log, asp, ...) : 
 # formal argument pch matched by multiple actual arguments

A.K.
   


- Original Message -
From: Birdada Simret birdad...@gmail.com
To: r-help@r-project.org
Cc: 
Sent: Saturday, June 15, 2013 8:18 AM
Subject: [R] Plotting two y-axis vs non-numeric x-axis

Hi dear all, the following code is correct. but I want to use non-numeric
x-axis, for example
if I replace   time - seq(0,72,6)  by
month -
c(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec,Pag)

Ofcourse I use factor(month)  instead of time; but I didn't get similar
plot as the example shown. any help is greatful ;)

month -
c(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec,Pag)
music - c(0.05,0.18,0.25,0.31,0.32,0.34,0.35,
0.36,0.37,0.38,0.39,0.40,0.41)
actor - c(0,1000,2000,3000,4000,5000,6000,7000,8000,9000,1,11000,12000)
par(mar=c(5, 4, 4, 4) + 0.1)
plot(factor(month), music, pch=16, axes=F, ylim=c(0,1), xlab=, ylab=,
type=b,col=black, main=Enjoy)
axis(2, ylim=c(0,1),col=black)
mtext(Music,side=2,line=2.5)
box()
par(new=T)
plot(factor(month), actor, pch=15,  xlab=, ylab=, ylim=c(0,13000),
axes=F,  type=b, col=red)
mtext(Actor,side=4,col=red,line=2.5)
axis(4, ylim=c(0,13000), col=red,col.axis=red)
axis(1,pretty(range(month),10))
mtext(Month,side=1,col=black,line=2.5)
legend(5,13000,legend=c(Music,Actor),text.col=c(black,red),pch=c(16,15),col=c(black,red))

    [[alternative HTML version deleted]]

__
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, reproducible code.


__
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, reproducible code.


Re: [R] transform summary table list to summary table (for .csv output)

2013-06-15 Thread arun
Hi,
You could try this:
#In one of the list element

SampleSummary$ConcLow
#   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
# 0.4200  0.6100  0.7300  0.7373  0.8150  1.6600   1 

#additional entry for NA.  You may need to check the data and remove the 
missing value.  Here, I removed that entry.


library(stringr)

res-data.frame(lapply(SampleSummary,function(x) 
{x1-x[names(x)!=NA's];Nch1-max(nchar(names(x1)));x2-str_pad(names(x1),Nch1,side=right,pad=
 );paste(x2,x1,sep=:) }),stringsAsFactors=FALSE)
 res1-as.table(as.matrix(res))

dimnames(res1)[[1]]-rep(,nrow(res1))
 str(res1)
# 'table' chr [1:6, 1:17] Min.   :1995-10-10 1st Qu.:1996-06-16 ...
# - attr(*, dimnames)=List of 2
#  ..$ : chr [1:6] ...
#  ..$ : chr [1:17] Date ConcLow ConcHigh Uncen ...

 str(summarySample)
# 'table' chr [1:6, 1:17] Min.   :2002-05-23   1st Qu.:2002-09-02   ...
# - attr(*, dimnames)=List of 2
#  ..$ : chr [1:6] ...
#  ..$ : chr [1:17]  Date    ConcLow    ConcHigh     Uncen ...
 summarySample[,1:3]
#  Date ConcLow    ConcHigh   
# Min.   :2002-05-23   Min.   :0.5800   Min.   :0.5800  
# 1st Qu.:2002-09-02   1st Qu.:0.7525   1st Qu.:0.7525  
# Median :2003-01-07   Median :0.7800   Median :0.7800  
# Mean   :2003-01-16   Mean   :0.8100   Mean   :0.8100  
# 3rd Qu.:2003-05-29   3rd Qu.:0.9025   3rd Qu.:0.9025  
# Max.   :2003-09-04   Max.   :1.0900   Max.   :1.0900  
 res1[,1:3]
# Date ConcLow  ConcHigh    
# Min.   :1995-10-10 Min.   :0.42   Min.   :0.27  
# 1st Qu.:1996-06-16 1st Qu.:0.61   1st Qu.:0.605 
# Median :1996-12-10 Median :0.73   Median :0.7275
# Mean   :1998-01-08 Mean   :0.7373 Mean   :0.7322
# 3rd Qu.:1998-03-12 3rd Qu.:0.815  3rd Qu.:0.8125
# Max.   :2003-09-04 Max.   :1.66   Max.   :1.66  


#There is some space on the right for each column of summarySample.   Not sure 
if you wanted that in res1. 

A.K.


Hi, I have a R object called Sample which I am obtaining the summary 
table for through 2 methods: summarySample - summary(Sample)  
SampleSummary - lapply(Sample, summary). I would like to transform 
the results of lapply(Sample, summary) into the same format as 
summary(Sample). I have included dput for both summary results. After I 
obtain the summary results I am exporting the table to a .csv and I 
would like both .csv files to be similarly formatted; however, I am not 
able to do that now. I have searched online for assistance, but I have 
not been successful yet. 

Thank you. 

Irucka Embry 

summarySample 
dput(summarySample) 
structure(c(Min.   :2002-05-23  , 1st Qu.:2002-09-02  , Median :2003-01-07 
 , 
Mean   :2003-01-16  , 3rd Qu.:2003-05-29  , Max.   :2003-09-04  , 
Min.   :0.5800  , 1st Qu.:0.7525  , Median :0.7800  , Mean   :0.8100  , 
3rd Qu.:0.9025  , Max.   :1.0900  , Min.   :0.5800  , 1st Qu.:0.7525  , 
Median :0.7800  , Mean   :0.8100  , 3rd Qu.:0.9025  , Max.   :1.0900  , 
Min.   :1  , 1st Qu.:1  , Median :1  , Mean   :1  , 3rd Qu.:1  , 
Max.   :1  , Min.   :0.5800  , 1st Qu.:0.7525  , Median :0.7800  , 
Mean   :0.8100  , 3rd Qu.:0.9025  , Max.   :1.0900  , Min.   :55659  , 
1st Qu.:55762  , Median :55888  , Mean   :55898  , 3rd Qu.:56031  , 
Max.   :56128  , Min.   : 2  , 1st Qu.: 5  , Median : 7  , 
Mean   : 7  , 3rd Qu.: 9  , Max.   :12  , Min.   : 35.0  , 
1st Qu.:142.5  , Median :201.5  , Mean   :199.3  , 3rd Qu.:247.2  , 
Max.   :345.0  , Min.   :2002  , 1st Qu.:2003  , Median :2003  , 
Mean   :2003  , 3rd Qu.:2003  , Max.   :2004  , Min.   :1829  , 
1st Qu.:1833  , Median :1837  , Mean   :1837  , 3rd Qu.:1841  , 
Max.   :1845  , Min.   :-0.9670  , 1st Qu.:-0.8075  , Median :-0.2531  
, 
Mean   :-0.1224  , 3rd Qu.: 0.5788  , Max.   : 0.9906  , 
Min.   :-0.9917  , 1st Qu.:-0.7986  , Median :-0.5209  , 
Mean   :-0.3123  , 3rd Qu.: 0.1663  , Max.   : 0.9327  , 
Min.   :0.1189  , 1st Qu.:0.5154  , Median :1.3734  , Mean   :1.6672  , 
3rd Qu.:2.6618  , Max.   :5.7483  , Min.   :-2.12921  , 
1st Qu.:-0.71031  , Median : 0.30516  , Mean   : 0.02173  , 
3rd Qu.: 0.97834  , Max.   : 1.74891  , Min.   :-0.4057  , 
1st Qu.:-0.2986  , Median :-0.2131  , Mean   :-0.2022  , 
3rd Qu.:-0.1459  , Max.   : 0.0798  , Min.   :0.02030  , 
1st Qu.:0.03857  , Median :0.06197  , Mean   :0.06628  , 
3rd Qu.:0.08225  , Max.   :0.17336  , Min.   :0.6766  , 
1st Qu.:0.7432  , Median :0.8117  , Mean   :0.8259  , 3rd Qu.:0.8646  , 
Max.   :1.0838  ), .Dim = c(6L, 17L), .Dimnames = list(c(, 
, , , , ), c(     Date,    ConcLow,    ConcHigh, 
    Uncen,    ConcAve,     Julian,     Month,      Day, 
   DecYear,    MonthSeq,     SinDY,     CosDY,       Q, 
     LogQ,      yHat,       SE,    ConcHat)), class = table) 


SampleSummary 
dput(SampleSummary) 
structure(list(Date = structure(c(9413, 9663, 9840, 10234.0652174, 
10297.75, 12299), .Names = c(Min., 1st Qu., Median, Mean, 
3rd Qu., Max.), class = c(summaryDefault, table, Date 
)), ConcLow = structure(c(0.42, 0.61, 0.73, 0.7373, 0.815, 1.66, 
1), .Names = c(Min., 1st Qu., 

Re: [R] Windows R_LIBS_USER confusion under R-3.0.1

2013-06-15 Thread Uwe Ligges



On 12.06.2013 16:35, Paul Johnson wrote:

I would appreciate ideas about MS Windows install issues. I'm at our stats
summer camp and have been looking at a lot of Windows R installs and there
are some wrinkles about R_LIBS_USER.

On a clean Win7 or Win8 system, with R-3.0.1, we see the user library for
packages defaulting to  $HOME/R/win-library.

I think that's awesome, the way it should be. Yea! But it does not appear
that way on all systems, and I think it is because of lingering
after-effects of previous R installs.

In previous versions of R, R_LIBS_USER defaulted to
$HOME/AppData/Roaming/... That was not so great because it was (default)
hidden to the students and they were disoriented about how something that
does not exist (or show) could hold packages. Aside from teaching them how
to configure the file manager, we could navigate that.

The problem is that with R-3.0.1, sometimes we are seeing the user package
installs going into $HOME/AppData/Roaming/

In the user account, there is no $HOME/.Rprofile or $HOME/.Renviron.

I hate to tell non-expert users that they ought to go fishing in the
Windows registry, but I'm starting to suspect that is what they ought to
do.  What do you think?



There is nothing in the registry, but maybe some startup file in the 
current working directory? Some declaration of environment variables 
somewhere else?


Best,
Uwe Ligges




PJ



__
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, reproducible code.


Re: [R] Calculate days with R

2013-06-15 Thread arun
Hi,
May be this helps:
dat1- read.table(text=
pbnr    dat  dep  dys  sop  ago  mis age female
1 10023 1994-02-21 0.75 1.00 0.50 0.50 0.75  35  1
2 10023 1994-05-25 0.75 1.00 0.50 0.50 0.75  35  1
3 10028 1994-02-01 2.00 1.75 3.00 0.50 1.50  42  1
4 10028 1999-01-15 1.25 0.75 2.25 0.50 0.25  42  1
5 10053 1994-03-16 2.50 0.75 1.25 0.50 1.25  22  1
6 10053 1994-09-23 3.25 1.25 1.25 0.75 2.25  22  1
,sep=,header=TRUE,stringsAsFactors=FALSE)
dat1$dat- as.Date(dat1$dat)
 with(dat1,tapply(dat,list(pbnr),FUN=diff))
#10023 10028 10053 
#   93  1809   191 
library(plyr)
 ddply(dat1,.(pbnr),mutate,Datediff=diff(dat))
 #  pbnr    dat  dep  dys  sop  ago  mis age female Datediff
#1 10023 1994-02-21 0.75 1.00 0.50 0.50 0.75  35  1   93
#2 10023 1994-05-25 0.75 1.00 0.50 0.50 0.75  35  1   93
#3 10028 1994-02-01 2.00 1.75 3.00 0.50 1.50  42  1 1809
#4 10028 1999-01-15 1.25 0.75 2.25 0.50 0.25  42  1 1809
#5 10053 1994-03-16 2.50 0.75 1.25 0.50 1.25  22  1  191
#6 10053 1994-09-23 3.25 1.25 1.25 0.75 2.25  22  1  191

#or
 dat2-aggregate(dat~pbnr,data=dat1,diff)
 colnames(dat2)[2]- Datediff
 join(dat1,dat2,by=pbnr)
#   pbnr    dat  dep  dys  sop  ago  mis age female Datediff
#1 10023 1994-02-21 0.75 1.00 0.50 0.50 0.75  35  1  93 
#2 10023 1994-05-25 0.75 1.00 0.50 0.50 0.75  35  1  93 
#3 10028 1994-02-01 2.00 1.75 3.00 0.50 1.50  42  1    1809 
#4 10028 1999-01-15 1.25 0.75 2.25 0.50 0.25  42  1    1809 
#5 10053 1994-03-16 2.50 0.75 1.25 0.50 1.25  22  1 191 
#6 10053 1994-09-23 3.25 1.25 1.25 0.75 2.25  22  1 191 


A.K.



Hi, I am new to this forum, and have a problem. I have data that looks like 
this: 

pbnr        dat  dep  dys  sop  ago  mis age female 
1 10023 1994-02-21 0.75 1.00 0.50 0.50 0.75  35      1 
2 10023 1994-05-25 0.75 1.00 0.50 0.50 0.75  35      1 
3 10028 1994-02-01 2.00 1.75 3.00 0.50 1.50  42      1 
4 10028 1999-01-15 1.25 0.75 2.25 0.50 0.25  42      1 
5 10053 1994-03-16 2.50 0.75 1.25 0.50 1.25  22      1 
6 10053 1994-09-23 3.25 1.25 1.25 0.75 2.25  22      1 
. 
And I want to know how many days each person (pbnr) has been in 
therapy. row 1 is first a date for person 10023 and row 2 the second but
 what do I do now 
Thanks for you help!! 
Sophie

__
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, reproducible code.


[R] [igraph] Counting edges for each vertex

2013-06-15 Thread Mulone
Hi all,

I'm analysing an e-mail network. I loaded the following information in a
directed igraph:

*Vertex* types: person, e-mail
V(g)[ type == person ]
V(g)[ type == email ]

*Edge* types: sends, receives
E(g)[ type == send ]
E(g)[ type == receive ]

So for example:

John --send-- email1 --receive-- Mary
John --send-- email2 --receive-- Mary
Mary --send-- email3 --receive-- John

I would like to generate a summary of the e-mail activity, with edges with
an attribute representing the number of emails:

John --2-- Mary
Mary --1-- John

I tried to do this, but I haven't figured it out yet.
I managed to get in/out edges for each letter, but then I don't know what to
do to hold a count.

  lapply(V(g)[type==email],
function(e){
  outedges = V(g) [ from(e) ]
  print(outedges)
  inedges = V(g) [ to(e) ]
  print(inedges)
})

I just started using igraph, and I find even basic operations quite
difficult to carry out. :-/
How would I go about to do that?

Thanks,
Mulone



--
View this message in context: 
http://r.789695.n4.nabble.com/igraph-Counting-edges-for-each-vertex-tp4669613.html
Sent from the R help mailing list archive at Nabble.com.

__
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, reproducible code.


Re: [R] Plotting two y-axis vs non-numeric x-axis

2013-06-15 Thread Birdada Simret
Thank you.
@David: The example is exactly this:
time - seq(0,72,6)
music - c(0.05,0.18,0.25,0.31,0.32,0.34,0.35,
0.36,0.37,0.38,0.39,0.40,0.41)
actor - c(0,1000,2000,3000,4000,5000,6000,7000,8000,9000,1,11000,12000)
par(mar=c(5, 4, 4, 4) + 0.1)
plot(time, music, pch=16, axes=F, ylim=c(0,1), xlab=, ylab=,
 type=b,col=black, main=Enjoy)
 axis(2, ylim=c(0,1),col=black)
mtext(Music,side=2,line=2.5)
 box()
par(new=T)
 plot(time, actor, pch=15,  xlab=, ylab=, ylim=c(0,13000), axes=F,
 type=b, col=red)
 mtext(Actor,side=4,col=red,line=2.5)
axis(4, ylim=c(0,13000), col=red,col.axis=red)
 axis(1,pretty(range(time),10))
mtext(Time (Hours),side=1,col=black,line=2.5)
legend(5,13000,legend=c(Music,Actor),text.col=c(black,red),pch=c(16,15),col=c(black,red))

Now, what if time is replaced by month -
c(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec,Pag)

when I tried
I got error like
In pretty.default(range(month), 10) : NAs introduced by coercion   I am
newbie to R ;) many thanks

@Arun, It is really helpful, thank you. though only the red marked plot is
perfectly shown.


On Sat, Jun 15, 2013 at 6:20 PM, arun smartpink...@yahoo.com wrote:



 Hi,

 You could use ?twoord.plot() from library(plotrix):
 library(plotrix)
 dat2- data.frame(month,music,actor)
 dat2$month- factor(month,labels=c(month.abb,Pag))
 dat2New-dat2[order(dat2$month),]

  with(dat2New,twoord.plot(month,music,actor,
 lylim=c(0,1),rylim=c(0,13000),
 ylab=Music,
 rylab=Actor,main=Enjoy,

 type=c(p,b),lcol=1,rcol=red,xtickpos=month,xticklab=month))

 legend(5,13000,legend=c(Music,Actor),text.col=c(black,red),col=c(black,red))

 #I tried to change the plotting symbol using pch inside the
 twoord.plot(), but it seems to be not working.
  with(dat2New,twoord.plot(month,music,actor,
  lylim=c(0,1),rylim=c(0,13000),
  ylab=Music,
  rylab=Actor,main=Enjoy,

 type=c(p,b),pch=c(1,4),lcol=1,rcol=red,xtickpos=month,xticklab=month))
 #Error in localWindow(xlim, ylim, log, asp, ...) :
  # formal argument pch matched by multiple actual arguments

 A.K.



 - Original Message -
 From: Birdada Simret birdad...@gmail.com
 To: r-help@r-project.org
 Cc:
 Sent: Saturday, June 15, 2013 8:18 AM
 Subject: [R] Plotting two y-axis vs non-numeric x-axis

 Hi dear all, the following code is correct. but I want to use non-numeric
 x-axis, for example
 if I replace   time - seq(0,72,6)  by
 month -

 c(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec,Pag)

 Ofcourse I use factor(month)  instead of time; but I didn't get similar
 plot as the example shown. any help is greatful ;)

 month -

 c(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec,Pag)
 music - c(0.05,0.18,0.25,0.31,0.32,0.34,0.35,
 0.36,0.37,0.38,0.39,0.40,0.41)
 actor -
 c(0,1000,2000,3000,4000,5000,6000,7000,8000,9000,1,11000,12000)
 par(mar=c(5, 4, 4, 4) + 0.1)
 plot(factor(month), music, pch=16, axes=F, ylim=c(0,1), xlab=, ylab=,
 type=b,col=black, main=Enjoy)
 axis(2, ylim=c(0,1),col=black)
 mtext(Music,side=2,line=2.5)
 box()
 par(new=T)
 plot(factor(month), actor, pch=15,  xlab=, ylab=, ylim=c(0,13000),
 axes=F,  type=b, col=red)
 mtext(Actor,side=4,col=red,line=2.5)
 axis(4, ylim=c(0,13000), col=red,col.axis=red)
 axis(1,pretty(range(month),10))
 mtext(Month,side=1,col=black,line=2.5)

 legend(5,13000,legend=c(Music,Actor),text.col=c(black,red),pch=c(16,15),col=c(black,red))

 [[alternative HTML version deleted]]

 __
 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, reproducible code.



[[alternative HTML version deleted]]

__
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, reproducible code.


Re: [R] Plotting two y-axis vs non-numeric x-axis

2013-06-15 Thread David Winsemius

On Jun 15, 2013, at 11:14 AM, Birdada Simret wrote:

 Thank you.
 @David: The example is exactly this:
 time - seq(0,72,6)
 music - c(0.05,0.18,0.25,0.31,0.32,0.34,0.35,
 0.36,0.37,0.38,0.39,0.40,0.41)
 actor - c(0,1000,2000,3000,4000,5000,6000,7000,8000,9000,1,11000,12000)
 par(mar=c(5, 4, 4, 4) + 0.1)
 plot(time, music, pch=16, axes=F, ylim=c(0,1), xlab=, ylab=,
 type=b,col=black, main=Enjoy)
 axis(2, ylim=c(0,1),col=black)
 mtext(Music,side=2,line=2.5)
 box()
 par(new=T)
 plot(time, actor, pch=15,  xlab=, ylab=, ylim=c(0,13000), axes=F,
 type=b, col=red)
 mtext(Actor,side=4,col=red,line=2.5)
 axis(4, ylim=c(0,13000), col=red,col.axis=red)
 axis(1,pretty(range(time),10))
 mtext(Time (Hours),side=1,col=black,line=2.5)
 legend(5,13000,legend=c(Music,Actor),text.col=c(black,red),pch=c(16,15),col=c(black,red))
 
 Now, what if time is replaced by month -
 c(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec,Pag)
 
 when I tried
 I got error like
 In pretty.default(range(month), 10) : NAs introduced by coercion   I am
 newbie to R ;) many thanks

Er, Not really. The error was the line above that warning:

Error in plot.window(...) : need finite 'xlim' values
In addition: Warning messages:
1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
2: In min(x) : no non-missing arguments to min; returning Inf
3: In max(x) : no non-missing arguments to max; returning -Inf

You are sending a character vector to plot() as the first argument, and 
plotting dispatch system cannot find a 'plot.character' method so it sends it 
to 'plot.default' which is expecting a numeric vector for x and things all fall 
apart from there.

You could use: seq_along(month)  # instead of month

(And obviously the xlab would need to be changed, since you are no longer 
working with Hours.)

And. Please learn to post in plain text.

-- David


 @Arun, It is really helpful, thank you. though only the red marked plot is
 perfectly shown.
 
 
 On Sat, Jun 15, 2013 at 6:20 PM, arun smartpink...@yahoo.com wrote:
 
 
 
 Hi,
 
 You could use ?twoord.plot() from library(plotrix):
 library(plotrix)
 dat2- data.frame(month,music,actor)
 dat2$month- factor(month,labels=c(month.abb,Pag))
 dat2New-dat2[order(dat2$month),]
 
 with(dat2New,twoord.plot(month,music,actor,
lylim=c(0,1),rylim=c(0,13000),
ylab=Music,
rylab=Actor,main=Enjoy,
 
 type=c(p,b),lcol=1,rcol=red,xtickpos=month,xticklab=month))
 
 legend(5,13000,legend=c(Music,Actor),text.col=c(black,red),col=c(black,red))
 
 #I tried to change the plotting symbol using pch inside the
 twoord.plot(), but it seems to be not working.
 with(dat2New,twoord.plot(month,music,actor,
 lylim=c(0,1),rylim=c(0,13000),
 ylab=Music,
 rylab=Actor,main=Enjoy,
 
 type=c(p,b),pch=c(1,4),lcol=1,rcol=red,xtickpos=month,xticklab=month))
 #Error in localWindow(xlim, ylim, log, asp, ...) :
 # formal argument pch matched by multiple actual arguments
 
 A.K.
 
 
 
 - Original Message -
 From: Birdada Simret birdad...@gmail.com
 To: r-help@r-project.org
 Cc:
 Sent: Saturday, June 15, 2013 8:18 AM
 Subject: [R] Plotting two y-axis vs non-numeric x-axis
 
 Hi dear all, the following code is correct. but I want to use non-numeric
 x-axis, for example
 if I replace   time - seq(0,72,6)  by
 month -
 
 c(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec,Pag)
 
 Ofcourse I use factor(month)  instead of time; but I didn't get similar
 plot as the example shown. any help is greatful ;)
 
 month -
 
 c(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec,Pag)
 music - c(0.05,0.18,0.25,0.31,0.32,0.34,0.35,
 0.36,0.37,0.38,0.39,0.40,0.41)
 actor -
 c(0,1000,2000,3000,4000,5000,6000,7000,8000,9000,1,11000,12000)
 par(mar=c(5, 4, 4, 4) + 0.1)
 plot(factor(month), music, pch=16, axes=F, ylim=c(0,1), xlab=, ylab=,
 type=b,col=black, main=Enjoy)
 axis(2, ylim=c(0,1),col=black)
 mtext(Music,side=2,line=2.5)
 box()
 par(new=T)
 plot(factor(month), actor, pch=15,  xlab=, ylab=, ylim=c(0,13000),
 axes=F,  type=b, col=red)
 mtext(Actor,side=4,col=red,line=2.5)
 axis(4, ylim=c(0,13000), col=red,col.axis=red)
 axis(1,pretty(range(month),10))
 mtext(Month,side=1,col=black,line=2.5)
 
 legend(5,13000,legend=c(Music,Actor),text.col=c(black,red),pch=c(16,15),col=c(black,red))
 
[[alternative HTML version deleted]]
 
 

David Winsemius
Alameda, CA, USA

__
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, reproducible code.


[R] Downloading CSV file - RCurl help

2013-06-15 Thread jcrosbie
There are some CSV file from the link below. 

I'm having trouble installing the package. Is this the package I have to use
or is there another one I need to use? If so how do I get this one loaded. 



https://www.enmax.com/Power/Energy+Retailers/Settlement+Reports/Profile+settlement+report.htm

 install.packages(RCurl, repos =
http://cran.r-project.org/bin/windows/contrib/r-release/RCurl_1.95-4.1.zip;,
type=source)
Installing package into ‘C:/Users/James/Documents/R/win-library/3.0’
(as ‘lib’ is unspecified)
Warning: unable to access index for repository
http://cran.r-project.org/bin/windows/contrib/r-release/RCurl_1.95-4.1.zip/src/contrib
Warning message:
package ‘RCurl’ is not available (for R version 3.0.1) 



--
View this message in context: 
http://r.789695.n4.nabble.com/Downloading-CSV-file-RCurl-help-tp4669616.html
Sent from the R help mailing list archive at Nabble.com.

__
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, reproducible code.


Re: [R] Downloading CSV file - RCurl help

2013-06-15 Thread David Winsemius

On Jun 15, 2013, at 11:41 AM, jcrosbie wrote:

 There are some CSV file from the link below. 
 
 I'm having trouble installing the package. Is this the package I have to use
 or is there another one I need to use? If so how do I get this one loaded. 
 
 
 
 https://www.enmax.com/Power/Energy+Retailers/Settlement+Reports/Profile+settlement+report.htm
 
 install.packages(RCurl, repos =
 http://cran.r-project.org/bin/windows/contrib/r-release/RCurl_1.95-4.1.zip;,
 type=source)

Packages of type=source are not generally distributed as zip files. So R is 
unable to find it in the CRAN source directory. If you do want source you will 
also need RTools. But why not install as a binary file?

 Installing package into ‘C:/Users/James/Documents/R/win-library/3.0’
 (as ‘lib’ is unspecified)
 Warning: unable to access index for repository
 http://cran.r-project.org/bin/windows/contrib/r-release/RCurl_1.95-4.1.zip/src/contrib
 Warning message:
 package ‘RCurl’ is not available (for R version 3.0.1) 
 
-- 

David Winsemius
Alameda, CA, USA

__
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, reproducible code.


[R] quick Help needed

2013-06-15 Thread Sophie Homeyer
Hi,
i am new to this forum and not sure how it works,
I am trying to do deskriptive descripe my data in terms of gender:

head(scltotal)

   pbnrdat  dep  dys  sop  ago  mis age female messpunkt2
messpunkt1 tage eintrittsjahr

1 10023 1994-02-21 0.75 1.00 0.50 0.50 0.75  35  1   8817
88170  1994

2 10023 1994-05-25 0.75 1.00 0.50 0.50 0.75  35  1   8910
8817   93  1994

3 10028 1994-02-01 2.00 1.75 3.00 0.50 1.50  42  1   8797
87970  1994

4 10028 1999-01-15 1.25 0.75 2.25 0.50 0.25  42  1  10606
8797 1809  1999

5 10053 1994-03-16 2.50 0.75 1.25 0.50 1.25  22  1   8840
88400  1994

6 10053 1994-09-23 3.25 1.25 1.25 0.75 2.25  22  1   9031
8840  191  1994
so female is either 0 or 1 I assume 0 is male and 1 is female. And I want
to look at dep, dys, sop, ago and mis how they are in terms of gender
(female or male) I have no clue what to do :-(
thanks for your help
sophie

[[alternative HTML version deleted]]

__
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, reproducible code.


[R] How can make loop more faster?

2013-06-15 Thread Fabrice Tourre
Dear expert,

How can I make follow codematrix function more faster?

top20.dat - top20.dat[,7:length(top20.dat[1,])]
top40.dat -
read.table(top40snps.ped,header=F,sep=\t,stringsAsFactors=F)
row.names(top40.dat) - top40.dat[,1]
top40.dat - top40.dat[,7:length(top40.dat[1,])]
codematrix - function(dat)
{
new.dat - dat
for(col in 1:length(dat[1,]))
{
tbl - table(dat[,col])
max.allel - names(which(tbl==max(table(dat[,col]
for(row in 1:length(dat[,1]))
{
if(dat[row,col]==0 0)
{
new.dat[row,col]=NA
}else{
if(dat[row,col]==max.allel) {
new.dat[row,col]=0
}else{
allele - unlist(strsplit(
as.character(dat[row,col]), ))
if(allele[1]==allele[2]){
new.dat[row,col]=2
}else{
new.dat[row,col]=1
}
}
}
}
#})
cat(paste(col, ,sep=))
}
return(new.dat)
}
code.top20 - codematrix(top20.dat)

[[alternative HTML version deleted]]

__
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, reproducible code.


Re: [R] quick Help needed

2013-06-15 Thread Bhupendrasinh Thakre
table(scltotal$female,scltotal$dys)


Best Regards,

Bhupendrasinh Thakre

Sent from my iPad

On Jun 15, 2013, at 3:58 PM, Sophie Homeyer sophie.home...@googlemail.com 
wrote:

 Hi,
 i am new to this forum and not sure how it works,
 I am trying to do deskriptive descripe my data in terms of gender:
 
 head(scltotal)
 
   pbnrdat  dep  dys  sop  ago  mis age female messpunkt2
 messpunkt1 tage eintrittsjahr
 
 1 10023 1994-02-21 0.75 1.00 0.50 0.50 0.75  35  1   8817
 88170  1994
 
 2 10023 1994-05-25 0.75 1.00 0.50 0.50 0.75  35  1   8910
 8817   93  1994
 
 3 10028 1994-02-01 2.00 1.75 3.00 0.50 1.50  42  1   8797
 87970  1994
 
 4 10028 1999-01-15 1.25 0.75 2.25 0.50 0.25  42  1  10606
 8797 1809  1999
 
 5 10053 1994-03-16 2.50 0.75 1.25 0.50 1.25  22  1   8840
 88400  1994
 
 6 10053 1994-09-23 3.25 1.25 1.25 0.75 2.25  22  1   9031
 8840  191  1994
 so female is either 0 or 1 I assume 0 is male and 1 is female. And I want
 to look at dep, dys, sop, ago and mis how they are in terms of gender
 (female or male) I have no clue what to do :-(
 thanks for your help
 sophie
 
[[alternative HTML version deleted]]
 
 __
 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, reproducible code.

__
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, reproducible code.


Re: [R] How can make loop more faster?

2013-06-15 Thread David Winsemius

On Jun 15, 2013, at 2:38 PM, Fabrice Tourre wrote:

 Dear expert,
 
 How can I make follow codematrix function more faster?
 
 top20.dat - top20.dat[,7:length(top20.dat[1,])]
 top40.dat -
 read.table(top40snps.ped,header=F,sep=\t,stringsAsFactors=F)

Did you attach a file with a non-'.txt' extension?

 row.names(top40.dat) - top40.dat[,1]
 top40.dat - top40.dat[,7:length(top40.dat[1,])]
 codematrix - function(dat)
 {
new.dat - dat
for(col in 1:length(dat[1,]))
{

I'm guessing that using `ifelse` would be much faster than going column by 
column and and then row by painful row through this testing with nested 
`if(cond){conseq}else{alter}` . You should gain efficiency by setting up the 
results of the `strsplit` operation on a full column at a time. Build a 
function that would work one column at a time and then lapply it to the 
dataframe.

tbl - table(dat[,col])
max.allel - names(which(tbl==max(table(dat[,col]
for(row in 1:length(dat[,1]))
{
if(dat[row,col]==0 0)
{
new.dat[row,col]=NA
}else{
if(dat[row,col]==max.allel) {
new.dat[row,col]=0
}else{
allele - unlist(strsplit(
 as.character(dat[row,col]), ))
if(allele[1]==allele[2]){
new.dat[row,col]=2
}else{
new.dat[row,col]=1

You could leave the ==max.allelle test on the outer of nested ifelse 
operations to overwrite the resutls of the testing of the two split-bits. But 
I would make it a %in%-test so that it won't fail when mor than one maximum 
occur.

Perhaps (untested and a lot of guesswork):

testsplitfunc - function(col){
 temptbl - table(col)
 tempspl -  strsplit(as.character(col) , split= )
 allele -cbind( sapply(temp, [, 1),
 sapply(temp, [, 2) )
 res - ifelse ( col %in% names(temptbl)[ which(tbl==max(temptbl))] , 
 0,
 ifelse( allele[,1]==allele[,2], 2, 1) )
 is.na(res) - col==0 0
 }

code.top20 - do.call(cbind, lapply(top20.dat, testsplitfunc) )
 




}
}
}
}
#})
cat(paste(col, ,sep=))
}
return(new.dat)
 }
 code.top20 - codematrix(top20.dat)

In the absence of a problem description I will leave the details unaddressed.
 
   [[alternative HTML version deleted]]


David Winsemius
Alameda, CA, USA

__
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, reproducible code.


[R] Optimization of a function using optim

2013-06-15 Thread Graham McDannel
I am attempting to optimize a function I have developed using optim.

I am getting the below error message:

Error in n  1: 'n' is missing

Could some one provide some additional clarity regarding this message and
what it entails, as well as, how to rectify this issue.

Thanks

[[alternative HTML version deleted]]

__
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, reproducible code.


Re: [R] Optimization of a function using optim

2013-06-15 Thread Jeff Newmiller
Not unless you read the Posting Guide, stop posting in HTML mail format, and 
provide a reproducible example.
---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

Graham McDannel graham.mcdan...@gmail.com wrote:

I am attempting to optimize a function I have developed using optim.

I am getting the below error message:

Error in n  1: 'n' is missing

Could some one provide some additional clarity regarding this message
and
what it entails, as well as, how to rectify this issue.

Thanks

   [[alternative HTML version deleted]]

__
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, reproducible code.

__
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, reproducible code.


Re: [R] Plotting two y-axis vs non-numeric x-axis

2013-06-15 Thread Jim Lemon

On 06/16/2013 04:14 AM, Birdada Simret wrote:

Thank you.
@David: The example is exactly this:
time - seq(0,72,6)
music - c(0.05,0.18,0.25,0.31,0.32,0.34,0.35,
0.36,0.37,0.38,0.39,0.40,0.41)
actor - c(0,1000,2000,3000,4000,5000,6000,7000,8000,9000,1,11000,12000)
par(mar=c(5, 4, 4, 4) + 0.1)
plot(time, music, pch=16, axes=F, ylim=c(0,1), xlab=, ylab=,
  type=b,col=black, main=Enjoy)
  axis(2, ylim=c(0,1),col=black)
mtext(Music,side=2,line=2.5)
  box()
par(new=T)
  plot(time, actor, pch=15,  xlab=, ylab=, ylim=c(0,13000), axes=F,
  type=b, col=red)
  mtext(Actor,side=4,col=red,line=2.5)
axis(4, ylim=c(0,13000), col=red,col.axis=red)
  axis(1,pretty(range(time),10))
mtext(Time (Hours),side=1,col=black,line=2.5)
legend(5,13000,legend=c(Music,Actor),text.col=c(black,red),pch=c(16,15),col=c(black,red))

Now, what if time is replaced by month -
c(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec,Pag)


Hi Birdada,
You can get the month labels using something like this:

twoord.plot(time,music,time,actor,lylim=c(0,1),type=c(l,b),
 xtickpos=seq(0,70,by=10),xticklab=month.abb[1:8])

Hi arun,
This question may already have been answered, but to change the symbols, 
you have to use lpch= and rpch=. I get the appropriate types of plot 
when using the above, and I tried several combinations of point, line, 
both that all worked okay. If I figure out what happened in your example 
I'll email the answer.


Jim

__
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, reproducible code.


Re: [R] Optimization of a function using optim

2013-06-15 Thread Rolf Turner



The r-help list should institute a prize for Most Obtuse Question
of the Month.  This one should be a shoe-in for the June 2013 prize.

cheers,

Rolf Turner

On 16/06/13 12:08, Graham McDannel wrote:

I am attempting to optimize a function I have developed using optim.

I am getting the below error message:

Error in n  1: 'n' is missing

Could some one provide some additional clarity regarding this message and
what it entails, as well as, how to rectify this issue.

Thanks


__
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, reproducible code.


Re: [R] quick Help needed

2013-06-15 Thread arun
Hi,
It is better to ?dput() the dummy dataset.
I made up some data for female==0
dat1- read.table(text=
 pbnr    dat  dep  dys  sop  ago  mis age female messpunkt2 messpunkt1 tage 
eintrittsjahr
1 10023 1994-02-21 0.75 1.00 0.50 0.50 0.75  35  1   8817 8817    0 
 1994
2 10023 1994-05-25 0.75 1.00 0.50 0.50 0.75  35  1   8910 8817   93 
 1994
3 10028 1994-02-01 2.00 1.75 3.00 0.50 1.50  42  1   8797 8797    0 
 1994
4 10028 1999-01-15 1.25 0.75 2.25 0.50 0.25  42  1  10606 8797 1809 
 1999
5 10053 1994-03-16 2.50 0.75 1.25 0.50 1.25  22  1   8840 8840    0 
 1994
6 10053 1994-09-23 3.25 1.25 1.25 0.75 2.25  22  1   9031 8840  191 
 1994
7 10043 1994-02-21 0.85 1.20 0.51 0.55 0.95  45  0   8917 8817    0 
 1994
8 10043 1994-05-25 0.95 1.10 0.55 0.55 0.85  35  0   8950 8717   93 
 1994
9 10038 1994-02-01 2.50 1.85 3.20 0.70 1.70  45  0   9797 8897    0 
 1994
10 10038 1999-01-15 1.55 0.85 2.35 0.70 0.55  47  0  11606 9797 1809
  1999
11 10063 1994-03-16 2.20 0.65 1.55 0.85 1.25  28  0   8940 8850    0
  1994
12 10063 1994-09-23 3.55 1.35 1.55 0.95 2.35  32  0   9531 8340  191
  1994
,sep=,header=TRUE,stringsAsFactors=FALSE)

 by(dat1[, c(3:8)], dat1[,female], summary)
#or
library(psych)
describeBy(dat1[,3:8],dat1$female)
#or
 describeBy(dat1[,3:8],dat1$female,mat=TRUE)


A.K.



- Original Message -
From: Sophie Homeyer sophie.home...@googlemail.com
To: r-help@r-project.org
Cc: 
Sent: Saturday, June 15, 2013 4:58 PM
Subject: [R] quick Help needed

Hi,
i am new to this forum and not sure how it works,
I am trying to do deskriptive descripe my data in terms of gender:

head(scltotal)

   pbnr        dat  dep  dys  sop  ago  mis age female messpunkt2
messpunkt1 tage eintrittsjahr

1 10023 1994-02-21 0.75 1.00 0.50 0.50 0.75  35      1       8817
8817    0          1994

2 10023 1994-05-25 0.75 1.00 0.50 0.50 0.75  35      1       8910
8817   93          1994

3 10028 1994-02-01 2.00 1.75 3.00 0.50 1.50  42      1       8797
8797    0          1994

4 10028 1999-01-15 1.25 0.75 2.25 0.50 0.25  42      1      10606
8797 1809          1999

5 10053 1994-03-16 2.50 0.75 1.25 0.50 1.25  22      1       8840
8840    0          1994

6 10053 1994-09-23 3.25 1.25 1.25 0.75 2.25  22      1       9031
8840  191          1994
so female is either 0 or 1 I assume 0 is male and 1 is female. And I want
to look at dep, dys, sop, ago and mis how they are in terms of gender
(female or male) I have no clue what to do :-(
thanks for your help
sophie

    [[alternative HTML version deleted]]

__
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, reproducible code.


__
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, reproducible code.


[R] extract all numbers from a string

2013-06-15 Thread Nick Matzke

Hi all,

I have been beating my head against this problem for a bit, 
but I can't figure it out.


I have a series of strings of variable length, and each will 
have one or more numbers, of varying format.  E.g., I might 
have:



tmpstr = The first number is: 32.  Another one is: 32.1. 
Here's a number in scientific format, 0.3523e10, and 
another, 0.3523e-10, and a negative, -313.1


How could I get R to just give me a list of numerics 
containing the numbers therein?


Thanks very much to the regexp wizards!

Cheers,
Nick



--

Nicholas J. Matzke
Ph.D. Candidate, Graduate Student Researcher

Huelsenbeck Lab
Center for Theoretical Evolutionary Genomics
4151 VLSB (Valley Life Sciences Building)
Department of Integrative Biology
University of California, Berkeley

Graduate Student Instructor, IB200B
Principles of Phylogenetics: Ecology and Evolution
http://ib.berkeley.edu/courses/ib200b/
http://phylo.wikidot.com/


Lab websites:
http://ib.berkeley.edu/people/lab_detail.php?lab=54
http://fisher.berkeley.edu/cteg/hlab.html
Dept. personal page: 
http://ib.berkeley.edu/people/students/person_detail.php?person=370
Lab personal page: 
http://fisher.berkeley.edu/cteg/members/matzke.html

Lab phone: 510-643-6299
Dept. fax: 510-643-6264

Cell phone: 510-301-0179
Email: mat...@berkeley.edu

Mailing address:
Department of Integrative Biology
1005 Valley Life Sciences Building #3140
Berkeley, CA 94720-3140

-
[W]hen people thought the earth was flat, they were wrong. 
When people thought the earth was spherical, they were 
wrong. But if you think that thinking the earth is spherical 
is just as wrong as thinking the earth is flat, then your 
view is wronger than both of them put together.


Isaac Asimov (1989). The Relativity of Wrong. The 
Skeptical Inquirer, 14(1), 35-44. Fall 1989.

http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm

__
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, reproducible code.


Re: [R] extract all numbers from a string

2013-06-15 Thread arun


HI,
One way would be:

library(stringr)
tmpstr = The first number is: 32.  Another one is: 32.1.
Here's a number in scientific format, 0.3523e10, and
another, 0.3523e-10, and a negative, -313.1
pattern- 
(\\d)+|(\\d+\\.\\d+)|(-\\d+\\.\\d+)|(\\d+.\\d+e\\d+)|(\\d+\\.\\d+e-\\d+)
str_extract_all(tmpstr,pattern)[[1]]
#[1] 32 32.1   0.3523e10  0.3523e-10 -313.1    
 as.numeric(str_extract_all(tmpstr,pattern)[[1]])
A.K.



- Original Message -
From: Nick Matzke mat...@berkeley.edu
To: R-help@r-project.org
Cc: 
Sent: Sunday, June 16, 2013 1:06 AM
Subject: [R] extract all numbers from a string

Hi all,

I have been beating my head against this problem for a bit, 
but I can't figure it out.

I have a series of strings of variable length, and each will 
have one or more numbers, of varying format.  E.g., I might 
have:


tmpstr = The first number is: 32.  Another one is: 32.1. 
Here's a number in scientific format, 0.3523e10, and 
another, 0.3523e-10, and a negative, -313.1

How could I get R to just give me a list of numerics 
containing the numbers therein?

Thanks very much to the regexp wizards!

Cheers,
Nick



-- 

Nicholas J. Matzke
Ph.D. Candidate, Graduate Student Researcher

Huelsenbeck Lab
Center for Theoretical Evolutionary Genomics
4151 VLSB (Valley Life Sciences Building)
Department of Integrative Biology
University of California, Berkeley

Graduate Student Instructor, IB200B
Principles of Phylogenetics: Ecology and Evolution
http://ib.berkeley.edu/courses/ib200b/
http://phylo.wikidot.com/


Lab websites:
http://ib.berkeley.edu/people/lab_detail.php?lab=54
http://fisher.berkeley.edu/cteg/hlab.html
Dept. personal page: 
http://ib.berkeley.edu/people/students/person_detail.php?person=370
Lab personal page: 
http://fisher.berkeley.edu/cteg/members/matzke.html
Lab phone: 510-643-6299
Dept. fax: 510-643-6264

Cell phone: 510-301-0179
Email: mat...@berkeley.edu

Mailing address:
Department of Integrative Biology
1005 Valley Life Sciences Building #3140
Berkeley, CA 94720-3140

-
[W]hen people thought the earth was flat, they were wrong. 
When people thought the earth was spherical, they were 
wrong. But if you think that thinking the earth is spherical 
is just as wrong as thinking the earth is flat, then your 
view is wronger than both of them put together.

Isaac Asimov (1989). The Relativity of Wrong. The 
Skeptical Inquirer, 14(1), 35-44. Fall 1989.
http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm

__
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, reproducible code.


__
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, reproducible code.


Re: [R] extract all numbers from a string

2013-06-15 Thread Duncan Mackay

Nick

try

as.numeric(
 strsplit(gsub([[:alpha:][:punct:][:space:]]{2,},,,tmpstr),,)[[1]][-1]
)

see ?regexpr for information

HTH

Duncan


Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au



At 15:06 16/06/2013, you wrote:

Hi all,

I have been beating my head against this problem for a bit, but I 
can't figure it out.


I have a series of strings of variable length, and each will have 
one or more numbers, of varying format.  E.g., I might have:



tmpstr = The first number is: 32.  Another one is: 32.1. Here's a 
number in scientific format, 0.3523e10, and another, 0.3523e-10, and 
a negative, -313.1


How could I get R to just give me a list of numerics containing the 
numbers therein?


Thanks very much to the regexp wizards!

Cheers,
Nick



--

Nicholas J. Matzke
Ph.D. Candidate, Graduate Student Researcher

Huelsenbeck Lab
Center for Theoretical Evolutionary Genomics
4151 VLSB (Valley Life Sciences Building)
Department of Integrative Biology
University of California, Berkeley

Graduate Student Instructor, IB200B
Principles of Phylogenetics: Ecology and Evolution
http://ib.berkeley.edu/courses/ib200b/
http://phylo.wikidot.com/


Lab websites:
http://ib.berkeley.edu/people/lab_detail.php?lab=54
http://fisher.berkeley.edu/cteg/hlab.html
Dept. personal page: 
http://ib.berkeley.edu/people/students/person_detail.php?person=370

Lab personal page: http://fisher.berkeley.edu/cteg/members/matzke.html
Lab phone: 510-643-6299
Dept. fax: 510-643-6264

Cell phone: 510-301-0179
Email: mat...@berkeley.edu

Mailing address:
Department of Integrative Biology
1005 Valley Life Sciences Building #3140
Berkeley, CA 94720-3140

-
[W]hen people thought the earth was flat, they were wrong. When 
people thought the earth was spherical, they were wrong. But if you 
think that thinking the earth is spherical is just as wrong as 
thinking the earth is flat, then your view is wronger than both of 
them put together.


Isaac Asimov (1989). The Relativity of Wrong. The Skeptical 
Inquirer, 14(1), 35-44. Fall 1989.

http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm

__
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, reproducible code.



__
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, reproducible code.