[R] Sorting data.frame and again sorting within data.frame

2013-04-15 Thread Katherine Gobin
Dear R forum,

I have a data.frame as defied below - 

df = data.frame(names = c(C, A, A, B, C, B, A, B, C), dates = 
c(4/15/2013, 4/13/2013, 4/15/2013, 4/13/2013, 4/13/2013, 4/15/2013, 
4/14/2013, 4/14/2013,4/14/2013 ),values = c(10, 31, 31, 17, 11, 34, 102, 
47, 29))

 df
  names dates values
1 C 4/15/2013 10
2 A 4/13/2013 31
3 A 4/15/2013 31
4 B 4/13/2013 17
5 C 4/13/2013 11
6 B
 4/15/2013 34
7 A 4/14/2013    102
8 B 4/14/2013 47
9 C 4/14/2013 29

I need to sort df first on names in increasing order and then further on 
dates in a decreasing order i.e. I need

names    dates    values
A    4/15/2013  31
A    4/14/2013 102
A    4/13/2013  31
B    4/15/2013 
 34
B    4/14/2013  47
B    4/13/2013  17
C    4/15/2013  10
C    4/14/2013  29
C    4/13/2013  11

I tried

df_sorted = df[order(df$names, (as.Date(df$dates, %m/%d/%Y)), decreasing = 
TRUE),]

 df_sorted
  names dates values
1 C 4/15/2013 10
9 C 4/14/2013 29
5 C 4/13/2013
 11
6 B 4/15/2013 34
8 B 4/14/2013 47
4 B 4/13/2013 17
3 A 4/15/2013 31
7 A 4/14/2013    102
2 A 4/13/2013 31


I need A to appear first with all three corresponding dates in decreasing 
order, then B and so on.

Please guide.

With regards

Katherine


