Re: [R] multi-condition summing puzzle

2013-07-12 Thread arun
Hi,
May be this helps:

dat1<- read.table(text="
ID county date company 
1   x  1   comp1
2   y  1   comp3
3   y  2   comp1
4   y  3   comp1
5    x  2  comp2
",sep="",header=TRUE,stringsAsFactors=FALSE)
dat2<- dat1
dat1$answer<-unsplit(lapply(split(dat1,dat1$county),function(x) 
do.call(rbind,lapply(seq_len(nrow(x)),function(i) {x1<-x[1:i,]; 
x2<-table(x1$company)/sum(table(x1$company));sum(x2^2)}))),dat1$county)
 dat1
#  ID county date company    answer
#1  1  x    1   comp1 1.000
#2  2  y    1   comp3 1.000
#3  3  y    2   comp1 0.500
#4  4  y    3   comp1 0.556
#5  5  x    2   comp2 0.500

#or
dat2$answer<-with(dat2,unlist(ave(company,county,FUN=function(x) 
lapply(seq_along(x),function(i) {x1<-table(x[1:i]);sum((x1/sum(x1))^2)}
 dat2
#  ID county date company    answer
#1  1  x    1   comp1 1.000
#2  2  y    1   comp3 1.000
#3  3  y    2   comp1 0.500
#4  4  y    3   comp1 0.556
#5  5  x    2   comp2 0.500

A.K.

Hi - 

I have a seemingly complex data summarizing problem that I am having a hard 
time wrapping my mind around. 

What I'm trying to do is sum the square of all company market 
shares  in a given county, UP TO that corresponding time. Sum of market 
share is defined as: Number of company observations/ Total observations. 

Here is example data and desired answer: 

ID  county  datecompany answer
1      x      1        comp1           1
2      y      1        comp3           1
3      y      2        comp1           0.5
4      y      3        comp1           0.6
5       x     2       comp2           0.5

For example, to get the answer for ID 4, we look at county y, dates 1, 2, 3 and 
sum:  [(2/3)comp1]^2 +[(1/3)comp3]^2 = 0.6 

I've tried cumsum, but am simply stuck given all of the 
different conditions.  I have a large matrix of data for this with 
several hundred companies, tens of counties and unique dates. 

Any help would be extremely appreciated. 

Thank you,

__
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 new matrix from user-defined function

2013-07-12 Thread arun
Hi,
One alternative would be to change colnames:

colnames(dat3)<-1:4

 data.frame(MW_EEsDue_ERRORS=with(dat3,`1`[`4`!=rowSums(cbind(`2`,`3`))]))
  #MW_EEsDue_ERRORS
#1 1882
#2 1884
#3 1885


Also, check these:
with(dat3,4)
#[1] 4
 with(dat3,`4`)
#[1]   7   9   5   6 112
with(dat3,7)
#[1] 7
 with(dat3,`7`)
#Error in eval(expr, envir, enclos) : object '7' not found


A.K.

- Original Message -
From: bcrombie 
To: r-help@r-project.org
Cc: 
Sent: Friday, July 12, 2013 4:45 PM
Subject: Re: [R] create new matrix from user-defined function

AK, I decided to convert your “with” statement back to index-by-number, and I 
did look up the ?with help info, but I’m confused about my replacement code 
below.  I got the wrong answer (R didn’t apply the function to my column 1 
variable “A_CaseID”).  What am I doing wrong?  Do I need to change my function 
code re: index “4” (otherwise known as “D_MW_EEsDueTotal” --- my attempts at 
that have failed also)?  thanks.

#this is your correct code

> data.frame(MW_EEsDue_ERRORS=with(dat3,A_CaseID[D_MW_EEsDueTotal!=rowSums(cbind(B_MW_EEsDue1,C_MW_EEsDue2))]))

#  MW_EEsDue_ERRORS

#1             1882

#2             1884

#3             1885

#these are my incorrect scripts
> data.frame(MW_EEsDue_ERRORS=with(dat3,A_CaseID[4!=rowSums(cbind(2,3))]))
#  MW_EEsDue_ERRORS
#1             1881
#2             1882
#3             1883
#4             1884
#5             1885


> data.frame(MW_EEsDue_ERRORS=with(dat3,dat3[[1]][4!=rowSums(cbind(2,3))]))

#  MW_EEsDue_ERRORS

#1             1881

#2             1882

#3             1883

#4             1884

#5             1885


> data.frame(MW_EEsDue_ERRORS=with(dat3,1[4!=rowSums(cbind(2,3))]))

#  MW_EEsDue_ERRORS

#1                1

Original database:
dat3 = data.frame(A_CaseID = c(1881, 1882, 1883, 1884, 1885),
                  B_MW_EEsDue1 = c(2, 2, 1, 4, 6),
                  C_MW_EEsDue2 = c(5, 5, 4, 1, 6),
                  D_MW_EEsDueTotal = c(7, 9, 5, 6, 112))
dat3
# A_CaseID B_MW_EEsDue1 C_MW_EEsDue2 D_MW_EEsDueTotal
# 1     1881            2            5                7
# 2     1882            2            5                9
# 3     1883            1            4                5
# 4     1884            4            1                6
# 5     1885            6            6              112


From: arun kirshna [via R] [mailto:ml-node+s789695n4671365...@n4.nabble.com]
Sent: Thursday, July 11, 2013 4:55 PM
To: Crombie, Burnette N
Subject: Re: create new matrix from user-defined function

Hi BNC,
No problem.
You could also use ?with()

data.frame(MW_EEsDue_ERRORS=with(dat3,A_CaseID[D_MW_EEsDueTotal!=rowSums(cbind(B_MW_EEsDue1,C_MW_EEsDue2))]))
#  MW_EEsDue_ERRORS
#1             1882
#2             1884
#3             1885
A.K.






--
View this message in context: 
http://r.789695.n4.nabble.com/create-new-matrix-from-user-defined-function-tp4671250p4671445.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-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] syntactical meaning of fullstop in R functions

2013-07-12 Thread Rolf Turner

On 13/07/13 08:57, Kay Cichini wrote:

just found it myself:

in '.GADM' the leading period designates an internal function - the source
can be viewed with:
getAnywhere('.GADM')


I think that's a bit misleading.  In general, the names of functions (or 
other objects) which
are "internal" to a package need *not* begin with a full stop.  That is 
just a convention that
the author of the "dismo" package is using.  What makes an object 
"internal" really is

not being exported in the NAMESPACE of the package.

The general impact of beginning the name of an object with a full stop 
is to make that
object "invisible" to ls().  I.e. if you do an ls() of the environment 
in which that object

"lives" then you will *not* see the name of that object unless you do

ls(.,all.names=TRUE)

See help(ls).

cheers,

Rolf Turner

__
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] memory problem of betadiver of vegan

2013-07-12 Thread Elaine Kuo
Hello List,

I solved the problem by using the code with 31 votes
http://stackoverflow.com/questions/1358003/tricks-to-manage-the-available-memory-in-an-r-session


On Sat, Jul 13, 2013 at 6:15 AM, Elaine Kuo  wrote:

> Hello List,
>
> This is Elaine.
> I am running betadiver for a dataset of 4873 rows and 2749 columns.
> (4873 rows = 4873 gridcell of the study region and 2749 columns for the
> bird species)
> The dataset was produced by combing 5 dbf.
>
> When running the code o, an error message jumped out, saying
> "Error: cannot allocate vector of size 90.6 Mb"
>
> I posted the issue in r-help and checked the previous mails about R memory
> problems.
> gc() and save .Rdata were tried but did not work.
> Also, I tried to transformed the dataset into a matrix, using the code m
> below.
> However, an error also appeared, saying
> "Error in ifelse(x > 0, 1, 0) :
>   (list) object cannot be coerced to type 'double'."
>
> Please kindly advise how to alleviate the memory problem, particularly in
> modifying the code of betadiver of vegan.
> Thank you.
>
> Elaine
>
> code m
> matrixR<-matrix(data = dataR, nrow = 4873, ncol = 2749)
> d  <-  betadiver(matrixR,  "sim")
>
>
>
> code o
> # Non-Passerine table
> dataNP_1 <-read.dbf("H:/temp_D/stage_4_R_2748/NP_1-10.dbf", as.is = FALSE)
> dataNP_2 <-read.dbf("H:/temp_D/stage_4_R_2748/NP_11-19.dbf", as.is =
> FALSE)
> dataNP<-merge(dataNP_1,dataNP_2,by=c("GID"),all=T)
>
> .. skip...
>
> # Non-Passerine and Passerine table (2748 species)
> dataR<-merge(dataP,dataNP,by=c("GID"),all=T)
> dim(dataR)
> str(dataR)
>
> library(vegan)
>
>   ##  The  beta sim  index (Lennon 2001)
>   d  <-  betadiver(dataR,  "sim")
>

[[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] replace multiple values in vector at once

2013-07-12 Thread Law, Jason
In the plyr package there are also the functions revalue and mapvalues:

library(plyr)
x <- c("a", "b", "c")
revalue(x, c(a = "A", c = "C"))
mapvalues(x, c("a", "c"), c("A", "C"))

mapvalues works on numeric, character and factor.

Jason

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Trevor Davies
Sent: Friday, July 12, 2013 2:57 PM
To: r-help@r-project.org
Subject: Re: [R] replace multiple values in vector at once

I always think that replying to your own r-help feels silly but it's good to 
close these things out.

here's my hack solution:

x1<-merge(data.frame(A=x),data.frame(A=c('x','y','z'),B=c(1,2,2)),by='A')[,2]

Well that works and should for my more complex situation.  If anyone has 
something a little less heavy handed I'd live to hear it.

Have a great weekend.


On Fri, Jul 12, 2013 at 2:18 PM, Trevor Davies wrote:

>
> I'm trying to find a function that can replace multiple instances of 
> values or characters in a vector in a one step operation.  As an 
> example, the vector:
>
> x <- c(rep('x',3),rep('y',3),rep('z',3))
>
> > x
> [1] "x" "x" "x" "y" "y" "y" "z" "z" "z"
>
> I would simply like to replace all of the x's with 1's, y:2 & z:3 (or 
> other characters).
> i.e:
> > x
> [1] "1" "1" "1" "2" "2" "2" "3" "3" "3"
>
> Of course, I'm aware of the replace function but this obviously gets a 
> little unwieldy when there are :
> x<-replace(x,x=='x',1)
> x<-replace(x,y=='x',2)
> x<-replace(x,z=='x',3)
>
> but I can't figure out how to do it in a one stop operation.  My real 
> needs is more complex obviously.  This is one of those seemingly 
> simple r-operations that should be obvious but I'm coming up empty on this 
> one.
>
> Thanks for the help.
> Trevor
>

[[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] replace multiple values in vector at once

2013-07-12 Thread Bert Gunter
David is right, but it's trivial if x is a factor (which is the
default when you create character columns in a data frame).

(Note also how to use rep() properly -- read the docs: ?rep)

x <- factor(rep(LETTERS[1:3],e=3))
x
[1] A A A B B B C C C
Levels: A B C

levels(x) <- 1:3
x
[1] 1 1 1 2 2 2 3 3 3
Levels: 1 2 3

Cheers,
Bert
On Fri, Jul 12, 2013 at 3:05 PM, David Winsemius  wrote:
>
> On Jul 12, 2013, at 2:56 PM, Trevor Davies wrote:
>
>> I always think that replying to your own r-help feels silly but it's good
>> to close these things out.
>>
>> here's my hack solution:
>>
>> x1<-merge(data.frame(A=x),data.frame(A=c('x','y','z'),B=c(1,2,2)),by='A')[,2]
>
> That fairly tortured compared with:
>
> x <- c(rep('x',3),rep('y',3),rep('z',3))
>
> x1b <- as.character(1:3)[ match(x, c("x","y","z") ) ]
> x1b
>
> Furthermore, your solution does not deliver the answer you expected.
>
> --
> David.
>
>>
>> Well that works and should for my more complex situation.  If anyone has
>> something a little less heavy handed I'd live to hear it.
>>
>> Have a great weekend.
>>
>>
>> On Fri, Jul 12, 2013 at 2:18 PM, Trevor Davies 
>> wrote:
>>
>>>
>>> I'm trying to find a function that can replace multiple instances of
>>> values or characters in a vector in a one step operation.  As an example,
>>> the vector:
>>>
>>> x <- c(rep('x',3),rep('y',3),rep('z',3))
>>>
 x
>>> [1] "x" "x" "x" "y" "y" "y" "z" "z" "z"
>>>
>>> I would simply like to replace all of the x's with 1's, y:2 & z:3 (or
>>> other characters).
>>> i.e:
 x
>>> [1] "1" "1" "1" "2" "2" "2" "3" "3" "3"
>>>
>>> Of course, I'm aware of the replace function but this obviously gets a
>>> little unwieldy when there are :
>>> x<-replace(x,x=='x',1)
>>> x<-replace(x,y=='x',2)
>>> x<-replace(x,z=='x',3)
>>>
>>> but I can't figure out how to do it in a one stop operation.  My real
>>> needs is more complex obviously.  This is one of those seemingly simple
>>> r-operations that should be obvious but I'm coming up empty on this one.
>>>
>>> Thanks for the help.
>>> Trevor
>>>
>>
>>   [[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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] SH test results

2013-07-12 Thread Vahab Pourfaraj


Hi all,


I am a phylogenetic student, I'm running SH test to examine free (tree1) and 
constrained (tree2) trees using R phangorn package. The outputs are like the 
following and i'm confused how should i interpret them!!!
 
Trees  ln L           Diff ln L    p-value
[1,] 1 -1422.921   0.0  0.4952
[2,] 2 -1457.282  34.36085  0.0201

Why it gives us two p values? Would you please help me with that?

Regards,
Vahab
[[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] replace multiple values in vector at once

2013-07-12 Thread arun
Hi,
library(car)
 recode(x,"'x'=1;'y'=2;'z'=3")
#[1] 1 1 1 2 2 2 3 3 3
#or
as.numeric(factor(x))
#[1] 1 1 1 2 2 2 3 3 3
A.K.




- Original Message -
From: Trevor Davies 
To: "r-help@r-project.org" 
Cc: 
Sent: Friday, July 12, 2013 5:56 PM
Subject: Re: [R] replace multiple values in vector at once

I always think that replying to your own r-help feels silly but it's good
to close these things out.

here's my hack solution:

x1<-merge(data.frame(A=x),data.frame(A=c('x','y','z'),B=c(1,2,2)),by='A')[,2]

Well that works and should for my more complex situation.  If anyone has
something a little less heavy handed I'd live to hear it.

Have a great weekend.


On Fri, Jul 12, 2013 at 2:18 PM, Trevor Davies wrote:

>
> I'm trying to find a function that can replace multiple instances of
> values or characters in a vector in a one step operation.  As an example,
> the vector:
>
> x <- c(rep('x',3),rep('y',3),rep('z',3))
>
> > x
> [1] "x" "x" "x" "y" "y" "y" "z" "z" "z"
>
> I would simply like to replace all of the x's with 1's, y:2 & z:3 (or
> other characters).
> i.e:
> > x
> [1] "1" "1" "1" "2" "2" "2" "3" "3" "3"
>
> Of course, I'm aware of the replace function but this obviously gets a
> little unwieldy when there are :
> x<-replace(x,x=='x',1)
> x<-replace(x,y=='x',2)
> x<-replace(x,z=='x',3)
>
> but I can't figure out how to do it in a one stop operation.  My real
> needs is more complex obviously.  This is one of those seemingly simple
> r-operations that should be obvious but I'm coming up empty on this one.
>
> Thanks for the help.
> Trevor
>

    [[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] memory problem of betadiver of vegan

2013-07-12 Thread Elaine Kuo
Hello List,

This is Elaine.
I am running betadiver for a dataset of 4873 rows and 2749 columns.
(4873 rows = 4873 gridcell of the study region and 2749 columns for the
bird species)
The dataset was produced by combing 5 dbf.

When running the code o, an error message jumped out, saying
"Error: cannot allocate vector of size 90.6 Mb"

I posted the issue in r-help and checked the previous mails about R memory
problems.
gc() and save .Rdata were tried but did not work.
Also, I tried to transformed the dataset into a matrix, using the code m
below.
However, an error also appeared, saying
"Error in ifelse(x > 0, 1, 0) :
  (list) object cannot be coerced to type 'double'."

Please kindly advise how to alleviate the memory problem, particularly in
modifying the code of betadiver of vegan.
Thank you.

Elaine

code m
matrixR<-matrix(data = dataR, nrow = 4873, ncol = 2749)
d  <-  betadiver(matrixR,  "sim")



code o
# Non-Passerine table
dataNP_1 <-read.dbf("H:/temp_D/stage_4_R_2748/NP_1-10.dbf", as.is = FALSE)
dataNP_2 <-read.dbf("H:/temp_D/stage_4_R_2748/NP_11-19.dbf", as.is = FALSE)
dataNP<-merge(dataNP_1,dataNP_2,by=c("GID"),all=T)

.. skip...

# Non-Passerine and Passerine table (2748 species)
dataR<-merge(dataP,dataNP,by=c("GID"),all=T)
dim(dataR)
str(dataR)

library(vegan)

  ##  The  beta sim  index (Lennon 2001)
  d  <-  betadiver(dataR,  "sim")

[[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] replace multiple values in vector at once

2013-07-12 Thread Trevor Davies
Yes, I caught my error once I posted it - I was fiddling with match prior
to hammering down with merge but your solution is much better.  Thank you.


On Fri, Jul 12, 2013 at 3:05 PM, David Winsemius wrote:

>
> On Jul 12, 2013, at 2:56 PM, Trevor Davies wrote:
>
> > I always think that replying to your own r-help feels silly but it's good
> > to close these things out.
> >
> > here's my hack solution:
> >
> >
> x1<-merge(data.frame(A=x),data.frame(A=c('x','y','z'),B=c(1,2,2)),by='A')[,2]
>
> That fairly tortured compared with:
>
> x <- c(rep('x',3),rep('y',3),rep('z',3))
>
> x1b <- as.character(1:3)[ match(x, c("x","y","z") ) ]
> x1b
>
> Furthermore, your solution does not deliver the answer you expected.
>
> --
> David.
>
> >
> > Well that works and should for my more complex situation.  If anyone has
> > something a little less heavy handed I'd live to hear it.
> >
> > Have a great weekend.
> >
> >
> > On Fri, Jul 12, 2013 at 2:18 PM, Trevor Davies  >wrote:
> >
> >>
> >> I'm trying to find a function that can replace multiple instances of
> >> values or characters in a vector in a one step operation.  As an
> example,
> >> the vector:
> >>
> >> x <- c(rep('x',3),rep('y',3),rep('z',3))
> >>
> >>> x
> >> [1] "x" "x" "x" "y" "y" "y" "z" "z" "z"
> >>
> >> I would simply like to replace all of the x's with 1's, y:2 & z:3 (or
> >> other characters).
> >> i.e:
> >>> x
> >> [1] "1" "1" "1" "2" "2" "2" "3" "3" "3"
> >>
> >> Of course, I'm aware of the replace function but this obviously gets a
> >> little unwieldy when there are :
> >> x<-replace(x,x=='x',1)
> >> x<-replace(x,y=='x',2)
> >> x<-replace(x,z=='x',3)
> >>
> >> but I can't figure out how to do it in a one stop operation.  My real
> >> needs is more complex obviously.  This is one of those seemingly simple
> >> r-operations that should be obvious but I'm coming up empty on this one.
> >>
> >> Thanks for the help.
> >> Trevor
> >>
> >
> >   [[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
>
>

[[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] replace multiple values in vector at once

2013-07-12 Thread David Winsemius

On Jul 12, 2013, at 2:56 PM, Trevor Davies wrote:

> I always think that replying to your own r-help feels silly but it's good
> to close these things out.
> 
> here's my hack solution:
> 
> x1<-merge(data.frame(A=x),data.frame(A=c('x','y','z'),B=c(1,2,2)),by='A')[,2]

That fairly tortured compared with:

x <- c(rep('x',3),rep('y',3),rep('z',3))

x1b <- as.character(1:3)[ match(x, c("x","y","z") ) ]
x1b

Furthermore, your solution does not deliver the answer you expected.

-- 
David.

> 
> Well that works and should for my more complex situation.  If anyone has
> something a little less heavy handed I'd live to hear it.
> 
> Have a great weekend.
> 
> 
> On Fri, Jul 12, 2013 at 2:18 PM, Trevor Davies wrote:
> 
>> 
>> I'm trying to find a function that can replace multiple instances of
>> values or characters in a vector in a one step operation.  As an example,
>> the vector:
>> 
>> x <- c(rep('x',3),rep('y',3),rep('z',3))
>> 
>>> x
>> [1] "x" "x" "x" "y" "y" "y" "z" "z" "z"
>> 
>> I would simply like to replace all of the x's with 1's, y:2 & z:3 (or
>> other characters).
>> i.e:
>>> x
>> [1] "1" "1" "1" "2" "2" "2" "3" "3" "3"
>> 
>> Of course, I'm aware of the replace function but this obviously gets a
>> little unwieldy when there are :
>> x<-replace(x,x=='x',1)
>> x<-replace(x,y=='x',2)
>> x<-replace(x,z=='x',3)
>> 
>> but I can't figure out how to do it in a one stop operation.  My real
>> needs is more complex obviously.  This is one of those seemingly simple
>> r-operations that should be obvious but I'm coming up empty on this one.
>> 
>> Thanks for the help.
>> Trevor
>> 
> 
>   [[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] Testing of Diagnostic residuals in R

2013-07-12 Thread ntamjo achille


Hi there,

 I want to ask a question about any function in r that helps test residuals of  
the vector error correction model. I find it on Pfaff(2008) but he tests only 
residual for VAR(vector autoregressive model).

I need to workout Portmanteau test, Normality test and Heteroskedasticty for 
the VECM. Anyway, Pfaff proposes a diagnostic test for the function vec2var. 
But it ends up to test VAR residuals. Is anybody can tell me if it is possible 
to use that function to analyse the diagnostic of vecm residuals?

Thank you

Vec2var codes:
vecm.level <- vec2var(vecm1, r = 2)

vecm.norm <- normality(vecm.level)

vecm.arch <- arch(vecm.level)
vecm.serial <- serial(vecm.level)

Diagnostic for VAR
var2c.serial <- serial(VAR)
> var2c.arch <- arch(VAR)
> var2c.norm <- normality(VAR)


I want something like
vecmfemales<-ca.jo(b,type="trace",spec="transitory")

vecm.r2<-serial.test(vecmfemales)
vecm.norm <- normality(vecm.r2) but i receive this message


Error in serial.test(vecmfemale) : 
Please provide an object of class 'varest', generated by 'var()', or an object 
of class 'vec2var' generated by 'vec2var()'.
By reading this message, i can conclude that there is only 2 ways to make 
residuals in R: VAR and vec2var?




Thank you for your answer
[[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 new matrix from user-defined function

2013-07-12 Thread bcrombie
AK, I decided to convert your “with” statement back to index-by-number, and 
I did look up the ?with help info, but I’m confused about my replacement code 
below.  I got the wrong answer (R didn’t apply the function to my column 1 
variable “A_CaseID”).  What am I doing wrong?  Do I need to change my 
function code re: index “4” (otherwise known as “D_MW_EEsDueTotal” --- 
my attempts at that have failed also)?  thanks.

#this is your correct code

> data.frame(MW_EEsDue_ERRORS=with(dat3,A_CaseID[D_MW_EEsDueTotal!=rowSums(cbind(B_MW_EEsDue1,C_MW_EEsDue2))]))

#  MW_EEsDue_ERRORS

#1 1882

#2 1884

#3 1885

#these are my incorrect scripts
> data.frame(MW_EEsDue_ERRORS=with(dat3,A_CaseID[4!=rowSums(cbind(2,3))]))
#  MW_EEsDue_ERRORS
#1 1881
#2 1882
#3 1883
#4 1884
#5 1885


> data.frame(MW_EEsDue_ERRORS=with(dat3,dat3[[1]][4!=rowSums(cbind(2,3))]))

#  MW_EEsDue_ERRORS

#1 1881

#2 1882

#3 1883

#4 1884

#5 1885


> data.frame(MW_EEsDue_ERRORS=with(dat3,1[4!=rowSums(cbind(2,3))]))

#  MW_EEsDue_ERRORS

#11

Original database:
dat3 = data.frame(A_CaseID = c(1881, 1882, 1883, 1884, 1885),
  B_MW_EEsDue1 = c(2, 2, 1, 4, 6),
  C_MW_EEsDue2 = c(5, 5, 4, 1, 6),
  D_MW_EEsDueTotal = c(7, 9, 5, 6, 112))
dat3
# A_CaseID B_MW_EEsDue1 C_MW_EEsDue2 D_MW_EEsDueTotal
# 1 1881257
# 2 1882259
# 3 1883145
# 4 1884416
# 5 188566  112


From: arun kirshna [via R] [mailto:ml-node+s789695n4671365...@n4.nabble.com]
Sent: Thursday, July 11, 2013 4:55 PM
To: Crombie, Burnette N
Subject: Re: create new matrix from user-defined function

Hi BNC,
No problem.
You could also use ?with()

data.frame(MW_EEsDue_ERRORS=with(dat3,A_CaseID[D_MW_EEsDueTotal!=rowSums(cbind(B_MW_EEsDue1,C_MW_EEsDue2))]))
#  MW_EEsDue_ERRORS
#1 1882
#2 1884
#3 1885
A.K.






--
View this message in context: 
http://r.789695.n4.nabble.com/create-new-matrix-from-user-defined-function-tp4671250p4671445.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.


Re: [R] replace multiple values in vector at once

2013-07-12 Thread Trevor Davies
I always think that replying to your own r-help feels silly but it's good
to close these things out.

here's my hack solution:

x1<-merge(data.frame(A=x),data.frame(A=c('x','y','z'),B=c(1,2,2)),by='A')[,2]

Well that works and should for my more complex situation.  If anyone has
something a little less heavy handed I'd live to hear it.

Have a great weekend.


On Fri, Jul 12, 2013 at 2:18 PM, Trevor Davies wrote:

>
> I'm trying to find a function that can replace multiple instances of
> values or characters in a vector in a one step operation.  As an example,
> the vector:
>
> x <- c(rep('x',3),rep('y',3),rep('z',3))
>
> > x
> [1] "x" "x" "x" "y" "y" "y" "z" "z" "z"
>
> I would simply like to replace all of the x's with 1's, y:2 & z:3 (or
> other characters).
> i.e:
> > x
> [1] "1" "1" "1" "2" "2" "2" "3" "3" "3"
>
> Of course, I'm aware of the replace function but this obviously gets a
> little unwieldy when there are :
> x<-replace(x,x=='x',1)
> x<-replace(x,y=='x',2)
> x<-replace(x,z=='x',3)
>
> but I can't figure out how to do it in a one stop operation.  My real
> needs is more complex obviously.  This is one of those seemingly simple
> r-operations that should be obvious but I'm coming up empty on this one.
>
> Thanks for the help.
> Trevor
>

[[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] replace multiple values in vector at once

2013-07-12 Thread Trevor Davies
I'm trying to find a function that can replace multiple instances of values
or characters in a vector in a one step operation.  As an example, the
vector:

x <- c(rep('x',3),rep('y',3),rep('z',3))

> x
[1] "x" "x" "x" "y" "y" "y" "z" "z" "z"

I would simply like to replace all of the x's with 1's, y:2 & z:3 (or other
characters).
i.e:
> x
[1] "1" "1" "1" "2" "2" "2" "3" "3" "3"

Of course, I'm aware of the replace function but this obviously gets a
little unwieldy when there are :
x<-replace(x,x=='x',1)
x<-replace(x,y=='x',2)
x<-replace(x,z=='x',3)

but I can't figure out how to do it in a one stop operation.  My real needs
is more complex obviously.  This is one of those seemingly simple
r-operations that should be obvious but I'm coming up empty on this one.

Thanks for the help.
Trevor

[[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] vegan capscale 'subscript out of bounds' error

2013-07-12 Thread Zhao Jin
Hi list,

I am using the capscale function in vegan_2.0-7 to do a constrained
principal coordinates analysis, and I kept getting the following error
message:
Error in Y.r[, oo, drop = FALSE] : subscript out of bounds

I googled but I couldn't find an answer. Could anyone tell me why this
error msg and what to do?

Here is the command I used:
mod=capscale(as.dist(dist)~mydataset$Var1+Condition(mydataset$Var2))

My dataset looks like the output of column-binding the 'varespec' and
'varechem' datasets, and has 92 rows and about 3500 columns. I also fed
capscale a similarity matrix in the formula.

Here is more info on the R version and the OS:
R version 3.0.1 (2013-05-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)

Thanks a lot for any help or comment,
Zhao

-- 
Zhao JIN
Ph.D. Candidate
Ruth Ley Lab
467 Biotech
Field of Microbiology, Cornell University
Lab: 607.255.4954
Cell: 412.889.3675

[[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] syntactical meaning of fullstop in R functions

2013-07-12 Thread Kay Cichini
just found it myself:

in '.GADM' the leading period designates an internal function - the source
can be viewed with:
getAnywhere('.GADM')



2013/7/12 Kay Cichini 

> hello,
>
> what is the meaning of a fullstop in the below R-Ffunction (like in
> '.GADM')
>
> > library(dismo)
> Lade nötiges Paket: raster
> Warnmeldungen:
> 1: Paket ‘dismo’ wurde unter R Version 2.15.3 erstellt
> 2: Paket ‘raster’ wurde unter R Version 2.15.3 erstellt
> > getData
> function (name = "GADM", download = TRUE, path = "", ...)
> {
> path <- .getDataPath(path)
> if (name == "GADM") {
> .GADM(..., download = download, path = path)
> }
> else if (name == "SRTM") {
> .SRTM(..., download = download, path = path)
> }
> else if (name == "alt") {
> .raster(..., name = name, download = download, path = path)
> }
> else if (name == "worldclim") {
> .worldclim(..., download = download, path = path)
> }
> else if (name == "ISO3") {
> .ISO()[, c(2, 1)]
> }
> else if (name == "countries") {
> .countries(download = download, path = path, ...)
> }
> else {
> stop(name, " not recognized as a valid name.")
> }
> }
> 
> 
>
> thanks in advance,
> kay
>
> --
>
> Kay Cichini, MSc Biol
>
> Grubenweg 22, 6071 Aldrans
>
> Tel.: 0650 9359101
>
> E-Mail: kay.cich...@gmail.com
>
> Web: 
> www.theBioBucket.blogspot.co.at
> --
>



-- 

Kay Cichini, MSc Biol

Grubenweg 22, 6071 Aldrans

Tel.: 0650 9359101

E-Mail: kay.cich...@gmail.com

Web: 
www.theBioBucket.blogspot.co.at
--

[[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] syntactical meaning of fullstop in R functions

2013-07-12 Thread Kay Cichini
hello,

what is the meaning of a fullstop in the below R-Ffunction (like in '.GADM')

> library(dismo)
Lade nötiges Paket: raster
Warnmeldungen:
1: Paket ‘dismo’ wurde unter R Version 2.15.3 erstellt
2: Paket ‘raster’ wurde unter R Version 2.15.3 erstellt
> getData
function (name = "GADM", download = TRUE, path = "", ...)
{
path <- .getDataPath(path)
if (name == "GADM") {
.GADM(..., download = download, path = path)
}
else if (name == "SRTM") {
.SRTM(..., download = download, path = path)
}
else if (name == "alt") {
.raster(..., name = name, download = download, path = path)
}
else if (name == "worldclim") {
.worldclim(..., download = download, path = path)
}
else if (name == "ISO3") {
.ISO()[, c(2, 1)]
}
else if (name == "countries") {
.countries(download = download, path = path, ...)
}
else {
stop(name, " not recognized as a valid name.")
}
}



thanks in advance,
kay

-- 

Kay Cichini, MSc Biol

Grubenweg 22, 6071 Aldrans

Tel.: 0650 9359101

E-Mail: kay.cich...@gmail.com

Web: 
www.theBioBucket.blogspot.co.at
--

[[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 does not optimise!

2013-07-12 Thread Stephen Clark
Hello, 

I have the following code and data. I am basically trying to select individuals 
in a sample (by setting some weights) to match known counts for a zone. This is 
been done by matching gender and age bands. I have tested the function to be 
optimised and it does behave as I would expect when the weights are changed. 
However when I run the optimisation I get the following output 

> optout<-optim(weights0, func_opt, control=list(REPORT=1))
[1] 27164
[1] 27163.8
[1] 27163.8
[1] 27163.8
[1] 27163.8
[1] 27163.8
[1] 27163.8
[1] 27163.8
[1] 27163.8
etc

which suggest an initial change but thereafter the optimisation does not appear 
to adapt the weights at all. Can anyone see what this is happening and how to 
make the problem optimise?

sample<-read.csv(file="C:\\sample.csv")
cons1<-read.csv(file="C:\\Gender.csv")
cons2<-read.csv(file="C:\\Age9.csv")
weights0 <- array(dim = c(nrow(sample)))

for (zone in 1:2){
weights0 <- rep(1, nrow(sample))
optout<-optim(weights0, func_opt, control=list(REPORT=1))
optout.value
} 

func_opt<-function(weights){
TAE <- 0.0
sumMale <- sum(weights[sample[1:nrow(sample),2]=="Male"])
sumFemale <- sum(weights[sample[1:nrow(sample),2]=="Female"])

sumAged50to54 <-sum(weights[sample[1:nrow(sample),3]=="Aged 50 to 54"])
sumAged55to59 <-sum(weights[sample[1:nrow(sample),3]=="Aged 55 to 59"])
sumAged60to64 <-sum(weights[sample[1:nrow(sample),3]=="Aged 60 to 64"])
sumAged65to69 <-sum(weights[sample[1:nrow(sample),3]=="Aged 65 to 69"])
sumAged70to74 <-sum(weights[sample[1:nrow(sample),3]=="Aged 70 to 74"])
sumAged75to79 <-sum(weights[sample[1:nrow(sample),3]=="Aged 75 to 79"])
sumAged80to84 <-sum(weights[sample[1:nrow(sample),3]=="Aged 80 to 84"])
sumAged85to89 <-sum(weights[sample[1:nrow(sample),3]=="Aged 85 to 89"])
sumAged90andolder <-sum(weights[sample[1:nrow(sample),3]=="Aged90 and older"])

TAE <- abs(cons1[zone, 2] - sumMale)
TAE <- TAE + abs(cons1[zone, 3] - sumFemale)

TAE <- TAE + abs(cons2[zone, 2] - sumAged50to54)
TAE <- TAE + abs(cons2[zone, 3] - sumAged55to59)
TAE <- TAE + abs(cons2[zone, 4] - sumAged60to64)
TAE <- TAE + abs(cons2[zone, 5] - sumAged65to69)
TAE <- TAE + abs(cons2[zone, 6] - sumAged70to74)
TAE <- TAE + abs(cons2[zone, 7] - sumAged75to79)
TAE <- TAE + abs(cons2[zone, 8] - sumAged80to84)
TAE <- TAE + abs(cons2[zone, 9] - sumAged85to89)
TAE <- TAE + abs(cons2[zone, 10] - sumAged90andolder)

print(TAE)
return(TAE)
}

sample.csv
id  sex Age10
103712  Female  Aged 50 to 54
103713  MaleAged 65 to 69
103715  Female  Aged 60 to 64
103716  MaleAged 65 to 69
103717  MaleAged 70 to 74
103718  Female  Aged 80 to 84
103721  Female  Aged 65 to 69
103722  MaleAged 70 to 74
103723  MaleAged 65 to 69
103724  Female  Aged 60 to 64
103728  MaleAged 65 to 69
103729  Female  Aged 50 to 54
103730  MaleAged 75 to 79
103731  Female  Aged 50 to 54
103733  Female  Aged 55 to 59
(this goes on for 1 individuals)

Gender.csv
ZoneMaleFemale
Z1  10547   13234
Z2  16393   18759
Z3  57136462
Z4  19651   21834
Z5  26918   33992
Z6  17596   19665

Age9.csv
LA  Aged50to54  Aged55to59  Aged60to64  Aged65to69  
Aged70to74  Aged75to79  Aged80to84  Aged85to89  Aged90andolder
Z1  42743852330730963123272818961056449
Z2  74166015540248524304340522701047441
Z3  242520931864175715201218766 376 156
Z4  92367713601352574696407227021293503
Z5  965588418199825283757559551131981320
Z6  7797721057544851421636642376994 399

__
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] simplify a dataframe

2013-07-12 Thread Rui Barradas

Hello,

My solution is missing a row, but maybe you can find some inspiration.


cols <- c("Matricule", "Nom", "Sexe", "DateNaissance", "contrat", "Pays")
irow1 <- duplicated(df1[, cols])
irow2 <- c(FALSE, df1$Debut[-1] == df1$Fin[-nrow(df1)])

df3 <- df1[!irow1 & !irow2, ]

dim(df2); dim(df3)  # df3 has one row less
df2; df3


Hope this helps,

Rui Barradas

Em 12-07-2013 20:45, Arnaud Michel escreveu:

Hello

I have the following problem : group the lines of a dataframe when no
information change (Matricule, Nom, Sexe, DateNaissance, Contrat, Pays)
and when the value of Debut of lines i = value Fin of lines i-1
I can obtain it with a do loop. Is it possible to avoid the loop ?

The dataframe initial is df1
dput(df1)
structure(list(Matricule = c(1L, 1L, 1L, 6L, 6L, 6L, 6L, 6L,
6L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 934L, 934L, 934L, 934L,
934L, 934L, 934L, 934L, 934L, 934L, 934L, 934L, 934L, 934L, 934L,
934L, 934L, 934L, 934L, 934L, 934L, 934L, 934L, 934L, 934L, 934L,
934L, 934L, 934L, 934L), Nom = c("VERON", "VERON", "VERON", "BENARD",
"BENARD", "BENARD", "BENARD", "BENARD", "BENARD", "DALNIC", "DALNIC",
"DALNIC", "DALNIC", "DALNIC", "DALNIC", "DALNIC", "DALNIC", "DALNIC",
"FORNI", "FORNI", "FORNI", "FORNI", "FORNI", "FORNI", "FORNI",
"FORNI", "FORNI", "FORNI", "FORNI", "FORNI", "FORNI", "FORNI",
"FORNI", "FORNI", "FORNI", "FORNI", "FORNI", "FORNI", "FORNI",
"FORNI", "FORNI", "FORNI", "FORNI", "FORNI", "FORNI", "FORNI",
"FORNI", "FORNI"), Sexe = c("Féminin", "Féminin", "Féminin",
"Masculin", "Masculin", "Masculin", "Masculin", "Masculin", "Masculin",
"Féminin", "Féminin", "Féminin", "Féminin", "Féminin", "Féminin",
"Féminin", "Féminin", "Féminin", "Masculin", "Masculin", "Masculin",
"Masculin", "Masculin", "Masculin", "Masculin", "Masculin", "Masculin",
"Masculin", "Masculin", "Masculin", "Masculin", "Masculin", "Masculin",
"Masculin", "Masculin", "Masculin", "Masculin", "Masculin", "Masculin",
"Masculin", "Masculin", "Masculin", "Masculin", "Masculin", "Masculin",
"Masculin", "Masculin", "Masculin"), DateNaissance = c("02/09/1935",
"02/09/1935", "02/09/1935", "01/04/1935", "01/04/1935", "01/04/1935",
"01/04/1935", "01/04/1935", "01/04/1935", "19/02/1940", "19/02/1940",
"19/02/1940", "19/02/1940", "19/02/1940", "19/02/1940", "19/02/1940",
"19/02/1940", "19/02/1940", "10/07/1961", "10/07/1961", "10/07/1961",
"10/07/1961", "10/07/1961", "10/07/1961", "10/07/1961", "10/07/1961",
"10/07/1961", "10/07/1961", "10/07/1961", "10/07/1961", "10/07/1961",
"10/07/1961", "10/07/1961", "10/07/1961", "10/07/1961", "10/07/1961",
"10/07/1961", "10/07/1961", "10/07/1961", "10/07/1961", "10/07/1961",
"10/07/1961", "10/07/1961", "10/07/1961", "10/07/1961", "10/07/1961",
"10/07/1961", "10/07/1961"), contrat = c("CDI commun", "CDI commun",
"CDI commun", "CDI commun", "CDI commun", "CDI commun", "CDI commun",
"CDI commun", "CDI commun", "CDI commun", "CDI commun", "CDI commun",
"CDI commun", "CDI commun", "CDI commun", "CDI commun", "CDI commun",
"CDI commun", "CDD détaché ext. Cirad", "CDD détaché ext. Cirad",
"CDD détaché ext. Cirad", "CDD détaché ext. Cirad", "CDD détaché ext.
Cirad",
"CDD détaché ext. Cirad", "CDD détaché ext. Cirad", "CDD détaché ext.
Cirad",
"CDD détaché ext. Cirad", "CDI Détachés Autres", "CDI Détachés Autres",
"CDI Détachés Autres", "CDI Détachés Autres", "CDI Détachés Autres",
"CDI Détachés Autres", "CDI Détachés Autres", "CDI Détachés Autres",
"CDI Détachés Autres", "CDI Détachés Autres", "CDI Détachés Autres",
"CDI Détachés Autres", "CDI Détachés Autres", "CDI commun", "CDI commun",
"CDI commun", "CDI commun", "CDI commun", "CDI commun", "CDI commun",
"CDI commun"), Pays = c("France", "France", "France", "Philippines",
"Philippines", "Philippines", "France", "France", "France", "France",
"France", "Martinique", "Martinique", "Martinique", "Martinique",
"Martinique", "Martinique", "Martinique", "Cameroun", "Cameroun",
"Cameroun", "Cameroun", "Cameroun", "Cameroun", "Cameroun", "Cameroun",
"Cameroun", "France", "France", "France", "France", "France",
"France", "France", "Congo", "Congo", "Congo", "Congo", "Congo",
"Congo", "Gabon", "Gabon", "Gabon", "Gabon", "Gabon", "Gabon",
"Congo", "Congo"), Debut = c("24/01/1995", "01/05/1997", "31/12/1997",
"02/02/1995", "28/02/1995", "01/03/1995", "13/03/1995", "01/01/1996",
"31/01/1996", "24/01/1995", "01/07/1995", "01/09/1995", "01/07/1997",
"01/01/1998", "01/08/1998", "01/01/2000", "17/01/2000", "29/02/2000",
"26/01/1995", "01/07/1996", "16/09/1997", "01/01/1998", "01/07/1998",
"04/11/1999", "01/01/2001", "01/04/2001", "31/08/2001", "01/09/2001",
"02/09/2001", "01/12/2001", "01/02/2003", "01/04/2003", "01/01/2004",
"01/03/2004", "01/09/2004", "01/01/2005", "01/04/2005", "28/10/2006",
"01/01/2007", "01/04/2007", "01/09/2007", "01/01/2009", "01/04/2009",
"01/01/2010", "01/01/2011", "01/04/2011", "05/09/2012", "01/01/2013"
), Fin = c("30/04/1997", "30/12/1997", "31/12/1997", "27/02/1995",
"28/02/1995", "12/03/1995", "30/06/1995", "30/01/1996", "31/01/1996",
"3

Re: [R] Upgrade from R 2.11 to R 3.0.1

2013-07-12 Thread Marc Schwartz
Chirag,

Please keep replies on the list by using 'reply-all'. That way, the responses 
are available to assist future users in the searchable archives and you also 
enable others to contribute to the thread.

The code below will install R to the default location for a source install, 
presuming that you have root access and did not get any errors or warnings as a 
result of that process.

That begs the question then, how was the prior version of R installed? It 
sounds like there is a conflict in that the prior version is in a location that 
precedes the new version in your $PATH.

Commonly, I believe, the executable for R on Linux is installed in 
/usr/local/bin, but may be elsewhere (eg. /usr/bin), depending upon how it was 
installed.  You can locate which R is being executed on your system by using:

  which R

in a console.

That will give you some hints as to location. Within the version of R that is 
running, you can use:

  R.home()

to find out where the old primary R tree has been installed, including 
packages.  I would use that information to remove the old installation.

If you are on RHEL or a compatible server distribution like CentOS (you did not 
answer that) and have root access, I would recommend using the EPEL:

  http://fedoraproject.org/wiki/EPEL

to configure your system to use the pre-built binary RPMs for R via yum. You 
can then use:

  yum install R

as root to install R and also handle future updates via yum. You should remove 
all vestiges of both the old R install and the new source R install before 
doing that however.

Regards,

Marc



On Jul 12, 2013, at 2:10 PM, Chirag Gupta  wrote:

> I used these commands
> 
> >wget htt://cran.r-project.org/src/base/R-3/R-3.0.1.tar.gz
> >tar xzf R-3.0.1.tar.gz
> >cd R-3.0.1
> >./configure
> >make
> >make install
> 
> Thanks!
> 
> 
> On Fri, Jul 12, 2013 at 12:12 PM, Marc Schwartz  wrote:
> On Jul 12, 2013, at 11:58 AM, Chirag Gupta  wrote:
> 
> > Hi
> >
> > I am trying to upgrade R version 2.11 to 3.0.1 on Linux server.
> > I downloaded the latest version it installed correctly. Now when I run R
> > and check the version, it still shows an older version.
> > I am new to Linux. If anyone can tell me how to remove/uninstall R
> > completely from the server, I can try and re-install the newer version and
> > try.
> >
> > Thanks.
> 
> 
> What Linux server? RHEL?
> 
> Do you have root access to the server?
> 
> How did you download and install R? Did you download and install a binary RPM 
> locally, install a binary using a package manager like yum or did you 
> download the source tarball, compile and install?
> 
> Need more information.
> 
> Regards,
> 
> Marc Schwartz
> 
> 
> 
> 
> -- 
> Chirag Gupta
> Department of Crop, Soil, and Environmental Sciences,
> 115 Plant Sciences Building, Fayetteville, Arkansas 72701


[[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] simplify a dataframe

2013-07-12 Thread Arnaud Michel

Hello

I have the following problem : group the lines of a dataframe when no 
information change (Matricule, Nom, Sexe, DateNaissance, Contrat, Pays) 
and when the value of Debut of lines i = value Fin of lines i-1

I can obtain it with a do loop. Is it possible to avoid the loop ?

The dataframe initial is df1
dput(df1)
structure(list(Matricule = c(1L, 1L, 1L, 6L, 6L, 6L, 6L, 6L,
6L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 934L, 934L, 934L, 934L,
934L, 934L, 934L, 934L, 934L, 934L, 934L, 934L, 934L, 934L, 934L,
934L, 934L, 934L, 934L, 934L, 934L, 934L, 934L, 934L, 934L, 934L,
934L, 934L, 934L, 934L), Nom = c("VERON", "VERON", "VERON", "BENARD",
"BENARD", "BENARD", "BENARD", "BENARD", "BENARD", "DALNIC", "DALNIC",
"DALNIC", "DALNIC", "DALNIC", "DALNIC", "DALNIC", "DALNIC", "DALNIC",
"FORNI", "FORNI", "FORNI", "FORNI", "FORNI", "FORNI", "FORNI",
"FORNI", "FORNI", "FORNI", "FORNI", "FORNI", "FORNI", "FORNI",
"FORNI", "FORNI", "FORNI", "FORNI", "FORNI", "FORNI", "FORNI",
"FORNI", "FORNI", "FORNI", "FORNI", "FORNI", "FORNI", "FORNI",
"FORNI", "FORNI"), Sexe = c("Féminin", "Féminin", "Féminin",
"Masculin", "Masculin", "Masculin", "Masculin", "Masculin", "Masculin",
"Féminin", "Féminin", "Féminin", "Féminin", "Féminin", "Féminin",
"Féminin", "Féminin", "Féminin", "Masculin", "Masculin", "Masculin",
"Masculin", "Masculin", "Masculin", "Masculin", "Masculin", "Masculin",
"Masculin", "Masculin", "Masculin", "Masculin", "Masculin", "Masculin",
"Masculin", "Masculin", "Masculin", "Masculin", "Masculin", "Masculin",
"Masculin", "Masculin", "Masculin", "Masculin", "Masculin", "Masculin",
"Masculin", "Masculin", "Masculin"), DateNaissance = c("02/09/1935",
"02/09/1935", "02/09/1935", "01/04/1935", "01/04/1935", "01/04/1935",
"01/04/1935", "01/04/1935", "01/04/1935", "19/02/1940", "19/02/1940",
"19/02/1940", "19/02/1940", "19/02/1940", "19/02/1940", "19/02/1940",
"19/02/1940", "19/02/1940", "10/07/1961", "10/07/1961", "10/07/1961",
"10/07/1961", "10/07/1961", "10/07/1961", "10/07/1961", "10/07/1961",
"10/07/1961", "10/07/1961", "10/07/1961", "10/07/1961", "10/07/1961",
"10/07/1961", "10/07/1961", "10/07/1961", "10/07/1961", "10/07/1961",
"10/07/1961", "10/07/1961", "10/07/1961", "10/07/1961", "10/07/1961",
"10/07/1961", "10/07/1961", "10/07/1961", "10/07/1961", "10/07/1961",
"10/07/1961", "10/07/1961"), contrat = c("CDI commun", "CDI commun",
"CDI commun", "CDI commun", "CDI commun", "CDI commun", "CDI commun",
"CDI commun", "CDI commun", "CDI commun", "CDI commun", "CDI commun",
"CDI commun", "CDI commun", "CDI commun", "CDI commun", "CDI commun",
"CDI commun", "CDD détaché ext. Cirad", "CDD détaché ext. Cirad",
"CDD détaché ext. Cirad", "CDD détaché ext. Cirad", "CDD détaché ext. 
Cirad",
"CDD détaché ext. Cirad", "CDD détaché ext. Cirad", "CDD détaché ext. 
Cirad",

"CDD détaché ext. Cirad", "CDI Détachés Autres", "CDI Détachés Autres",
"CDI Détachés Autres", "CDI Détachés Autres", "CDI Détachés Autres",
"CDI Détachés Autres", "CDI Détachés Autres", "CDI Détachés Autres",
"CDI Détachés Autres", "CDI Détachés Autres", "CDI Détachés Autres",
"CDI Détachés Autres", "CDI Détachés Autres", "CDI commun", "CDI commun",
"CDI commun", "CDI commun", "CDI commun", "CDI commun", "CDI commun",
"CDI commun"), Pays = c("France", "France", "France", "Philippines",
"Philippines", "Philippines", "France", "France", "France", "France",
"France", "Martinique", "Martinique", "Martinique", "Martinique",
"Martinique", "Martinique", "Martinique", "Cameroun", "Cameroun",
"Cameroun", "Cameroun", "Cameroun", "Cameroun", "Cameroun", "Cameroun",
"Cameroun", "France", "France", "France", "France", "France",
"France", "France", "Congo", "Congo", "Congo", "Congo", "Congo",
"Congo", "Gabon", "Gabon", "Gabon", "Gabon", "Gabon", "Gabon",
"Congo", "Congo"), Debut = c("24/01/1995", "01/05/1997", "31/12/1997",
"02/02/1995", "28/02/1995", "01/03/1995", "13/03/1995", "01/01/1996",
"31/01/1996", "24/01/1995", "01/07/1995", "01/09/1995", "01/07/1997",
"01/01/1998", "01/08/1998", "01/01/2000", "17/01/2000", "29/02/2000",
"26/01/1995", "01/07/1996", "16/09/1997", "01/01/1998", "01/07/1998",
"04/11/1999", "01/01/2001", "01/04/2001", "31/08/2001", "01/09/2001",
"02/09/2001", "01/12/2001", "01/02/2003", "01/04/2003", "01/01/2004",
"01/03/2004", "01/09/2004", "01/01/2005", "01/04/2005", "28/10/2006",
"01/01/2007", "01/04/2007", "01/09/2007", "01/01/2009", "01/04/2009",
"01/01/2010", "01/01/2011", "01/04/2011", "05/09/2012", "01/01/2013"
), Fin = c("30/04/1997", "30/12/1997", "31/12/1997", "27/02/1995",
"28/02/1995", "12/03/1995", "30/06/1995", "30/01/1996", "31/01/1996",
"30/06/1995", "31/08/1995", "30/06/1997", "31/12/1997", "31/07/1998",
"31/12/1999", "16/01/2000", "28/02/2000", "29/02/2000", "30/06/1996",
"15/09/1997", "31/12/1997", "30/06/1998", "03/11/1999", "31/12/2000",
"31/03/2001", "30/08/2001", "31/08/2001", "01/09/2001", "30/11/2001",
"31/01/2003", "31/03/2003", "31/12/2003", "29/02/2004", "31/08/2004",
"31/12/2004", "31/03/2005", "27/10/2006", "31/12/2006"

Re: [R] While using R CMD check: LaTex error: File `inconsolata.sty' not found

2013-07-12 Thread Berend Hasselman

On 12-07-2013, at 18:04, Ravi Varadhan  wrote:

> Hi,
> While using R CMD check I get the following Latex error message which occurs 
> when creating PDF version of manual:
> LaTex error:  File `inconsolata.sty' not found
> I am using Windows 7 (64-bit) and R 3.0.1.  I have MikTex 2.9.
> I see that the incosolata.sty is present under \doc\fonts folder.  How can I 
> eliminate this problem?

I've just now updated MacTeX 2013.

After the update kpsewhich inconsolata.sty gives:

/usr/local/texlive/2013/texmf-dist/tex/latex/inconsolata/inconsolata.sty

and  kpsewhich zi4.sty gives

/usr/local/texlive/2013/texmf-dist/tex/latex/inconsolata/zi4.sty

These are essentially identical.

In the package itself there is no tex/inconsolata.sty
The README of the inconsolata package tells you what you could do with 
doc/fonts/inconsolata.sty

See http://www.ctan.org/tex-archive/fonts/inconsolata

It appears that the MacTeX update has automatically taken care of the 
inconsolata.sty and zi4.sty issue.

Berend

__
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] While using R CMD check: LaTex error: File `inconsolata.sty' not found

2013-07-12 Thread Berend Hasselman


On 12-07-2013, at 19:49, Berend Hasselman  wrote:

> 
> On 12-07-2013, at 18:04, Ravi Varadhan  wrote:
> 
>> Hi,
>> While using R CMD check I get the following Latex error message which occurs 
>> when creating PDF version of manual:
>> LaTex error:  File `inconsolata.sty' not found
>> I am using Windows 7 (64-bit) and R 3.0.1.  I have MikTex 2.9.
>> I see that the incosolata.sty is present under \doc\fonts folder.  How can I 
>> eliminate this problem?
> 

MiKTeX search path corrupted? Filename databse problem?

> See 
> http://r.789695.n4.nabble.com/inconsolata-sty-is-liable-to-disappear-texinfo-5-1-td4669976.html
> 
> Get R-patched.
> 

Other option:

Try another MiKTeX update.

I've just had a look at what TeX Live Utility would want to update in MacTeX 
2013 and it appears that inconsolata is back.
And it's also on CTAN: http://www.ctan.org/pkg/inconsolata (dated 2013-07-03).

Berend

> Berend
> 
> __
> 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] While using R CMD check: LaTex error: File `inconsolata.sty' not found

2013-07-12 Thread David Winsemius

On Jul 12, 2013, at 9:04 AM, Ravi Varadhan wrote:

> Hi,
> While using R CMD check I get the following Latex error message which occurs 
> when creating PDF version of manual:
> LaTex error:  File `inconsolata.sty' not found
> I am using Windows 7 (64-bit) and R 3.0.1.  I have MikTex 2.9.
> I see that the incosolata.sty is present under \doc\fonts folder.  How can I 
> eliminate this problem?

I seem to remember that this was described in a posting in the last month ortwo 
on r-devel and that  workaround or two were described:

http://markmail.org/search/?q=list%3Aorg.r-project.r-devel+inconsolata.sty

-- 


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] While using R CMD check: LaTex error: File `inconsolata.sty' not found

2013-07-12 Thread Berend Hasselman

On 12-07-2013, at 18:04, Ravi Varadhan  wrote:

> Hi,
> While using R CMD check I get the following Latex error message which occurs 
> when creating PDF version of manual:
> LaTex error:  File `inconsolata.sty' not found
> I am using Windows 7 (64-bit) and R 3.0.1.  I have MikTex 2.9.
> I see that the incosolata.sty is present under \doc\fonts folder.  How can I 
> eliminate this problem?

See 
http://r.789695.n4.nabble.com/inconsolata-sty-is-liable-to-disappear-texinfo-5-1-td4669976.html

Get R-patched.

Berend

__
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 determine the pdf of a gamma distribution using the estimated parameters?

2013-07-12 Thread Ben Bolker
On 13-07-12 01:38 PM, Kaptue Tchuente, Armel wrote:

> Sorry not to be more precise in my previous message.

> My question is how to use dgamma with the obtained shape and scale
  parameters in order to approximate the observed pdf since the
  results of dgamma (seq(4,28,4), shape,rate) are very different from
  the observed pdf [pdf obs_pdf<-c(0.600, 0.175, 0.100, 0.025, 0.050,
  0.025, 0.025)]?

You need to compute the integral of the relevant sections of the
CDF.  What I've done here is not exactly the same as your classes
((1-4),(5-8),(9-12),...), you'll need to sort that out (what happens
to values between 4 and 5?  If your data are discrete, then the
Gamma distribution isn't a perfect match -- it might be a reasonable
approximation, but you'll have to figure out for yourself how
you want to make the correspondence between your discrete data
and a continuous distribution ... maybe your ranges should be (0.5-4.5),
(4.5-8.5), ... ?)

This looks _reasonably_ close ...
obs_pdf<-c(0.600, 0.175, 0.100, 0.025, 0.050, 0.025, 0.025)
pred_pdf <- diff(pgamma(seq(0,28,4),shape=0.8276,rate=0.1448))
plot(obs_pdf,pred_pdf)
abline(a=0,b=1)

> Armel
> 
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
> Behalf Of Ben Bolker
> Sent: Friday, July 12, 2013 11:58 AM
> To: r-h...@stat.math.ethz.ch
> Subject: Re: [R] How to determine the pdf of a gamma distribution using the 
> estimated parameters?
> 
> Kaptue Tchuente, Armel  sdstate.edu> writes:
> 
>>
> 
> [snip]
> 
>> With th bar histogram (number of occurrences)
>>  hist<-c(24,7,4,1,2,1,1) of seven equally spaces classes ]1-4], ]5-8], 
>> ]9-12], ]13-16], ]17-20], ]21-24], ]25-28], I obtained shape=0.8276 
>> and rate=0.1448.
>>
>> I would like to know how to build the continuous pdf of a this gamma 
>> distribution knowing these two estimated parameters such that I will 
>> be able to predict the pdf of any positive value.
> 
>   Are you talking about dgamma(x,shape=0.8276,rate=0.1448),
> where x is the value you are trying to predict for?  dgamma gives probability 
> density, pgamma gives cumulative density/distribution function.
>

__
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 determine the pdf of a gamma distribution using the estimated parameters?

2013-07-12 Thread Kaptue Tchuente, Armel
Sorry not to be more precise in my previous message.
My question is how to use dgamma with the obtained shape and scale parameters 
in order to approximate the observed pdf since the results of dgamma 
(seq(4,28,4), shape,rate) are very different from the observed pdf [pdf 
obs_pdf<-c(0.600, 0.175, 0.100, 0.025, 0.050, 0.025, 0.025)]?
Armel

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Ben Bolker
Sent: Friday, July 12, 2013 11:58 AM
To: r-h...@stat.math.ethz.ch
Subject: Re: [R] How to determine the pdf of a gamma distribution using the 
estimated parameters?

Kaptue Tchuente, Armel  sdstate.edu> writes:

> 

[snip]

> With th bar histogram (number of occurrences)
>  hist<-c(24,7,4,1,2,1,1) of seven equally spaces classes ]1-4], ]5-8], 
> ]9-12], ]13-16], ]17-20], ]21-24], ]25-28], I obtained shape=0.8276 
> and rate=0.1448.
> 
> I would like to know how to build the continuous pdf of a this gamma 
> distribution knowing these two estimated parameters such that I will 
> be able to predict the pdf of any positive value.

  Are you talking about dgamma(x,shape=0.8276,rate=0.1448),
where x is the value you are trying to predict for?  dgamma gives probability 
density, pgamma gives cumulative density/distribution function.

__
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] While using R CMD check: LaTex error: File `inconsolata.sty' not found

2013-07-12 Thread Ravi Varadhan
Hi,
While using R CMD check I get the following Latex error message which occurs 
when creating PDF version of manual:
LaTex error:  File `inconsolata.sty' not found
I am using Windows 7 (64-bit) and R 3.0.1.  I have MikTex 2.9.
I see that the incosolata.sty is present under \doc\fonts folder.  How can I 
eliminate this problem?

Thanks,
Ravi

[[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 find the probability of falling in a bivariate ellipse

2013-07-12 Thread Anamika Chaudhuri
Hi All:

How would you find out the probability that a point lies within an ellipse?
For eg if I was plotting (x,y) for 300 datasets in an 95% ellipsoid region,
how do I calculate how many times out of 300 will my points fall inside the
ellipse?

Heres the code I am using

library(MASS)
seed<-1234
x<-NULL
k<-20
Sigma2 <- matrix(c(.72,.57,.57,.46),2,2)
Sigma2
rho <- Sigma2[1,2]/sqrt(Sigma2[1,1]*Sigma2[2,2])
rho
eta1<-replicate(300,mvrnorm(k, mu=c(-1.59,-2.44), Sigma2))

library(car)
dataEllipse(eta1[1,],eta1[2,], levels=c(0.05, 0.95))

Thanks for your help.

[[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] Upgrade from R 2.11 to R 3.0.1

2013-07-12 Thread Marc Schwartz
On Jul 12, 2013, at 11:58 AM, Chirag Gupta  wrote:

> Hi
> 
> I am trying to upgrade R version 2.11 to 3.0.1 on Linux server.
> I downloaded the latest version it installed correctly. Now when I run R
> and check the version, it still shows an older version.
> I am new to Linux. If anyone can tell me how to remove/uninstall R
> completely from the server, I can try and re-install the newer version and
> try.
> 
> Thanks.


What Linux server? RHEL?

Do you have root access to the server?

How did you download and install R? Did you download and install a binary RPM 
locally, install a binary using a package manager like yum or did you download 
the source tarball, compile and install?

Need more information.

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] What is the maximum limit for an array?

2013-07-12 Thread Ben Bolker
Jonsson  Bordeaux.inra.fr> writes:

> 
> So If download R 3,my problem will be gone?

  If you also install it :-)  and if you have a 64-bit OS and if
you have enough memory to handle the resulting object (see David
Winsemius's response).

__
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] LDA and confidence ellipse

2013-07-12 Thread Lluis
Thanks again



--
View this message in context: 
http://r.789695.n4.nabble.com/LDA-and-confidence-ellipse-tp4671308p4671427.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] [XML packages] how to get the sub-node according to the sub-node's attribute?

2013-07-12 Thread Chris Stubben

My question is:
Is there a function that can get the sub-node according to the sub-node's 
attribute ?
like that,in the mtcar.xml ,there is sub-node as follow:
30.4   4  95.1 113 3.77 1.513 16.90  1  15
2
I want to get the specific sub-node according to the attribute "id="Lotus 
Europa".
Is there a simple function in the xml package?



Just use xpathSApply with brackets to specify the specific id...

doc <- xmlParse(system.file("exampleData", "mtcars.xml", package="XML"))

xpathSApply(doc, "//record[@id='Lotus Europa']", xmlValue)
[1] "30.4   4  95.1 113 3.77 1.513 16.90  1  152"

#OR?
xpathSApply(doc, "//record[@id='Lotus Europa']")
getNodeSet(doc, "//record[@id='Lotus Europa']")

# And to list all Ids...

xpathSApply(doc, "//record", xmlGetAttr, "id")
[1] "Mazda RX4"   "Mazda RX4 Wag"   "Datsun 710"   .   


--

Chris Stubben

Los Alamos National Lab
Bioscience Division
MS M888
Los Alamos, NM 87545

__
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] Upgrade from R 2.11 to R 3.0.1