[[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 to transform string to Camel Case?

2013-04-15 Thread Liviu Andronic
Dear all,
Given the following vector:
 (z - c('R project', 'hello world', 'something Else'))
[1] R project  hello worldsomething Else

I know how to obtain all capitals or all lower case letters:
 tolower(z)
[1] r project  hello worldsomething else
 toupper(z)
[1] R PROJECT  HELLO WORLDSOMETHING ELSE

I saw the tocamel() function in 'rapport', but it doesn't do what I
want to achieve as it actually proceeds to camelCase/CamelCase the
strings:
 tocamel(z)
[1] RProject  helloWorldsomethingElse


But how should I proceed to obtain Camel Case? Here's what I'd like to get:
c('R Project', 'Hello World', 'Something Else')


Regards,
Liviu


-- 
Do you know how to read?
http://www.alienetworks.com/srtest.cfm
http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
Do you know how to write?
http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail

__
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 to transform string to Camel Case?

2013-04-15 Thread Pascal Oettli

Hi,

There is an example of how to do do what you are looking for in ?toupper

Regards,
Pascal

On 04/15/2013 03:50 PM, Liviu Andronic wrote:

Dear all,
Given the following vector:

(z - c('R project', 'hello world', 'something Else'))

[1] R project  hello worldsomething Else

I know how to obtain all capitals or all lower case letters:

tolower(z)

[1] r project  hello worldsomething else

toupper(z)

[1] R PROJECT  HELLO WORLDSOMETHING ELSE

I saw the tocamel() function in 'rapport', but it doesn't do what I
want to achieve as it actually proceeds to camelCase/CamelCase the
strings:

tocamel(z)

[1] RProject  helloWorldsomethingElse


But how should I proceed to obtain Camel Case? Here's what I'd like to get:
c('R Project', 'Hello World', 'Something Else')


Regards,
Liviu




__
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 to transform string to Camel Case?

2013-04-15 Thread Henrik Bengtsson
See for instance capitalize() in the R.utils package.

Henrik
On Apr 14, 2013 11:51 PM, Liviu Andronic landronim...@gmail.com wrote:

 Dear all,
 Given the following vector:
  (z - c('R project', 'hello world', 'something Else'))
 [1] R project  hello worldsomething Else

 I know how to obtain all capitals or all lower case letters:
  tolower(z)
 [1] r project  hello worldsomething else
  toupper(z)
 [1] R PROJECT  HELLO WORLDSOMETHING ELSE

 I saw the tocamel() function in 'rapport', but it doesn't do what I
 want to achieve as it actually proceeds to camelCase/CamelCase the
 strings:
  tocamel(z)
 [1] RProject  helloWorldsomethingElse


 But how should I proceed to obtain Camel Case? Here's what I'd like to get:
 c('R Project', 'Hello World', 'Something Else')


 Regards,
 Liviu


 --
 Do you know how to read?
 http://www.alienetworks.com/srtest.cfm
 http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
 Do you know how to write?
 http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail

 __
 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] how to transform string to Camel Case?

2013-04-15 Thread peter dalgaard

On Apr 15, 2013, at 08:50 , Liviu Andronic wrote:

 Dear all,
 Given the following vector:
 (z - c('R project', 'hello world', 'something Else'))
 [1] R project  hello worldsomething Else
 
 I know how to obtain all capitals or all lower case letters:
 tolower(z)
 [1] r project  hello worldsomething else
 toupper(z)
 [1] R PROJECT  HELLO WORLDSOMETHING ELSE
 
 I saw the tocamel() function in 'rapport', but it doesn't do what I
 want to achieve as it actually proceeds to camelCase/CamelCase the
 strings:
 tocamel(z)
 [1] RProject  helloWorldsomethingElse
 
 
 But how should I proceed to obtain Camel Case? Here's what I'd like to get:
 c('R Project', 'Hello World', 'Something Else')

That'll be capitalization, not camel case, camel-casing is when wordsHaveHumps 
inTheMiddle. 

As for actually solving your problem, I'd try googling for regular expression 
to capitalize word and convert to use with gsub(). (I did do the googling, but 
regexps being  what they are - unreadable gibberish at first sight - I thought 
I'd leave the hard work for others...). Or, as Pascal points out: 
example(toupper).

-pd


 
 
 Regards,
 Liviu
 
 
 -- 
 Do you know how to read?
 http://www.alienetworks.com/srtest.cfm
 http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
 Do you know how to write?
 http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail
 
 __
 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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.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] Sorting data.frame and again sorting within data.frame

2013-04-15 Thread Jeff Newmiller
The examples in ?order show a method that could be applied if you avoid the 
decreasing argument and instead convert the Date to numeric for purposes of 
sorting.
---
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.

Katherine Gobin katherine_go...@yahoo.com wrote:

Dear R forum,

I have a data.frame as defied below - 

df = data.frame(names = c(C, A, A, B, C, B, A, B, C),
dates = c(4/15/2013, 4/13/2013, 4/15/2013, 4/13/2013,
4/13/2013, 4/15/2013, 4/14/2013, 4/14/2013,4/14/2013 ),values
= c(10, 31, 31, 17, 11, 34, 102, 47, 29))

 df
� names dates values
1 C 4/15/2013 10
2 A 4/13/2013 31
3 A 4/15/2013 31
4 B 4/13/2013 17
5 C 4/13/2013 11
6 B
 4/15/2013 34
7 A 4/14/2013��� 102
8 B 4/14/2013 47
9 C 4/14/2013 29

I need to sort df first on names in increasing order and then further
on dates in a decreasing order i.e. I need

names��� dates��� values
A��� 4/15/2013� 31
A��� 4/14/2013 102
A��� 4/13/2013� 31
B��� 4/15/2013�
 34
B��� 4/14/2013� 47
B��� 4/13/2013� 17
C��� 4/15/2013� 10
C��� 4/14/2013� 29
C��� 4/13/2013� 11

I tried

df_sorted = df[order(df$names, (as.Date(df$dates, %m/%d/%Y)),
decreasing = TRUE),]

 df_sorted
� names dates values
1 C 4/15/2013 10
9 C 4/14/2013 29
5 C 4/13/2013
 11
6 B 4/15/2013 34
8 B 4/14/2013 47
4 B 4/13/2013 17
3 A 4/15/2013 31
7 A 4/14/2013��� 102
2 A 4/13/2013 31


I need A to appear first with all three corresponding dates in
decreasing order, then B and so on.

Please guide.

With regards

Katherine


   [[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] Imputation with SOM using kohonen package

2013-04-15 Thread Ben Harrison
I have a data set with 10 variables, and about 8000 instances (or
objects/rows/samples). In addition I have one more ('class') variable that
I have about 10 instances for, but for which I wish to impute values for.

I am a little confused how to go about doing this, mostly as I'm not
well-versed in it. Do I train the SOM with a data object that contains just
the first 10 variables (exclude the 'class' variable), then predict using
an object that has all of the variables (including the class variable)?

(I am using the kohonen package, and in general I am using the SOM
technique as a comparison to some other methods).

I don't know if providing some or all data is useful, please let me know if
you think it is.

# get the data
bw - read.csv(bw.csv)
# some missing values in data
bwm - data.frame(na.approx(bw, na.rm=FALSE, rule=2))
bw10 - bwm[, 1:10]
bw10.sc - scale(bw10)
bw.som - som(data=bw10.sc, grid=somgrid(25,20,'hexagonal'))  # playing
with diff grid sizes

# the different plots of the som at this point show some interesting
features to me, but are quite difficult to interpret.
# there's much work needed here to understand it, but for now I want to see
if it's possible to impute values for another variable...

# here's where I lose it, missing values, trainY, don't get it.
bw.predict - predict(bw.som, newdata=scale(bw), trainX=???, trainY=???)

Ben.

[[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] how to transform string to Camel Case?

2013-04-15 Thread Gergely Daróczi
Dear Liviu,

I have just updated tocamel to have a new argument, so the development
version of the package would produce:

  tocamel(z, upper = TRUE, sep = ' ')
[1] R Project  Hello WorldSomething Else

Best,
Gergely

PS #1: to install the dev branch you might give a try to the devtools
package:

 library(devtools)
 install_github('rapport', 'rapporter', 'development')

PS #2: Alex (cc) pls verify.


On 15 April 2013 08:50, Liviu Andronic landronim...@gmail.com wrote:

 Dear all,
 Given the following vector:
  (z - c('R project', 'hello world', 'something Else'))
 [1] R project  hello worldsomething Else

 I know how to obtain all capitals or all lower case letters:
  tolower(z)
 [1] r project  hello worldsomething else
  toupper(z)
 [1] R PROJECT  HELLO WORLDSOMETHING ELSE

 I saw the tocamel() function in 'rapport', but it doesn't do what I
 want to achieve as it actually proceeds to camelCase/CamelCase the
 strings:
  tocamel(z)
 [1] RProject  helloWorldsomethingElse


 But how should I proceed to obtain Camel Case? Here's what I'd like to get:
 c('R Project', 'Hello World', 'Something Else')


 Regards,
 Liviu


 --
 Do you know how to read?
 http://www.alienetworks.com/srtest.cfm
 http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
 Do you know how to write?
 http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail

 __
 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.


[R] create an access file

2013-04-15 Thread Aileen Lin
Hi there,

I have seen this post.
https://stat.ethz.ch/pipermail/r-help/2007-June/133606.html

have odbc installed in my machine. Now I have the following message:


channel2 - odbcDriverConnect(test.mdb)Warning messages:1: In
odbcDriverConnect(test.mdb) :
  [RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver
Manager] Data source name not found and no default driver specified2:
In odbcDriverConnect(test.mdb) :
  [RODBC] ERROR: state 01S00, code 0, message [Microsoft][ODBC Driver
Manager] Invalid connection string attribute3: In
odbcDriverConnect(test.mdb) : ODBC connection failed


Did I miss anything?
-- 
Aileen L.

View my Linkedin profile: http://au.linkedin.com/in/aileen2

 Being happy doesn't mean you're perfect. It just means you've decided to
look beyond the imperfections- K.B Indiana (age
14)http://www.boardofwisdom.com/default.asp?topic=1010search=K%2EB+Indiana+%28age+14%29

[[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] model frame and formula mismatch in model.matrix()

2013-04-15 Thread jul 2-pom
Hi Eva,

you're right, it works with 50 variables. Then, how could I change this
variable limit in the lm function?

Thank you very much for your help.
Julien.



--
View this message in context: 
http://r.789695.n4.nabble.com/model-frame-and-formula-mismatch-in-model-matrix-tp4664093p4664226.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] create an access file

2013-04-15 Thread Prof Brian Ripley

On 15/04/2013 07:12, Aileen Lin wrote:

Hi there,

I have seen this post.
https://stat.ethz.ch/pipermail/r-help/2007-June/133606.html

have odbc installed in my machine. Now I have the following message:


channel2 - odbcDriverConnect(test.mdb)Warning messages:1: In
odbcDriverConnect(test.mdb) :
   [RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver
Manager] Data source name not found and no default driver specified2:
In odbcDriverConnect(test.mdb) :
   [RODBC] ERROR: state 01S00, code 0, message [Microsoft][ODBC Driver
Manager] Invalid connection string attribute3: In
odbcDriverConnect(test.mdb) : ODBC connection failed


Did I miss anything?


That is not doing what the URL you gave suggested.  Please do follow it.


--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
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] nearest stations in distance matrix

2013-04-15 Thread eliza botto
Dear R-user,
Is there a way in R to locate the nearest 5 indices to a station, based on 
distances in a distance matrix. In other words i want to have nearest stations 
based on the distances in the matrix. The distance matrix, i have, has 
dimension 44*44.
Thankyou very much in advance
Elisa

  
[[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] nearest stations in distance matrix

2013-04-15 Thread ONKELINX, Thierry
Dear Eliza,

If you have the coordinates of the stations you can use the nnwhich() function 
from the spatstat package.

Best regards,

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and 
Forest
team Biometrie  Kwaliteitszorg / team Biometrics  Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium
+ 32 2 525 02 51
+ 32 54 43 61 85
thierry.onkel...@inbo.be
www.inbo.be

To call in the statistician after the experiment is done may be no more than 
asking him to perform a post-mortem examination: he may be able to say what the 
experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not ensure 
that a reasonable answer can be extracted from a given body of data.
~ John Tukey

-Oorspronkelijk bericht-
Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens 
eliza botto
Verzonden: maandag 15 april 2013 12:36
Aan: r-help@r-project.org
Onderwerp: [R] nearest stations in distance matrix

Dear R-user,
Is there a way in R to locate the nearest 5 indices to a station, based on 
distances in a distance matrix. In other words i want to have nearest stations 
based on the distances in the matrix. The distance matrix, i have, has 
dimension 44*44.
Thankyou very much in advance
Elisa


[[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.
* * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * *
Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en 
binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is 
door een geldig ondertekend document.
The views expressed in this message and any annex are purely those of the 
writer and may not be regarded as stating an official position of INBO, as long 
as the message is not confirmed by a duly signed document.

__
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] Fwd: Dotchart per groups

2013-04-15 Thread zuzana zajkova
Hi all,

I would like to ask you for advice. I did a dotplot - using dotchart
function.
There are two localites (loc) with values 75 or 56 in my data ZZ.
The f column has 4 levels: P1, S1, S8, R6.
The dataframe is ordered by N value, pchloc value is assign to use pch in
plot.

 head(ZZ)
loc  fN color ordered pchloc
98   75 S1 6.39 green   1 16
99   75 S8 6.44  blue   2 16
71   75 S8 6.60  blue   3 16
100  75 R6 6.64 black   4 16
70   75 S1 6.81 green   5 16
51   75 S8 6.83  blue   6 16


 dput(ZZ)
structure(list(loc = c(75L, 75L, 75L, 75L, 75L, 75L, 75L, 75L,
56L, 56L, 75L, 75L, 75L, 75L, 75L, 75L, 75L, 56L, 75L, 75L, 56L,
56L, 75L, 75L, 75L, 56L, 75L, 56L, 56L, 75L, 75L, 75L, 75L, 75L,
75L, 56L, 56L, 75L, 75L, 75L, 75L, 56L, 75L, 75L, 75L, 75L, 56L,
56L, 56L, 56L, 75L, 75L, 75L, 75L, 75L, 75L, 75L, 56L, 75L, 56L,
75L, 75L, 75L, 75L, 75L, 56L, 75L, 75L, 75L, 75L, 56L, 75L, 75L,
56L, 75L, 56L, 75L, 75L, 56L, 56L, 75L, 75L, 75L, 75L, 75L, 75L,
56L, 75L, 56L, 75L, 75L, 75L, 75L, 75L, 56L, 75L, 56L, 75L, 56L,
75L, 75L, 75L, 75L, 75L, 75L, 75L, 56L, 75L, 75L, 75L, 75L, 75L,
56L, 75L, 56L, 56L, 56L, 75L, 75L, 56L, 75L, 56L, 75L, 56L, 56L,
56L, 56L, 56L), f = structure(c(2L, 3L, 3L, 4L, 2L, 3L, 4L, 3L,
2L, 3L, 2L, 2L, 2L, 2L, 3L, 2L, 3L, 2L, 4L, 3L, 1L, 3L, 1L, 3L,
3L, 4L, 3L, 2L, 4L, 4L, 3L, 2L, 2L, 4L, 2L, 3L, 4L, 2L, 3L, 3L,
3L, 4L, 4L, 2L, 3L, 3L, 3L, 2L, 3L, 2L, 3L, 1L, 3L, 4L, 2L, 2L,
2L, 3L, 2L, 2L, 3L, 4L, 2L, 2L, 4L, 1L, 4L, 1L, 2L, 2L, 3L, 1L,
4L, 2L, 3L, 2L, 3L, 1L, 3L, 4L, 1L, 3L, 1L, 4L, 1L, 1L, 1L, 2L,
1L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 4L,
4L, 4L, 1L, 4L, 4L, 4L, 4L, 1L, 4L, 4L, 1L, 4L, 2L, 1L, 4L, 3L,
4L, 4L, 1L, 4L, 1L, 4L, 1L, 1L), .Label = c(P1, S1, S8,
R6), class = factor), N = c(6.39, 6.44, 6.6, 6.64, 6.81,
6.83, 6.84, 6.91, 6.93, 6.93, 6.94, 6.95, 7.01, 7.04, 7.12, 7.16,
7.24, 7.26, 7.26, 7.27, 7.29, 7.34, 7.34, 7.34, 7.41, 7.42, 7.42,
7.43, 7.43, 7.43, 7.44, 7.44, 7.45, 7.47, 7.49, 7.51, 7.52, 7.53,
7.53, 7.54, 7.54, 7.55, 7.55, 7.57, 7.57, 7.58, 7.59, 7.61, 7.61,
7.65, 7.67, 7.68, 7.69, 7.69, 7.7, 7.72, 7.72, 7.73, 7.75, 7.76,
7.78, 7.78, 7.78, 7.8, 7.81, 7.86, 7.86, 7.88, 7.92, 7.94, 7.95,
7.95, 7.98, 8, 8, 8.01, 8.02, 8.04, 8.11, 8.16, 8.17, 8.22, 8.23,
8.23, 8.26, 8.27, 8.31, 8.35, 8.37, 8.37, 8.41, 8.44, 8.45, 8.47,
8.49, 8.52, 8.55, 8.59, 8.62, 8.71, 8.71, 8.72, 8.78, 8.85, 8.91,
8.95, 9.02, 9.07, 9.07, 9.1, 9.12, 9.17, 9.19, 9.34, 9.36, 9.46,
9.46, 9.52, 9.63, 9.82, 10.01, 10.33, 10.33, 10.49, 10.88, 11.01,
11.24, 12.6), color = c(green, blue, blue, black, green,
blue, black, blue, green, blue, green, green, green,
green, blue, green, blue, green, black, blue, red,
blue, red, blue, blue, black, blue, green, black,
black, blue, green, green, black, green, blue,
black, green, blue, blue, blue, black, black, green,
blue, blue, blue, green, blue, green, blue, red,
blue, black, green, green, green, blue, green,
green, blue, black, green, green, black, red, black,
red, green, green, blue, red, black, green, blue,
green, blue, red, blue, black, red, blue, red,
black, red, red, red, green, red, red, green,
red, red, red, green, red, blue, red, red, red,
red, red, red, black, black, black, red, black,
black, black, black, red, black, black, red, black,
green, red, black, blue, black, black, red, black,
red, black, red, red), ordered = c(1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86,
87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101,
102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
128), pchloc = c(16, 16, 16, 16, 16, 16, 16, 16, 1, 1, 16, 16,
16, 16, 16, 16, 16, 1, 16, 16, 1, 1, 16, 16, 16, 1, 16, 1, 1,
16, 16, 16, 16, 16, 16, 1, 1, 16, 16, 16, 16, 1, 16, 16, 16,
16, 1, 1, 1, 1, 16, 16, 16, 16, 16, 16, 16, 1, 16, 1, 16, 16,
16, 16, 16, 1, 16, 16, 16, 16, 1, 16, 16, 1, 16, 1, 16, 16, 1,
1, 16, 16, 16, 16, 16, 16, 1, 16, 1, 16, 16, 16, 16, 16, 1, 16,
1, 16, 1, 16, 16, 16, 16, 16, 16, 16, 1, 16, 16, 16, 16, 16,
1, 16, 1, 1, 1, 16, 16, 1, 16, 1, 16, 1, 1, 1, 1, 1)), .Names = c(loc,
f, N, color, ordered, pchloc), row.names = c(98L, 99L,
71L, 100L, 70L, 51L, 68L, 83L, 34L, 35L, 82L, 50L, 42L, 46L,
63L, 62L, 43L, 6L, 44L, 87L, 5L, 31L, 61L, 79L, 55L, 36L, 67L,
2L, 32L, 108L, 47L, 66L, 86L, 88L, 122L, 11L, 16L, 94L, 95L,
115L, 123L, 24L, 80L, 78L, 111L, 103L, 3L, 22L, 23L, 10L, 107L,
97L, 75L, 96L, 106L, 102L, 118L, 7L, 110L, 30L, 59L, 76L, 114L,
74L, 104L, 1L, 64L, 73L, 54L, 58L, 19L, 69L, 92L, 14L, 119L,
18L, 127L, 41L, 15L, 8L, 49L, 91L, 65L, 120L, 113L, 93L, 17L,
126L, 29L, 105L, 90L, 77L, 81L, 45L, 38L, 85L, 39L, 53L, 9L,
121L, 125L, 109L, 

Re: [R] how to transform string to Camel Case?

2013-04-15 Thread Liviu Andronic
On Mon, Apr 15, 2013 at 9:25 AM, Henrik Bengtsson h...@biostat.ucsf.edu wrote:
 See for instance capitalize() in the R.utils package.

Unfortunately this also fails when NA values are present:
 z - c(R project, hello world, something Else, NA)
 R.utils::capitalize(z)
[1] R project  Hello worldSomething Else NANA

Any pointers how to work around that? Thanks,
Liviu


 Henrik

 On Apr 14, 2013 11:51 PM, Liviu Andronic landronim...@gmail.com wrote:

 Dear all,
 Given the following vector:
  (z - c('R project', 'hello world', 'something Else'))
 [1] R project  hello worldsomething Else

 I know how to obtain all capitals or all lower case letters:
  tolower(z)
 [1] r project  hello worldsomething else
  toupper(z)
 [1] R PROJECT  HELLO WORLDSOMETHING ELSE

 I saw the tocamel() function in 'rapport', but it doesn't do what I
 want to achieve as it actually proceeds to camelCase/CamelCase the
 strings:
  tocamel(z)
 [1] RProject  helloWorldsomethingElse


 But how should I proceed to obtain Camel Case? Here's what I'd like to
 get:
 c('R Project', 'Hello World', 'Something Else')


 Regards,
 Liviu


 --
 Do you know how to read?
 http://www.alienetworks.com/srtest.cfm
 http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
 Do you know how to write?
 http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail

 __
 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.



-- 
Do you know how to read?
http://www.alienetworks.com/srtest.cfm
http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
Do you know how to write?
http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail

__
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 to transform string to Camel Case?

2013-04-15 Thread Liviu Andronic
On Mon, Apr 15, 2013 at 9:20 AM, Pascal Oettli kri...@ymail.com wrote:
 There is an example of how to do do what you are looking for in ?toupper

Unfortunately this fails when NA values are present:
z - c(R project, hello world, something Else, NA)
 tocapwords(z)
[1] R Project  Hello WorldSomething Else NANA


Liviu


 Regards,
 Pascal


 On 04/15/2013 03:50 PM, Liviu Andronic wrote:

 Dear all,
 Given the following vector:

 (z - c('R project', 'hello world', 'something Else'))

 [1] R project  hello worldsomething Else

 I know how to obtain all capitals or all lower case letters:

 tolower(z)

 [1] r project  hello worldsomething else

 toupper(z)

 [1] R PROJECT  HELLO WORLDSOMETHING ELSE

 I saw the tocamel() function in 'rapport', but it doesn't do what I
 want to achieve as it actually proceeds to camelCase/CamelCase the
 strings:

 tocamel(z)

 [1] RProject  helloWorldsomethingElse


 But how should I proceed to obtain Camel Case? Here's what I'd like to
 get:
 c('R Project', 'Hello World', 'Something Else')


 Regards,
 Liviu






-- 
Do you know how to read?
http://www.alienetworks.com/srtest.cfm
http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
Do you know how to write?
http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail

__
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 to transform string to Camel Case?

2013-04-15 Thread Liviu Andronic
On Mon, Apr 15, 2013 at 10:10 AM, Gergely Daróczi gerg...@snowl.net wrote:
 Dear Liviu,

 I have just updated tocamel to have a new argument, so the development
 version of the package would produce:

  tocamel(z, upper = TRUE, sep = ' ')
 [1] R Project  Hello WorldSomething Else

Thanks for putting this in. Unfortunately as with other approaches it
fails on NA values:
z - c(R project, hello world, something Else, NA)
 tocamel(z, sep=' ', upper=T)
[1] R Project  Hello WorldSomething Else NANA

Can this be fixed? Thanks,
Liviu

__
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 to transform string to Camel Case?

2013-04-15 Thread Rainer M. Krug
Liviu Andronic landronim...@gmail.com writes:

 On Mon, Apr 15, 2013 at 9:25 AM, Henrik Bengtsson h...@biostat.ucsf.edu 
 wrote:
 See for instance capitalize() in the R.utils package.

 Unfortunately this also fails when NA values are present:
  z - c(R project, hello world, something Else, NA)
 R.utils::capitalize(z)
 [1] R project  Hello worldSomething Else NANA

 Any pointers how to work around that? Thanks,

would 

 R.utils::capitalize(z[is.character(z)])

work in your case?

Rainer


 Liviu


 Henrik

 On Apr 14, 2013 11:51 PM, Liviu Andronic landronim...@gmail.com wrote:

 Dear all,
 Given the following vector:
  (z - c('R project', 'hello world', 'something Else'))
 [1] R project  hello worldsomething Else

 I know how to obtain all capitals or all lower case letters:
  tolower(z)
 [1] r project  hello worldsomething else
  toupper(z)
 [1] R PROJECT  HELLO WORLDSOMETHING ELSE

 I saw the tocamel() function in 'rapport', but it doesn't do what I
 want to achieve as it actually proceeds to camelCase/CamelCase the
 strings:
  tocamel(z)
 [1] RProject  helloWorldsomethingElse


 But how should I proceed to obtain Camel Case? Here's what I'd like to
 get:
 c('R Project', 'Hello World', 'Something Else')


 Regards,
 Liviu


 --
 Do you know how to read?
 http://www.alienetworks.com/srtest.cfm
 http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
 Do you know how to write?
 http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail

 __
 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.
#secure method=pgpmime mode=sign

-- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, 
UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel :   +33 - (0)9 53 10 27 44
Cell:   +33 - (0)6 85 62 59 98
Fax :   +33 - (0)9 58 10 27 44

Fax (D):+49 - (0)3 21 21 25 22 44

email:  rai...@krugs.de

Skype:  RMkrug

__
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 to transform string to Camel Case?

2013-04-15 Thread Gergely Daróczi
On 15 April 2013 14:10, Liviu Andronic landronim...@gmail.com wrote:

 On Mon, Apr 15, 2013 at 10:10 AM, Gergely Daróczi gerg...@snowl.net
 wrote:
  Dear Liviu,
 
  I have just updated tocamel to have a new argument, so the development
  version of the package would produce:
 
   tocamel(z, upper = TRUE, sep = ' ')
  [1] R Project  Hello WorldSomething Else
 
 Thanks for putting this in. Unfortunately as with other approaches it
 fails on NA values:
 z - c(R project, hello world, something Else, NA)
  tocamel(z, sep=' ', upper=T)
 [1] R Project  Hello WorldSomething Else NANA

 Can this be fixed? Thanks,
 Liviu


I have added an extra check in the function for NA values before applying
`paste` at
https://github.com/Rapporter/rapport/compare/34ca6a35fb...a04abc8b21
Alex might not like it :)

Example:

  tocamel(z, upper = TRUE, sep = ' ')
[1] R Project  Hello WorldSomething Else NA

Best,
Gergely

[[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] Indices of lowest values in matrix

2013-04-15 Thread eliza botto
Dear R users,Sorry for such a basic question. I really need to know that how 
can i pick the indices of 5 lowest values from each row of a matrix with 
dimensions 12*12??Thank you very much in advance
Elisa
  
[[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] importing and merging many time series

2013-04-15 Thread Joshua Ulrich
On Sun, Apr 7, 2013 at 7:40 AM, Anton Lebedevich mab...@gmail.com wrote:
 Hello.

 I've got many (5-20k) files with time series in a text format like this:

 1359635460  2.006747
 1359635520  1.886745
 1359635580  3.066988
 1359635640  3.633578
 1359635700  2.140082
 1359635760  2.033564
 1359635820  1.980123
 1359635880  2.060131
 1359635940  2.113416
 1359636000  2.440172

 First field is a unix timestamp, second is a float number. Its a text
 export of http://graphite.readthedocs.org/en/latest/whisper.html
 databases. Time series could have different resolutions, start/end
 times, and possibly gaps inside.

 Current way of importing them:

 read.file - function(file.name) {
   read.zoo(
 file.name,
 na.strings=None,
 colClasses=c(integer, numeric),
 col.names=c(time, basename(file.name)),
 FUN=function(t) {as.POSIXct(t, origin=1970-01-01 00:00.00, tz=UTC)},
 drop=FALSE)
 }

 load.metrics - function(path=.) {
   do.call(merge.zoo, lapply(list.files(path, full.names=TRUE), read.file))
 }

 It works for 6k time series with 2k points in each, but fails with out
 of memory error on 16Gb box when I try to import 10k time series with
 10k points.

You're trying to merge 10,000 objects in a single call.  I'm not
surprised you run out of RAM.

 I've tried to make merging incremental by using Reduce but import speed
 became unacceptable:

This is similar to growing an object in a for loop, which is also slow.

 load.metrics - function(path=.) {
   Reduce(
 function(a, b) {
   if (class(a) == character) {
 a - read.file(a)
   }
   merge.zoo(a, read.file(b))
 },
 list.files(path, full.names=TRUE))
 }

 Is there faster and less memory consuming way to import and merge a lot
 of time series?

Try something in between the two extremes (merging all objects at
once, versus merging every new object with the accumulated object).
For example, try merging 100-1000 objects at a time.

You might also benefit from converting your objects to xts, so you can
use xts' optimized merge.  You can always convert the final object
back to zoo.

 Regards,
 Anton Lebedevich.


Best,
--
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com

R/Finance 2013: Applied Finance with R  | www.RinFinance.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] Indices of lowest values in matrix

2013-04-15 Thread peter dalgaard

On Apr 15, 2013, at 14:27 , eliza botto wrote:

 Dear R users,Sorry for such a basic question. I really need to know that how 
 can i pick the indices of 5 lowest values from each row of a matrix with 
 dimensions 12*12??Thank you very much in advance

Something like this?

 m
  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
 [1,]  1.2 -2.5  0.4 -0.2  1.4 -1.8 -1.6 -0.1 -0.1  -0.3  -0.2  -0.5
 [2,] -0.2 -1.9  0.9  0.0 -1.0  0.2 -0.8  0.7 -1.5  -1.4   1.8   0.4
 [3,] -0.9  0.7  0.4 -0.4 -1.6  0.6  1.1 -0.9  2.3   1.0   0.6   0.8
 [4,]  1.4 -0.7  0.0 -2.3  0.4  1.0  1.5 -0.8  1.0  -0.1   0.6   0.3
 [5,]  0.8 -0.1  1.3 -0.1  1.8 -0.7 -1.4 -0.9  0.6   0.7   0.3   1.4
 [6,]  0.4  0.0  0.6 -0.4  0.7 -0.3  1.5  1.6 -1.9  -1.1   0.3   0.6
 [7,]  0.5 -0.4 -1.9 -2.4  0.3  0.3  0.1  0.6 -0.9   0.2   0.0   1.4
 [8,] -0.2  0.4 -1.4 -0.1 -0.1  1.2  0.2  0.0 -0.9   0.4  -0.3  -2.0
 [9,] -0.3  1.0 -0.7  0.9 -1.7 -0.8  1.8 -0.4  0.1   0.2   0.4   1.2
[10,] -0.6  0.7 -0.1  0.3  1.4  0.7 -0.1  1.0 -0.8   0.9   0.0  -0.6
[11,] -0.1  0.2  0.4 -0.3 -1.5 -0.2  1.0  1.0 -0.5  -0.4  -1.2   1.1
[12,] -1.1  0.3  0.7 -0.9  0.2 -1.0  0.2 -1.1 -1.2  -0.3   0.8  -0.9

 apply(m,1,order)[1:5,]
 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
[1,]2254794   125 9 5 9
[2,]69188   10336 111 1
[3,]7   10826499312 9 8
[4,]   1254   10262   118 310 6
[5,]   1073342   1111 7 4 4


-- 
Peter Dalgaard, Professor
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.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] how to transform string to Camel Case?

2013-04-15 Thread Liviu Andronic
On Mon, Apr 15, 2013 at 2:22 PM, Gergely Daróczi gerg...@snowl.net wrote:
 I have added an extra check in the function for NA values before applying
 `paste` at
 https://github.com/Rapporter/rapport/compare/34ca6a35fb...a04abc8b21
 Alex might not like it :)

 Example:

  tocamel(z, upper = TRUE, sep = ' ')
 [1] R Project  Hello WorldSomething Else NA

Thanks! Now I'm getting somewhere:
z - c(R project, hello world, something Else, something-else,
NA)
 tocamel(z, sep=' ', upper=T, delim= )
[1] R Project  Hello WorldSomething Else Something-else
[5] NA


I hope Alex likes your fixes. Thanks,
Liviu

__
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] Sorting data.frame and again sorting within data.frame

2013-04-15 Thread arun
library(plyr)
arrange(df,names,desc(dates))
#  names dates values
#1 A 4/15/2013 31
#2 A 4/14/2013    102
#3 A 4/13/2013 31
#4 B 4/15/2013 34
#5 B 4/14/2013 47
#6 B 4/13/2013 17
#7 C 4/15/2013 10
#8 C 4/14/2013 29
#9 C 4/13/2013 11
#or
df[with(df,order(names,desc(dates))),]
#  names dates values
#3 A 4/15/2013 31
#7 A 4/14/2013    102
#2 A 4/13/2013 31
#6 B 4/15/2013 34
#8 B 4/14/2013 47
#4 B 4/13/2013 17
#1 C 4/15/2013 10
#9 C 4/14/2013 29
#5 C 4/13/2013 11
A.K.



- Original Message -
From: Katherine Gobin katherine_go...@yahoo.com
To: r-help@r-project.org
Cc: 
Sent: Monday, April 15, 2013 2:01 AM
Subject: [R] Sorting data.frame and again sorting within data.frame

Dear R forum,

I have a data.frame as defied below - 

df = data.frame(names = c(C, A, A, B, C, B, A, B, C), dates = 
c(4/15/2013, 4/13/2013, 4/15/2013, 4/13/2013, 4/13/2013, 4/15/2013, 
4/14/2013, 4/14/2013,4/14/2013 ),values = c(10, 31, 31, 17, 11, 34, 102, 
47, 29))

 df
  names dates values
1 C 4/15/2013 10
2 A 4/13/2013 31
3 A 4/15/2013 31
4 B 4/13/2013 17
5 C 4/13/2013 11
6 B
4/15/2013 34
7 A 4/14/2013    102
8 B 4/14/2013 47
9 C 4/14/2013 29

I need to sort df first on names in increasing order and then further on 
dates in a decreasing order i.e. I need

names    dates    values
A    4/15/2013  31
A    4/14/2013 102
A    4/13/2013  31
B    4/15/2013 
34
B    4/14/2013  47
B    4/13/2013  17
C    4/15/2013  10
C    4/14/2013  29
C    4/13/2013  11

I tried

df_sorted = df[order(df$names, (as.Date(df$dates, %m/%d/%Y)), decreasing = 
TRUE),]

 df_sorted
  names dates values
1 C 4/15/2013 10
9 C 4/14/2013 29
5 C 4/13/2013
11
6 B 4/15/2013 34
8 B 4/14/2013 47
4 B 4/13/2013 17
3 A 4/15/2013 31
7 A 4/14/2013    102
2 A 4/13/2013 31


I need A to appear first with all three corresponding dates in decreasing 
order, then B and so on.

Please guide.

With regards

Katherine


    [[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] Sorting data.frame and again sorting within data.frame

2013-04-15 Thread arun
You can also use:
df[order(df$names,-xtfrm(df$dates),decreasing=FALSE),]
 # names dates values
#3 A 4/15/2013 31
#7 A 4/14/2013    102
#2 A 4/13/2013 31
#6 B 4/15/2013 34
#8 B 4/14/2013 47
#4 B 4/13/2013 17
#1 C 4/15/2013 10
#9 C 4/14/2013 29
#5 C 4/13/2013 11
A.K.




- Original Message -
From: arun smartpink...@yahoo.com
To: Katherine Gobin katherine_go...@yahoo.com
Cc: R help r-help@r-project.org
Sent: Monday, April 15, 2013 8:57 AM
Subject: Re: [R] Sorting data.frame and again sorting within data.frame

library(plyr)
arrange(df,names,desc(dates))
#  names dates values
#1 A 4/15/2013 31
#2 A 4/14/2013    102
#3 A 4/13/2013 31
#4 B 4/15/2013 34
#5 B 4/14/2013 47
#6 B 4/13/2013 17
#7 C 4/15/2013 10
#8 C 4/14/2013 29
#9 C 4/13/2013 11
#or
df[with(df,order(names,desc(dates))),]
#  names dates values
#3 A 4/15/2013 31
#7 A 4/14/2013    102
#2 A 4/13/2013 31
#6 B 4/15/2013 34
#8 B 4/14/2013 47
#4 B 4/13/2013 17
#1 C 4/15/2013 10
#9 C 4/14/2013 29
#5 C 4/13/2013 11
A.K.



- Original Message -
From: Katherine Gobin katherine_go...@yahoo.com
To: r-help@r-project.org
Cc: 
Sent: Monday, April 15, 2013 2:01 AM
Subject: [R] Sorting data.frame and again sorting within data.frame

Dear R forum,

I have a data.frame as defied below - 

df = data.frame(names = c(C, A, A, B, C, B, A, B, C), dates = 
c(4/15/2013, 4/13/2013, 4/15/2013, 4/13/2013, 4/13/2013, 4/15/2013, 
4/14/2013, 4/14/2013,4/14/2013 ),values = c(10, 31, 31, 17, 11, 34, 102, 
47, 29))

 df
  names dates values
1 C 4/15/2013 10
2 A 4/13/2013 31
3 A 4/15/2013 31
4 B 4/13/2013 17
5 C 4/13/2013 11
6 B
4/15/2013 34
7 A 4/14/2013    102
8 B 4/14/2013 47
9 C 4/14/2013 29

I need to sort df first on names in increasing order and then further on 
dates in a decreasing order i.e. I need

names    dates    values
A    4/15/2013  31
A    4/14/2013 102
A    4/13/2013  31
B    4/15/2013 
34
B    4/14/2013  47
B    4/13/2013  17
C    4/15/2013  10
C    4/14/2013  29
C    4/13/2013  11

I tried

df_sorted = df[order(df$names, (as.Date(df$dates, %m/%d/%Y)), decreasing = 
TRUE),]

 df_sorted
  names dates values
1 C 4/15/2013 10
9 C 4/14/2013 29
5 C 4/13/2013
11
6 B 4/15/2013 34
8 B 4/14/2013 47
4 B 4/13/2013 17
3 A 4/15/2013 31
7 A 4/14/2013    102
2 A 4/13/2013 31


I need A to appear first with all three corresponding dates in decreasing 
order, then B and so on.

Please guide.

With regards

Katherine


    [[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] Kruskal-Wallis

2013-04-15 Thread arun
Hi,

set.seed(25)
 myFile1-as.data.frame(matrix(sample(1:40,50,replace=TRUE),nrow=10))
 row.names(myFile1)- LETTERS[1:10]
groups - rep (0:1, c(3,2))
kruskal-apply(myFile1,1,kruskal.test,groups)
 p_kruskal - sapply(kruskal, function(x) x$p.value)
 p_kruskal
# A  B  C  D  E  F  G 
#0.08326452 0.08326452 0.56370286 0.56370286 0.24821308 1. 0.08326452 
 #    H  I  J 
#1. 0.37425932 0.56370286 
#or
 sapply(seq_len(nrow(myFile1)),function(i) 
kruskal.test(unlist(myFile1[i,]),groups)$p.value)
 [1] 0.08326452 0.08326452 0.56370286 0.56370286 0.24821308 1.
 [7] 0.08326452 1. 0.37425932 0.56370286
A.K.

- Original Message -
From: Chintanu chint...@gmail.com
To: R help r-help@r-project.org
Cc: 
Sent: Monday, April 15, 2013 1:18 AM
Subject: [R] Kruskal-Wallis

Hi,

I have got two groups of samples; and for every row, I wish to calculate
Kruskal-Wallis' p-value.
In the example below, and the stars () show where I am struggling to
design and put things together. Any help would be appreciated.


myFile - data.frame(Sample_1a = 1:10, Sample_1b = 2:11, Sample_1c = 3:12,
Sample_2a=4:13, Sample_2b=7:16, row.names=LETTERS[1:10])

groups - rep (0:1, c(3,2))

kruskal - apply(myFile [1:nrow(myFile),], 1,  kruskal.test, **)

p_kruskal - sapply(kruskal, function(x) x$p.value)

Thanks,
Chintanu

    [[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] Kruskal-Wallis

2013-04-15 Thread Charles Determan Jr
One statistical point beyond A.K.'s well done response.  As you should well
know, Kruskal-Wallis is a non-parametric equivalent of ANOVA.  However, you
only have two groups and do not require an ANOVA approach.  You could
simply use a Mann-Whitney U (aka.. independent Wilcoxon) test using
wilcox.test().

Charles

On Mon, Apr 15, 2013 at 8:23 AM, arun smartpink...@yahoo.com wrote:

 Hi,

 set.seed(25)
  myFile1-as.data.frame(matrix(sample(1:40,50,replace=TRUE),nrow=10))
  row.names(myFile1)- LETTERS[1:10]
 groups - rep (0:1, c(3,2))
 kruskal-apply(myFile1,1,kruskal.test,groups)
  p_kruskal - sapply(kruskal, function(x) x$p.value)
  p_kruskal
 # A  B  C  D  E
 F  G
 #0.08326452 0.08326452 0.56370286 0.56370286 0.24821308 1.
 0.08326452
  #H  I  J
 #1. 0.37425932 0.56370286
 #or
  sapply(seq_len(nrow(myFile1)),function(i)
 kruskal.test(unlist(myFile1[i,]),groups)$p.value)
  [1] 0.08326452 0.08326452 0.56370286 0.56370286 0.24821308 1.
  [7] 0.08326452 1. 0.37425932 0.56370286
 A.K.

 - Original Message -
 From: Chintanu chint...@gmail.com
 To: R help r-help@r-project.org
 Cc:
 Sent: Monday, April 15, 2013 1:18 AM
 Subject: [R] Kruskal-Wallis

 Hi,

 I have got two groups of samples; and for every row, I wish to calculate
 Kruskal-Wallis' p-value.
 In the example below, and the stars () show where I am struggling to
 design and put things together. Any help would be appreciated.


 myFile - data.frame(Sample_1a = 1:10, Sample_1b = 2:11, Sample_1c = 3:12,
 Sample_2a=4:13, Sample_2b=7:16, row.names=LETTERS[1:10])

 groups - rep (0:1, c(3,2))

 kruskal - apply(myFile [1:nrow(myFile),], 1,  kruskal.test, **)

 p_kruskal - sapply(kruskal, function(x) x$p.value)

 Thanks,
 Chintanu

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




-- 
Charles Determan
Integrated Biosciences PhD Student
University of Minnesota

[[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] Overlay two stat_ecdf() plots

2013-04-15 Thread Robin Mjelle
I want to plot two scdf-plots in the same graph.
I have two input tables with one column each:

 Targets - read.table(/media/, sep=, header=T)
 NonTargets - read.table(/media/..., sep=, header=T)

 head(Targets)
V1
1 3.160514
2 6.701948
3 4.093844
4 1.992014
5 1.604751
6 2.076802

 head(NonTargets)
 V1
1  3.895934
2  1.990506
3 -1.746919
4 -3.451477
5  5.156554
6  1.195109

 Targets.m - melt(Targets)
 head(Targets.m)
  variablevalue
1   V1 3.160514
2   V1 6.701948
3   V1 4.093844
4   V1 1.992014
5   V1 1.604751
6   V1 2.076802

 NonTargets.m - melt(NonTargets)
 head(NonTargets.m)
  variable value
1   V1  3.895934
2   V1  1.990506
3   V1 -1.746919
4   V1 -3.451477
5   V1  5.156554
6   V1  1.195109


How do I proceed to plot them in one Graph using ecdf_stat()

[[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] need help with R

2013-04-15 Thread sam tingey
hey there

can i email questions to this address to get help with using R

thanks sam

[[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] (no subject)

2013-04-15 Thread ilovestats
Hi, I'm trying to decide between doing a FA or PCA and would appreciate some
pointers. I've got a questionnaire with latent items which the participants
answered on a Likert scale, and all I want to do at this point is to explore
the data and extract a number of factors/components. Would FA or PCA be most
appropriate in this case?
Cheers,
Hannah




--
View this message in context: 
http://r.789695.n4.nabble.com/no-subject-tp4664248.html
Sent from the R help mailing list archive at Nabble.com.
[[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] Optimisation and NaN Errors using clm() and clmm()

2013-04-15 Thread Thomas

Dear List,

I am using both the clm() and clmm() functions from the R package 
'ordinal'.


I am fitting an ordinal dependent variable with 5 categories to 9 
continuous predictors, all of which have been normalised (mean 
subtracted then divided by standard deviation), using a probit link 
function. From this global model I am generating a confidence set of 200 
models using clm() and the 'glmulti' R package. This produces these errors:


/ model.2.10 - glmulti(as.factor(dependent) ~ 
predictor_1*predictor_2*predictor_3*predictor_4*predictor_5*predictor_6*predictor_7*predictor_8*predictor_9, 
data = database, fitfunc = clm, link = probit, method = g, crit = 
aicc, confsetsize = 200, marginality = TRUE)

...
After 670 generations:
Best model: 
as.factor(dependent)~1+predictor_1+predictor_2+predictor_3+predictor_4+predictor_5+predictor_6+predictor_8+predictor_9+predictor_4:predictor_3+predictor_6:predictor_2+predictor_8:predictor_5+predictor_9:predictor_1+predictor_9:predictor_4+predictor_9:predictor_5+predictor_9:predictor_6

Crit= 183.716706496392
Mean crit= 202.022138576506
Improvements in best and average IC have bebingo en below the specified 
goals.

Algorithm is declared to have converged.
Completed.
There were 24 warnings (use warnings() to see them)
 warnings()
Warning messages:
1: optimization failed: step factor reduced below minimum
2: optimization failed: step factor reduced below minimum
3: optimization failed: step factor reduced below minimum/
etc.


I am then re-fitting each of the 200 models with the clmm() function, 
with 2 random factors (family nested within order). I get this error in 
a few of the re-fitted models:


/ model.2.glmm.2 - clmm(as.factor(dependent) ~ 1 + predictor_1 + 
predictor_2 + predictor_3 + predictor_6 + predictor_7 + predictor_8 + 
predictor_9 + predictor_6:predictor_2 + predictor_7:predictor_2 + 
predictor_7:predictor_3 + predictor_8:predictor_2 + 
predictor_9:predictor_1 + predictor_9:predictor_2 + 
predictor_9:predictor_3 + predictor_9:predictor_6 + 
predictor_9:predictor_7 + predictor_9:predictor_8+ (1|order/family), 
link = probit, data = database)

 summary(model.2.glmm.2)

Cumulative Link Mixed Model fitted with the Laplace approximation

formula: as.factor(dependent) ~ 1 + predictor_1 + predictor_2 + 
predictor_3 + predictor_6 + predictor_7 + predictor_8 + predictor_9 + 
predictor_6:predictor_2 + predictor_7:predictor_2 +
predictor_7:predictor_3 + predictor_8:predictor_2 + 
predictor_9:predictor_1 + predictor_9:predictor_2 +
predictor_9:predictor_3 + predictor_9:predictor_6 + 
predictor_9:predictor_7 + predictor_9:predictor_8 + (1 | order/family)

data: database

link threshold nobs logLik AIC niter max.grad cond.H
probit flexible 103 -65.56 173.13 58(3225) 8.13e-06 4.3e+03

Random effects:
Var Std.Dev
family:order 7.493e-11 8.656e-06
order 1.917e-12 1.385e-06
Number of groups: family:order 12, order 4

Coefficients:
Estimate Std. Error z value Pr(|z|)
predictor_1 0.40802 0.78685 0.519 0.6041
predictor_2 0.02431 0.26570 0.092 0.9271
predictor_3 -0.84486 0.32056 -2.636 0.0084 **
predictor_6 0.65392 0.34348 1.904 0.0569 .
predictor_7 0.71730 0.29596 2.424 0.0154 *
predictor_8 -1.37692 0.75660 -1.820 0.0688 .
predictor_9 0.15642 0.28969 0.540 0.5892
predictor_2:predictor_6 -0.46880 0.18829 -2.490 0.0128 *
predictor_2:predictor_7 4.97365 0.82692 6.015 1.80e-09 ***
predictor_3:predictor_7 -1.13192 0.46639 -2.427 0.0152 *
predictor_2:predictor_8 -5.52913 0.88476 -6.249 4.12e-10 ***
predictor_1:predictor_9 4.28519 NA NA NA
predictor_2:predictor_9 -0.26558 0.10541 -2.520 0.0117 *
predictor_3:predictor_9 -1.49790 NA NA NA
predictor_6:predictor_9 -1.31538 NA NA NA
predictor_7:predictor_9 -4.41998 NA NA NA
predictor_8:predictor_9 3.99709 NA NA NA
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Threshold coefficients:
Estimate Std. Error z value
0|1 -0.2236 0.3072 -0.728
1|2 1.4229 0.3634 3.915
(211 observations deleted due to missingness)
Warning message:
In sqrt(diag(vc)[1:npar]) : NaNs produced/


I have tried a number of different approaches, each has its own 
problems. I have fixed these using various suggestions from online 
forums (eg 
https://stat.ethz.ch/pipermail/r-sig-mixed-models/2011q1/015328.html, 
https://stat.ethz.ch/pipermail/r-sig-mixed-models/2011q2/016165.html) 
and this is as good as I can get it.


After the first stage (generating the model set with glmulti) I tested 
every model in the confidence set individually - there were no errors - 
but there was clearly a problem during the model selection process. 
Should I be worried?


No errors appear in the top 5% of re-fitted models (which are the only 
ones I will be using) however I am concerned that errors may be 
indicative of a problem with my approach.


A further worry is that the errors might be removing models that could 
otherwise be included.


Any help would be much appreciated.

Tom

__
R-help@r-project.org mailing list

Re: [R] how to transform string to Camel Case?

2013-04-15 Thread arun
HI,
You could use:
gsub((^|\\s+)([a-z]),\\1\\U\\2,z,perl=TRUE)
#[1] R Project  Hello World    Something Else

#or
 gsub(\\b([a-z]),\\U\\1,z,perl=TRUE)
#[1] R Project  Hello World    Something Else
A.K.



- Original Message -
From: Liviu Andronic landronim...@gmail.com
To: r-help r-h...@stat.math.ethz.ch
Cc: 
Sent: Monday, April 15, 2013 2:50 AM
Subject: [R] how to transform string to Camel Case?

Dear all,
Given the following vector:
 (z - c('R project', 'hello world', 'something Else'))
[1] R project      hello world    something Else

I know how to obtain all capitals or all lower case letters:
 tolower(z)
[1] r project      hello world    something else
 toupper(z)
[1] R PROJECT      HELLO WORLD    SOMETHING ELSE

I saw the tocamel() function in 'rapport', but it doesn't do what I
want to achieve as it actually proceeds to camelCase/CamelCase the
strings:
 tocamel(z)
[1] RProject      helloWorld    somethingElse


But how should I proceed to obtain Camel Case? Here's what I'd like to get:
c('R Project', 'Hello World', 'Something Else')


Regards,
Liviu


-- 
Do you know how to read?
http://www.alienetworks.com/srtest.cfm
http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
Do you know how to write?
http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail

__
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] need help with R

2013-04-15 Thread Sarah Goslee
Yes, but do read:
http://www.R-project.org/posting-guide.html
first.

Sarah

On Mon, Apr 15, 2013 at 2:09 AM, sam tingey sam.ting...@gmail.com wrote:
 hey there

 can i email questions to this address to get help with using R

 thanks sam


 __
 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.



-- 
Sarah Goslee
http://www.functionaldiversity.org

__
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] Cross validation for Naive Bayes and Bayes Networks

2013-04-15 Thread Marco Scutari
Hi Guilherme,

On Sun, Apr 14, 2013 at 11:48 PM, Guilherme Ferraz de Arruda
gu...@yahoo.com.br wrote:
 Hi,
 I need to classify, using Naive Bayes and Bayes Networks,  and estimate
 their performance using cross validation.
 How can I do this?
 I tried the bnlearn package for Bayes Networks, althought I need to get
 more indexes, not only the error rate (precision, sensitivity, ...).

You can do that using the object returned by bn.cv(), because it
contains the predicted values and the indexes of the corresponding
observations in the original data, for each fold. It's just a matter
to reassemble observed and predicted class labels and compute your
metrics.

 I also tried the *e1071* package, but I could not find a way to do
 cross-validation.

You might be able to trick the tune() function to do it, but I am not sure.

Marco

-- 
Marco Scutari, Ph.D.
Research Associate, Genetics Institute (UGI)
University College London (UCL), United Kingdom

__
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] Indices of lowest values in matrix

2013-04-15 Thread arun
Hi,
TRy this:
set.seed(30)
 mat1- matrix(sample(1:50,12*12,replace=TRUE),ncol=12)
mat1
  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
 [1,]    5   28   13    4   47    3   30   16    3    39    42 9
 [2,]   25   44   15   21    9    5   32    5    4    33    30    21
 [3,]   19   12   24    2    7   37   36    3   13 9    33    33
 [4,]   22   47   13   14    9   29   20    3    1    25    14    29
 [5,]   16   13   41   22   15   39   50   44   10    50    32    32
 [6,]    8   42   24   32   21   31   45   32   41    44    22    31
 [7,]   45   31   31   39    4   25    1   19   28    16    20    48
 [8,]   12   22   12   25   45   10    5    7   31    27    18    30
 [9,]   49    8   25   10    6   30    8   29   14    10    48    44
[10,]    8   30   31   35    4   50   25   33    7    15    17    38
[11,]    4    2   15   40   30   49   44   14    3    33    41    12
[12,]   20   17   34   14   43    2   40   50   42    42    23    20


#If you need the lowest values:
 sapply(seq_len(nrow(mat1)),function(i) {x1- mat1[i,]; x1[order(x1)][1:5]})
#    [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
#[1,]    3    4    2    1   10    8    1    5    6 4 2 2
#[2,]    3    5    3    3   13   21    4    7    8 7 3    14
#[3,]    4    5    7    9   15   22   16   10    8 8 4    17
#[4,]    5    9    9   13   16   24   19   12   10    15    12    20
#[5,]    9   15   12   14   22   31   20   12   10    17    14    20


#indices

sapply(seq_len(nrow(mat1)),function(i) {order(mat1[i,])})[1:5,]
  #   [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
#[1,]    6    9    4    9    9    1    7    7    5 5 2 6
#[2,]    9    6    8    8    2    5    5    8    2 9 9 4
#[3,]    4    8    5    5    5   11   10    6    7 1 1 2
#[4,]    1    5   10    3    1    3    8    1    4    10    12 1
#[5,]   12    3    2    4    4    6   11    3   10    11 8    12
A.K.





- Original Message -
From: eliza botto eliza_bo...@hotmail.com
To: r-help@r-project.org r-help@r-project.org
Cc: 
Sent: Monday, April 15, 2013 8:27 AM
Subject: [R] Indices of lowest values in matrix

Dear R users,Sorry for such a basic question. I really need to know that how 
can i pick the indices of 5 lowest values from each row of a matrix with 
dimensions 12*12??Thank you very much in advance
Elisa
                          
    [[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] need help with R

2013-04-15 Thread Dieter Menne

Sam tingey wrote:
 can i email questions to this address to get help with using R

Sarah Goslee replied; 
Yes, but do read:
http://www.R-project.org/posting-guide.html

Dieter Menne thought:

Catch 42. When you are so good that you can create a reproducible example
without using R, you only will post answers.



--
View this message in context: 
http://r.789695.n4.nabble.com/need-help-with-R-tp4664259p4664264.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] (no subject)

2013-04-15 Thread peter dalgaard

On Apr 15, 2013, at 14:30 , ilovestats wrote:

 Hi, I'm trying to decide between doing a FA or PCA and would appreciate some
 pointers. I've got a questionnaire with latent items which the participants
 answered on a Likert scale, and all I want to do at this point is to explore
 the data and extract a number of factors/components. Would FA or PCA be most
 appropriate in this case?
 Cheers,
 Hannah
 
 


Not really an R question, is it? 

Stats.StackExchange.com is  - that way!

In terms of theory, PCA is essentially FA with the same residual variance in 
all responses. With all-Likert scales, it is unlikely that there will be much 
of a difference.

In practical terms:

- factanal can diverge (Heywood cases) which is a bit of a bother

on the other hand

- factor rotation is based on factanal() output; may require a little extra 
diddling to work with prcomp().

I think I'd try factanal() first, and if it acts up, switch to prcomp().

-- 
Peter Dalgaard, Professor
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.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] as.date not reading Hour/Minute am/pm Data

2013-04-15 Thread arun


Hi,
Try:
x- c(2/26/13 11:59 PM, 2/25/13 10:25 AM)
strptime(x,%m/%d/%y %I:%M %p)
#[1] 2013-02-26 23:59:00 2013-02-25 10:25:00

#or
library(lubridate)
parse_date_time(x,%m/%d/%y %I:%M %p)
# 2 parsed with %m/%d/%y %I:%M %p
#[1] 2013-02-26 23:59:00 UTC 2013-02-25 10:25:00 UTC
A.K.


I'm a newbie to R but not programming.   

I've researched online and through this forum and am unsure of 
why I'm not getting a as.date object to only store a limited amount of 
data.  The date is in the format of: 2/26/13 11:59 PM in a .csv file 
with over 5000 data points.  My as.date function reads: 

 gld - read.csv(c:/data/gbpdata.csv, stringsAsFactors=F) 
 gld_dates - as.Date(gld[,1], format=%m/%d/%y %H:%M %p) 
 gld_dates: 

[36775] 2013-04-03 2013-04-03 2013-04-03 2013-04-03 2013-04-03 
2013-04-03 2013-04-03 2013-04-03 2013-04-03 

What am I doing wrong?  Thanks in advance for your replies.

__
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] use of simulate.Arima (forecast package)

2013-04-15 Thread Stefano Sofia
I would like to simulate some SARIMA models, e.g. a SARIMA (1,0,1)(1,0,1)[4] 
process.

I installed the package 'forecast', where the function simulate.Arima should do 
what I am trying to do.
I am not able to understand how it works
Could somebody help me with an example?

thank you
Stefano Sofia


AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere 
informazioni confidenziali, pertanto è destinato solo a persone autorizzate 
alla ricezione. I messaggi di posta elettronica per i client di Regione Marche 
possono contenere informazioni confidenziali e con privilegi legali. Se non si 
è il destinatario specificato, non leggere, copiare, inoltrare o archiviare 
questo messaggio. Se si è ricevuto questo messaggio per errore, inoltrarlo al 
mittente ed eliminarlo completamente dal sistema del proprio computer. Ai sensi 
dell’art. 6 della  DGR n. 1394/2008 si segnala che, in caso di necessità ed 
urgenza, la risposta al presente messaggio di posta elettronica può essere 
visionata da persone estranee al destinatario.
IMPORTANT NOTICE: This e-mail message is intended to be received only by 
persons entitled to receive the confidential information it may contain. E-mail 
messages to clients of Regione Marche may contain information that is 
confidential and legally privileged. Please do not read, copy, forward, or 
store this message unless you are an intended recipient of it. If you have 
received this message in error, please forward it to the sender and delete it 
completely from your computer system.
__
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] Using R commander within R Studio (Mac)

2013-04-15 Thread h moore
Hi.

I am a R studio user and would like to use RCommander within R studio. Each
time I try to install and use Rcommander, I see the following message:

Loading Tcl/Tk interface ... Error : .onLoad failed in loadNamespace() for
'tcltk', details:
  call: dyn.load(file, DLLpath = DLLpath, ...)
  error: unable to load shared object
'/Library/Frameworks/R.framework/Versions/2.15/Resources/library/tcltk/libs/x86_64/tcltk.so':

dlopen(/Library/Frameworks/R.framework/Versions/2.15/Resources/library/tcltk/libs/x86_64/tcltk.so,
10): Library not loaded: /usr/local/lib/libtcl8.5.dylib
  Referenced from:
/Library/Frameworks/R.framework/Versions/2.15/Resources/library/tcltk/libs/x86_64/tcltk.so
  Reason: image not found
In addition: Warning message:
package ‘Rcmdr’ was built under R version 2.15.3
Error: package/namespace load failed for ‘Rcmdr’

I went to get X11 and installed it as I believed this was the problem, but
I get the same message.

Would anyone get me some clues on what is going on?

[[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] how to transform string to Camel Case?

2013-04-15 Thread Gabor Grothendieck
On Mon, Apr 15, 2013 at 2:50 AM, Liviu Andronic landronim...@gmail.com wrote:
 Dear all,
 Given the following vector:
 (z - c('R project', 'hello world', 'something Else'))
 [1] R project  hello worldsomething Else

 I know how to obtain all capitals or all lower case letters:
 tolower(z)
 [1] r project  hello worldsomething else
 toupper(z)
 [1] R PROJECT  HELLO WORLDSOMETHING ELSE

 I saw the tocamel() function in 'rapport', but it doesn't do what I
 want to achieve as it actually proceeds to camelCase/CamelCase the
 strings:
 tocamel(z)
 [1] RProject  helloWorldsomethingElse


 But how should I proceed to obtain Camel Case? Here's what I'd like to get:
 c('R Project', 'Hello World', 'Something Else')


Here is a one liner using gsubfn from the gsubfn package
(http://gsubfn.googlecode.com).  gsubfn is like gsubfn except the
second argument can be a function (or a list or a proto object).  The
regular expression here matches a space followed by any character.
For each such match gsubfn will call the function denoted by the
second argument using the two parenthesized portions of the regular
expression as the two arguments.  It supports an optional formula
notation to express the function for compactness so ... ~ toupper(..2)
denotes function(...) toupper(..2) which is equivalent to function(x,
y) toupper(y) .  It replaces the input with the output of that
function.  Finally we check if any of the components of the input are
NA and replace those with NA in the output:

 replace(gsubfn(( )(.), ... ~ toupper(..2), z), is.na(z), NA)
[1] RProject  helloWorldsomethingElse NA

__
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] Using R commander within R Studio (Mac)

2013-04-15 Thread John Fox
Dear Helene,

I don't think that your problem has anything to do with RStudio. I suspect that 
you haven't installed Tcl/Tk for X-Windows on your Mac, as is required by the 
tcltk package for versions of R on the Mac prior to 3.0.0. Please read the 
Rcmdr installation instructions at 
http://socserv.socsci.mcmaster.ca/jfox/Misc/Rcmdr/installation-notes.html for 
detailed information (and see in particular the link to Mac OS X installation 
notes for the R Commander under older versions of R).

That said, I suggest that upgrade to R 3.0.0. You should also know that while 
the Rcmdr runs under RStudio, there are some problems, particularly with the 
RStudio graphics device.

I hope this helps,
 John


John Fox
Sen. William McMaster Prof. of Social Statistics
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
http://socserv.mcmaster.ca/jfox/

On Mon, 15 Apr 2013 10:19:24 -0400
 h moore helene.mo...@ryerson.ca wrote:
 Hi.
 
 I am a R studio user and would like to use RCommander within R studio. Each
 time I try to install and use Rcommander, I see the following message:
 
 Loading Tcl/Tk interface ... Error : .onLoad failed in loadNamespace() for
 'tcltk', details:
   call: dyn.load(file, DLLpath = DLLpath, ...)
   error: unable to load shared object
 '/Library/Frameworks/R.framework/Versions/2.15/Resources/library/tcltk/libs/x86_64/tcltk.so':
 
 dlopen(/Library/Frameworks/R.framework/Versions/2.15/Resources/library/tcltk/libs/x86_64/tcltk.so,
 10): Library not loaded: /usr/local/lib/libtcl8.5.dylib
   Referenced from:
 /Library/Frameworks/R.framework/Versions/2.15/Resources/library/tcltk/libs/x86_64/tcltk.so
   Reason: image not found
 In addition: Warning message:
 package ‘Rcmdr’ was built under R version 2.15.3
 Error: package/namespace load failed for ‘Rcmdr’
 
 I went to get X11 and installed it as I believed this was the problem, but
 I get the same message.
 
 Would anyone get me some clues on what is going on?
 
   [[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] how to transform string to Camel Case?

2013-04-15 Thread Gabor Grothendieck
On Mon, Apr 15, 2013 at 10:56 AM, Gabor Grothendieck
ggrothendi...@gmail.com wrote:
 On Mon, Apr 15, 2013 at 2:50 AM, Liviu Andronic landronim...@gmail.com 
 wrote:
 Dear all,
 Given the following vector:
 (z - c('R project', 'hello world', 'something Else'))
 [1] R project  hello worldsomething Else

 I know how to obtain all capitals or all lower case letters:
 tolower(z)
 [1] r project  hello worldsomething else
 toupper(z)
 [1] R PROJECT  HELLO WORLDSOMETHING ELSE

 I saw the tocamel() function in 'rapport', but it doesn't do what I
 want to achieve as it actually proceeds to camelCase/CamelCase the
 strings:
 tocamel(z)
 [1] RProject  helloWorldsomethingElse


 But how should I proceed to obtain Camel Case? Here's what I'd like to get:
 c('R Project', 'Hello World', 'Something Else')


 Here is a one liner using gsubfn from the gsubfn package
 (http://gsubfn.googlecode.com).  gsubfn is like gsubfn except the
 second argument can be a function (or a list or a proto object).  The
 regular expression here matches a space followed by any character.
 For each such match gsubfn will call the function denoted by the
 second argument using the two parenthesized portions of the regular
 expression as the two arguments.  It supports an optional formula
 notation to express the function for compactness so ... ~ toupper(..2)
 denotes function(...) toupper(..2) which is equivalent to function(x,
 y) toupper(y) .  It replaces the input with the output of that
 function.  Finally we check if any of the components of the input are
 NA and replace those with NA in the output:

 replace(gsubfn(( )(.), ... ~ toupper(..2), z), is.na(z), NA)
 [1] RProject  helloWorldsomethingElse NA

Above gsubfn is like gsubfn should read gsubfn is like gsub

Also here is a further simplification:

 replace(gsubfn( (.), toupper, z), is.na(z), NA)
[1] RProject  helloWorldsomethingElse NA


--
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.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] Indices of lowest values in matrix

2013-04-15 Thread eliza botto
Dear Arun,
Thankyou very much. it worked out
:D
Elisa

 Date: Mon, 15 Apr 2013 07:19:40 -0700
 From: smartpink...@yahoo.com
 Subject: Re: [R] Indices of lowest values in matrix
 To: eliza_bo...@hotmail.com
 
 Hi Elisa,
 I am not sure how you got that values for the first rows of mat1.  Is it from 
 other dataset
 set.seed(30)
  mat1- matrix(sample(1:50,12*12,replace=TRUE),ncol=12)
 mat1[1,]
 # [1]  5 28 13  4 47  3 30 16  3 39 42  9
 #So, here the lowest 5 values are 3,3,4,5,9
 
 sort(mat1[1,],index.return=TRUE)
 #$x
  #[1]  3  3  4  5  9 13 16 28 30 39 42 47
 
 #$ix 
 
 #[1]  6  9  4  1 12  3  8  2  7 10 11  5
 
 From my previous solution:
 sapply(seq_len(nrow(mat1)),function(i) {order(mat1[i,])})[1:5,1]
 #[1]  6  9  4  1 12 #which are the column numbers.
 A.K.
 
 
 
  From: eliza botto eliza_bo...@hotmail.com
 To: smartpink...@yahoo.com smartpink...@yahoo.com 
 Sent: Monday, April 15, 2013 10:09 AM
 Subject: RE: [R] Indices of lowest values in matrix
  
 
 
  
 Thankyou very much.
 
 
 one additional question is that what if i am interest to find that along the 
 row 1 which are 5 lowest values?  more precisely, for row 1 of mat1 the five 
 lowest values are
 
 3,5,8,19,21
 
 therefore, i should have
 
 1,2,8,5,4 (the column numbers which contain these values)
 
 Thanks in advance
 
 Elisa
 
 
 
  Date: Mon, 15 Apr 2013 06:53:32 -0700
  From: smartpink...@yahoo.com
  Subject: Re: [R] Indices of lowest values in matrix
  To: eliza_bo...@hotmail.com
  CC: r-help@r-project.org
  
  Hi,
  TRy this:
  set.seed(30)
  Ámat1- matrix(sample(1:50,12*12,replace=TRUE),ncol=12)
  mat1
  Á [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
  Á[1,]ÁÁÁ 5ÁÁ 28ÁÁ 13ÁÁÁ 4ÁÁ 47ÁÁÁ 3ÁÁ 30ÁÁ 16ÁÁÁ 3ÁÁÁ 39ÁÁÁ 42 9
  Á[2,]ÁÁ 25ÁÁ 44ÁÁ 15ÁÁ 21ÁÁÁ 9ÁÁÁ 5ÁÁ 32ÁÁÁ 5ÁÁÁ 4ÁÁÁ 33ÁÁÁ 30ÁÁÁ 21
  Á[3,]ÁÁ 19ÁÁ 12ÁÁ 24ÁÁÁ 2ÁÁÁ 7ÁÁ 37ÁÁ 36ÁÁÁ 3ÁÁ 13 9ÁÁÁ 33ÁÁÁ 33
  Á[4,]ÁÁ 22ÁÁ 47ÁÁ 13ÁÁ 14ÁÁÁ 9ÁÁ 29ÁÁ 20ÁÁÁ 3ÁÁÁ 1ÁÁÁ 25ÁÁÁ 14ÁÁÁ 29
  Á[5,]ÁÁ 16ÁÁ 13ÁÁ 41ÁÁ 22ÁÁ 15ÁÁ 39ÁÁ 50ÁÁ 44ÁÁ 10ÁÁÁ 50ÁÁÁ 32ÁÁÁ 32
  Á[6,]ÁÁÁ 8ÁÁ 42ÁÁ 24ÁÁ 32ÁÁ 21ÁÁ 31ÁÁ 45ÁÁ 32ÁÁ 41ÁÁÁ 44ÁÁÁ 22ÁÁÁ 31
  Á[7,]ÁÁ 45ÁÁ 31ÁÁ 31ÁÁ 39ÁÁÁ 4ÁÁ 25ÁÁÁ 1ÁÁ 19ÁÁ 28ÁÁÁ 16ÁÁÁ 20ÁÁÁ 48
  Á[8,]ÁÁ 12ÁÁ 22ÁÁ 12ÁÁ 25ÁÁ 45ÁÁ 10ÁÁÁ 5ÁÁÁ 7ÁÁ 31ÁÁÁ 27ÁÁÁ 18ÁÁÁ 30
  Á[9,]ÁÁ 49ÁÁÁ 8ÁÁ 25ÁÁ 10ÁÁÁ 6ÁÁ 30ÁÁÁ 8ÁÁ 29ÁÁ 14ÁÁÁ 10ÁÁÁ 48ÁÁÁ 44
  [10,]ÁÁÁ 8ÁÁ 30ÁÁ 31ÁÁ 35ÁÁÁ 4ÁÁ 50ÁÁ 25ÁÁ 33ÁÁÁ 7ÁÁÁ 15ÁÁÁ 17ÁÁÁ 38
  [11,]ÁÁÁ 4ÁÁÁ 2ÁÁ 15ÁÁ 40ÁÁ 30ÁÁ 49ÁÁ 44ÁÁ 14ÁÁÁ 3ÁÁÁ 33ÁÁÁ 41ÁÁÁ 12
  [12,]ÁÁ 20ÁÁ 17ÁÁ 34ÁÁ 14ÁÁ 43ÁÁÁ 2ÁÁ 40ÁÁ 50ÁÁ 42ÁÁÁ 42ÁÁÁ 23ÁÁÁ 20
  
  
  #If you need the lowest values:
  Ásapply(seq_len(nrow(mat1)),function(i) {x1- mat1[i,]; x1[order(x1)][1:5]})
  #ÁÁÁ [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
  #[1,]ÁÁÁ 3ÁÁÁ 4ÁÁÁ 2ÁÁÁ 1ÁÁ 10ÁÁÁ 8ÁÁÁ 1ÁÁÁ 5ÁÁÁ 6 4 2 2
  #[2,]ÁÁÁ 3ÁÁÁ 5ÁÁÁ 3ÁÁÁ 3ÁÁ 13ÁÁ 21ÁÁÁ 4ÁÁÁ 7ÁÁÁ 8 7 3ÁÁÁ 14
  #[3,]ÁÁÁ 4ÁÁÁ 5ÁÁÁ 7ÁÁÁ 9ÁÁ 15ÁÁ 22ÁÁ 16ÁÁ 10ÁÁÁ 8 8 4ÁÁÁ 17
  #[4,]ÁÁÁ 5ÁÁÁ 9ÁÁÁ 9ÁÁ 13ÁÁ 16ÁÁ 24ÁÁ 19ÁÁ 12ÁÁ 10ÁÁÁ 15ÁÁÁ 12ÁÁÁ 20
  #[5,]ÁÁÁ 9ÁÁ 15ÁÁ 12ÁÁ 14ÁÁ 22ÁÁ 31ÁÁ 20ÁÁ 12ÁÁ 10ÁÁÁ 17ÁÁÁ 14ÁÁÁ 20
  
  
  #indices
  
  sapply(seq_len(nrow(mat1)),function(i) {order(mat1[i,])})[1:5,]
  Á # Á [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
  #[1,]ÁÁÁ 6ÁÁÁ 9ÁÁÁ 4ÁÁÁ 9ÁÁÁ 9ÁÁÁ 1ÁÁÁ 7ÁÁÁ 7ÁÁÁ 5 5 2 6
  #[2,]ÁÁÁ 9ÁÁÁ 6ÁÁÁ 8ÁÁÁ 8ÁÁÁ 2ÁÁÁ 5ÁÁÁ 5ÁÁÁ 8ÁÁÁ 2 9 9 4
  #[3,]ÁÁÁ 4ÁÁÁ 8ÁÁÁ 5ÁÁÁ 5ÁÁÁ 5ÁÁ 11ÁÁ 10ÁÁÁ 6ÁÁÁ 7 1 1 2
  #[4,]ÁÁÁ 1ÁÁÁ 5ÁÁ 10ÁÁÁ 3ÁÁÁ 1ÁÁÁ 3ÁÁÁ 8ÁÁÁ 1ÁÁÁ 4ÁÁÁ 10ÁÁÁ 12 1
  #[5,]ÁÁ 12ÁÁÁ 3ÁÁÁ 2ÁÁÁ 4ÁÁÁ 4ÁÁÁ 6ÁÁ 11ÁÁÁ 3ÁÁ 10ÁÁÁ 11 8ÁÁÁ 12
  A.K.
  
  
  
  
  
  - Original Message -
  From: eliza botto eliza_bo...@hotmail.com
  To: r-help@r-project.org r-help@r-project.org
  Cc: 
  Sent: Monday, April 15, 2013 8:27 AM
  Subject: [R] Indices of lowest values in matrix
  
  Dear R users,Sorry for such a basic question. I really need to know that 
  how can i pick the indices of 5 lowest values from each row of a matrix 
  with dimensions 12*12??Thank you very much in advance
  Elisa
  ÁÁÁ ÁÁÁ  ÁÁÁ Á  ÁÁÁ ÁÁÁ Á 
  ÁÁÁ [[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] RJSONIO Installation

2013-04-15 Thread Uwe Ligges



On 13.04.2013 08:22, Jeff Newmiller wrote:

R CMD build
will only work on Windows if you have Rtools installed. Visit your local CRAN 
mirror and read... this is not exactly trivial.


Not exactly true:

pure R code / data packages typically R CMD build and R CMD INSTALL 
without those tools installed. And, if you disable the rebuilt of 
vignettes, R CMD build will always work without the tools installed, ad 
far as I know.


Best,
Uwe Ligges




---
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.

John Henry johnmghe...@gmail.com wrote:


Trying to install rjsonio and I've run into a couple of issues.
1. When installing from R, it's starts to download, then I get
* installing *source* package 'RJSONIO' ...
ERROR: configuration failed for package 'RJSONIO'
* removing 'C:/Program Files/R/R-3.0.0/library/RJSONIO'

2. I've tried similar steps on the cmd(I'm win7).
I receive the same message, starts to install then, configuration
failed.

3. Looking into the 'read_me' doc that comes with rjsonio it mentions
libjson C libraries.
They give a special command if you don't have this installed, which I
tried,
but it didn't work.

At this point I want to generate the libjson libraries to try the other
'read_me' suggestions or just get it to work from R.
FYI, on the R CMD I've tried --binary and I've tried --build, neither
work.
Please help, running out of options.

[[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-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] Is it possible to create Dual y axes with ggplot2 package?

2013-04-15 Thread jpm miao
Hi,

   Is it possible to create Dual y axes with ggplot2 package? If so, is
there any sample codes that reaches (or partially) this goal?

   The author of the package, Dr Hadley Wickham, seem to discourage the
dual axes, but some remedies were provided by other users (If I am wrong,
please correct me).

   I have done some homework:

   This is the discussion which I find most helpful.

   https://groups.google.com/forum/?fromgroups=#!topic/ggplot2/tImExPZg61o

   This is a nice graph with dual axes

   http://blog.revolutionanalytics.com/2010/01/r-package-growth.html

   Codes are provided here


http://onertipaday.blogspot.tw/2010/01/scatter-plot-with-4-axes-labels-and.html

   Is it possible to modify the code so that it produces ggplot2 style
dual-axis graph?

   Thanks,

Miao

[[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] group data

2013-04-15 Thread Ye Lin
What if more generally that the group name doest have anything to do with
the ID, eg. for ID=AL1 and AL2, I want to name the group as Key1, how can
I approach that?

Thanks,


On Thu, Apr 11, 2013 at 11:54 AM, Rui Barradas ruipbarra...@sapo.pt wrote:

 Hello,

 Try the following.


 dat - read.table(text = 

 ID  Value
 AL1  1
 AL2  2
 CA1  3
 CA4  4
 , header = TRUE, stringsAsFactors = FALSE)

 dat$State - substr(dat$ID, 1, 2)


 Note that this dependes on having State being defined by the first two
 characters of ID.

 Hope this helps,

 Rui Barradas


 Em 11-04-2013 19:37, Ye Lin escreveu:

 Hey,

 I have a dataset and I want to identify the records by groups for further
 use in ggplot.

 Here is a sample data:

 ID  Value
 AL1  1
 AL2  2
 CA1  3
 CA4  4

 I want to identify all the records that in the same state (AL1 AND A2),
 group them as AL, and do the same for CA1 and CA4. How can I have an
 output like:

 ID  Value State
 AL1  1   AL
 AL2  2  AL
 CA1  3  CA
 CA4  4 CA

 Thanks for your help!

 [[alternative HTML version deleted]]

 __**
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/**
 posting-guide.html 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] Sorting data.frame and again sorting within data.frame

2013-04-15 Thread David Winsemius

On Apr 14, 2013, at 11:01 PM, Katherine Gobin wrote:

 Dear R forum,
 
 I have a data.frame as defied below - 
 
 df = data.frame(names = c(C, A, A, B, C, B, A, B, C), dates 
 = c(4/15/2013, 4/13/2013, 4/15/2013, 4/13/2013, 4/13/2013, 
 4/15/2013, 4/14/2013, 4/14/2013,4/14/2013 ),values = c(10, 31, 31, 
 17, 11, 34, 102, 47, 29))
 
 df
   names dates values
 1 C 4/15/2013 10
 2 A 4/13/2013 31
 3 A 4/15/2013 31
 4 B 4/13/2013 17
 5 C 4/13/2013 11
 6 B
 4/15/2013 34
 7 A 4/14/2013102
 8 B 4/14/2013 47
 9 C 4/14/2013 29
 
 I need to sort df first on names in increasing order and then further on 
 dates in a decreasing order i.e. I need
 

So far no one has pointed out that these are not really Dates in the R sense 
and will not sort correctly if any of the proposed methods are applied to 
sequences that extend beyond6 months, i.e, until October forward. You would be 
advised to convert to real Date-classed variables.

?strptime
?as.Date

-- 

David


 namesdatesvalues
 A4/15/2013  31
 A4/14/2013 102
 A4/13/2013  31
 B4/15/2013 
 34
 B4/14/2013  47
 B4/13/2013  17
 C4/15/2013  10
 C4/14/2013  29
 C4/13/2013  11
 
 I tried
 
 df_sorted = df[order(df$names, (as.Date(df$dates, %m/%d/%Y)), decreasing = 
 TRUE),]
 
 df_sorted
   names dates values
 1 C 4/15/2013 10
 9 C 4/14/2013 29
 5 C 4/13/2013
 11
 6 B 4/15/2013 34
 8 B 4/14/2013 47
 4 B 4/13/2013 17
 3 A 4/15/2013 31
 7 A 4/14/2013102
 2 A 4/13/2013 31
 
 
 I need A to appear first with all three corresponding dates in decreasing 
 order, then B and so on.
 
 Please guide.
 
 With regards
 
 Katherine
 
 
   [[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.

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] regression with paired left-censored data

2013-04-15 Thread Laura MacCalman

HI

I am trying to analyse data which is left-censored (i.e. has values below the 
detection limit). I have been using the NADA package of R to derive summary 
statistics and do some regression. I am now trying to carry out regression on 
paired data where both my X and Y have left-censored data within them.

I have tried various commands in R:

rega = cenreg(Cen(conc, cens_ind) ~ Gp_ident)) 
with all X and Y data stacked and using a group identifier to look at the 
differences

this doesn't take account of the paired data though.

I have also tried splitting the data and regessing one on the other

rega = cenreg(Cen(conc1, censind1) ~ Cen(conc2,censind2))

which doesn't work.

Does anyone know of a command that will work - or perhaps suggest another 
package that I could use?

I have also looked at multiple imputation packages but they all seem to impute 
data depending on other columns - whereas I would want to impute data between 
zero and the censored value.

Any guidance/advice would be very much appreciated.

Laura


 
Dr Laura MacCalman Msci MSc PhD Gradstat
Senior Statistician

Institute of Occupational Medicine
Research Avenue North
Riccarton
Edinburgh
EH14 4AP

Tel: 0131 449 8078
Fax: 0131 449 8084
Mob: 07595 054 881
Email: laura.maccal...@iom-world.org

Web: http://www.iom-world.org
 

--
 
The Institute of Occupational Medicine (IOM) is a company limited by guarantee, 
registered in Scotland (No.SC123972) and a Registered Scottish Charity 
(No.SC000365). IOM Consulting Ltd is a wholly owned subsidiary of IOM and a 
private limited company registered in Scotland (No. SC205670). Registered 
Office: Research Avenue North, Riccarton, Edinburgh, EH14 4AP, Tel +44 (0)131 
449 8000.

This email and any files transmitted with it are confide...{{dropped:18}}

__
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] Latent variable manual construction

2013-04-15 Thread Taman Powell
Dear all,

I had a question around how to manually construct latent variables. I'll 
provide a little background….

Basically I have a SEM with 17 items, 6 latent variables and 615 rows of data.

I have all my model data (loadings, t values etc.) from lavaan, as well as 
correlation matrices.

I wanted to get p-values for my correlation matrix (items and latent variables) 
and understand I can't get this from lavaan. So I've done this for the items 
manually in r, but not sure how to construct/calculate the latent variables so 
that I can then determine the p-values.

Alternatively maybe there'a much easier way. As constructing the correlation 
matrices again when already have them from lavaan seems a little unnecessary, 
however, need to get these p-values somehow!

Any help much appreciated!

Best, Taman

__
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] Convert results from print(survfit(formula, ...)) into a matrix or data frame

2013-04-15 Thread Paul Miller
Hello All,

Below is some sample survival analysis code. I'd like to able to get the 
results from print(gehan.surv) into a matrix or data frame, so I can manipulate 
them and then create a table using odfWeave. Trouble is, I'm not quite sure how 
make such a conversion using the results from a print method.

Is there some simple way of doing this?

Thanks,

Paul

require(survival)
require(MASS)

attach(gehan)
gehan.surv - survfit(Surv(time, cens) ~ treat, data= gehan, conf.type = 
log-log)
print(gehan.surv)

__
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] Sorting data.frame and again sorting within data.frame

2013-04-15 Thread Jeff Newmiller
Yes, that would be because she converted to Date on the fly in her example, and 
so apparently did not need this reminder.
---
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.

David Winsemius dwinsem...@comcast.net wrote:


On Apr 14, 2013, at 11:01 PM, Katherine Gobin wrote:

 Dear R forum,
 
 I have a data.frame as defied below - 
 
 df = data.frame(names = c(C, A, A, B, C, B, A, B,
C), dates = c(4/15/2013, 4/13/2013, 4/15/2013, 4/13/2013,
4/13/2013, 4/15/2013, 4/14/2013, 4/14/2013,4/14/2013 ),values
= c(10, 31, 31, 17, 11, 34, 102, 47, 29))
 
 df
   names dates values
 1 C 4/15/2013 10
 2 A 4/13/2013 31
 3 A 4/15/2013 31
 4 B 4/13/2013 17
 5 C 4/13/2013 11
 6 B
 4/15/2013 34
 7 A 4/14/2013102
 8 B 4/14/2013 47
 9 C 4/14/2013 29
 
 I need to sort df first on names in increasing order and then
further on dates in a decreasing order i.e. I need
 

So far no one has pointed out that these are not really Dates in the
R sense and will not sort correctly if any of the proposed methods are
applied to sequences that extend beyond6 months, i.e, until October
forward. You would be advised to convert to real Date-classed
variables.

?strptime
?as.Date

__
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] Convert results from print(survfit(formula, ...)) into a matrix or data frame

2013-04-15 Thread Marc Schwartz

On Apr 15, 2013, at 11:31 AM, Paul Miller pjmiller...@yahoo.com wrote:

 Hello All,
 
 Below is some sample survival analysis code. I'd like to able to get the 
 results from print(gehan.surv) into a matrix or data frame, so I can 
 manipulate them and then create a table using odfWeave. Trouble is, I'm not 
 quite sure how make such a conversion using the results from a print method.
 
 Is there some simple way of doing this?
 
 Thanks,
 
 Paul
 
 require(survival)
 require(MASS)
 
 attach(gehan)
 gehan.surv - survfit(Surv(time, cens) ~ treat, data= gehan, conf.type = 
 log-log)
 print(gehan.surv)
 



Hi Paul,

If I am correctly understanding the output that you want to save, which is the 
summary results table output:

 gehan.surv
Call: survfit(formula = Surv(time, cens) ~ treat, data = gehan, conf.type = 
log-log)

  records n.max n.start events median 0.95LCL 0.95UCL
treat=6-MP 2121  21  9 23  13  NA
treat=control  2121  21 21  8   4  11


You can use:

 summary(gehan.surv)$table
  records n.max n.start events median 0.95LCL 0.95UCL
treat=6-MP 2121  21  9 23  13  NA
treat=control  2121  21 21  8   4  11


 str(summary(gehan.surv)$table)
 num [1:2, 1:7] 21 21 21 21 21 21 9 21 23 8 ...
 - attr(*, dimnames)=List of 2
  ..$ : chr [1:2] treat=6-MP treat=control
  ..$ : chr [1:7] records n.max n.start events ...


See ?summary.survfit and note the 'table' part of the Value section.

Regards,

Marc Schwartz

__
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] Convert results from print(survfit(formula, ...)) into a matrix or data frame

2013-04-15 Thread Paul Miller
Hi Marc,

Oh, yes. That is quite simple. Silly me for not recognizing this. Thanks very 
much for your help.

Paul

__
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] Remove Rows Based on Factor

2013-04-15 Thread Sparks, John James
Dear R Helpers,

I did a search for deleting rows based on conditions but wasn't able to
find an example that addressed the error that I am getting.  I am hoping
that this is a simple syntax phenomenon that somebody else knows off the
top of their head.  My apologies for not providing a reproducible example
but I think that the information given will allow someone to give me a
hint.

I want to delete the rows of the data frame ZZ where Index is earlier that
Jan 1 of 2007.  That Index column is a factor.  When I tired a couple of
different methods, I got the error shown below.  Can anybody tell me what
I am doing wrong?  I would really appreciate it.

--John Sparks

 str(ZZ)
'data.frame':   1584 obs. of  7 variables:
 $ Index   : Factor w/ 1583 levels 2006-04-07,2006-04-10,..: 1 2 3 4 5
6 7 8 9 10 ...
 $ Open: num  17.5 17.6 16.8 17.2 17 ...
 $ High: num  18.2 17.6 17.2 17.2 17.1 ...
 $ Low : num  17.3 16.8 16.8 16.8 16.6 ...
 $ Close   : num  17.5 16.8 17.1 16.8 16.7 ...
 $ Volume  : num  23834500 2916000 1453700 991400 967400 ...
 $ Adjusted: num  16.8 16.2 16.4 16.2 16 ...
 test-ZZ[ZZ$Index2007-01-01,]
Warning message:
In Ops.factor(ZZ$Index, 2007-01-01) :  not meaningful for factors

 test-subset(ZZ,Index2007-01-01)
Warning message:
In Ops.factor(Index, 2007 - 1 - 1) :  not meaningful for factors

__
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] Sorting data.frame and again sorting within data.frame

2013-04-15 Thread David Winsemius

On Apr 15, 2013, at 9:33 AM, Jeff Newmiller wrote:

 Yes, that would be because she converted to Date on the fly in her example, 
 and so apparently did not need this reminder.

I apologize, Iobviously  missed that. So the answer was simply to put a minus 
sign in front of the as.Date() expression. And that was what you were hoping 
she would see when she looked at the second and third examples help page that 
even had helpful comments.  As you suggested:

df_sorted = df[order(df$names, -as.numeric( as.Date(df$dates, %m/%d/%Y) ), ]


-- 
David

---
 
 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.
 
 David Winsemius dwinsem...@comcast.net wrote:
 
 
 On Apr 14, 2013, at 11:01 PM, Katherine Gobin wrote:
 
 Dear R forum,
 
 I have a data.frame as defied below - 
 
 df = data.frame(names = c(C, A, A, B, C, B, A, B,
 C), dates = c(4/15/2013, 4/13/2013, 4/15/2013, 4/13/2013,
 4/13/2013, 4/15/2013, 4/14/2013, 4/14/2013,4/14/2013 ),values
 = c(10, 31, 31, 17, 11, 34, 102, 47, 29))
 
 df
  names dates values
 1 C 4/15/2013 10
 2 A 4/13/2013 31
 3 A 4/15/2013 31
 4 B 4/13/2013 17
 5 C 4/13/2013 11
 6 B
 4/15/2013 34
 7 A 4/14/2013102
 8 B 4/14/2013 47
 9 C 4/14/2013 29
 
 I need to sort df first on names in increasing order and then
 further on dates in a decreasing order i.e. I need
 
 
 So far no one has pointed out that these are not really Dates in the
 R sense and will not sort correctly if any of the proposed methods are
 applied to sequences that extend beyond6 months, i.e, until October
 forward. You would be advised to convert to real Date-classed
 variables.
 
 ?strptime
 ?as.Date
 

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] Remove Rows Based on Factor

2013-04-15 Thread David Winsemius

On Apr 15, 2013, at 9:58 AM, Sparks, John James wrote:

 Dear R Helpers,
 
 I did a search for deleting rows based on conditions but wasn't able to
 find an example that addressed the error that I am getting.  I am hoping
 that this is a simple syntax phenomenon that somebody else knows off the
 top of their head.  My apologies for not providing a reproducible example
 but I think that the information given will allow someone to give me a
 hint.
 
 I want to delete the rows of the data frame ZZ where Index is earlier that
 Jan 1 of 2007.  That Index column is a factor.  When I tired a couple of
 different methods, I got the error shown below.  Can anybody tell me what
 I am doing wrong?  I would really appreciate it.
 
 --John Sparks
 
 str(ZZ)
 'data.frame':   1584 obs. of  7 variables:
 $ Index   : Factor w/ 1583 levels 2006-04-07,2006-04-10,..: 1 2 3 4 5
 6 7 8 9 10 ...
 $ Open: num  17.5 17.6 16.8 17.2 17 ...
 $ High: num  18.2 17.6 17.2 17.2 17.1 ...
 $ Low : num  17.3 16.8 16.8 16.8 16.6 ...
 $ Close   : num  17.5 16.8 17.1 16.8 16.7 ...
 $ Volume  : num  23834500 2916000 1453700 991400 967400 ...
 $ Adjusted: num  16.8 16.2 16.4 16.2 16 ...
 test-ZZ[ZZ$Index2007-01-01,]

It should work using string comparisons:

test-ZZ[as.character(ZZ$Index)  2007-01-01, ]

-- 
David

 Warning message:
 In Ops.factor(ZZ$Index, 2007-01-01) :  not meaningful for factors
 
 test-subset(ZZ,Index2007-01-01)
 Warning message:
 In Ops.factor(Index, 2007 - 1 - 1) :  not meaningful for factors
 
 __
 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.

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] Remove Rows Based on Factor

2013-04-15 Thread arun
Hi,
May be this helps:
ZZ- 
data.frame(Index=c(2006-04-07,2006-04-08,2007-01-01,2007-01-01,2008-01-04,2008-01-04),Open=c(17.5,17.6,16.8,17.2,17.3,17.5),High=c(18.2,17.6,17.2,17.2,17.5,17.6),Low=c(17.3,16.8,16.8,16.8,16.2,15.8),Close=c(17.5,16.8,17.1,16.8,15.9,16.2),Volume=c(23834500,2916000,1453700,991400,443522,38990),Adjusted=c(16.8,16.2,16.4,16.2,16.5,17.6))
ZZ$Index- as.Date(ZZ$Index,format=%Y-%m-%d)
library(xts)
 ZZ1-xts(ZZ[,-1],ZZ[,1])
ZZ1
#   Open High  Low Close   Volume Adjusted
#2006-04-07 17.5 18.2 17.3  17.5 23834500 16.8
#2006-04-08 17.6 17.6 16.8  16.8  2916000 16.2
#2007-01-01 16.8 17.2 16.8  17.1  1453700 16.4
#2007-01-01 17.2 17.2 16.8  16.8   991400 16.2
#2008-01-04 17.3 17.5 16.2  15.9   443522 16.5
#2008-01-04 17.5 17.6 15.8  16.2    38990 17.6

Suppose, I wanted to get only the rows starting from 2006-04-08
 ZZ1['2006-04-08/']
#   Open High  Low Close  Volume Adjusted
#2006-04-08 17.6 17.6 16.8  16.8 2916000 16.2
#2007-01-01 16.8 17.2 16.8  17.1 1453700 16.4
#2007-01-01 17.2 17.2 16.8  16.8  991400 16.2
#2008-01-04 17.3 17.5 16.2  15.9  443522 16.5
#2008-01-04 17.5 17.6 15.8  16.2   38990 17.6
A.K.




- Original Message -
From: Sparks, John James jspa...@uic.edu
To: r-help@r-project.org
Cc: 
Sent: Monday, April 15, 2013 12:58 PM
Subject: [R] Remove Rows Based on Factor

Dear R Helpers,

I did a search for deleting rows based on conditions but wasn't able to
find an example that addressed the error that I am getting.  I am hoping
that this is a simple syntax phenomenon that somebody else knows off the
top of their head.  My apologies for not providing a reproducible example
but I think that the information given will allow someone to give me a
hint.

I want to delete the rows of the data frame ZZ where Index is earlier that
Jan 1 of 2007.  That Index column is a factor.  When I tired a couple of
different methods, I got the error shown below.  Can anybody tell me what
I am doing wrong?  I would really appreciate it.

--John Sparks

 str(ZZ)
'data.frame':   1584 obs. of  7 variables:
$ Index   : Factor w/ 1583 levels 2006-04-07,2006-04-10,..: 1 2 3 4 5
6 7 8 9 10 ...
$ Open    : num  17.5 17.6 16.8 17.2 17 ...
$ High    : num  18.2 17.6 17.2 17.2 17.1 ...
$ Low     : num  17.3 16.8 16.8 16.8 16.6 ...
$ Close   : num  17.5 16.8 17.1 16.8 16.7 ...
$ Volume  : num  23834500 2916000 1453700 991400 967400 ...
$ Adjusted: num  16.8 16.2 16.4 16.2 16 ...
 test-ZZ[ZZ$Index2007-01-01,]
Warning message:
In Ops.factor(ZZ$Index, 2007-01-01) :  not meaningful for factors

 test-subset(ZZ,Index2007-01-01)
Warning message:
In Ops.factor(Index, 2007 - 1 - 1) :  not meaningful for factors

__
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] Remove Rows Based on Factor

2013-04-15 Thread arun
Hi,
In addition:
You can subset based on time or date:
ZZ1['2006']
#   Open High  Low Close   Volume Adjusted
#2006-04-07 17.5 18.2 17.3  17.5 23834500 16.8
#2006-04-08 17.6 17.6 16.8  16.8  2916000 16.2


ZZ1['2007-01/2008-01']
#   Open High  Low Close  Volume Adjusted
#2007-01-01 16.8 17.2 16.8  17.1 1453700 16.4
#2007-01-01 17.2 17.2 16.8  16.8  991400 16.2
#2008-01-04 17.3 17.5 16.2  15.9  443522 16.5
#2008-01-04 17.5 17.6 15.8  16.2   38990 17.6
 ZZ1['2007/2008']
#   Open High  Low Close  Volume Adjusted
#2007-01-01 16.8 17.2 16.8  17.1 1453700 16.4
#2007-01-01 17.2 17.2 16.8  16.8  991400 16.2
#2008-01-04 17.3 17.5 16.2  15.9  443522 16.5
#2008-01-04 17.5 17.6 15.8  16.2   38990 17.6



ZZ2- data.frame(Index=c(2006-04-07 02:30:00,2006-04-08 
02:00:00,2007-01-01 01:30:00,2007-01-01 02:30:00,2008-01-04 
03:00:00,2008-01-04 
03:30:00),Open=c(17.5,17.6,16.8,17.2,17.3,17.5),High=c(18.2,17.6,17.2,17.2,17.5,17.6),Low=c(17.3,16.8,16.8,16.8,16.2,15.8),Close=c(17.5,16.8,17.1,16.8,15.9,16.2),Volume=c(23834500,2916000,1453700,991400,443522,38990),Adjusted=c(16.8,16.2,16.4,16.2,16.5,17.6),stringsAsFactors=FALSE)
ZZ2$Index- as.POSIXct(ZZ2$Index,format=%Y-%m-%d %H:%M:%S)
library(xts)
 ZZ3-xts(ZZ2[,-1],ZZ2[,1])
 ZZ3[T02:30/T03:00]
#    Open High  Low Close   Volume Adjusted
#2006-04-07 02:30:00 17.5 18.2 17.3  17.5 23834500 16.8
#2007-01-01 02:30:00 17.2 17.2 16.8  16.8   991400 16.2
#2008-01-04 03:00:00 17.3 17.5 16.2  15.9   443522 16.5
A.K.



- Original Message -
From: arun smartpink...@yahoo.com
To: Sparks, John James jspa...@uic.edu
Cc: R help r-help@r-project.org
Sent: Monday, April 15, 2013 1:32 PM
Subject: Re: [R] Remove Rows Based on Factor

Hi,
May be this helps:
ZZ- 
data.frame(Index=c(2006-04-07,2006-04-08,2007-01-01,2007-01-01,2008-01-04,2008-01-04),Open=c(17.5,17.6,16.8,17.2,17.3,17.5),High=c(18.2,17.6,17.2,17.2,17.5,17.6),Low=c(17.3,16.8,16.8,16.8,16.2,15.8),Close=c(17.5,16.8,17.1,16.8,15.9,16.2),Volume=c(23834500,2916000,1453700,991400,443522,38990),Adjusted=c(16.8,16.2,16.4,16.2,16.5,17.6))
ZZ$Index- as.Date(ZZ$Index,format=%Y-%m-%d)
library(xts)
 ZZ1-xts(ZZ[,-1],ZZ[,1])
ZZ1
#   Open High  Low Close   Volume Adjusted
#2006-04-07 17.5 18.2 17.3  17.5 23834500 16.8
#2006-04-08 17.6 17.6 16.8  16.8  2916000 16.2
#2007-01-01 16.8 17.2 16.8  17.1  1453700 16.4
#2007-01-01 17.2 17.2 16.8  16.8   991400 16.2
#2008-01-04 17.3 17.5 16.2  15.9   443522 16.5
#2008-01-04 17.5 17.6 15.8  16.2    38990 17.6

Suppose, I wanted to get only the rows starting from 2006-04-08
 ZZ1['2006-04-08/']
#   Open High  Low Close  Volume Adjusted
#2006-04-08 17.6 17.6 16.8  16.8 2916000 16.2
#2007-01-01 16.8 17.2 16.8  17.1 1453700 16.4
#2007-01-01 17.2 17.2 16.8  16.8  991400 16.2
#2008-01-04 17.3 17.5 16.2  15.9  443522 16.5
#2008-01-04 17.5 17.6 15.8  16.2   38990 17.6
A.K.




- Original Message -
From: Sparks, John James jspa...@uic.edu
To: r-help@r-project.org
Cc: 
Sent: Monday, April 15, 2013 12:58 PM
Subject: [R] Remove Rows Based on Factor

Dear R Helpers,

I did a search for deleting rows based on conditions but wasn't able to
find an example that addressed the error that I am getting.  I am hoping
that this is a simple syntax phenomenon that somebody else knows off the
top of their head.  My apologies for not providing a reproducible example
but I think that the information given will allow someone to give me a
hint.

I want to delete the rows of the data frame ZZ where Index is earlier that
Jan 1 of 2007.  That Index column is a factor.  When I tired a couple of
different methods, I got the error shown below.  Can anybody tell me what
I am doing wrong?  I would really appreciate it.

--John Sparks

 str(ZZ)
'data.frame':   1584 obs. of  7 variables:
$ Index   : Factor w/ 1583 levels 2006-04-07,2006-04-10,..: 1 2 3 4 5
6 7 8 9 10 ...
$ Open    : num  17.5 17.6 16.8 17.2 17 ...
$ High    : num  18.2 17.6 17.2 17.2 17.1 ...
$ Low     : num  17.3 16.8 16.8 16.8 16.6 ...
$ Close   : num  17.5 16.8 17.1 16.8 16.7 ...
$ Volume  : num  23834500 2916000 1453700 991400 967400 ...
$ Adjusted: num  16.8 16.2 16.4 16.2 16 ...
 test-ZZ[ZZ$Index2007-01-01,]
Warning message:
In Ops.factor(ZZ$Index, 2007-01-01) :  not meaningful for factors

 test-subset(ZZ,Index2007-01-01)
Warning message:
In Ops.factor(Index, 2007 - 1 - 1) :  not meaningful for factors

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

Re: [R] group data

2013-04-15 Thread arun
Hi,
You could do this:
dat1- read.table(text=
ID  Value
AL1  1
AL2  2
CA1  3
CA4  4
,sep=,header=TRUE,stringsAsFactors=FALSE)
 lst1-split(dat1,gsub(\\d+,,dat1$ID))
res-do.call(rbind,lapply(seq_along(lst1),function(i) {x1-lst1[[i]]; 
x1$group- paste0(Key,i);x1}))
 res
#   ID Value group
#1 AL1 1  Key1
#2 AL2 2  Key1
#3 CA1 3  Key2
#4 CA4 4  Key2
A.K.



- Original Message -
From: Ye Lin ye...@lbl.gov
To: Rui Barradas ruipbarra...@sapo.pt
Cc: R help r-help@r-project.org
Sent: Monday, April 15, 2013 11:50 AM
Subject: Re: [R] group data

What if more generally that the group name doest have anything to do with
the ID, eg. for ID=AL1 and AL2, I want to name the group as Key1, how can
I approach that?

Thanks,


On Thu, Apr 11, 2013 at 11:54 AM, Rui Barradas ruipbarra...@sapo.pt wrote:

 Hello,

 Try the following.


 dat - read.table(text = 

 ID  Value
 AL1  1
 AL2  2
 CA1  3
 CA4  4
 , header = TRUE, stringsAsFactors = FALSE)

 dat$State - substr(dat$ID, 1, 2)


 Note that this dependes on having State being defined by the first two
 characters of ID.

 Hope this helps,

 Rui Barradas


 Em 11-04-2013 19:37, Ye Lin escreveu:

 Hey,

 I have a dataset and I want to identify the records by groups for further
 use in ggplot.

 Here is a sample data:

 ID  Value
 AL1  1
 AL2  2
 CA1  3
 CA4  4

 I want to identify all the records that in the same state (AL1 AND A2),
 group them as AL, and do the same for CA1 and CA4. How can I have an
 output like:

 ID  Value State
 AL1  1       AL
 AL2  2      AL
 CA1  3      CA
 CA4  4     CA

 Thanks for your help!

         [[alternative HTML version deleted]]

 __**
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/**
 posting-guide.html 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.


__
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] regression with paired left-censored data

2013-04-15 Thread MacQueen, Don
I would probably start with maximum likelihood estimation.

I suppose you could impute X and Y separately using ros() from the NADA
package, and then run you ordinary regression on the imputed values.
Obviously, this ignores any relationship between X and Y, since each is
imputed independently of the other. I have no idea whether ordinary
inferences on the parameter estimates would be valid. Probably not.
Probably, MLE would be better.

-Don

-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 4/15/13 8:55 AM, Laura MacCalman laura.maccal...@iom-world.org
wrote:


HI

I am trying to analyse data which is left-censored (i.e. has values below
the detection limit). I have been using the NADA package of R to derive
summary statistics and do some regression. I am now trying to carry out
regression on paired data where both my X and Y have left-censored data
within them.

I have tried various commands in R:

rega = cenreg(Cen(conc, cens_ind) ~ Gp_ident))
with all X and Y data stacked and using a group identifier to look at the
differences

this doesn't take account of the paired data though.

I have also tried splitting the data and regessing one on the other

rega = cenreg(Cen(conc1, censind1) ~ Cen(conc2,censind2))

which doesn't work.

Does anyone know of a command that will work - or perhaps suggest another
package that I could use?

I have also looked at multiple imputation packages but they all seem to
impute data depending on other columns - whereas I would want to impute
data between zero and the censored value.

Any guidance/advice would be very much appreciated.

Laura


 
Dr Laura MacCalman Msci MSc PhD Gradstat
Senior Statistician

Institute of Occupational Medicine
Research Avenue North
Riccarton
Edinburgh
EH14 4AP

Tel: 0131 449 8078
Fax: 0131 449 8084
Mob: 07595 054 881
Email: laura.maccal...@iom-world.org

Web: http://www.iom-world.org
 

--
 
The Institute of Occupational Medicine (IOM) is a company limited by
guarantee, registered in Scotland (No.SC123972) and a Registered Scottish
Charity (No.SC000365). IOM Consulting Ltd is a wholly owned subsidiary of
IOM and a private limited company registered in Scotland (No. SC205670).
Registered Office: Research Avenue North, Riccarton, Edinburgh, EH14 4AP,
Tel +44 (0)131 449 8000.

This email and any files transmitted with it are confide...{{dropped:18}}

__
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] regression with paired left-censored data

2013-04-15 Thread David Winsemius

On Apr 15, 2013, at 8:55 AM, Laura MacCalman wrote:

 
 HI
 
 I am trying to analyse data which is left-censored (i.e. has values below the 
 detection limit). I have been using the NADA package of R to derive summary 
 statistics and do some regression. I am now trying to carry out regression on 
 paired data where both my X and Y have left-censored data within them.
 
 I have tried various commands in R:
 
 rega = cenreg(Cen(conc, cens_ind) ~ Gp_ident)) 
 with all X and Y data stacked and using a group identifier to look at the 
 differences
 
 this doesn't take account of the paired data though.
 
 I have also tried splitting the data and regessing one on the other
 
 rega = cenreg(Cen(conc1, censind1) ~ Cen(conc2,censind2))
 
 which doesn't work.
 
 Does anyone know of a command that will work - or perhaps suggest another 
 package that I could use?
 
 I have also looked at multiple imputation packages but they all seem to 
 impute data depending on other columns - whereas I would want to impute data 
 between zero and the censored value.
 
 Any guidance/advice would be very much appreciated.

The `survival::Surv` function allows left censoring and the `coxph` function 
allows strata or clusters to be specified. My understanding is that for many 
years analysts used the Cox regression machinery to crank out conditional 
logistic regression by creating two-member (or 1+n) member strata/cluster. I'm 
wondering if that could be made to work here, since this seems even closer to a 
real survival analysis problem.

This response from Terry Therneau (looked up with Markmail) to a question about 
a right-censored situation suggests that the use of cluster() rather than 
strata() might be be more powerful:

http://markmail.org/message/c2oqqd34nujxvuvi?q=list:org%2Er-project%2Er-help+paired+survival+coxph+strata

-- 
David.


 
 Laura
 
 
  
 Dr Laura MacCalman Msci MSc PhD Gradstat
 Senior Statistician
 
 Institute of Occupational Medicine
 Research Avenue North
 Riccarton
 Edinburgh
 EH14 4AP
 
 Tel: 0131 449 8078
 Fax: 0131 449 8084
 Mob: 07595 054 881
 Email: laura.maccal...@iom-world.org
 
 Web: http://www.iom-world.org
  
 
 --
  
 The Institute of Occupational Medicine (IOM) is a company limited by 
 guarantee, registered in Scotland (No.SC123972) and a Registered Scottish 
 Charity (No.SC000365). IOM Consulting Ltd is a wholly owned subsidiary of IOM 
 and a private limited company registered in Scotland (No. SC205670). 
 Registered Office: Research Avenue North, Riccarton, Edinburgh, EH14 4AP, Tel 
 +44 (0)131 449 8000.
 
 This email and any files transmitted with it are confide...{{dropped:18}}
 
 __
 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.

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] Smallest Space Analysis help

2013-04-15 Thread Diego Cesar
Hello fellow R users, I need to perform Guttman's Smallest Space Analysis,
which is a type of Non-metric Multidimensional Scaling. Not wanting to
reinvent the wheel i decided to look for a package which may have an
implementation of it, but no success at all. Do you guys know of any
package that perform SSA? I found 'isoMDS' and 'sammon', both on the MASS
package, but though they perform MDS, both don't perform SSA.


Thanks a lot for any info.
Diego Queiroz

[[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] Removing multiple elements from a vector or list

2013-04-15 Thread arun
Hi,
 vec1- letters
vec1[!grepl(b|r|x,alp)]
# [1] a c d e f g h i j k l m n o p q s t 
u
#[20] v w y z
 vec1[!vec1%in% c(b,r,x) ]
# [1] a c d e f g h i j k l m n o p q s t 
u
#[20] v w y z

alp-lapply(seq_along(vec1),function(i) vec1[i])
 res-alp[!grepl(b|r|x,alp)]
unlist(res)
# [1] a c d e f g h i j k l m n o p q s t 
u
#[20] v w y z
unlist(alp[!alp%in%c(b,r,x)])
 #[1] a c d e f g h i j k l m n o p q s t 
u
#[20] v w y z
A.K.

If I for example have a list (or vector)  that contains all the letters in the 
alphabet. 

alp - list(a,b,c,...z)  this is of course not the 
exact code 

How can I remove multiple elements at one time without knowing their location 
in the list. Say I want to remove b,r,x? 
Same question if apl is a vector 

I have tried 

alp - alp[-c(b,r,x)] 

this does not work 

Thanks, 
Johnny

__
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] View saved workspace commands

2013-04-15 Thread Sourabh Sinha
R version : 2.15.2
Windows: 7 32-bit

Hello,
   I was trying to load a saved workspace image from the working directory.
I issued the command load('image_name') in R console. It did not throw any
error, but then it returned the prompt. I want to view the commands (or
history) I typed there, how do I do that? Pressing up arrow does not bring
any of this workspace command, it rather brings older ones, same as  the
output of history(). Any help will be appreciated.

N.B. To save the workspace I pressed the save button on RGui.

Thanks.

-- 
Sourabh Sinha, PhD
Department of Physics
Arizona State University
Tempe, AZ 85287
USA
http://phy.asu.edu/faculty.php?name=ssinha5

[[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] matching multiple fields from a matrix

2013-04-15 Thread jercrowley
I have been trying many ways to match 2 separate fields in a matrix.  Here is
a simplified version of the matrix:

site1   depth1  year1   site2   depth2  year2
10  30  1860NA  NA  NA
NA  NA  NA  50  30  1860

Basically I am trying to identify the sites which have a common year and
depth from 2 datasets.  What I would like to do is match all of the year1
field to year2 field and the depth1 field and to depth2 field.  Then I would
like to output site1, site2, depth, and year.

I have been trying if loops, which(), isTRUE(), etc. but I have not come up
with anything that works.

Any help would be greatly appreciated.

Jeremy



--
View this message in context: 
http://r.789695.n4.nabble.com/matching-multiple-fields-from-a-matrix-tp4664309.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.


[R] Can not load Rcmdr

2013-04-15 Thread Ludwig Asam
Hello,

I have the same problem on my mac and it doesn't work to load Rcmdr..

  library(Rcmdr)
Error : .onAttach failed in attachNamespace() for 'Rcmdr', details:
   call: structure(.External(.C_dotTclObjv, objv), class = tclObj)
   error: [tcl] invalid command name image.

Error: package or namespace load failed for 'Rcmdr'
  sessionInfo()
R version 3.0.0 (2013-04-03)
Platform: x86_64-apple-darwin10.8.0 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] tcltk stats graphics  grDevices utils datasets methods   
base

other attached packages:
[1] car_2.0-16  nnet_7.3-6  MASS_7.3-26

loaded via a namespace (and not attached):
[1] Rcmdr_1.9-6 tools_3.0.0

What can I do to load the package?

Best regards,
Ludwig
-- 

Ludwig Asam

Hauptstraße 3

86438 Kissing

Tel.: 08233 210866

Handy: 0163 3133304


[[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] Removing multiple elements from a vector or list

2013-04-15 Thread David Winsemius

On Apr 15, 2013, at 2:30 PM, arun wrote:

 Hi,
  vec1- letters

alp - as.list(letters) would have constructed the vector that was described.

 vec1[!grepl(b|r|x,alp)]
 # [1] a c d e f g h i j k l m n o p q s t 
 u
 #[20] v w y z
  vec1[!vec1%in% c(b,r,x) ]
 # [1] a c d e f g h i j k l m n o p q s t 
 u
 #[20] v w y z
 
 alp-lapply(seq_along(vec1),function(i) vec1[i])
  res-alp[!grepl(b|r|x,alp)]
 unlist(res)
 # [1] a c d e f g h i j k l m n o p q s t 
 u
 #[20] v w y z
 unlist(alp[!alp%in%c(b,r,x)])
  #[1] a c d e f g h i j k l m n o p q s t 
 u
 #[20] v w y z
 A.K.

All good. There would be an additional way to do this if the list were first 
assigned names. (At the moment the list only has positions for reference.)

alp - setNames(alp, letters[1:26])
# Something like that initial code would succeed:

alp - alp[ !names(alp) %in% c(b,r,x)]

The result is still a list.


 
 If I for example have a list (or vector)  that contains all the letters in 
 the alphabet. 
 
 alp - list(a,b,c,...z)  this is of course not 
 the exact code 
 
 How can I remove multiple elements at one time without knowing their 
 location in the list. Say I want to remove b,r,x? 
 Same question if apl is a vector 
 
 I have tried 
 
 alp - alp[-c(b,r,x)] 

You _cannot_use_negative_indexing_with_names (or values). You could have used 
logical indexing:

alp [ sapply(alp, function(x) !x %in% c(b,r,x) ) ]

# OR perhaps the most compact solution offered so far;  numeric indexing with 
the minus unary operator:

alp[ -grep(b|r|x, alp) ]

-- 

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] Can not load Rcmdr

2013-04-15 Thread David Winsemius

On Apr 15, 2013, at 1:51 PM, Ludwig Asam wrote:

 Hello,
 
 I have the same problem on my mac and it doesn't work to load Rcmdr..
 
 library(Rcmdr)
 Error : .onAttach failed in attachNamespace() for 'Rcmdr', details:
   call: structure(.External(.C_dotTclObjv, objv), class = tclObj)
   error: [tcl] invalid command name image.
 
 Error: package or namespace load failed for 'Rcmdr'
 sessionInfo()
 R version 3.0.0 (2013-04-03)
 Platform: x86_64-apple-darwin10.8.0 (64-bit)
 
 locale:
 [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
 
 attached base packages:
 [1] tcltk stats graphics  grDevices utils datasets methods   
 base
 
 other attached packages:
 [1] car_2.0-16  nnet_7.3-6  MASS_7.3-26
 
 loaded via a namespace (and not attached):
 [1] Rcmdr_1.9-6 tools_3.0.0

You already have Rcmdr loaded

 
 What can I do to load the package?

Start a new session an load it again?

Maybe you have an .Rprofile file that is loading it at Startup?


 
 Best regards,
 Ludwig
 -- 

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] nearest stations in distance matrix

2013-04-15 Thread Rolf Turner


Presumably --- based on the question she actually *asked* --- she does
NOT have the coordinates of the stations; only the distance matrix.

I believe that the following will do the job:  Let M be the distance matrix.

diag(M) - Inf
nn5 - apply(M,1,function(x){((1:length(x))[order(x)])[1:5]})

Check:

require(spatstat)
set.seed(42)
X - runifpoint(44)
M - crossdist(X,X)
diag(M) - Inf
nn5 - apply(M,1,function(x){((1:length(x))[order(x)])[1:5]})

plot(X)
plot(X[1],add=TRUE,chars=20,cols=red)
plot(X[nn5[,1]],add=TRUE,chars=20,cols=blue)
# Looks right to me.

cheers,

Rolf Turner

On 15/04/13 22:42, ONKELINX, Thierry wrote:

Dear Eliza,

If you have the coordinates of the stations you can use the nnwhich() function 
from the spatstat package.

Best regards,

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and 
Forest
team Biometrie  Kwaliteitszorg / team Biometrics  Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium
+ 32 2 525 02 51
+ 32 54 43 61 85
thierry.onkel...@inbo.be
www.inbo.be

To call in the statistician after the experiment is done may be no more than 
asking him to perform a post-mortem examination: he may be able to say what the 
experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not ensure 
that a reasonable answer can be extracted from a given body of data.
~ John Tukey

-Oorspronkelijk bericht-
Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens 
eliza botto
Verzonden: maandag 15 april 2013 12:36
Aan: r-help@r-project.org
Onderwerp: [R] nearest stations in distance matrix

Dear R-user,
Is there a way in R to locate the nearest 5 indices to a station, based on 
distances in a distance matrix. In other words i want to have nearest stations 
based on the distances in the matrix. The distance matrix, i have, has 
dimension 44*44.
Thankyou very much in advance
Elisa


__
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] Fwd: Imputation with SOM using kohonen package

2013-04-15 Thread Ben Harrison
Trying re-send as plain text.

I have a data set with 10 variables, and about 8000 instances (or
objects/rows/samples). In addition I have one more ('class') variable
that I have about 10 instances for, but for which I wish to impute
values for.

I am a little confused how to go about doing this, mostly as I'm not
well-versed in it. Do I train the SOM with a data object that contains
just the first 10 variables (exclude the 'class' variable), then
predict using an object that has all of the variables (including the
class variable)?

(I am using the kohonen package, and in general I am using the SOM
technique as a comparison to some other methods).

I don't know if providing some or all data is useful, please let me
know if you think it is.

# get the data
bw - read.csv(bw.csv)
# some missing values in data
bwm - data.frame(na.approx(bw, na.rm=FALSE, rule=2))
bw10 - bwm[, 1:10]
bw10.sc - scale(bw10)
bw.som - som(data=bw10.sc, grid=somgrid(25,20,'hexagonal'))  #
playing with diff grid sizes

# the different plots of the som at this point show some interesting
features to me, but are quite difficult to interpret.
# there's much work needed here to understand it, but for now I want
to see if it's possible to impute values for another variable...

# here's where I lose it, missing values, trainY, don't get it.
bw.predict - predict(bw.som, newdata=scale(bw), trainX=???, trainY=???)

Ben.

__
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] nearest stations in distance matrix

2013-04-15 Thread Rolf Turner


There was a bit of cranial wind-passing in my previous message.
(A bit of redundancy.)

My solution should have read:

diag(M) - Inf
nn5 - apply(M,1,function(x){order(x)[1:5]})

What I wrote gave the right answer; there was just a bunch of
unnecessary ring-around-the-rosy playing in it.

Sorry 'bout that.

cheers,

Rolf Turner


-Oorspronkelijk bericht-
Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens 
eliza botto
Verzonden: maandag 15 april 2013 12:36
Aan: r-help@r-project.org
Onderwerp: [R] nearest stations in distance matrix

Dear R-user,
Is there a way in R to locate the nearest 5 indices to a station, based on 
distances in a distance matrix. In other words i want to have nearest stations 
based on the distances in the matrix. The distance matrix, i have, has 
dimension 44*44.
Thankyou very much in advance
Elisa


__
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] View saved workspace commands

2013-04-15 Thread Uwe Ligges



On 15.04.2013 21:53, Sourabh Sinha wrote:

R version : 2.15.2
Windows: 7 32-bit

Hello,
I was trying to load a saved workspace image from the working directory.
I issued the command load('image_name') in R console. It did not throw any
error, but then it returned the prompt. I want to view the commands (or
history) I typed there, how do I do that? Pressing up arrow does not bring
any of this workspace command, it rather brings older ones, same as  the
output of history(). Any help will be appreciated.



To load the workspace, use load(), for the history, use loadhistory().

Uwe Ligges


N.B. To save the workspace I pressed the save button on RGui.

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] create an access file

2013-04-15 Thread Aileen Lin
worked it out. Thank you. misunderstood the post earlier.

Aileen

On 15 April 2013 20:17, Prof Brian Ripley rip...@stats.ox.ac.uk wrote:

 On 15/04/2013 07:12, Aileen Lin wrote:

 Hi there,

 I have seen this post.
 https://stat.ethz.ch/**pipermail/r-help/2007-June/**133606.htmlhttps://stat.ethz.ch/pipermail/r-help/2007-June/133606.html

 have odbc installed in my machine. Now I have the following message:


 channel2 - odbcDriverConnect(test.mdb)**Warning messages:1: In

 odbcDriverConnect(test.mdb) :
[RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver
 Manager] Data source name not found and no default driver specified2:
 In odbcDriverConnect(test.mdb) :
[RODBC] ERROR: state 01S00, code 0, message [Microsoft][ODBC Driver
 Manager] Invalid connection string attribute3: In

 odbcDriverConnect(test.mdb) : ODBC connection failed


 Did I miss anything?


 That is not doing what the URL you gave suggested.  Please do follow it.


 --
 Brian D. Ripley,  rip...@stats.ox.ac.uk
 Professor of Applied Statistics,  
 http://www.stats.ox.ac.uk/~**ripley/http://www.stats.ox.ac.uk/~ripley/
 University of Oxford, Tel:  +44 1865 272861 (self)
 1 South Parks Road, +44 1865 272866 (PA)
 Oxford OX1 3TG, UKFax:  +44 1865 272595




-- 
Aileen L.

View my Linkedin profile: http://au.linkedin.com/in/aileen2

 Being happy doesn't mean you're perfect. It just means you've decided to
look beyond the imperfections- K.B Indiana (age
14)http://www.boardofwisdom.com/default.asp?topic=1010search=K%2EB+Indiana+%28age+14%29

[[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] create an access file

2013-04-15 Thread Aileen Lin
Hi there,

I tried the command in https://stat.ethz.ch/**pipermail/r-help/2007-June/**
133606.html https://stat.ethz.ch/pipermail/r-help/2007-June/133606.html
In R, it works OK. In Rstudio, there seems to be a problem:


library(RODBC)ch - odbcDriverConnect(Driver={Microsoft Access Driver
(*.mdb)})Warning messages:1: In odbcDriverConnect(Driver={Microsoft
Access Driver (*.mdb)}) :
  [RODBC] ERROR: Could not SQLDriverConnect2: In
odbcDriverConnect(Driver={Microsoft Access Driver (*.mdb)}) :
  ODBC connection failed


I use R 2.15.3 and Rstudio 0.97.336. Did I miss anything?

Regards,
Aileen
On 15 April 2013 20:17, Prof Brian Ripley rip...@stats.ox.ac.uk wrote:

 On 15/04/2013 07:12, Aileen Lin wrote:

 Hi there,

 I have seen this post.
 https://stat.ethz.ch/**pipermail/r-help/2007-June/**133606.htmlhttps://stat.ethz.ch/pipermail/r-help/2007-June/133606.html

 have odbc installed in my machine. Now I have the following message:


 channel2 - odbcDriverConnect(test.mdb)**Warning messages:1: In

 odbcDriverConnect(test.mdb) :
[RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver
 Manager] Data source name not found and no default driver specified2:
 In odbcDriverConnect(test.mdb) :
[RODBC] ERROR: state 01S00, code 0, message [Microsoft][ODBC Driver
 Manager] Invalid connection string attribute3: In

 odbcDriverConnect(test.mdb) : ODBC connection failed


 Did I miss anything?


 That is not doing what the URL you gave suggested.  Please do follow it.


 --
 Brian D. Ripley,  rip...@stats.ox.ac.uk
 Professor of Applied Statistics,  
 http://www.stats.ox.ac.uk/~**ripley/http://www.stats.ox.ac.uk/~ripley/
 University of Oxford, Tel:  +44 1865 272861 (self)
 1 South Parks Road, +44 1865 272866 (PA)
 Oxford OX1 3TG, UKFax:  +44 1865 272595




-- 
Aileen L.

View my Linkedin profile: http://au.linkedin.com/in/aileen2

 Being happy doesn't mean you're perfect. It just means you've decided to
look beyond the imperfections- K.B Indiana (age
14)http://www.boardofwisdom.com/default.asp?topic=1010search=K%2EB+Indiana+%28age+14%29

[[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] Can not load Rcmdr

2013-04-15 Thread John Fox
Dear Lugwig,

Have you followed the steps in the Rcmdr installation notes at 
http://socserv.socsci.mcmaster.ca/jfox/Misc/Rcmdr/installation-notes.html? In 
particular, have you installed X-Windows? Mac OS X Mountain Lion does not come 
with X-Windows installed.

Best,
 John


John Fox
Sen. William McMaster Prof. of Social Statistics
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
http://socserv.mcmaster.ca/jfox/

On Mon, 15 Apr 2013 22:51:49 +0200
 Ludwig Asam asamlu...@gmx.de wrote:
 Hello,
 
 I have the same problem on my mac and it doesn't work to load Rcmdr..
 
   library(Rcmdr)
 Error : .onAttach failed in attachNamespace() for 'Rcmdr', details:
call: structure(.External(.C_dotTclObjv, objv), class = tclObj)
error: [tcl] invalid command name image.
 
 Error: package or namespace load failed for 'Rcmdr'
   sessionInfo()
 R version 3.0.0 (2013-04-03)
 Platform: x86_64-apple-darwin10.8.0 (64-bit)
 
 locale:
 [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
 
 attached base packages:
 [1] tcltk stats graphics  grDevices utils datasets methods   
 base
 
 other attached packages:
 [1] car_2.0-16  nnet_7.3-6  MASS_7.3-26
 
 loaded via a namespace (and not attached):
 [1] Rcmdr_1.9-6 tools_3.0.0
 
 What can I do to load the package?
 
 Best regards,
 Ludwig
 -- 
 
 Ludwig Asam
 
 Hauptstraße 3
 
 86438 Kissing
 
 Tel.: 08233 210866
 
 Handy: 0163 3133304
 
 
   [[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] create an access file

2013-04-15 Thread Jeff Newmiller
You missed that this is not the RStudio support forum.

You probably also missed that R comes in both 32-bit and 64-bit flavors in the 
Windows binary distribution, and you have to use the one that matches the ODBC 
drivers you want to use. You can specify which version RStudio is to use.
---
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.

Aileen Lin aileenshanhong@gmail.com wrote:

Hi there,

I tried the command in
https://stat.ethz.ch/**pipermail/r-help/2007-June/**
133606.html
https://stat.ethz.ch/pipermail/r-help/2007-June/133606.html
In R, it works OK. In Rstudio, there seems to be a problem:


library(RODBC)ch - odbcDriverConnect(Driver={Microsoft Access Driver
(*.mdb)})Warning messages:1: In odbcDriverConnect(Driver={Microsoft
Access Driver (*.mdb)}) :
  [RODBC] ERROR: Could not SQLDriverConnect2: In
odbcDriverConnect(Driver={Microsoft Access Driver (*.mdb)}) :
  ODBC connection failed


I use R 2.15.3 and Rstudio 0.97.336. Did I miss anything?

Regards,
Aileen
On 15 April 2013 20:17, Prof Brian Ripley rip...@stats.ox.ac.uk
wrote:

 On 15/04/2013 07:12, Aileen Lin wrote:

 Hi there,

 I have seen this post.

https://stat.ethz.ch/**pipermail/r-help/2007-June/**133606.htmlhttps://stat.ethz.ch/pipermail/r-help/2007-June/133606.html

 have odbc installed in my machine. Now I have the following message:


 channel2 - odbcDriverConnect(test.mdb)**Warning messages:1: In

 odbcDriverConnect(test.mdb) :
[RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC
Driver
 Manager] Data source name not found and no default driver
specified2:
 In odbcDriverConnect(test.mdb) :
[RODBC] ERROR: state 01S00, code 0, message [Microsoft][ODBC
Driver
 Manager] Invalid connection string attribute3: In

 odbcDriverConnect(test.mdb) : ODBC connection failed


 Did I miss anything?


 That is not doing what the URL you gave suggested.  Please do follow
it.


 --
 Brian D. Ripley,  rip...@stats.ox.ac.uk
 Professor of Applied Statistics, 
http://www.stats.ox.ac.uk/~**ripley/http://www.stats.ox.ac.uk/~ripley/
 University of Oxford, Tel:  +44 1865 272861 (self)
 1 South Parks Road, +44 1865 272866 (PA)
 Oxford OX1 3TG, UKFax:  +44 1865 272595


__
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] converting blank cells to NAs

2013-04-15 Thread arun
You can use na.strings= in read.table() or read.csv()


library(stringr)

vec1-unlist(str_split(readLines(textConnection(3,7,11,,12,14,15,,17,18,19)),,))
 vec1[vec1==]- NA
 vec1
# [1] 3  7  11 NA   12 14 15 NA   17 18 19

#or
scan(text=3,7,11,,12,14,15,,17,18,19,sep=,)
#Read 11 items
 #[1]  3  7 11 NA 12 14 15 NA 17 18 19
set.seed(25)
 arr1- array(sample(letters,40,replace=TRUE),dim=c(5,4,2))
arr1[5,3,2]-
arr1[arr1==]- NA
arr1[,,2]
# [,1] [,2] [,3] [,4]
#[1,] b  h  v  k 
#[2,] l  b  j  y 
#[3,] c  p  g  j 
#[4,] e  n  c  e 
#[5,] h  g  NA   d 

 arr2- array(1:40,dim=c(5,4,2))
 arr2[5,3,2]- 
arr2[arr2==]- NA
arr2- apply(arr2,c(2,3),as.numeric)
arr2[,,2]
# [,1] [,2] [,3] [,4]
#[1,]   21   26   31   36
#[2,]   22   27   32   37
#[3,]   23   28   33   38
#[4,]   24   29   34   39
#[5,]   25   30   NA   40


A.K.



Is there a way to convert blank cells in a vector or array into NAs? 
 Alternatively, is there a test for blank cells the way one can use 
is.na to test for NAs? 

Thanks in advance.

__
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 to add a row vector in a dataframe

2013-04-15 Thread arun
Hi,

May be this helps you.

#Using
set.seed(12345)

S=10

simdata - replicate(S, generate(250))
lstpshat-lapply(seq_len(ncol(simdata)),function(i) 
{glm.t-glm(t~x1+x2+x3+x4+x5+x6+x7+I(x2^2)+I(x4^2)+I(x7^2)+x1:x3+x2:x4+x3:x5+x4:x6+x5:x7+x1:x6+x2:x3+x3:x4+x4:x5+x5:x6,family=binomial,data=simdata[,i]);
 pshat- predict(glm.t,type=response)})
simdata1-rbind(simdata,pshat=lstpshat)

pdf(hist1.pdf)
lapply(seq_len(ncol(simdata1)),function(i){ x1- simdata1[,i]; 
pshat0-x1$pshat[x1$t==0];pshat1- x1$pshat[x1$t==1]; 
hist(pshat1,xlim=c(0,1),col=rgb(0.7,0,0,0.5)); 
hist(pshat0,add=T,col=rgb(0,0,1,0.3))})
dev.off()
(You need to change the colors as per your requirements)
A.K.


thanks! it really helps! 

anyway, how will i have a histogram of the lstpshat basing on 
the value of t, that is, fot t=1, the color is red, for t=0, the color 
is blue and for their overlap, the color is green? thanks a lot! 


 
set.seed(12345) 
S=1000 
generate - function(size) { 
x1 - rnorm(size, mean=0, sd=1) 
x2 - rnorm(size, mean=0, sd=1) 
x3 - rnorm(size, mean=0, sd=1) 
x4 - rnorm(size, mean=0, sd=1) 
x5 - rnorm(size, mean=0, sd=1) 
x6 - rnorm(size, mean=0, sd=1) 
x7 - rnorm(size, mean=0, sd=1) 
x8 - rnorm(size, mean=0, sd=1) 
x9 - rnorm(size, mean=0, sd=1) 
x10 - rnorm(size, mean=0, sd=1) 
e-rnorm(size, mean=0, sd=1) 
t_trueps - (1 + exp( -(b0 + b1*x1 + b2*x2 + b3*x3 + b4*x4 + b5*x5 + b6*x6 + 
b7*x7 
+ b2*x2*x2 + b4*x4*x4 + b7*x7*x7 + b1*0.5*x1*x3 + b2*0.7*x2*x4 +b3*0.5*x3*x5 
+ b4*0.7*x4*x6 + b5*0.5*x5*x7 + b1*0.5*x1*x6 + b2*0.7*x2*x3 + b3*0.5*x3*x4 
+ b4*0.5*x4*x5 + b5*0.5*x5*x6) ) )^-1 
prob.exposure - runif(size) 
t - ifelse(t_trueps  prob.exposure, 1, 0) 
y - a0 + a1*x1 + a2*x2 + a3*x3 + a4*x4 +a5*x8 + a6*x9 + a7*x10 + g1*t + e 
sim - as.data.frame(cbind(x1, x2, x3 ,x4, x5, x6, x7, x8, x9, x10, t, y)) 
return(sim) 
} 
b0 - 0.05 
b1 - 0.95 
b2 - -0.25 
b3 - 0.6 
b4 - -0.4 
b5 - -0.8 
b6 - -0.5 
b7 - 0.7 
a0 - -3.85 
a1 - 0.3 
a2 - -0.36 
a3 - -0.73 
a4 - -0.2 
a5 - 0.71 
a6 - -0.19 
a7 - 0.26 
g1 - -0.4 
simdata - replicate(S, generate(3000)) 
 
lstpshat-lapply(seq_len(ncol(simdata)),function(i) 
{glm.t-glm(t~x1+x2+x3+x4+x5+x6+x7+I(x2^2)+I(x4^2)+I(x7^2)+x1:x3+x2:x4+x3:x5+x4:x6+x5:x7+x1:x6+x2:x3+x3:x4+x4:x5+x5:x6,family=binomial,data=simdata[,i]);
 

 pshat- predict(glm.t,type=response)}) 
simdata1-rbind(simdata,pshat=lstpshat) 
 
simdata.ps1- simdata1 
simdata.ps1[]-do.call(c,lapply(seq_len(ncol(simdata1)),function(i)
 lapply(simdata1[,i],function(x) x[simdata1[,i]$t==1]))) 
lstm1- lapply(seq_len(ncol(simdata.ps1)),function(i) 
{dat-do.call(data.frame,lapply(simdata.ps1[,i],function(x) 
x));if(nrow(dat)!=0) {glm.1-glm(y~x1+x2+x3+x4+x8+x9+x10,data=dat)} 
else NULL; glm.1; m1- predict(glm.1)}) 
 
simdata.ps0- simdata1 
simdata.ps0[]-do.call(c,lapply(seq_len(ncol(simdata1)),function(i)
 lapply(simdata1[,i],function(x) x[simdata1[,i]$t==0]))) 
lstm0-lapply(seq_len(ncol(simdata.ps0)),function(i) 
{dat-do.call(data.frame,lapply(simdata.ps0[,i],function(x) 
x));if(nrow(dat)!=0) {glm.0-glm(y~x1+x2+x3+x4+x8+x9+x10,data=dat)} 
else NULL; glm.0; m0- predict(glm.0)}) 
 
simdata.psm1- rbind(simdata.ps1,m1=lstm1) 
simdata.psm0- rbind(simdata.ps0,m0=lstm0) 
 


hist1.pdf
Description: Adobe PDF document
__
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] matching multiple fields from a matrix

2013-04-15 Thread arun
HI,
May be this helps:
dat1- read.table(text=
site1 depth1 year1 site2 depth2 year2
10 30 1860 NA NA NA
NA NA NA 50 30 1860 
10 20 1850  11 20 1850
11 25 1950  12 25 1960
10 NA 1870  12 30 1960
11 25 1880  15 22  1890
14 22 1890  14 25 1880
,sep=,header=TRUE,stringsAsFactors=FALSE)
 
res-merge(dat1[,1:3],dat1[,4:6],by.x=c(depth1,year1),by.y=c(depth2,year2))
 names(res)[1:2]- gsub(\\d+,,names(res))[1:2]
 na.omit(res)
#  depth year site1 site2
#1    20 1850    10    11
#2    22 1890    14    15
#3    25 1880    11    14
#4    30 1860    10    50
A.K.




- Original Message -
From: jercrowley jcrowl...@mtech.edu
To: r-help@r-project.org
Cc: 
Sent: Monday, April 15, 2013 5:07 PM
Subject: [R] matching multiple fields from a matrix

I have been trying many ways to match 2 separate fields in a matrix.  Here is
a simplified version of the matrix:

site1    depth1    year1    site2    depth2    year2
10    30    1860    NA    NA    NA
NA    NA    NA    50    30    1860

Basically I am trying to identify the sites which have a common year and
depth from 2 datasets.  What I would like to do is match all of the year1
field to year2 field and the depth1 field and to depth2 field.  Then I would
like to output site1, site2, depth, and year.

I have been trying if loops, which(), isTRUE(), etc. but I have not come up
with anything that works.

Any help would be greatly appreciated.

Jeremy



--
View this message in context: 
http://r.789695.n4.nabble.com/matching-multiple-fields-from-a-matrix-tp4664309.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.


__
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] HMM Package parameter estimation

2013-04-15 Thread Richard Philip
Hi,

I am having difficulties estimating the parameters of a HMM using the HMM
package. I have simulated a sequence of observations from a known HMM. When
I estimate the parameters of a HMM using these simulated observations the
parameters are not at all close to the known ones. I realise the estimated
parameters are not going to be exactly the same as the known/true
parameters, but these are nowhere close. Below is my code used. Any ideas
or possible suggestions regarding this issue would be greatly appreciated?


library(HMM)

## DECLARE PARAMETERS OF THE KNOWN MODEL
states = c(1,2,3)
symbols = c(1,2)
startProb = c(0.5,0.25,0.25)
transProb = matrix(c(0.8,0.05,0.15,0.2,0.6,0.2,0.2,0.3,0.5),3,3,TRUE)
emissionProb =  matrix(c(0.9,0.1,0.2,0.8,0.7,0.3), 3,2,TRUE)

# CREATE THE KNOWN MODEL
hmmTrue = initHMM(states, symbols, startProb, transProb , emissionProb)

# SIMULATE 1000 OBSERVATIONS OF THE KNOWN MODEL
observation = simHMM(hmmTrue, 1000)
obs = observation$observation

#ESTIMATE A MODEL USING THE OBSERVATIONS GENERATED FROM THE KNOWN MODEL
hmmInit = initHMM(states, symbols, c(1/3,1/3,1/3))
hmmFit = baumWelch(hmmInit, obs)


#The parameters of hmmTrue and hmmFit are not at all alike, why is this?



Kind Regards,
Richard

[[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] rdagum(Library (VGAM))

2013-04-15 Thread Shant Ch
Hello!

I am working with a procedure where I need to draw one observation at a time 
from dagum distribution. I used the function defined in the VGAM library. 

when I did,
 rdagum(n=1, 0.2,1,4.5))
it says: Error in qdagum(runif(n), shape1.a = shape1.a, scale = scale, shape2.p 
= shape2.p) :   object 'Scale' not found.

In the description of dagum in R website I found that the sample size, n, that 
we need to draw using this function, should be strictly 1.

Can you please let me know what should I do in this case?

Thank you very much.
Shant
[[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.