2013-07-12 Thread Chirag Gupta
Hi

I am trying to upgrade R version 2.11 to 3.0.1 on Linux server.
I downloaded the latest version it installed correctly. Now when I run R
and check the version, it still shows an older version.
I am new to Linux. If anyone can tell me how to remove/uninstall R
completely from the server, I can try and re-install the newer version and
try.

Thanks.

-- 
*Chirag Gupta*
Department of Crop, Soil, and Environmental Sciences,
115 Plant Sciences Building, Fayetteville, Arkansas 72701

[[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 determine the pdf of a gamma distribution using the estimated parameters?

2013-07-12 Thread Ben Bolker
Kaptue Tchuente, Armel  sdstate.edu> writes:

> 

[snip]

> With th bar histogram (number of occurrences)
>  hist<-c(24,7,4,1,2,1,1) of seven equally spaces classes
> ]1-4], ]5-8], ]9-12], ]13-16], ]17-20], ]21-24], ]25-28], 
> I obtained shape=0.8276 and rate=0.1448.
> 
> I would like to know how to build the continuous pdf of a this
> gamma distribution knowing these two estimated
> parameters such that I will be able to predict the pdf of any
> positive value.

  Are you talking about dgamma(x,shape=0.8276,rate=0.1448),
where x is the value you are trying to predict for?  dgamma gives
probability density, pgamma gives cumulative density/distribution
function.

__
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 determine the pdf of a gamma distribution using the estimated parameters?

2013-07-12 Thread Kaptue Tchuente, Armel


Hello everyone,

With th bar histogram (number of occurrences) hist<-c(24,7,4,1,2,1,1) of seven 
equally spaces classes ]1-4], ]5-8], ]9-12], ]13-16], ]17-20], ]21-24], 
]25-28], I obtained shape=0.8276 and rate=0.1448.

I would like to know how to build the continuous pdf of a this gamma 
distribution knowing these two estimated parameters such that I will be able to 
predict the pdf of any positive value.

Thanks
Armel

[[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] What is the maximum limit for an array?

2013-07-12 Thread David Winsemius

On Jul 12, 2013, at 6:42 AM, Ben Bolker wrote:

> Jonsson  Bordeaux.inra.fr> writes:
> 
>> 
>> Hello All,
>> I am having a problem with this:
>> 
>> file<-array(dim=c(1440,720,700,3))
>>  Error in array(dim = c(1440, 720, 700, 3)) : 
>>   'dim' specifies too large an array
>> 
>> I have a memory of 20GB, But I do not know where is the problem!Any help
>> 
>> When I replaced 700 by any number bellow like( 600,500),it worked without
>> any problem.
> 
> From
> 
> http://stat.ethz.ch/R-manual/R-devel/library/base/html/LongVectors.html :
> 
> Prior to R 3.0.0, all vectors in R were restricted to at most 2^31 - 1 
> 
>> 1440*720*700*3
> [1] 217728
>> 2^31-1
> [1] 2147483647
> 
>  So you need R>=3.0.0 (on a 64-bit system).

And (unfortunately) perhaps three times the currently installed RAM will be 
needed for productive use of such an R data-object. The memory requirements of 
a numeric array are roughly 10 times the product of the dimensions:

10*prod( c(1440,720,700,3))
#[1] 2177280 
# G  M  K

So the hardware limitations are now a constraint. I am a bit surprised that 
object with those lower dimensions could be handled "without any problem." 
Generally an object of dim =c(1440,720,700,3) will not be able to be 
productively used for anything except read access. Copying it or even assigning 
new values to it, which of necessity creates a copy,  would generally overflow 
installed RAM and push your session into "virtual memory" at which point my 
system starts to display molasses-like behavior. Occassionally waiting on the 
order of 5-20 minutes allows the process to complete, but in many instances 
terminating the session is needed.

-- 
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] error of betadiver in vegan

2013-07-12 Thread David Winsemius

On Jul 12, 2013, at 1:47 AM, Elaine Kuo wrote:

> Hello,
> 
> Thanks for Jari's comment.
> It worked well after correction.
> However, an error jumped out for the code below.
> "Error: cannot allocate vector of size 90.6 Mb"
> 
> Please kindly advise how to modify it.

Elaine;

This problem has literally been addressed hundreds of times on R-help:

http://markmail.org/search/?q=list%3Aorg.r-project.r-help+%22Error%3A+cannot+allocate+vector+of+size%22

And it's either been asked or answered 54 times on StackOverflow:

http://stackoverflow.com/search?q=[r]+%22Error%3A+cannot+allocate+vector+of+size%22

Th lack of contiguous RAM is small enought that the problem should be 
manageable after reading a few of the solutions offered.

-- 
David.


> Thank you.
> 
> Elaine
> 
> Code
> # Non-Passerine table
> dataNP_1 <-read.dbf("H:/temp_D/stage_4_R_2748/NP_1-10.dbf", as.is = FALSE)
> dataNP_2 <-read.dbf("H:/temp_D/stage_4_R_2748/NP_11-19.dbf", as.is = FALSE)
> dataNP<-merge(dataNP_1,dataNP_2,by=c("GID"),all=T)
> 
> .. skip...
> 
> # Non-Passerine and Passerine table (2748 species)
> dataR<-merge(dataP,dataNP,by=c("GID"),all=T)
> dim(dataR)
> str(dataR)
> 
> library(vegan)
> 
>  ##  The  beta sim  index (Lennon 2001)
>  d  <-  betadiver(dataR,  "sim")
> 
> 
> On Fri, Jul 12, 2013 at 2:13 PM, Jari Oksanen  wrote:
> 
>> Elaine Kuo  gmail.com> writes:
>> 
>>> 
>>> Hello,
>>> 
>>> I am using betadiver (vegan) to calculate beta diversity.
>>> However, an error message shows
>>> 
>>> Error in ifelse(x > 0, 1, 0) :
>>>  (list) object cannot be coerced to type 'double'
>> ...snip...
>> 
>>>  ##  Raw  data
>>>  R  <-  betadiver(dataR)
>>> 
>>>  ##  The  indices
>>>  betadiver(help=TRUE)
>>> 
>>>  ##  The  beta sim  index (Lennon 2001)
>>>  d  <-  betadiver(R,  "sim")
>>> 
>> Elaine,
>> 
>> Look carefully what you do here: betadiver needs data as input -- not beta
>> diversities. Your last command is equal to this oneliner:
>> 
>> d <- betadiver(betadiver(dataR), "sim")
>> 
>> This is guaranteed to fail. Use instead
>> 
>> d <- betadiver(dataR, "sim")
>> 
>> Cheers, Jari Oksanen
-- 

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] What is the maximum limit for an array?

2013-07-12 Thread Jonsson
So If download R 3,my problem will be gone?



--
View this message in context: 
http://r.789695.n4.nabble.com/What-is-the-maximum-limit-for-an-array-tp4671395p4671409.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] Sparse matrix no longer sparse (Matrix Package)

2013-07-12 Thread Doran, Harold
It could be done that way, but when you do the part A %*% D it returns an 
object of class dsCmatrix. What I see happening here, in plain English is as 
follows:

If you take the inverse of an object of class dsCMatrix, you get in return a 
matrix of class dgCMatrix. 

But, if you take the inverse of an object of class dgCMatrix, you get in return 
an object of class dgeMatrix and this is a huge memory hog even though it 
retains its sparseness and I think should be stored as a sparse matrix of some 
form. 

Example,

A1 <- as(diag(5, 10), 'dgCMatrix')
A2 <- as(diag(5, 10), 'dsCMatrix')

> object.size(solve(A2))
1640 bytes
> object.size(solve(A1))
1912 bytes




-Original Message-
From: William Dunlap [mailto:wdun...@tibco.com] 
Sent: Friday, July 12, 2013 11:49 AM
To: Doran, Harold
Subject: RE: [R] Sparse matrix no longer sparse (Matrix Package)

> ### Create a symmetric matrix of class dsCMatrix A <- diag(5, 10) A[1, 
> 5] <- A[5,1] <- 2

Did you mean the first command to be
   A <- as(diag(5, 10), "dsCMatrix")
?

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Doran, Harold
> Sent: Friday, July 12, 2013 6:24 AM
> To: 'Jeff Newmiller'; John Kane; r-help@r-project.org
> Cc: dmba...@gmail.com; maech...@stat.math.ethz.ch
> Subject: Re: [R] Sparse matrix no longer sparse (Matrix Package)
> 
> Here is code to completely replicate the issue with comments. I remain 
> confused why simply changing one element of the ddi matrix to be 
> non-integer changes two things: 1) It changes the class of the object I need 
> (A Inverse) and it increases its memory.
> 
> Ideally, A inverse will remain stored as a sparse matrix no matter 
> what (as it is sparse in my real world problem). When it is converted 
> to a dense object, it blows up in memory and my R program halts.
> 
> library(Matrix)
> 
> ### Create a symmetric matrix of class dsCMatrix A <- diag(5, 10) A[1, 
> 5] <- A[5,1] <- 2
> 
> ### Create a diagonal matrix of class ddi D <- Diagonal(10, 50)
> 
> ### This returns the inverse of A stored as a sparse matrix ### In my 
> real world problem it consumes almost no memory at all ### this is the 
> ideal type A <- A %*%D (aa <- solve(A))
> class(aa)
> object.size(aa)
> 
> ### Now, let's only change one element of D to be non-integer D[1] <- 
> 1.5
> 
> ### Notice here the inverse of the matrix A ### is now stored as a 
> different object class than before ### even though the pattern of 0s 
> and non-zeros remains the same ### It also increases in memory size 
> ### In my real world problem, the matrix increases from ### about .03 
> megabytes to almost 2 megabytes and this causes R to choke and die
> 
> A <- A %*% D
> (aa <- solve(A))
> class(aa)
> object.size(aa)
> 
> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Jeff Newmiller
> Sent: Thursday, July 11, 2013 3:22 PM
> To: John Kane; r-help@r-project.org
> Cc: dmba...@gmail.com; maech...@stat.math.ethz.ch
> Subject: Re: [R] Sparse matrix no longer sparse (Matrix Package)
> 
> It seems to me that this issue should be reproducible with a small 
> matrix, since the concern is the representation rather than the values.
> ---
> Jeff NewmillerThe .   .  Go Live...
> DCN:Basics: ##.#.   ##.#.  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 Kane  wrote:
> 
> >Just about anything I knew about matrices, I forgot years ago so I'm 
> >no help here but I'd suggest putting the matrix on something like 
> >Mediafire http://www.mediafire.com/ or Dropbox 
> >https://www.dropbox.com so people can download it and have a look.
> >
> >I agree that dput() is not really good for "big" data sets.
> >
> >Kingston ON Canada
> >
> >
> >> -Original Message-
> >> From: hdo...@air.org
> >> Sent: Thu, 11 Jul 2013 17:10:54 +
> >> To: hdo...@air.org, jrkrid...@inbox.com, r-help@r-project.org
> >> Subject: RE: [R] Sparse matrix no longer sparse (Matrix Package)
> >>
> >> This is a terrible example as I didn't realize my code actually 
> >> does create a non-symmetric matrix and in this case the function 
> >> behaves
> >as
> >> expected. Nonetheless, my original issue stands and that issue 
> >> still
> >does
> >> not make sense.
> >>
> >> Apologies for bad example code.
> >>
> >> -Original Message-
> >> From: r-help-boun...@r-project.org
> >[mailto:r-help-boun...@r-project.org]
> >> On Behalf Of Doran, Harold
> >> Sent: Thursday, 

Re: [R] Help with IF command strings

2013-07-12 Thread arun
Hi,
Regarding the 2nd issue of mean=3.8 being "too high", could you explain it.
#Using the same example:
 dat1$V21[dat1$V2==1|dat1$V2==0]
#[1]  6  2  1 10  0
 (6+2+1+10+0)/5
#[1] 3.8
 mean(dat1$V21[dat1$V2==1|dat1$V2==0])
#[1] 3.8

About missing data:
set.seed(55)
dat2<- as.data.frame(matrix(sample(c(NA,0:4),26*10,replace=TRUE),ncol=26))  
new example dataset
 dat2$V2
 #[1]  4 NA  0  0  1  3  2  4  2  1
dat2$V21
 #[1] NA  3  0  0  2  0  4  0  3 NA
(dat2$V2==1|dat2$V2==0) &!is.na(dat2$V2)
# [1] FALSE FALSE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE  TRUE
 dat2$V21[(dat2$V2==1|dat2$V2==0) &!is.na(dat2$V2)]
#[1]  0  0  2 NA
mean(dat2$V21[(dat2$V2==1|dat2$V2==0) &!is.na(dat2$V2)],na.rm=TRUE)
#[1] 0.667
 (0+0+2)/3
#[1] 0.667


If this doesn't solve the problem, please provide a reproducible example using 
?dput() 
ex:
dput(head(dataset,20))

A.K.



When I enter that formula I get "NA" or NaN" as an answer.  I have some 
missing data, which was entered in as NA, so I'm not sure if that is the
 problem.  Originally I thought I would need to do the entire set of 
equations you posted, but that gave me 3.8 as a mean, which I know is 
too high to be the mean for this data set. 

Thanks 



- Original Message -
From: arun 
To: R help 
Cc: 
Sent: Friday, July 12, 2013 8:21 AM
Subject: Re: Help with IF command strings

Hi,

Not sure I understand your question.
Suppose `data1` is your real data, but if the column names are different, 
change "V21", "V2" by those in the real data. Based on your initial post, the 
column names seemed to be the same.
mean(data1$V21[data1$V2==1|data1$V2==0])

A.K.  


What values would I substitute by real data.  I did everything the way 
you posted, and I got 3.8 as well.  So I'm curious what values I would 
change to get the mean for the actual data? 


- Original Message -
From: arun 
To: R help 
Cc: 
Sent: Thursday, July 11, 2013 9:21 PM
Subject: Re: Help with IF command strings

HI,
Try this:
set.seed(485)
dat1<- as.data.frame(matrix(sample(0:10,26*10,replace=TRUE),ncol=26))
mean(dat1$V21[dat1$V2==1|dat1$V2==0])
#[1] 3.8
#or
with(dat1,mean(V21[V2==1|V2==0]))
#[1] 3.8


A.K.


I have data in 26 columns, I'm trying to get a mean for column 21 only for the 
participants that are either 0 or 1 in column 2. 

One of the commands I tried looked something like this 

mean(data1$V21, if(V2 = 1))   

So basically I need to have the program run a mean (and later 
other forms of analysis) on participants based on their condition. 
either 0 or 1. 

Help is greatly appreciated. 

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] Power of Kruskal-Wallis Test?

2013-07-12 Thread Greg Snow
Here are some examples from the archives:

http://tolstoy.newcastle.edu.au/R/e4/help/08/02/2499.html

https://stat.ethz.ch/pipermail/r-sig-mixed-models/2009q1/001790.html

https://stat.ethz.ch/pipermail/r-sig-mixed-models/2009q1/001819.html




On Fri, Jul 12, 2013 at 6:57 AM, Charles Determan Jr wrote:

> Thank you Greg,
> However, would you be able to direct me to either an example or further
> information regarding simulations to measure power?
>
> Charles
>
>
> On Thu, Jul 11, 2013 at 4:56 PM, Greg Snow <538...@gmail.com> wrote:
>
>> If there were a canned function for power for a non-parametric test, I
>> would not trust it.  This is because there are many assumptions that would
>> need to be made and I would not know if those in a canned function were
>> reasonable for my study.
>>
>> I would compute power by simulation.  Simulate data sets that match what
>> you think the real data will/may look like, analyze the simulated datasets
>> and see what proportion give significant results (that will be your power).
>>  You can do this for different sets of assumptions to get a  feel for how
>> the different assumptions affect your results.  This way you know exactly
>> what assumptions you are making to get your power.
>>
>>
>> On Tue, Jul 9, 2013 at 2:18 PM, Charles Determan Jr wrote:
>>
>>> Greetings,
>>>
>>> To calculate power for an ANOVA test I know I can use the
>>> pwr.anova.test()
>>> from the pwr package.  Is there a similar function for the nonparamentric
>>> equivalent, Kruskal-Wallis?  I have been searching but haven't come up
>>> with
>>> anything.
>>>
>>> Thanks,
>>>
>>> --
>>> Charles Determan
>>> Integrated Biosciences PhD Candidate
>>> 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.
>>>
>>
>>
>>
>> --
>> Gregory (Greg) L. Snow Ph.D.
>> 538...@gmail.com
>>
>
>
>
> --
> Charles Determan
> Integrated Biosciences PhD Candidate
> University of Minnesota
>



-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.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.


Re: [R] Help with installing a .tar.gz package on windows

2013-07-12 Thread Duncan Murdoch

On 13-07-12 3:26 PM, Michael Dewey wrote:

At 23:49 11/07/2013, Lucy Leigh wrote:


Hi everyone,

Thanks to everyone for all the advice. I should have been clearer in
my first email, the version of 'PReMiuM' I have is not
the one available on CRAN at the moment, but a version I was sent by
one of the authors, Silvia Liveriani, with a small bug fixed.
I don't know if this is the same as the next version to be released,
or whether the next will be different again. I asked about
compiling it myself because I didn't want to bother the authors
again if doing so was going to be a simple task I could
do myself, which I now realise is not the case.

I think the best option seems to me to be to contact the authors
again and request permission to send the version to
winbuilder to be compiled for me.


Lucy
The advantage of following Bill's instructions is that you will then
know how to install your own packages. Eventually when you have been
using R for a while you will have all sorts of useful functions and
one day you will think 'What I need is to make a package lucytools to
keep them together and documented.' This is easier than it looks, I
wish I had done it much earlier (except obviously I did not call mine
lucytools).




I just want to add here that you don't need Rtools to install simple 
packages.  If they contain only R code, you can install them without the 
tools.  This advice would likely apply to lucytools (or maybe michaeltools).


My advice doesn't apply to PReMiuM, because that package has C++ code in 
it.  For compiling C, C++, or Fortran code, you need the Rtools, so 
following something like Brian Ripley's or Bill Dunlap's advice is needed.


Duncan Murdoch





Thank you also Bill Dunlap for your detailed instructions on how to
use RTools, I am sure this will come in handy for me
in the future too, and I appreciate you taking the time to write it
all out for me.

Regards,
Lucy Leigh



Prof Brian Ripley  12/07/2013 6:03 am >>>

On 11/07/2013 20:21, David Winsemius wrote:


On Jul 11, 2013, at 1:37 AM, Rolf Turner wrote:


On 11/07/13 17:57, Prof Brian Ripley wrote:

On 11/07/2013 01:22, David Winsemius wrote:


On Jul 10, 2013, at 4:37 PM, Lucy Leigh wrote:


Hi,
I have had a look at the manual but it makes no sense to me. I have
downloaded RTools, and the InnoSetup,
but I don't understand how to use these to install my package? Am I
meant to be writing commands
in R itself, or in these other things I've downloaded?


Since you are clearly out of your league with respect to

compiling from source, now is the time to ask (again), why are you
not installing the binary package?


At the R command line just type:

install.packages("PReMiuM")  # should default to

type="win.binary" and use a CRAN mirror




Or as she seems to want to use a later version than on CRAN, to

ask again why she does not use winbuilder.




But the winbuilder web page explicitly says:


Please do not upload packages of other maintainers

(particularly not without changing the Maintainer field to your own
e-mail address, if you have permissions to do that), because the
maintainer indicated in the maintainer field of the DESCRIPTION
file get response from us. Please do not upload BioConductor
packages or CRAN packages. Both BioConductor and CRAN do have build
systems. If BioConductor or CRAN packages are not available for
Windows, there is a certainly a reason and also this service won't
be able to build the package properly.


So it would appear that it is *not* advisable for Ms. Leigh to

use winbuilder.


I read that paragraph as saying that if a specific package , i.e.

a particular numbered version, is already on CRAN or the BioC
server, then do not duplicate effort. Also do not submit if a CRAN
compilation resulted in an error. Especially in light of Prof.
Ripley's (reiterated) advice, I did not read it as saying that a
pre-release update to an existing package should not be submitted
(after suitable alterations of the DESCRIPTION file.)

You read correctly, and indeed this is what the R manuals and the rw-FAQ
say.  This is all assuming that Lucy does have Silvia's (the author of
PReMiuM) permission, but given that she has a unreleased version, that
seems eminently reasonable.

I am CCing Uwe Ligges (the provider of the winbuilder service) in case
he wants to expand the statement.  Although winbuilder does not have a
large capacity, new hardware was acquired fairly recently and it is not
as hard-pressed as it was.

In the particular case of PReMiuM compiling is tricky (it needs the
right version of Boost).  And because we've been here before, I know
that winbuilder has a suitable version of Boost.

An alternative would be for Silvia to submit that version to winbuilder
and send the link to Lucy to download.

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

Re: [R] Standardize GLS coefficients in R

2013-07-12 Thread Greg Snow
One fairly easy option is to just center and scale each of the x-variables,
then fit your model on the transformed variables.  This works best if your
x-variables are roughly symmetric mound shaped and could be meaningless if
any of the x-variables is highly skewed or has outliers.


On Thu, Jul 11, 2013 at 4:52 PM, TomW87  wrote:

> Hello,
>
> I have estimated the coefficients for my model using the 'pggls' function
> from the 'plm' package. Now I want to see the relative influence of those
> X's. How can some please tell me how to standardize those my results in R?
>
> Thank you!
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Standardize-GLS-coefficients-in-R-tp4671371.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.
>



-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.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.


Re: [R] readLines() problem-error

2013-07-12 Thread peter dalgaard
It's not really a problem or error, just a message that the system is closing a 
connection for you. Presumably, you have several previous instances of opening 
a connection and naming it "con".  

To avoid the message, just close(con) when you are done reading from it.

-pd

On Jul 12, 2013, at 15:04 , Zsurzsa Laszlo wrote:

> Hello everyone,
> 
> I have my program like this:
> 
> 
> while (length(oneLine <- readLines(con, n = 1, warn = FALSE)) > 0)  {
>   # here I process the line I read
> }
> 
> 
> The problem is it gives me different output every time. I get a problem/
> error like:
> 
> "Closing unused connection (con)". Sadly I can't provide the file because
> it's ,ore then a GB.
> 
> Thank you in advance,
> ---
> - László-András Zsurzsa,  -
> - Msc. Infromatics, Technical University Munich, -
> ---
> 
>   [[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.

-- 
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] Needing help for excluding vector elements

2013-07-12 Thread arun
Hi,
Try:
set.seed(41)
vec1<- sample(1:50,12000,replace=TRUE)
tail(vec1,-1000)
length(tail(vec1,-1000))
#[1] 11000


A.K.




- Original Message -
From: Olivier Charansonney 
To: r-help@r-project.org
Cc: 
Sent: Friday, July 12, 2013 6:06 AM
Subject: [R] Needing help for excluding vector elements

Hello,

R for Dummies.

How can I exclude the first 1000 values of a vector (length 12000)? More
generally all the values up to the ith?

Thanks for your help,



Dr Olivier Charansonney

Cardiologue

Centre Hospitalier Sud-Francilien, Corbeil-Essonnes, France




    [[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] Needing help for excluding vector elements

2013-07-12 Thread Jose Iparraguirre
Dear Olivier,

Perhaps you're looking for this?

> yourvector[-(1:1000)]



Kind regards,

José

Prof. José Iparraguirre
Chief Economist
Age UK

Age UK
Tavis House, 1- 6 Tavistock Square
London, WC1H 9NB

T 020 303 31482
E jose.iparragui...@ageuk.org.uk
Twitter @jose.iparraguirre@ageuk

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Olivier Charansonney
Sent: 12 July 2013 11:06
To: r-help@r-project.org
Subject: [R] Needing help for excluding vector elements

Hello,

R for Dummies.

How can I exclude the first 1000 values of a vector (length 12000)? More 
generally all the values up to the ith?

Thanks for your help,

 

Dr Olivier Charansonney

Cardiologue

Centre Hospitalier Sud-Francilien, Corbeil-Essonnes, France

 


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

The Wireless from Age UK | Radio for grown-ups.

www.ageuk.org.uk/thewireless


If you’re looking for a radio station that offers real variety, tune in to The 
Wireless from Age UK. 
Whether you choose to listen through the website at 
www.ageuk.org.uk/thewireless, on digital radio (currently available in London 
and Yorkshire) or through our TuneIn Radio app, you can look forward to an 
inspiring mix of music, conversation and useful information 24 hours a day.



 
---
Age UK is a registered charity and company limited by guarantee, (registered 
charity number 1128267, registered company number 6825798). 
Registered office: Tavis House, 1-6 Tavistock Square, London WC1H 9NA.

For the purposes of promoting Age UK Insurance, Age UK is an Appointed 
Representative of Age UK Enterprises Limited, Age UK is an Introducer 
Appointed Representative of JLT Benefit Solutions Limited and Simplyhealth 
Access for the purposes of introducing potential annuity and health 
cash plans customers respectively.  Age UK Enterprises Limited, JLT Benefit 
Solutions Limited and Simplyhealth Access are all authorised and 
regulated by the Financial Services Authority. 
--

This email and any files transmitted with it are confidential and intended 
solely for the use of the individual or entity to whom they are 
addressed. If you receive a message in error, please advise the sender and 
delete immediately.

Except where this email is sent in the usual course of our business, any 
opinions expressed in this email are those of the author and do not 
necessarily reflect the opinions of Age UK or its subsidiaries and associated 
companies. Age UK monitors all e-mail transmissions passing 
through its network and may block or modify mails which are deemed to be 
unsuitable.

Age Concern England (charity number 261794) and Help the Aged (charity number 
272786) and their trading and other associated companies merged 
on 1st April 2009.  Together they have formed the Age UK Group, dedicated to 
improving the lives of people in later life.  The three national 
Age Concerns in Scotland, Northern Ireland and Wales have also merged with Help 
the Aged in these nations to form three registered charities: 
Age Scotland, Age NI, Age Cymru.




__
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] Needing help for excluding vector elements

2013-07-12 Thread Bert Gunter
Make an effort to learn R. Read "An Introduction to R" -- at least the
beginning where you will learn about basic R structures and indexing.

Cheers,
Bert

On Fri, Jul 12, 2013 at 3:06 AM, Olivier Charansonney
 wrote:
> Hello,
>
> R for Dummies.
>
> How can I exclude the first 1000 values of a vector (length 12000)? More
> generally all the values up to the ith?
>
> Thanks for your help,
>
>
>
> Dr Olivier Charansonney
>
> Cardiologue
>
> Centre Hospitalier Sud-Francilien, Corbeil-Essonnes, France
>
>
>
>
> [[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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] What is the maximum limit for an array?

2013-07-12 Thread Ben Bolker
Jonsson  Bordeaux.inra.fr> writes:

> 
> Hello All,
> I am having a problem with this:
> 
> file<-array(dim=c(1440,720,700,3))
>   Error in array(dim = c(1440, 720, 700, 3)) : 
>'dim' specifies too large an array
> 
> I have a memory of 20GB, But I do not know where is the problem!Any help
> 
> When I replaced 700 by any number bellow like( 600,500),it worked without
> any problem.

From

http://stat.ethz.ch/R-manual/R-devel/library/base/html/LongVectors.html :

Prior to R 3.0.0, all vectors in R were restricted to at most 2^31 - 1 

> 1440*720*700*3
[1] 217728
> 2^31-1
[1] 2147483647

  So you need R>=3.0.0 (on a 64-bit system).

 Ben Bolker

__
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] apply problem

2013-07-12 Thread Amen Alyaari
I will try to explain my problem. There are 600 (global map)files (1440 
sample * 720 lines)in two directories dir1 and dir2, which have the same 
format ,byte,extend,etc. I computed the `bias` between two datasets 
using the function and code given below as follows:


Function:

bias <-function(pred,obs,na.rm=TRUE){
 mean((pred - obs), na.rm = na.rm)}

read files:

 dir1 <- list.files("/donnees/notghi", "*.img", full.names = TRUE)
 dir2 <- list.files("/donnees/baieSt", "*.img", full.names = TRUE)

for each x,y location, I would read it into a multi-dimensional array 
with dimensions:


  file_tot<-array(dim=c(1440,720,600,2))

Apply the code:

  for(i in 1:length(dir1)){
  file_tot[,,i,1] <- readBin(dir1[i], double(), size = 4 ,n = 1440* 
720 , signed = T)
  file_tot[,,i,2] <- readBin(dir2[i], double(), size = 4 ,n = 1440 
* 720, signed = T)

 }
calculate the `bias`:

result<-apply(file_tot,c(1,2),function(x){bias(x[,1],x[,2])})
This worked correctly and no problem with that.

now I want to modify the function and add third part(mod in the function 
which should come from different data (dir3) other than dir1 and dir2):

 function:

   err<-function(pred,obs,mod,na.rm=TRUE){
sqrt(mean(((pred-obs)*(pred-mod)), na.rm = na.rm))}

read the files(note that now dir3 is added and files have the same 
attributes):


dir1 <- list.files("/donnees/notghi", "*.img", full.names = TRUE)
dir2 <- list.files("/donnees/baieSt", "*.img", full.names = TRUE)
dir3 <- list.files("/donnees/modt", "*.img", full.names = TRUE)
 code:
I tried to do this,I put `3` instead of `2`:

file_tot<-array(dim=c(1440,720,600,3))## worked well

  and then change this line accordingly:
from:

   result<-apply(file_tot,c(1,2),function(x){bias(x[,1],x[,2])})

to :

  result<-apply(file_tot,c(1,3),function(x){err(x[,1],x[,2],x[,3])})
 ## not 3 instead of 2 and I added x[,3]
  Is that right?

This worked without errors but I checked the results and they were crap.

--
Amen Alyaari, UPMC
PhD student
Unit of Functional Ecology&  Environmental Physics [EPHYSE]
National Institute of Agricultural Research [INRA].
71, Avenue Edouard Bourlaux
33140 Villenave d'Ornon
Téléphone : +33(0) 5 57 12 24 27
Fax : +33 (0)5 57 12 24 20
FRANCE

__
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] What is the maximum limit for an array?

2013-07-12 Thread Jonsson
Hello All,
I am having a problem with this:

file<-array(dim=c(1440,720,700,3))
  Error in array(dim = c(1440, 720, 700, 3)) : 
   'dim' specifies too large an array

I have a memory of 20GB, But I do not know where is the problem!Any help

When I replaced 700 by any number bellow like( 600,500),it worked without
any problem.



--
View this message in context: 
http://r.789695.n4.nabble.com/What-is-the-maximum-limit-for-an-array-tp4671395.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 new matrix from user-defined function

2013-07-12 Thread bcrombie
Excellent.  I should have thought of the with statement, since it’s kind of a 
universal coding method.  Have a good wknd. BNC

From: arun kirshna [via R] [mailto:ml-node+s789695n4671365...@n4.nabble.com]
Sent: Thursday, July 11, 2013 4:55 PM
To: Crombie, Burnette N
Subject: Re: create new matrix from user-defined function

Hi BNC,
No problem.
You could also use ?with()

data.frame(MW_EEsDue_ERRORS=with(dat3,A_CaseID[D_MW_EEsDueTotal!=rowSums(cbind(B_MW_EEsDue1,C_MW_EEsDue2))]))
#  MW_EEsDue_ERRORS
#1 1882
#2 1884
#3 1885
A.K.



- Original Message -
From: "Crombie, Burnette N" <[hidden 
email]>
To: arun <[hidden email]>
Cc: R help <[hidden email]>
Sent: Thursday, July 11, 2013 4:40 PM
Subject: RE: [R] create new matrix from user-defined function

You understood me perfectly, and I agree is it easier to index using numbers 
than names.  I'm just afraid if my dataset gets too big I'll mess up which 
index numbers I'm supposed to be using.  "data.table()" looks very useful and a 
good way to approach the issue.  Thanks.  I really appreciate your (everyone's) 
help.  BNC

-Original Message-
From: arun [mailto:[hidden 
email]]
Sent: Thursday, July 11, 2013 4:29 PM
To: Crombie, Burnette N
Cc: R help
Subject: Re: [R] create new matrix from user-defined function

Hi,
Not sure I understand you correctly.
I found it easier to index using number than replace it by lengthy column names.
You could do it similar to the one below.

matNew<-matrix(dat3[rowSums(dat3[c("B_MW_EEsDue1","C_MW_EEsDue2")])!=dat3["D_MW_EEsDueTotal"],1],ncol=1,dimnames=list(NULL,"MW_EEsDue_ERRORS"))

 matNew
# MW_EEsDue_ERRORS
#[1,] 1882
#[2,] 1884
#[3,] 1885

If you have very large dataset, you could also check ?data.table().


library(data.table)
dt3<- data.table(dat3)
dtNew<-subset(dt3[D_MW_EEsDueTotal!=B_MW_EEsDue1+C_MW_EEsDue2],select=1)
 dtNew
#   A_CaseID
#1: 1882
#2: 1884
#3: 1885


#Some speed comparisons:
set.seed(1254)
datTest<- data.frame(A=sample(1000:15000,1e7,replace=TRUE),B= 
sample(1:10,1e7,replace=TRUE),C=sample(5:15,1e7,replace=TRUE),D=sample(5:25,1e7,replace=TRUE))

system.time(res1<- data.frame(MW_EEsDue_ERRORS=datTest[datTest[[4]] != 
datTest[[2]]+datTest[[3]],][[1]]))
# user  system elapsed
#  2.256   0.000   2.145

system.time(mat1<-matrix(datTest[rowSums(datTest[,2:3])!=datTest[,4],1],ncol=1,dimnames=list(NULL,"MW_EEsDue_ERRORS")))
 #  user  system elapsed
 # 0.756   0.088   0.849

system.time(res2<- 
data.frame(MW_EEsDue_ERRORS=datTest[addmargins(as.matrix(datTest[,2:3]),2)[,3]!=datTest[,4],1]))
#   user  system elapsed
#115.740   0.000 105.778

dtTest<- data.table(datTest)
system.time(res3<- subset(dtTest[D!=B+C],select=1))
 # user  system elapsed
 # 0.508   0.000   0.477

identical(res1,res2)
#[1] TRUE
setnames(res3,"A","MW_EEsDue_ERRORS")
 identical(res1,as.data.frame(res3))
#[1] TRUE
A.K.




- Original Message -
From: bcrombie <[hidden email]>
To: [hidden email]
Cc:
Sent: Thursday, July 11, 2013 3:54 PM
Subject: Re: [R] create new matrix from user-defined function

Dan and Arun, thank you very much for your replies.  They are both very helpful 
and I love to get different versions of an answer so I can learn more R code.  
You both used indexing to refer to the columns needed in the function, but 
since my real data frame will be much larger I'm assuming I can replace the 
index numbers with the names of the columns in quotes instead?   I'll try this 
on my own if you're busy with other forum questions.  Thanks, again.

From: Nordlund, Dan (DSHS/RDA) [via R] [mailto:[hidden 
email]]
Sent: Wednesday, July 10, 2013 5:46 PM
To: Crombie, Burnette N
Subject: Re: create new matrix from user-defined function

> -Original Message-
> From: [hidden email]
> [mailto:r-help-bounces@r-
> project.org]
>  On
> Behalf Of bcrombie
> Sent: Wednesday, July 10, 2013 12:19 PM
> To: [hidden email]
> Subject: [R] create new matrix from user-defined function
>
> #Let's say I have the following data set:
>
> dat3 = data.frame(A_CaseID = c(1881, 1882, 1883, 1884, 1885),
>   B_MW_EEsDue1 = c(2, 2, 1, 4, 6),
>   C_MW_EEsDue2 = c(5, 5, 4, 1, 6),
>   D_MW_EEsDueTotal = c(7, 9, 5, 6, 112))
> dat3
> # A_CaseID B_MW_EEsDue1 C_MW_EEsDue2 D_MW_EEsDueTotal  # 1 1881
>257  # 2 188225
>9  # 3 1883145  # 4
>1884416  # 5 1885
>66  112
>
> # I want to:
> #CREATE A NEW 1-COLUMN MATRIX (of unknown #rows) LISTING ONLY "A"'s
> WHERE "D != B + C"
> #THIS COLUMN CAN BE LABELED "MW_EEsDue_ERRORS", and output for this
> example should be:
>
> # MW_EEsDue_ERRORS
> # 1 1882
> # 2 18

[R] Needing help for excluding vector elements

2013-07-12 Thread Olivier Charansonney
Hello,

R for Dummies.

How can I exclude the first 1000 values of a vector (length 12000)? More
generally all the values up to the ith?

Thanks for your help,

 

Dr Olivier Charansonney

Cardiologue

Centre Hospitalier Sud-Francilien, Corbeil-Essonnes, France

 


[[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] Help with installing a .tar.gz package on windows

2013-07-12 Thread Michael Dewey

At 23:49 11/07/2013, Lucy Leigh wrote:


Hi everyone,

Thanks to everyone for all the advice. I should have been clearer in 
my first email, the version of 'PReMiuM' I have is not
the one available on CRAN at the moment, but a version I was sent by 
one of the authors, Silvia Liveriani, with a small bug fixed.
I don't know if this is the same as the next version to be released, 
or whether the next will be different again. I asked about
compiling it myself because I didn't want to bother the authors 
again if doing so was going to be a simple task I could

do myself, which I now realise is not the case.

I think the best option seems to me to be to contact the authors 
again and request permission to send the version to

winbuilder to be compiled for me.


Lucy
The advantage of following Bill's instructions is that you will then 
know how to install your own packages. Eventually when you have been 
using R for a while you will have all sorts of useful functions and 
one day you will think 'What I need is to make a package lucytools to 
keep them together and documented.' This is easier than it looks, I 
wish I had done it much earlier (except obviously I did not call mine 
lucytools).



Thank you also Bill Dunlap for your detailed instructions on how to 
use RTools, I am sure this will come in handy for me
in the future too, and I appreciate you taking the time to write it 
all out for me.


Regards,
Lucy Leigh


>>> Prof Brian Ripley  12/07/2013 6:03 am >>>
On 11/07/2013 20:21, David Winsemius wrote:
>
> On Jul 11, 2013, at 1:37 AM, Rolf Turner wrote:
>
>> On 11/07/13 17:57, Prof Brian Ripley wrote:
>>> On 11/07/2013 01:22, David Winsemius wrote:

 On Jul 10, 2013, at 4:37 PM, Lucy Leigh wrote:

> Hi,
> I have had a look at the manual but it makes no sense to me. I have
> downloaded RTools, and the InnoSetup,
> but I don't understand how to use these to install my package? Am I
> meant to be writing commands
> in R itself, or in these other things I've downloaded?

 Since you are clearly out of your league with respect to 
compiling from source, now is the time to ask (again), why are you 
not installing the binary package?


 At the R command line just type:

 install.packages("PReMiuM")  # should default to 
type="win.binary" and use a CRAN mirror


>>>
>>> Or as she seems to want to use a later version than on CRAN, to 
ask again why she does not use winbuilder.

>>>
>>>
>> But the winbuilder web page explicitly says:
>>
>>> Please do not upload packages of other maintainers 
(particularly not without changing the Maintainer field to your own 
e-mail address, if you have permissions to do that), because the 
maintainer indicated in the maintainer field of the DESCRIPTION 
file get response from us. Please do not upload BioConductor 
packages or CRAN packages. Both BioConductor and CRAN do have build 
systems. If BioConductor or CRAN packages are not available for 
Windows, there is a certainly a reason and also this service won't 
be able to build the package properly.

>>
>> So it would appear that it is *not* advisable for Ms. Leigh to 
use winbuilder.

>
> I read that paragraph as saying that if a specific package , i.e. 
a particular numbered version, is already on CRAN or the BioC 
server, then do not duplicate effort. Also do not submit if a CRAN 
compilation resulted in an error. Especially in light of Prof. 
Ripley's (reiterated) advice, I did not read it as saying that a 
pre-release update to an existing package should not be submitted 
(after suitable alterations of the DESCRIPTION file.)


You read correctly, and indeed this is what the R manuals and the rw-FAQ
say.  This is all assuming that Lucy does have Silvia's (the author of
PReMiuM) permission, but given that she has a unreleased version, that
seems eminently reasonable.

I am CCing Uwe Ligges (the provider of the winbuilder service) in case
he wants to expand the statement.  Although winbuilder does not have a
large capacity, new hardware was acquired fairly recently and it is not
as hard-pressed as it was.

In the particular case of PReMiuM compiling is tricky (it needs the
right version of Boost).  And because we've been here before, I know
that winbuilder has a suitable version of Boost.

An alternative would be for Silvia to submit that version to winbuilder
and send the link to Lucy to download.

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


Michael Dewey
i...@aghmed.fsnet.co.uk
http://www.aghmed.fsnet.co.uk/home.html

__
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/post

Re: [R] Sparse matrix no longer sparse (Matrix Package)

2013-07-12 Thread Doran, Harold
Here is code to completely replicate the issue with comments. I remain confused 
why simply changing one element of the ddi matrix to be non-integer changes two 
things: 1) It changes the class of the object I need (A Inverse) and it 
increases its memory. 

Ideally, A inverse will remain stored as a sparse matrix no matter what (as it 
is sparse in my real world problem). When it is converted to a dense object, it 
blows up in memory and my R program halts.

library(Matrix)

### Create a symmetric matrix of class dsCMatrix
A <- diag(5, 10)
A[1, 5] <- A[5,1] <- 2

### Create a diagonal matrix of class ddi
D <- Diagonal(10, 50)

### This returns the inverse of A stored as a sparse matrix 
### In my real world problem it consumes almost no memory at all
### this is the ideal type
A <- A %*%D
(aa <- solve(A))
class(aa)
object.size(aa)

### Now, let's only change one element of D to be non-integer
D[1] <- 1.5

### Notice here the inverse of the matrix A
### is now stored as a different object class than before
### even though the pattern of 0s and non-zeros remains the same
### It also increases in memory size
### In my real world problem, the matrix increases from 
### about .03 megabytes to almost 2 megabytes and this causes R to choke and die

A <- A %*% D
(aa <- solve(A))
class(aa)
object.size(aa)

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Jeff Newmiller
Sent: Thursday, July 11, 2013 3:22 PM
To: John Kane; r-help@r-project.org
Cc: dmba...@gmail.com; maech...@stat.math.ethz.ch
Subject: Re: [R] Sparse matrix no longer sparse (Matrix Package)

It seems to me that this issue should be reproducible with a small matrix, 
since the concern is the representation rather than the values.
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  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 Kane  wrote:

>Just about anything I knew about matrices, I forgot years ago so I'm no 
>help here but I'd suggest putting the matrix on something like 
>Mediafire http://www.mediafire.com/ or Dropbox https://www.dropbox.com 
>so people can download it and have a look.
>
>I agree that dput() is not really good for "big" data sets.  
>
>Kingston ON Canada
>
>
>> -Original Message-
>> From: hdo...@air.org
>> Sent: Thu, 11 Jul 2013 17:10:54 +
>> To: hdo...@air.org, jrkrid...@inbox.com, r-help@r-project.org
>> Subject: RE: [R] Sparse matrix no longer sparse (Matrix Package)
>> 
>> This is a terrible example as I didn't realize my code actually does 
>> create a non-symmetric matrix and in this case the function behaves
>as
>> expected. Nonetheless, my original issue stands and that issue still
>does
>> not make sense.
>> 
>> Apologies for bad example code.
>> 
>> -Original Message-
>> From: r-help-boun...@r-project.org
>[mailto:r-help-boun...@r-project.org]
>> On Behalf Of Doran, Harold
>> Sent: Thursday, July 11, 2013 11:36 AM
>> To: 'John Kane'; r-help@r-project.org
>> Cc: dmba...@gmail.com; maech...@stat.math.ethz.ch
>> Subject: Re: [R] Sparse matrix no longer sparse (Matrix Package)
>> 
>> Thank you, John. I originally used dput() but the output is huge.
>> However, here is a reproducible example of what I think very
>unexpected
>> behavior of some matrix functions.
>> 
>>> ### Create a symmetric matrix of class dsCMatrix A <- as(diag(5,
>10),
>>> 'dsCMatrix') A[1, 5] <- A[5,1] <- 2
>>> 
>>> ### Create a diagonal matrix of class ddi D <- Diagonal(10, 1)
>>> 
>>> ### This works as it should
>>> aa <- Cholesky(A %*% D)
>>> 
>>> ### Now, let's only change one element of D to be non-integer D[1]
><-
>>> 1.5
>>> 
>>> ### AD is still symmetric, but here the Cholesky function complains 
>>> that it is not aa <- Cholesky(A %*% D)
>> Error in Cholesky(as(A, "symmetricMatrix"), perm = perm, LDL = LDL,
>super
>> = super,  :
>>   error in evaluating the argument 'A' in selecting a method for
>function
>> 'Cholesky': Error in asMethod(object) :
>>   not a symmetric matrix; consider forceSymmetric() or symmpart()
>> 
>> ### For fun try this
>> 
>>> L <- update(aa, as(A %*% D, 'symmetricMatrix'))
>> Error in asMethod(object) :
>>   not a symmetric matrix; consider forceSymmetric() or symmpart()
>> 
>> ### This does indeed work, but should I need to implement this step?
>> 
>> Cholesky(forceSymmetric(A %*% D))
>> 
>> So, there is something about changing the elements of a ddi matrix
>that
>> causes subsequent problems. Is there a good reason this occurs and 
>> something I should be doing differently, or is this a bug?

[R] readLines() problem-error

2013-07-12 Thread Zsurzsa Laszlo
Hello everyone,

I have my program like this:


while (length(oneLine <- readLines(con, n = 1, warn = FALSE)) > 0)  {
   # here I process the line I read
}


The problem is it gives me different output every time. I get a problem/
error like:

"Closing unused connection (con)". Sadly I can't provide the file because
it's ,ore then a GB.

Thank you in advance,
---
- László-András Zsurzsa,  -
- Msc. Infromatics, Technical University Munich, -
---

[[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] Power of Kruskal-Wallis Test?

2013-07-12 Thread Charles Determan Jr
Thank you Greg,
However, would you be able to direct me to either an example or further
information regarding simulations to measure power?

Charles


On Thu, Jul 11, 2013 at 4:56 PM, Greg Snow <538...@gmail.com> wrote:

> If there were a canned function for power for a non-parametric test, I
> would not trust it.  This is because there are many assumptions that would
> need to be made and I would not know if those in a canned function were
> reasonable for my study.
>
> I would compute power by simulation.  Simulate data sets that match what
> you think the real data will/may look like, analyze the simulated datasets
> and see what proportion give significant results (that will be your power).
>  You can do this for different sets of assumptions to get a  feel for how
> the different assumptions affect your results.  This way you know exactly
> what assumptions you are making to get your power.
>
>
> On Tue, Jul 9, 2013 at 2:18 PM, Charles Determan Jr wrote:
>
>> Greetings,
>>
>> To calculate power for an ANOVA test I know I can use the pwr.anova.test()
>> from the pwr package.  Is there a similar function for the nonparamentric
>> equivalent, Kruskal-Wallis?  I have been searching but haven't come up
>> with
>> anything.
>>
>> Thanks,
>>
>> --
>> Charles Determan
>> Integrated Biosciences PhD Candidate
>> 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.
>>
>
>
>
> --
> Gregory (Greg) L. Snow Ph.D.
> 538...@gmail.com
>



-- 
Charles Determan
Integrated Biosciences PhD Candidate
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.


Re: [R] Replicating Rows

2013-07-12 Thread arun
Hi,

apple<- read.table(text="
Fam.name,Item,AMT.SALE.NET.PROMO,X.CY..QTY.SALE.TOT
9475,Imported Fruits,22110276001,0,436
9499,Imported Fruits,22110277001,0,236
9523,Imported Fruits,22110278001,0,71 
",sep=",",header=TRUE,stringsAsFactors=FALSE)
str(apple)
#'data.frame':    3 obs. of  4 variables:
# $ Fam.name  : chr  "Imported Fruits" "Imported Fruits" "Imported 
Fruits"
# $ Item  : num  2.21e+10 2.21e+10 2.21e+10
# $ AMT.SALE.NET.PROMO: int  0 0 0
# $ X.CY..QTY.SALE.TOT: num  436 236 71

Here, it changed the class of some of the variables.
new<-sapply(apple[,-4],rep,apple[,4]) 
str(as.data.frame(new,stringsAsFactors=FALSE))
#'data.frame':    743 obs. of  3 variables:
# $ Fam.name  : chr  "Imported Fruits" "Imported Fruits" "Imported 
Fruits" "Imported Fruits" ...
# $ Item  : chr  "22110276001" "22110276001" "22110276001" 
"22110276001" ...
# $ AMT.SALE.NET.PROMO: chr  "0" "0" "0" "0" ...



new1<-apple[rep(seq_len(nrow(apple)),apple[,4]),-4]
 row.names(new1)<- 1:nrow(new1)
 str(new1)
#'data.frame':    743 obs. of  3 variables:
# $ Fam.name  : chr  "Imported Fruits" "Imported Fruits" "Imported 
Fruits" "Imported Fruits" ...
# $ Item  : num  2.21e+10 2.21e+10 2.21e+10 2.21e+10 2.21e+10 ...
# $ AMT.SALE.NET.PROMO: int  0 0 0 0 0 0 0 0 0 0 ..
A.K.




I try to replicate the rows according to the number of quantity 
occurred. Its row should be be sum of the quantity. is there any wrong 
with my code? thanks. 

apple 
            Fam.name        Item AMT.SALE.NET.PROMO X.CY..QTY.SALE.TOT 
9475 Imported Fruits 22110276001                  0                436 
9499 Imported Fruits 22110277001                  0                236 
9523 Imported Fruits 22110278001                  0                 71 
9552 Imported Fruits 22110306001                  0                 69 
9571 Imported Fruits 22110314001                  0                 20 
9579 Imported Fruits 22110315001                  0                 80 
9604 Imported Fruits 22110317001                  0                 61 
9635 Imported Fruits 22110321001                  0               1026 
9697 Imported Fruits 22110334001                  0                223 
9720 Imported Fruits 22110335001                  0                214 
9744 Imported Fruits 22110336001                  0                102 
9768 Imported Fruits 22110337001                  0                146 
9868 Imported Fruits 22110354001              118.8                 17 
9893 Imported Fruits 22110360001                  0                 43 
9904 Imported Fruits 22110363001                  0                 49 
9920 Imported Fruits 22110364001                  0                  1 
9938 Imported Fruits 22110365001              205.4                 33 

new<-sapply(apple[,-4],rep,apple[,4]) 
nrow(new) 
[1] 33572

__
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] Help with IF command strings

2013-07-12 Thread arun
Hi,

Not sure I understand your question.
Suppose `data1` is your real data, but if the column names are different, 
change "V21", "V2" by those in the real data. Based on your initial post, the 
column names seemed to be the same.
mean(data1$V21[data1$V2==1|data1$V2==0])

A.K.  


What values would I substitute by real data.  I did everything the way 
you posted, and I got 3.8 as well.  So I'm curious what values I would 
change to get the mean for the actual data? 


- Original Message -
From: arun 
To: R help 
Cc: 
Sent: Thursday, July 11, 2013 9:21 PM
Subject: Re: Help with IF command strings

HI,
Try this:
set.seed(485)
dat1<- as.data.frame(matrix(sample(0:10,26*10,replace=TRUE),ncol=26))
mean(dat1$V21[dat1$V2==1|dat1$V2==0])
#[1] 3.8
#or
with(dat1,mean(V21[V2==1|V2==0]))
#[1] 3.8


A.K.


I have data in 26 columns, I'm trying to get a mean for column 21 only for the 
participants that are either 0 or 1 in column 2. 

One of the commands I tried looked something like this 

mean(data1$V21, if(V2 = 1))   

So basically I need to have the program run a mean (and later 
other forms of analysis) on participants based on their condition. 
either 0 or 1. 

Help is greatly appreciated. 

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] calculate time from dates

2013-07-12 Thread Rui Barradas

Hello,

It's better if you keep it on the list, the odds of getting more and 
better answers is greater.


As for your question, I've made up a dat2 with an extra column. Try the 
following, it's independent of the number of columns.




dat2 <- data.frame(ID = dat1$ID,
month = mondf("01/01/2008", dat1$date, format = "%m/%d/%Y") + 1,
other = rnorm(6))

dat2

sp <- split(dat2, list(dat2$ID, dat2$month))
result <- do.call(rbind, lapply(sp, tail, 1))
rownames(result) <- seq_len(nrow(result))
result


Hope this helps,

Rui Barradas


Em 12-07-2013 09:04, Gallon Li escreveu:

Dear Rui, I think your solution is the best. however, to keep only the
last one if month diff are equal part: because my data also have other
variables besides ID and month, your code doesn't work. where should i
modify it? in another word, my "dat2" contains more than 2 columns.i
tried to modify [1:2] to [1:p] where p is the total number of columns in
dat2 but it still doesn't work.

Best, Gallon


On Thu, Jul 11, 2013 at 7:00 PM, Rui Barradas mailto:ruipbarra...@sapo.pt>> wrote:

Hello,

The functions in stackoverflow need a date 'format' argument.



# Functions from
#

http://stackoverflow.com/__questions/1995933/number-of-__months-between-two-dates


# with a 'format' argument added
#
# turn a date into a 'monthnumber' relative to an origin
monnb <- function(d, format = "%Y-%m-%d") {
 lt <- as.POSIXlt(as.Date(d, origin="1900-01-01", format =
format))
 lt$year*12 + lt$mon
}
# compute a month difference as a difference between two monnb's
mondf <- function(d1, d2, format = "%Y-%m-%d") {
 monnb(d2, format = format) - monnb(d1, format = format)
}


dat1 <- read.table(text = "

ID date
1 4/12/2008
1 4/13/2008
1 5/11/2008
2 3/21/2009
2 4/22/2009
2 8/05/2009
", header = TRUE)

dat2 <- data.frame(ID = dat1$ID, month = mondf("01/01/2008",
dat1$date, format = "%m/%d/%Y") + 1)

# Now keep just the last one if month diffs are equal
result <- with(dat2, aggregate(month, list(ID, month), FUN = tail,
1))[1:2]
names(result) <- names(dat2)
result


Hope this helps,

Rui Barradas

Em 11-07-2013 11:03, andrija djurovic escreveu:

Hi.

See

http://stackoverflow.com/__questions/1995933/number-of-__months-between-two-dates



Andrija


On Thu, Jul 11, 2013 at 11:56 AM, Gallon Li mailto:gallon...@gmail.com>> wrote:

My data are from 2008 to 2010, with repeated measures for
same subjects. I
wish to compute number of months since january 2008.

The data are like the following:

ID date
1 4/12/2008
1 4/13/2008
1 5/11/2008
2 3/21/2009
2 4/22/2009
2 8/05/2009
...

the date column are in the format "%m/%d/%y". i wish to obtain

ID month
1 4
1 4
1 5
2 15
2 16
2 20
...

also, for the same ID with two identical month, I only want
to keep the
last one. can any expert help with this question?

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




__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] error of betadiver in vegan

2013-07-12 Thread Elaine Kuo
Hello,

Thanks for Jari's comment.
It worked well after correction.
However, an error jumped out for the code below.
"Error: cannot allocate vector of size 90.6 Mb"

Please kindly advise how to modify it.
Thank you.

Elaine

Code
# Non-Passerine table
dataNP_1 <-read.dbf("H:/temp_D/stage_4_R_2748/NP_1-10.dbf", as.is = FALSE)
dataNP_2 <-read.dbf("H:/temp_D/stage_4_R_2748/NP_11-19.dbf", as.is = FALSE)
dataNP<-merge(dataNP_1,dataNP_2,by=c("GID"),all=T)

.. skip...

# Non-Passerine and Passerine table (2748 species)
dataR<-merge(dataP,dataNP,by=c("GID"),all=T)
dim(dataR)
str(dataR)

library(vegan)

  ##  The  beta sim  index (Lennon 2001)
  d  <-  betadiver(dataR,  "sim")


On Fri, Jul 12, 2013 at 2:13 PM, Jari Oksanen  wrote:

> Elaine Kuo  gmail.com> writes:
>
> >
> > Hello,
> >
> > I am using betadiver (vegan) to calculate beta diversity.
> > However, an error message shows
> >
> > Error in ifelse(x > 0, 1, 0) :
> >   (list) object cannot be coerced to type 'double'
> ...snip...
>
> >   ##  Raw  data
> >   R  <-  betadiver(dataR)
> >
> >   ##  The  indices
> >   betadiver(help=TRUE)
> >
> >   ##  The  beta sim  index (Lennon 2001)
> >   d  <-  betadiver(R,  "sim")
> >
> Elaine,
>
> Look carefully what you do here: betadiver needs data as input -- not beta
> diversities. Your last command is equal to this oneliner:
>
> d <- betadiver(betadiver(dataR), "sim")
>
> This is guaranteed to fail. Use instead
>
> d <- betadiver(dataR, "sim")
>
> Cheers, Jari Oksanen
>
> __
> 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] Use R for data aggregation

2013-07-12 Thread Jeff Newmiller
This is off-topic here... you are looking for statistical advice, if not 
problem-domain-specific help. Please read the Posting Guide.
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  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.

nntx  wrote:

>I have a set of evaluation variables (n) for each sample (sample size
>is
>large enough) and I am trying to use R (nnet package) to aggregate the
>data.
>However, I don't know the weight for each variable (I am sure the
>weight
>shouldn't be equally assigned). Specifically, I have 12 indices (CO2,
>SO2,
>TSP...) for 100 cities and I want to calculate weight for each and
>finally
>obtain a comprehensive index and rankings for the cities. 
>
>Could anyone give me an idea how can I realize this? Thank you very
>much.  
>
>
>
>--
>View this message in context:
>http://r.789695.n4.nabble.com/Use-R-for-data-aggregation-tp4671384.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.


Re: [R] Sending carbon copy mails from R

2013-07-12 Thread Jadhav, Alok
Thanks prof. Ripley. I looked into create.post function. Unfortunately
this is not useful in my case. I want to send emails programmatically
from a server machine (error notifications etc.)
I am able to send emails from my workstation using Outlook com object
without any issues. However, on server machine I don't have access to
outlook object (or any other email client). Hence the need to explore
SMTP clients to be able to send mails from server. 


Regards,
Alok


-Original Message-
From: Prof Brian Ripley [mailto:rip...@stats.ox.ac.uk] 
Sent: Friday, July 12, 2013 1:41 PM
To: Jadhav, Alok
Cc: r-help@r-project.org
Subject: Re: [R] Sending carbon copy mails from R

Note that sendmailR is not 'from R'.  There are other possibilities, and

  I use create.post() from R itself, modified as I need.

On 12/07/2013 02:48, Alok Jadhav wrote:
> updated code pasted here. So I guess CC is not an option at all? In
that case
> is there any other package that would be useful?
>
> require(sendmailR)
> to <- c("v...@abc.com")
> header <- list(cc=c("a...@abc.com"))
> x <- sendmail("t...@abc.com", to, "test", "testing",
> header=header,control=list(smtpServer=server,verbose=TRUE))
> << 220 equity.xyz.com ESMTP Sendmail 8.11.7p1+Sun/8.11.7; Thu, 11 Jul
2013
> 21:31:43 -0400 (EDT)
>>> HELO  HKD03836654
> << 250 equity.xyz.com Hello HKD03836654.gbl.ad.net [169.34.175.142],
pleased
> to meet you
>>> MAIL FROM:  t...@abc.com
> << 250 2.1.0 t...@abc.com... Sender ok
>>> RCPT TO:  v...@abc.com
> << 250 2.1.5 v...@abc.com... Recipient ok
>>> DATA
> << 354 Enter mail, end with "." on a line by itself
>>> 
> << 250 2.0.0 r6C1Vh101169 Message accepted for delivery
>>> QUIT
> << 221 2.0.0 equity.csfb.com closing connection
>
>
>
> --
> View this message in context:
http://r.789695.n4.nabble.com/Sending-carbon-copy-mails-from-R-tp4671153
p4671376.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.
>


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

=== 
Please access the attached hyperlink for an important el...{{dropped:4}}

__
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 R for data aggregation

2013-07-12 Thread nntx
I have a set of evaluation variables (n) for each sample (sample size is
large enough) and I am trying to use R (nnet package) to aggregate the data.
However, I don't know the weight for each variable (I am sure the weight
shouldn't be equally assigned). Specifically, I have 12 indices (CO2, SO2,
TSP...) for 100 cities and I want to calculate weight for each and finally
obtain a comprehensive index and rankings for the cities. 

Could anyone give me an idea how can I realize this? Thank you very much.  



--
View this message in context: 
http://r.789695.n4.nabble.com/Use-R-for-data-aggregation-tp4671384.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.