Re: [R] estimate value from simulations

2013-05-15 Thread Pascal Oettli

Hi,

You probably should read R documentation and learn how to use "seq"

?seq
?rowMeans

HTH,
Pascal


On 05/16/2013 03:17 PM, Zilefac Elvis wrote:

Hello,

I need your help on this matrix:


  1 1 1 1 1 1
  2 2 2 2 2 2
  3 3 3 3 3 3
  5 5 5 5 5 5
  2 2 2 2 2 2
  3 3 3 3 3 3
  6 6 6 6 6 6
  2 2 2 2 2 2
  3 3 3 3 3 3
  1 1 1 1 1 1
  2 2 2 2 2 2
  3 3 3 3 3 3

First three rows represent first simulation, next three rows = second 
simulation etc.
I would like to estimate the values in row 1 for example by taking  the mean  
of rows 1, 4, 7, 10. Do same for all other rows. So the resulting matrix is
3-by-6.

Thanks
Atem.
[[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] estimate value from simulations

2013-05-15 Thread Zilefac Elvis
Hello,

I need your help on this matrix:
 

 1 1 1 1 1 1
 2 2 2 2 2 2
 3 3 3 3 3 3 
 5 5 5 5 5 5
 2 2 2 2 2 2
 3 3 3 3 3 3 
 6 6 6 6 6 6
 2 2 2 2 2 2
 3 3 3 3 3 3 
 1 1 1 1 1 1
 2 2 2 2 2 2
 3 3 3 3 3 3 

First three rows represent first simulation, next three rows = second 
simulation etc.
I would like to estimate the values in row 1 for example by taking  the mean  
of rows 1, 4, 7, 10. Do same for all other rows. So the resulting matrix is 
3-by-6.

Thanks
Atem.
[[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] R help: Batch read files based on names in a list

2013-05-15 Thread arun
HI,
You could use:
(# with 3 files in my folder)
lfiles<-list.files(pattern=".txt")
 lfiles
#[1] "file1.txt" "file2.txt" "file3.txt"
lst1<-lapply(lfiles,function(x) 
read.table(x,header=TRUE,sep="",stringsAsFactors=FALSE))
lst1
#[[1]]
#  col1 col2
#1    1  0.5
#2    2  0.2
#3    3  0.3
#4    4  0.3
#5    5  0.1
#6    6  0.2
#
#[[2]]
 # col1 col3
#1    1    A
#2    2    B
#3    3    C
#
#[[3]]
 # col1 col4
#1    1  0.1
#2    2  0.5
#3    4  0.9
library(plyr)
 join_all(lst1,by="col1")
#  col1 col2 col3 col4
#1    1  0.5    A  0.1
#2    2  0.2    B  0.5
#3    3  0.3    C   NA
#4    4  0.3   0.9
#5    5  0.1    NA
#6    6  0.2    NA

join_all(lst1,by="col1",type="inner")
#  col1 col2 col3 col4
#1    1  0.5    A  0.1
#2    2  0.2    B  0.5

#or
 Reduce(function(...) merge(...,all=TRUE),lst1)
#  col1 col2 col3 col4
#1    1  0.5    A  0.1
#2    2  0.2    B  0.5
#3    3  0.3    C   NA
#4    4  0.3   0.9
#5    5  0.1    NA
#6    6  0.2    NA

#Suppose you don't want to read "file3.txt"
 lfilesSub<-lfiles[!lfiles%in% "file3.txt"]
lfilesSub
#[1] "file1.txt" "file2.txt"

A.K.








- Original Message -
From: Jonathan Dry 
To: r-help@r-project.org
Cc: 
Sent: Wednesday, May 15, 2013 1:51 PM
Subject: [R] R help: Batch read files based on names in a list

*

I am currently reading in a series of files, applying the same functions to
them one at a time, and then merging the resulting data frames e.g.:

>MyRows <- c("RowA", "RowB", "RowC")>>File1_DF <- 
>read.delim("DirectoryToFiles\\File1_Folder\\File1.txt", 
>stringsAsFactors=FALSE, check.names=FALSE)>File1_DF <- 
>as.data.frame(t(File1_DF[MyRows,]))>File1_DF <- 
>as.data.frame(t(File1_DF))>mergeDF <- merge(mergeDF,File1_DF, by.x = 
>"Row.names", by.y="row.names")>>File2_DF <- 
>read.delim("DirectoryToFiles\\File2_Folder\\File2.txt", 
>stringsAsFactors=FALSE, check.names=FALSE)>File2_DF <- 
>as.data.frame(t(File2_DF[MyRows,]))>File2_DF <- 
>as.data.frame(t(File2_DF))>mergeDF <- merge(mergeDF,File2_DF, by.x = 
>"Row.names", by.y="row.names")

...etc

I want to know if I can use a list of the filenames c("File1", "File2",
"File2") etc. and apply a function to do this in a more automated fasion?
This would involve using the list value in the directory path to read in
the file i.e.

>*MyFilesValue*_DF <- 
>read.delim("DirectoryToFolders\\*MyFilesValue*_Folder\\*MyFilesValue*.txt",
> stringsAsFactors=FALSE, check.names=FALSE)

Any help appreciated
*

    [[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] matrix - pairwise comparison of columns

2013-05-15 Thread arun
Hi,
May be this helps:

c1<-combn(seq_len(ncol(m)),2)
 mat1<- matrix(0,ncol=3,nrow=3,dimnames=list(colnames(m),colnames(m)))
vec1<-unlist(lapply(seq_len(ncol(c1)),function(i) {m1<-m[,c1[,i]]; 
length(which(m1[,1]!=0 & m1[,2]!=0)) }))
mat1[lower.tri(mat1)]<-vec1
 mat1
#    rs1 rs2 rs3
#rs1   0   0   0
#rs2   1   0   0
#rs3   2   1   0

#Converting to sparseMatrix
library(Matrix)
 mat2<-as(mat1,"sparseMatrix")
#or

mat2<-Matrix(mat1,sparse=TRUE)
3 x 3 sparse Matrix of class "dtCMatrix"
#    rs1 rs2 rs3
#rs1   .   .   .
#rs2   1   .   .
#rs3   2   1   .




A.K.



- Original Message -
From: Hermann Norpois 
To: r-help 
Cc: 
Sent: Wednesday, May 15, 2013 3:57 PM
Subject: [R] matrix - pairwise comparison of columns

Hello,

I would like to do something with a matrix:
1) The columns should be compared pairwise.
2) And the result should be a matrix.

I try to illustrate the problem with a testset.

> m
     rs1 rs2 rs3
[1,]   1   1   1
[2,]   0   1   0
[3,]   2   0   1
> dput (m)
structure(c(1, 0, 2, 1, 1, 0, 1, 0, 1), .Dim = c(3L, 3L), .Dimnames = list(
    NULL, c("rs1", "rs2", "rs3")))
> which (m[,1] !=0&m[,2] != 0) #How many rows between two columns that are
both non zero

How can I automate the pairwise which-statement?

As result I would like to have a matrix like this

     rs1 rs2 rs3
rs1
rs2  1
rs3  2    1

Is there a tool in R that helps?

Thanks
Hermann

    [[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] R help: Batch read files based on names in a list

2013-05-15 Thread Enrico Schumann
On Wed, 15 May 2013, Jonathan Dry  writes:

> *
>
> I am currently reading in a series of files, applying the same functions to
> them one at a time, and then merging the resulting data frames e.g.:
>
>>MyRows <- c("RowA", "RowB", "RowC")>>File1_DF <- 
>>read.delim("DirectoryToFiles\\File1_Folder\\File1.txt", 
>>stringsAsFactors=FALSE, check.names=FALSE)>File1_DF <- 
>>as.data.frame(t(File1_DF[MyRows,]))>File1_DF <- 
>>as.data.frame(t(File1_DF))>mergeDF <- merge(mergeDF,File1_DF, by.x = 
>>"Row.names", by.y="row.names")>>File2_DF <- 
>>read.delim("DirectoryToFiles\\File2_Folder\\File2.txt", 
>>stringsAsFactors=FALSE, check.names=FALSE)>File2_DF <- 
>>as.data.frame(t(File2_DF[MyRows,]))>File2_DF <- 
>>as.data.frame(t(File2_DF))>mergeDF <- merge(mergeDF,File2_DF, by.x = 
>>"Row.names", by.y="row.names")
>
> ...etc
>
> I want to know if I can use a list of the filenames c("File1", "File2",
> "File2") etc. and apply a function to do this in a more automated fasion?
> This would involve using the list value in the directory path to read in
> the file i.e.

Something like this?

  files <- dir("my_directory")
  for (f in files) {
  ## do something with file 'f'
  }



-- 
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net

__
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] matrix - pairwise comparison of columns

2013-05-15 Thread Bert Gunter
I believe your query is too vague to coherently (and generally) answer, but
have a look at ?outer  .

-- Bert

On Wed, May 15, 2013 at 12:57 PM, Hermann Norpois wrote:

> Hello,
>
> I would like to do something with a matrix:
> 1) The columns should be compared pairwise.
> 2) And the result should be a matrix.
>
> I try to illustrate the problem with a testset.
>
> > m
>  rs1 rs2 rs3
> [1,]   1   1   1
> [2,]   0   1   0
> [3,]   2   0   1
> > dput (m)
> structure(c(1, 0, 2, 1, 1, 0, 1, 0, 1), .Dim = c(3L, 3L), .Dimnames = list(
> NULL, c("rs1", "rs2", "rs3")))
> > which (m[,1] !=0&m[,2] != 0) #How many rows between two columns that are
> both non zero
>
> How can I automate the pairwise which-statement?
>
> As result I would like to have a matrix like this
>
>  rs1 rs2 rs3
> rs1
> rs2  1
> rs3  21
>
> Is there a tool in R that helps?
>
> Thanks
> Hermann
>
> [[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

[[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] OFF TOPIC: Report on a conference on "Integrity in research"

2013-05-15 Thread Bert Gunter
For those on this list who are interested in "Reproducible Research"  and
related issues:

http://www.nature.com/news/meeting-targets-lab-lapses-1.12987

Cheers,
Bert

-- 

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

[[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] Fw: Request for information

2013-05-15 Thread Bert Gunter
Outrageous!

http://www.r-project.org/





On Tue, May 14, 2013 at 11:53 PM, Ravishankar Kandallu <
ravishankar.kanda...@tcs.com> wrote:

> Dear Sir,
>
> Greetings.  I am Ravishankar from Platform Solutions function of Tata
> Consultancy Services, Mumbai India.  I am associated with team within
> Platform Solutions group that specializes in statistical modeling
> solutions to various clients.  We are exploring various statistical
> computing software tools for building statistical models and meet our
> client requirements.  In the process, we identified your R-programming
> environment as one of the possible means to serve the purpose.
> We submit our request for more details to you regarding the usage of R for
> commercial purposes. In this regard, we also solicit a discussion with you
> for our further perusal.  We earnestly look forward to your reply.
>
> Thanks & Regards,
>
> Ravishankar Kandallu
> Platform Solutions Analytics-Support
> Tata Consultancy Services Limited
> Gateway Park, Road No.13
> MIDC, Andheri (E)
> Mumbai - 400093,Maharashtra
> India
> Ph:- 912267795049
> Buzz:- 4295049
> Cell:- 9920935970
> Mailto: ravishankar.kanda...@tcs.com
> Website: http://www.tcs.com
> 
> Experience certainty.   IT Services
> Business Solutions
> Consulting
> 
> =-=-=
> Notice: The information contained in this e-mail
> message and/or attachments to it may contain
> confidential or privileged information. If you are
> not the intended recipient, any dissemination, use,
> review, distribution, printing or copying of the
> information contained in this e-mail message
> and/or attachments to it are strictly prohibited. If
> you have received this communication in error,
> please notify us by reply e-mail or telephone and
> immediately and permanently delete the message
> and any attachments. Thank you
>
>
>
> [[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

[[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] erreur dans R

2013-05-15 Thread Pascal Oettli

Hello,

You should write your email in English rather than French.

And you should provide a reproducible example.

Regards,
Pascal

On 05/15/2013 06:14 PM, raymond mélaine taha wrote:

Bonjour,
dans la computation de mon modèle dans R avec le package deSolve pour des 
Equations Différentielles Ordinaires (ODEs), je rencontre l'erreur suivant:
Erreur dans checkFunc(Func2, times, y, rho) :
   The number of derivatives returned by func() (1457) must equal the length of 
the initial conditions vector (17)

à quoi devrais-je regarder?
merci




---
TAHA Raymond
Vétérinaire Inspecteur

Auditeur
Master of Science en Santé Animale Tropicale
option: épidémiologie

2012 - 2013
Anvers - BELGIQUE

+32 4.933.941.37
skype: raymond2taha


 
---
[[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] Unexpected behavior using `merge' by multiple columns

2013-05-15 Thread Eric DeWitt
I recently started using `merge()' to combine data frames that contained
different conditioned subsets of the same master data frame. In some conditions
the `by' columns had `NA' values and I was using `incomparables=c(NA, NaN)' to
avoid including these rows in the resulting merge. However, the behavior never
appeared to match the documentation. I continued to received partial matching
on columns that included `NA's. I attempted to understand the expected behavior
by looking at the example from the documentation and it appears to me to have
the same problem. Am I misinterpreting the documentation or is the behavior
inconsistent? Below is a reproducible example from the `merge' documentation.
The modified version run at the end uses the fix suggested in the example.

Best,
Eric

### base::merge potentially unexpected behavior

# The `merge' argument `incomparables' does not appear to behave in the manner
# described in the documentation. Including `NA' in comparables does not prevent
# NA matching.

# example from the documentation:

## example of using `incomparables'
x <- data.frame(k1 = c(NA,NA,3,4,5), k2 = c(1,NA,NA,4,5), data = 1:5)
y <- data.frame(k1 = c(NA,2,NA,4,5), k2 = c(NA,NA,3,4,5), data = 1:5)
merge(x, y, by = c("k1","k2")) # NA's match
  k1 k2 data.x data.y
1  4  4  4  4
2  5  5  5  5
3 NA NA  2  1
merge(x, y, by = c("k1","k2"), incomparables = NA)
  k1 k2 data.x data.y
1  4  4  4  4
2  5  5  5  5
3 NA NA  2  1
merge(x, y, by = "k1") # NA's match, so 6 rows
  k1 k2.x data.x k2.y data.y
1  44  44  4
2  55  55  5
3 NA1  1   NA  1
4 NA1  13  3
5 NA   NA  2   NA  1
6 NA   NA  23  3
merge(x, y, by = "k2", incomparables = NA) # 2 rows
  k2 k1.x data.x k1.y data.y
1  44  44  4
2  55  55  5

# Observing that when merging on two columns the `incomparables' appears to have
# no effect, it appears that the problem is located in the creation of the
# common index into the two data frames. debugging merge reveals that the
# problem is in the construction via paste which converts `NA' to "NA":
#
# debug: bz <- do.call("paste", c(rbind(bx, by), sep = "\r"))
# Browse[2]bz
#   [1] "NA\r1" "NA\rNA" "3\rNA""4\r4"   "5\r5"  "NA\rNA" 
"2\rNA"   "NA\r3" 
#   [9] "4\r4"   "5\r5" 
# debug: bx <- bz[seq_len(nx)]
# debug: by <- bz[nx + seq_len(ny)]
# Browse[2]bx
# [1] "NA\r1"  "NA\rNA" "3\rNA"  "4\r4"   "5\r5"  
# Browse[2]by
# [1] "NA\rNA" "2\rNA"  "NA\r3"  "4\r4"   "5\r5"  
# 
# which produces "NA\rNA" matches
#
# debug: comm <- match(bx, by, 0L)
# Browse[2]comm
# [1] 0 1 0 4 5
# 
# Given that this appears to the be intended behavior of `paste', the solution
# appears to require that the elements in `incomparables' be removed from the
# rows after to the paste operation. The following is an example (perhaps
# inefficient) that would solve the problem:
# 
# bx <- x[, by.x, drop = FALSE]
# by <- y[, by.y, drop = FALSE]
# names(bx) <- names(by) <- paste0("V", seq_len(ncol(bx)))
# bz <- do.call("paste", c(rbind(bx, by), sep = "\r"))
# bx <- bz[seq_len(nx)]
# by <- bz[nx + seq_len(ny)]
# bx[apply(is.na(x),1,any)] <- NA
# by[apply(is.na(y),1,any)] <- NA
# comm <- match(bx, by, 0L, incomparables)
#
# The resulting patched merge produces:
source("merge.fixed.R")
merge.fixed(x, y, by = c("k1","k2")) # NA's match
   k1 k2 data.x data.y
1   4  4  4  4
2   5  5  5  5
3  NA  1  1  1
4  NA  1  1  2
5  NA  1  1  3
6  NA NA  2  1
7  NA NA  2  2
8  NA NA  2  3
9   3 NA  3  1
10  3 NA  3  2
11  3 NA  3  3
merge.fixed(x, y, by = c("k1","k2"), incomparables = NA)
  k1 k2 data.x data.y
1  4  4  4  4
2  5  5  5  5
merge.fixed(x, y, by = "k1") # NA's match, so 6 rows
  k1 k2.x data.x k2.y data.y
1  44  44  4
2  55  55  5
3 NA1  1   NA  1
4 NA1  13  3
5 NA   NA  2   NA  1
6 NA   NA  23  3
merge.fixed(x, y, by = "k2", incomparables = NA) # 2 rows
  k2 k1.x data.x k1.y data.y
1  44  44  4
2  55  55  5

# This appears to match the documented behavior.

# R version
version
   _   
platform   x86_64-apple-darwin10.8.0   
arch   x86_64  
os darwin10.8.0
system x86_64, darwin10.8.0
status 
major  3   
minor  0.0 
year   2013
month  04  
day03  
svn rev62481   
language   R   
version.string R version 3.0.0 (2013-04-03)
nickname   Masked Marvel   
sessionInfo()
R version 3.0.

[R] matrix - pairwise comparison of columns

2013-05-15 Thread Hermann Norpois
Hello,

I would like to do something with a matrix:
1) The columns should be compared pairwise.
2) And the result should be a matrix.

I try to illustrate the problem with a testset.

> m
 rs1 rs2 rs3
[1,]   1   1   1
[2,]   0   1   0
[3,]   2   0   1
> dput (m)
structure(c(1, 0, 2, 1, 1, 0, 1, 0, 1), .Dim = c(3L, 3L), .Dimnames = list(
NULL, c("rs1", "rs2", "rs3")))
> which (m[,1] !=0&m[,2] != 0) #How many rows between two columns that are
both non zero

How can I automate the pairwise which-statement?

As result I would like to have a matrix like this

 rs1 rs2 rs3
rs1
rs2  1
rs3  21

Is there a tool in R that helps?

Thanks
Hermann

[[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] R help: Batch read files based on names in a list

2013-05-15 Thread Jonathan Dry
*

I am currently reading in a series of files, applying the same functions to
them one at a time, and then merging the resulting data frames e.g.:

>MyRows <- c("RowA", "RowB", "RowC")>>File1_DF <- 
>read.delim("DirectoryToFiles\\File1_Folder\\File1.txt", 
>stringsAsFactors=FALSE, check.names=FALSE)>File1_DF <- 
>as.data.frame(t(File1_DF[MyRows,]))>File1_DF <- 
>as.data.frame(t(File1_DF))>mergeDF <- merge(mergeDF,File1_DF, by.x = 
>"Row.names", by.y="row.names")>>File2_DF <- 
>read.delim("DirectoryToFiles\\File2_Folder\\File2.txt", 
>stringsAsFactors=FALSE, check.names=FALSE)>File2_DF <- 
>as.data.frame(t(File2_DF[MyRows,]))>File2_DF <- 
>as.data.frame(t(File2_DF))>mergeDF <- merge(mergeDF,File2_DF, by.x = 
>"Row.names", by.y="row.names")

...etc

I want to know if I can use a list of the filenames c("File1", "File2",
"File2") etc. and apply a function to do this in a more automated fasion?
This would involve using the list value in the directory path to read in
the file i.e.

>*MyFilesValue*_DF <- 
>read.delim("DirectoryToFolders\\*MyFilesValue*_Folder\\*MyFilesValue*.txt",
> stringsAsFactors=FALSE, check.names=FALSE)

Any help appreciated
*

[[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] mosaic plot (vcd)

2013-05-15 Thread Vanessa Vetter

   Hello everyone,
   is there a way to increase the distance between the legend label of the
   Pearson residuals and the bar, which shows the color of the residuals, in
   the mosaic plot argument (see picture attached)? The minus signs of the
   negative scale unfortunately run into the bar. They are therefore difficult
   to read.
   I would also like to change both, the color of the residuals as well as the
   "data driven cut-off points for residuals". But so far I could not combine
   the two commands. Is this possible?
   # Colorized with HCL default colors and data driven cut-off points for
   residuals:
   ipol <- function (x) pmin (x / 4, 1)
   mosaic (~ herbivory treatment + + + altitude competition, data = erillm1,
   shade  =  TRUE,  legend  =  TRUE, gp_args = list (interpolate = ipol),
   labeling_args = list (abbreviate_labs = c (herbivory = TRUE)))
   #  Colorized with HCL but color matched and default cut-off points for
   residuals:
   I have now been several papaer to vcd package and strucplot read, but could
   find no information on this.

   Thank you very much for your help!
   greeting
   Vanessa Vetter
   (Diploma Environmental Sciences, University of Koblenz-Landau)
<>__
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] Build R package with libjpeg - Symbol not found: _jpeg_CreateCompress

2013-05-15 Thread DcInfSys1
Hello,

I am trying to build an /Image Processing Package/, which has in the src-
folder a jpeg.c file which uses the libjpeg for reading/writing jpeg files.
I think this causes an error if i try to check my package. 

After the execution of "R CMD INSTALL ImagePackage"
i get the ImagePackage.tar.gz file,
with this i try "R CMD CHECK ImagePackage.tar.gz", 
Then i get the following error:

checking installed package size ... OK
* checking package directory ... OK
* checking for portable file names ... OK
* checking for sufficient/correct file permissions ... OK
* checking DESCRIPTION meta-information ... OK
* checking top-level files ... OK
* checking index information ... OK
* checking package subdirectories ... OK
* checking R files for non-ASCII characters ... OK
* checking R files for syntax errors ... OK
* loading checks for arch ‘i386’
** checking whether the package can be loaded ... ERROR
Error in dyn.load(file, DLLpath = DLLpath, ...) : 
 can not load shared object ‘/Users/work/
ImagePackage.Rcheck/ImagePackage/libs/i386/ImagePackage.so’ :
 
dlopen(/Users/work/ImagePackage.Rcheck/ImagePackage/libs/i386/ImagePackage.so,
6): Symbol not found: _jpeg_CreateCompress
  Referenced from: /Users/work/
ImagePackage.Rcheck/ImagePackage/libs/i386/ImagePackage.so
  Expected in: flat namespace
 in /Users/work/ ImagePackage.Rcheck/ImagePackage/libs/i386/ImagePackage.so
Error while loading the package/namespace for 'ImagePackage'
Execution halted


In the src-folder, i have a *Makevars* where i put the path to the
jpeg-library:

PKG_CPPFLAGS = -I/opt/local/include
PKG_LIBS = -L/opt/local/lib -ljpeg -lpng

#PKG_CPPFLAGS = -I/usr/include
#PKG_LIBS = -L/usr/lib64 -ljpeg -lpng

So i suppose that the linker knows where he can find the jpeg-library. 

My *namespace-file* has the content:
exportPattern("^[[:alpha:]]+")
S3method(print,picturemap)
useDynLib(ImagePackage)

The *beginning of my c-file * is:
#include 
#include 
#include 
#include 

So i tried to compile directly my jpeg.c file with R CMD SHLIB, and this is
working. So i am confused why he can not find the jpeg_createCompress
function. 

Can anybody help? :-)




--
View this message in context: 
http://r.789695.n4.nabble.com/Build-R-package-with-libjpeg-Symbol-not-found-jpeg-CreateCompress-tp4667129.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] Using Phyper

2013-05-15 Thread arun
Hi Shanthi,
May be this link helps you 
(http://stats.stackexchange.com/questions/10328/using-rs-phyper-to-get-the-probability-of-list-overlap).

A.K.






From: Shanthi Mulinti 
To: arun  
Sent: Wednesday, May 15, 2013 10:25 AM
Subject: Re: Displaying median value over the horizontal(median)line in the 
boxplot



Arun,
  I am very sorry for bothering you but I wanted to ask you if you have 
any suggestions on using and interpreting Phyper output.
  I am working with expression data from two different 
treatments(two gene lists) and would like to know if the overlap of 
genes between the gene lists is by chance or is it significant. Based on
literature search it says use hypergeometric distribution - Phyper in 
R. 
Here is my data 
Total number of genes 26062 
Gene list 1 - 1000 
Gene list 2 - 1000 
Overlap between two lists - 233 
Now this is what I did 
phyper(233, 1000, 26062, 1000, lower.tail = FALSE, log.p = FALSE) 
[1] 2.539644e-123 
and got the answer. 
Can please some tell me how to interpret the output and also if I am doing it 
right, 
So with that output how can I say that the overlap between two geen lists is by 
chance or if it is significant. 

Thank you very much in advance. I am still in the learning curve and would 
appreciate any help.


Thank you 
Shanthi 




On Thu, Mar 21, 2013 at 4:19 PM, arun  wrote:

Hi,
>set.seed(45)
>test1<-data.frame(columnA=rnorm(7,45),columnB=rnorm(7,10)) #used an example 
>probably similar to your actual data
>apply(test1,2,function(x) sprintf("%.1f",median(x)))
>#columnA columnB
># "44.5"  "10.2"
>par(mfrow=c(1,2))
>lapply(test1,function(x) {b<- 
>boxplot(x,range=0,horizontal=TRUE);mtext(sprintf("%.1f",b$stats[3]),side=3,at=b$stats[3],line=-8)})
>A.K.
>
>
>
>- Original Message -
>From: "shanthimuli...@gmail.com" 
>To: smartpink...@yahoo.com
>Cc:
>Sent: Thursday, March 21, 2013 4:05 PM
>Subject: Re: Displaying median value over the horizontal(median)line in the 
>boxplot
>
>Here is what I am doing
>my=read.csv("test.csv")
>apply(my,2,median,na.rm=TRUE)
>b<-boxplot(my,range=0, pars=list(boxwex=0.6))
>After this I am not sure how to automatically list the median in each of the 
>two boxplots
>
>test.csv has
>columnA  columnB
>1                 1       
>2                  2
>3                  3
>4                 4
>5                 5
>6                6
>7                7
>
>Finally how do I control the output. My actual data has a median value of 
>7.642552 but I only want it to be displayed as 7.6.
>
>Thank you so much for your help. I am very sorry for troubling you but I am 
>very very new to this programming and to R as you can see.
>
>
>
>
>Hi,
>Lines1<-readLines(textConnection("Column1 -1,2,3,4,5,6,6,7
>COlumn2- 3,4,5,6,7,8,8
>Column3-- 45,66,7,8,89,
>COlumn4-5,6,7,7,8,9
>Column5 -5,6,7,8,8"))
>vec1<-unlist(strsplit(Lines1,"-"))
>
>dat1<-as.data.frame(t(read.table(text=vec1[grepl(",",vec1)],sep=",",fill=TRUE)))
>row.names(dat1)<-NULL
>colnames(dat1)<-tolower(gsub(" $","",vec1[grepl("^C",vec1)]))
>dat1
>#  column1 column2 column3 column4 column5
>#1       1       3      45       5       5
>#2       2       4      66       6       6
>#3       3       5       7       7       7
>#4       4       6       8       7       8
>#5       5       7      89       8       8
>#6       6       8      NA       9      NA
>#7       6       8      NA      NA      NA
>#8       7      NA      NA      NA      NA
>apply(dat1,2,median,na.rm=TRUE)
>#column1 column2 column3 column4 column5
>#    4.5     6.0    45.0     7.0     7.0
>
>#to save it as a pdf
>pdf("Shanthiboxplot.pdf")
>par(mfrow=c(3,2))
>lapply(dat1,function(x)
>{b<-boxplot(x,range=0,horizontal=TRUE);mtext(b$stats[3],side=3,at=b$stats[3],line=-8)})
>dev.off()
>
>#to just print it on screen
>par(mfrow=c(3,2))# you can change this according to your need
>lapply(dat1,function(x)
>{b<-boxplot(x,range=0,horizontal=TRUE);mtext(b$stats[3],side=3,at=b$stats[3],line=-8)})
>A.K.
>
>Quoted from:
>http://r.789695.n4.nabble.com/Displaying-median-value-over-the-horizontal-median-line-in-the-boxplot-tp4661854p4661935.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/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Help me please: gplot, facets_wrap and ordering of x axis dates

2013-05-15 Thread David Lyon
Thank you very much for your help and time.

That works very nicelyThanks again!



- Original Message -
From: John Kane 
To: David Lyon ; r-help 
Cc: 
Sent: Wednesday, May 15, 2013 9:36 AM
Subject: Re: [R] Help me please: gplot, facets_wrap and ordering of x axis
  dates

My appologies, I was in a rush yesterday and a) completely misread the post  
and b) did not scroll down far enough.  David W is correct that you need to do 
something with the data set. <.6 is not a number. 

Also, as David says,  it  sounds like your coversion using as.Date did not work 
out.  The difficulty from here is that if is graphs then it sounds like your 
actual data.frame is not exactly the same as what I get if I try to read in the 
data you included. hat is why supplying the data using something like dput() is 
important.

I don't see how got something to plot.  However if I get rid of the < in the 
text file and read in the data , etc I get something that may look like what 
you want.  See code below.  I renamed the data.frame to dat1, just because it 
was handy and renamed the variable date to date1 since date is a reserved word 
in R . Type date() to see what I mean.

Again my applogies for completely misreading the problem
John Kane
Kingston ON Canada
#
library(lubridate)
library(ggplot2)
  
dat1  <-   structure(list(id = c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 4L, 
4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 
6L, 6L, 6L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 
10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 
12L, 12L, 13L, 13L, 13L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 
14L, 14L, 14L, 14L, 14L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 16L, 
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 17L, 17L, 18L, 18L, 18L, 
18L, 18L), date1 = c("8/16/10", "10/25/10", "11/8/10", "11/22/10", 
"12/6/10", "8/18/10", "10/25/10", "11/8/10", "11/22/10", "8/20/10", 
"10/25/10", "11/8/10", "11/22/10", "12/6/10", "10/26/11", "6/4/09", 
"6/18/10", "8/25/10", "9/15/10", "10/25/10", "11/8/10", "11/22/10", 
"12/6/10", "11/4/11", "9/23/10", "10/25/10", "11/8/10", "11/22/10", 
"12/6/10", "8/25/10", "10/25/10", "11/8/10", "12/6/10", "6/11/12", 
"10/6/10", "11/22/10", "2/2/11", "2/16/11", "3/2/11", "3/16/11", 
"9/14/10", "2/2/11", "2/16/11", "3/2/11", "3/16/11", "8/20/10", 
"2/2/11", "2/16/11", "3/2/11", "3/16/11", "10/26/11", "12/14/10", 
"2/2/11", "2/16/11", "3/2/11", "3/16/11", "11/13/09", "8/19/10", 
"2/2/11", "2/6/13", "4/24/13", "8/18/10", "10/5/10", "10/27/10", 
"2/2/11", "2/16/11", "3/2/11", "3/16/11", "6/29/11", "8/15/11", 
"8/15/12", "10/31/12", "12/10/10", "2/2/11", "3/2/11", "3/16/11", 
"12/17/10", "1/25/11", "2/2/11", "2/2/11", "2/16/11", "3/2/11", 
"3/16/11", "3/20/12", "3/26/12", "3/30/12", "4/2/12", "4/23/12", 
"11/17/11", "12/9/11", "2/25/13", "3/11/13", "3/25/13", "4/10/13", 
"4/22/13"), value = c(0.16, 0.16, 0.42, 0.81, 0.16, 2.93, 2.4, 
1.36, 1.22, 0.77, 0.85, 1.22, 0.21, 1.81, 0.54, 1.33, 1.32, 2.5, 
1.3, 1.1, 0.66, 0.84, 7.42, 1.21, 0.97, 2.25, 0.51, 0.53, 0.41, 
3.14, 3.58, 2.41, 2.08, 3.2, 0.24, 0.34, 0.58, 0.54, 0.25, 0.39, 
0.28, 0.19, 0.42, 0.39, 0.26, 0.16, 0.16, 0.16, 0.16, 1.76, 0.16, 
0.48, 1.2, 0.44, 0.32, 0.34, 0.73, 3.32, 13.7, 1.35, 0.85, 0.66, 
0.68, 0.53, 0.54, 0.49, 0.31, 0.4, 0.53, 0.55, 0.94, 0.74, 0.4, 
0.44, 0.38, 0.43, 0.18, 0.16, 0.53, 0.54, 0.46, 0.29, 0.2, 0.18, 
0.23, 0.52, 0.33, 0.3, 3.35, 2.56, 18.1, 14.9, 11.1, 8.47, 15.9
)), .Names = c("id", "date1", "value"), class = "data.frame", row.names = c(NA, 
-95L))
  
str(dat1)
dat1$date1  <-  mdy(dat1$date1) # using lubridate 
str(dat1) #  POSIXct object not date object as in your original code

ggplot(data=dat1) + geom_line(aes(x=date1, y=value, group=id, colour=
factor(id))) + facet_wrap(~id, scales = "free")
#

> -Original Message-
> From: david_ly...@yahoo.com
> Sent: Wed, 15 May 2013 05:49:18 -0700 (PDT)
> To: jrkrid...@inbox.com, r-help@r-project.org
> Subject: Re: [R] Help me please: gplot, facets_wrap and ordering of x
> axis dates
> 
> Thanks John for your reply.
> I did include the data if you scroll down to the end of my original
> email.
> 
> Can someone help me on this?
> 
> Thanks
> 
> 
> 
> 
> - Original Message -
> From: John Kane 
> To: David Lyon ; r-help 
> Cc:
> Sent: Tuesday, May 14, 2013 4:11 PM
> Subject: RE: [R] Help me please: gplot, facets_wrap and ordering of x
> axis
>   dates
> 
> Thank you for supplying the code. It would be easier to help you  if we
> also had some data to work with.  ?dput
> 
> https://github.com/hadley/devtools/wiki/Reproducibility
> 
> I think reorder() is likely to do the trick but I don't have enough time
> to mock up some data and check at the moment.
> 
> Have a look at
> http://stackoverflow.com/questions/3744178/ggplot2-sorting-a-plot
> 
> Good luck.
> John Kane
> Kingston ON Canada
> 
> 
>> -Original Message-
>> From: david_ly

Re: [R] NMDS using Vegan

2013-05-15 Thread Suparna Mitra
Dear Prof. Simpson,
Thanks a lot for your reply. Yes I know that I can change the labels
any time, but I was only worried if I am doing any mistake as default
output didn't match with the output shown in the Vegan tutorial
output.
Thanks,
Mitra


On 15 May 2013 22:43, Gavin Simpson  wrote:
> On Wed, 2013-05-15 at 12:06 +0800, Suparna Mitra wrote:
>> Hello R experts,
>>   I am new to Vegan and use trying to follow the tutorial to perform NMDS
>> for my data. But after performing the metaMDS, when I plotted my results
>> the default plot shows MDS1 vs MDS2. Thought according to the
>> tutorial Default ordination plot should display NMDS1vs NMDS2. Why is this
>> difference? Accourding to tutorial it says: Function metaMDS
>> is a wrapper to perform NMDS.
>> Can anybody please help me to understand this?
>> Thanks,
>> Mitra
>
> They are just labels and metaMDS **has** performed an NMDS. Not sure why
> Jari labelled these as "MDSx". If this bothers you so, add your own
> labels:
>
> require("vegan")
> data(dune)
> sol <- metaMDS(dune)
> plot(sol, xlab = "NMDS1", ylab = "NMDS2")
>
> HTH
>
> G
>
> --
> Gavin Simpson, PhD  [t] +1 306 337 8863
> Adjunct Professor, Department of Biology[f] +1 306 337 2410
> Institute of Environmental Change & Society [e] gavin.simp...@uregina.ca
> 523 Research and Innovation Centre  [tw] @ucfagls
> University of Regina
> Regina, SK S4S 0A2, Canada
>
>
>

__
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] Fw: Request for information

2013-05-15 Thread Ravishankar Kandallu
Dear Sir,

Greetings.  I am Ravishankar from Platform Solutions function of Tata 
Consultancy Services, Mumbai India.  I am associated with team within 
Platform Solutions group that specializes in statistical modeling 
solutions to various clients.  We are exploring various statistical 
computing software tools for building statistical models and meet our 
client requirements.  In the process, we identified your R-programming 
environment as one of the possible means to serve the purpose. 
We submit our request for more details to you regarding the usage of R for 
commercial purposes. In this regard, we also solicit a discussion with you 
for our further perusal.  We earnestly look forward to your reply.

Thanks & Regards,

Ravishankar Kandallu
Platform Solutions Analytics-Support
Tata Consultancy Services Limited
Gateway Park, Road No.13
MIDC, Andheri (E)
Mumbai - 400093,Maharashtra
India
Ph:- 912267795049
Buzz:- 4295049
Cell:- 9920935970
Mailto: ravishankar.kanda...@tcs.com
Website: http://www.tcs.com

Experience certainty.   IT Services
Business Solutions
Consulting

=-=-=
Notice: The information contained in this e-mail
message and/or attachments to it may contain 
confidential or privileged information. If you are 
not the intended recipient, any dissemination, use, 
review, distribution, printing or copying of the 
information contained in this e-mail message 
and/or attachments to it are strictly prohibited. If 
you have received this communication in error, 
please notify us by reply e-mail or telephone and 
immediately and permanently delete the message 
and any attachments. Thank you



[[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] New quotation

2013-05-15 Thread dvr
Hello my friend,  We produce CCTV camera, IP Cameras, DVR and HVR with high 
quality&very competitive price located in China.  Hope to find a way to 
cooperate with you. Visit us at www.sunivision.com
E-catalogues will be sent if needed. 
Write me back or call me pls, let's talk more in details.  Best Regards ­   
BellaKindly tell you that we will attend the Fair in April and May 2013 as 
below:  

1, April 12nd-15th, 2013, China Sourcing Fair (HK) 2012 Booth No.: 2L37D   
Add: AsiaWorld-Expo, Hongkong, China.
   
2, April  10th-12nd, 2013, ISC West  2013  ,Booth No.: 35031  Add:Sands 
Expo Center,Las Vegas, Nevada,USA 3, April  15th-18th,  2013   MIPS(Moscow) 
2013, Booth No.:B630  Add: All-Russian Exhibition Centre£¨VVC), Moscow, Russia  
   4, May 14th-16th,  2013   EXPOSEG  (BR)2013,  Booth No.:237  Add: Exhibition 
Centre Immigrants, Sao Paulo, Brazil 5, May 13rd-16th,  2013   IFSEC(UK) 
2013, Booth No.: 5/K60C   Add: National Exhibition Centre (NEC), Birmingham, UK
 

   Welcome you to visit our booth and let's show you our latest products. 
Sunivision Technology Development Co., ltd Contact Details:
ADD: Floor 3, Building B, Taoyuan Industrial Park, Huangpu East Development 
Zone, Guangzhou, China Email & MSN: sunivisi...@sunivision.com , 
Skype:Sunivision4
Tel: +86-20-28217659 exit 813 Fax: +86-20-28217656 exit 803   Mobile: 
+86-13650956184  
Website: www.sunivision.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] erreur dans R

2013-05-15 Thread raymond mélaine taha
Bonjour,
dans la computation de mon modèle dans R avec le package deSolve pour des 
Equations Différentielles Ordinaires (ODEs), je rencontre l'erreur suivant:
Erreur dans checkFunc(Func2, times, y, rho) : 
  The number of derivatives returned by func() (1457) must equal the length of 
the initial conditions vector (17)

à quoi devrais-je regarder?
merci

 


---
TAHA Raymond
Vétérinaire Inspecteur

Auditeur
Master of Science en Santé Animale Tropicale
option: épidémiologie

2012 - 2013
Anvers - BELGIQUE

+32 4.933.941.37
skype: raymond2taha


    
---
[[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] date and time coding question

2013-05-15 Thread Jeff Newmiller
The difference of two POSIXct values is of type difftime. You should not think 
of difftime as having units. Rather, you should think of the result of 
converting from difftime to numeric (using as.numeric) as the opportunity (or 
rather requirement) to specify what time units you want.  If you let R print 
the difftime object unconverted, it will print with whatever units seem 
appropriate given the magnitude of the difftime.
---
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.

"MacQueen, Don"  wrote:

>I think you probably want
>   format='%m/%d/%y %H:%M')
>(lower case "y")
>
>diff() as suggested by Jeff Newmiller is good, except that I don't know
>how to control the units using diff().
>
>## so a method that allows specifying units other than hours would be,
>for
>example, 
>
>datetime <-c("1/1/13 00:00","1/1/13 12:00","1/2/13 00:00","1/2/13
>12:00")
>datetime <-as.POSIXct(datetime,format='%m/%d/%y %H:%M')deltas <-
>difftime(
>datetime[-1], datetime[-length(datetime)] , units='min')
>
>-Don

__
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] x and y lengths differ

2013-05-15 Thread MacQueen, Don
This example illustrates your problem:

> plot(1:3,1:3)
> plot(1:3,1:4)
Error in xy.coords(x, y, xlabel, ylabel, log) :
  'x' and 'y' lengths differ

Now all you have to do is figure out which of your plot() commands gives
the error, and check the values you are giving to it to find out which
have different lengths.

Please also read the posting guide.

-Don


-- 
Don MacQueen

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





On 5/15/13 11:06 AM, "catalin roibu"  wrote:

>I have a problem with R. I try to compute the confidence interval for my
>df. When I want to create the plot I have this problem: Error in
>xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ.
>I try this code:
>library(dplR)
>df.rwi <- detrend(rwl = df, method = "Spline",nyrs=NULL)
>write.table(df.rwi,file="rwi.txt",quote=FALSE,row.names=TRUE)
>
>df.crn <- chron(df.rwi, prefix = "RGE",prewhiten = TRUE)
>write.table(df.crn,file="crn.txt",quote=FALSE,row.names=TRUE)
>##confidence interval
>library(boot)
>ci.func <- function(y) {
>  y <- y[!is.na(y)]
>  mean.fun <- function(y,i)
>  {
>m <- mean(y[i])
>n <- length(i)
>v <- (n-1)*var(y[i])/n^2
>c(m,v)
>  }
>  y.boot <- boot (y, mean.fun, R=1000)
>  y.ci=boot.ci (y.boot, conf=0.99, type = 'basic')
>  y.ci=y.ci$basic[c(4,5)]
>  names(y.ci)=c('lower','upper')
>  y.ci
>}
>df.trunc<-subset(df.crn,samp.depth>5)
>df.rwi.trunc <- subset(df.rwi, df.crn$samp.depth > 5)
>df.ci <- data.frame(t(apply(df.rwi.trunc,1,ci.func)))
>base<-cbind(df.trunc,df.ci)
>
>op=par(no.readonly=TRUE) # save par to reset
>par(mar=c(3,2,2,3)+0.1,mgp=c(1.25,0.25,0),tcl=0.25,tck=0.0125)
>yr.vec=as.numeric(rownames(df.trunc))
>samp.depth=df.trunc[,2]
>crn2=df.trunc[,-2]
>
>plot(yr.vec,crn2,type='n',xlab='Years',ylab='RWT',
> main='Gemenele')
>axis(1,at=seq(1900,2012,by=4))
>polygon(c(yr.vec,rev(yr.vec)), c(df.ci$lower,rev(df.ci#upper)),
>  
>col='grey80',border=NA)
> lines(yr.vec,crn2,col='black')
> abline(h=1)
> par(new=TRUE)
>
> plot(yr.vec,samp.depth,type='1',col='black',xlab='',ylab='',axes=FALSE,
>  lty=2)
> axis(4,at=pretty(samp.depth))
> mtext('Sample Depth',side=4,line=1.25)
> legend("topleft", c('Chronology', '99%
>CI', 'Samples'),
>
>col=c('black','grey50','black'),lwd=rep(2,3))
>
>My data is like this:
>structure(list(RGE01 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA,
>NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1.47, 3.11,
>2.87, 2.69, 1.98, 2.22, 1.93, 1, 0.61, 0.57, 0.55, 1, 1.41, 0.98,
>2.32, 1.86, 1.81, 1.48, 2.18, 2.29, 2.31, 2.28, 1.72, 1.8, 1.71,
>1.59, 1.11, 1.24, 1.1, 1.83, 0.43, 0.98, 0.71, 1.09, 0.79, 1.11,
>0.55, 0.44, 0.36, 0.5, 0.5, 0.51, 0.48, 0.42, 0.44, 0.44), RGE02 = c(NA,
>NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>1.97, 0.94, 1.95, 1.95, 1.92, 1.14, 1.84, 1.45, 1.63, 1.81, 1.24,
>1.29, 1.31, 1.41, 1.2, 2.04, 2.23, 2.44, 2.11, 2.24, 0.93, 1.89,
>1.93, 1.58, 2.36, 2.07, 1.79, 1.4, 1.05, 2.14, 2.14, 2.65, 3.47,
>2.93, 1.52), RGE03 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1.62,
>0.83, 0.81, 0.84, 0.83, 1.06, 0.13, 0.72, 0.98, 0.54, 0.8, 0.6,
>0.44, 0.59, 0.78, 0.62, 0.7, 0.98, 0.68, 0.58, 0.5, 0.45, 0.37,
>0.26, 0.44, 0.6, 0.48, 0.55, 0.88, 0.4, 0.4, 0.45, 0.46, 0.52,
>0.46, 0.36, 0.43, 0.36, 0.29, 0.36, 0.64, 0.49, 0.92, 0.9, 0.54,
>0.7, 0.84, 0.52, 0.81, 0.95, 0.8, 0.64, 0.84, 0.6, 0.78, 0.76,
>0.88, 0.74, 0.9), RGE04 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA,
>NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>NA, NA, NA, NA, NA, NA, NA, NA, NA, 2.29, 2.4, 1.74, 1.56, 2.06,
>1.11, 1.63, 1.83, 1.41, 1.37, 1.34, 1.18, 0.92, 1.64, 1.21, 1.5,
>1.12, 0.7, 1.05, 1.19, 1.17, 0.68, 0.62, 0.97, 0.71, 0.73, 0.92,
>0.64, 0.48, 0.45, 0.96, 0.84, 0.97, 0.33, 0.26, 0.31, 0.6, 0.71,
>0.5, 0.46, 0.24, 0.26, 0.65, 0.85, 0.9, 0.27, 0.3, 0.86, 0.82,
>0.6), RGE05 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
>NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 2.36,
>2.65, 1.78, 1.29, 1.08, 1.9, 2.33, 1.72, 1.45, 0.32, 1.42, 1.06,
>1.46, 1.61, 1.24, 1.56, 1.58, 1.66, 1.49, 0.55, 1.58, 1.96, 1.26,
>0.82, 0.92, 0.84, 0.72, 0.72, 0.68, 0.98, 0.5, 0.84, 0.4, 0.3,
>1.22, 0.74, 0.97, 

Re: [R] R update problem

2013-05-15 Thread Emre Sahin
On Wed, May 15, 2013 at 10:42:07AM -0700, carol white wrote:
> yes, and here is the output
> Executing: gpg --ignore-time-conflict --no-options --no-default-keyring
> --secret-keyring /tmp/tmp.DhD6e2Q3Xb --trustdb-name /etc/apt/trustdb.gpg
> --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg
> --keyserver keyserver.ubuntu.com --recv-keys E084DAB9
> gpg: requesting key E084DAB9 from hkp server keyserver.ubuntu.com
> gpg: key E084DAB9: public key "Michael Rutter " imported
> gpg: Total number processed: 1
> gpg:   imported: 1  (RSA: 1)
> 

Now you can 

$ sudo apt-get update 

and install. The error was meant to warn you about package
signatures. You could ignore and go on but this way it's better. 

BTW, I'd recommend 

sudo aptitude 

to use apt. 

Best. E.

__
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] date and time coding question

2013-05-15 Thread MacQueen, Don
I think you probably want
   format='%m/%d/%y %H:%M')
(lower case "y")

diff() as suggested by Jeff Newmiller is good, except that I don't know
how to control the units using diff().

## so a method that allows specifying units other than hours would be, for
example, 

datetime <-c("1/1/13 00:00","1/1/13 12:00","1/2/13 00:00","1/2/13 12:00")
datetime <-as.POSIXct(datetime,format='%m/%d/%y %H:%M')deltas <- difftime(
datetime[-1], datetime[-length(datetime)] , units='min')

-Don


-- 
Don MacQueen

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





On 5/10/13 10:24 AM, "Andras Farkas"  wrote:

>Dear All
> 
>I have the following code:
> 
>datetime <-c("1/1/13 00:00","1/1/13 12:00","1/2/13 00:00","1/2/13 12:00")
>datetime <-as.POSIXct(datetime,format='%m/%d/%Y %H:%M')
>times 
><-matrix(c(difftime(datetime[2],datetime[1],units="hours"),difftime(dateti
>me[3],datetime[2],units="hours"),difftime(datetime[4],datetime[3],units="h
>ours")))
>
>I would like to aks for some directions on how to make the 'times' object
>code a bit more "uniform" to accept differenth lenths of 'datetime'...
>Occasionally I have the 'datetime' object include up to 15 date and time
>points, but that code limits the system from accepting a longer
>'datetime' object. This is what that looks like (basically same as above,
>but much longer): 
> 
>datetime <-c("1/1/13 00:00","1/1/13 12:00","1/2/13 00:00","1/2/13 12:00")
>datetime <-as.POSIXct(datetime,format='%m/%d/%Y %H:%M')
>times 
><-matrix(c(difftime(datetime[2],datetime[1],units="hours"),difftime(dateti
>me[3],datetime[2],units="hours"),difftime(datetime[4],datetime[3],units="h
>ours"),difftime(datetime[5],datetime[4],units="hours"),difftime(datetime[6
>],datetime[5],units="hours"),difftime(datetime[7],datetime[6],units="hours
>"),difftime(datetime[8],datetime[7],units="hours"),difftime(datetime[9],da
>tetime[8],units="hours"),difftime(datetime[10],datetime[9],units="hours"),
>difftime(datetime[11],datetime[10],units="hours"),difftime(datetime[12],da
>tetime[11],units="hours"),difftime(datetime[13],datetime[12],units="hours"
>),difftime(datetime[14],datetime[13],units="hours"),difftime(datetime[15],
>datetime[14],units="hours"),difftime(datetime[16],datetime[15],units="hour
>s")))
>
>appreciate the help,
> 
>Andras
>   [[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] Problem with convergence in optim

2013-05-15 Thread Luis Felipe Parra
Thanks Rui, i already tried changin the reltol, but it didn't change the
outcome


On Wed, May 15, 2013 at 1:32 PM, Rui Barradas  wrote:

> Hello,
>
> It's impossible to tell what is happening without the function and the
> values for the other variables (including the initial parameters) but your
> setting of reltol is too small. Try using the default. It's
> sqrt(.Machine$double.eps), about 1e-8, you are using 1e-16.
>
> Hope this helps,
>
> Rui Barradas
>
> Em 15-05-2013 17:02, Luis Felipe Parra escreveu:
>
>> Hello to all,
>>
>> I have been using an optim with the following call:
>>
>> optim(param_ini,fun_errores2,**Precio_mercado=Precio,anos_**
>> pagosE2=anos_pagos,control=**list(maxit=1,reltol=1e-16)**)
>>
>> depending on the intial values I'm getting the same solution but once I
>> get
>> the convergence message=10 (no convergence) and  for the others I get
>> convergence message = 0
>>
>> Solution1:
>> $par
>> beta1   beta2  beta3 lambda
>> beta1 0.06537061 0.001474821 -0.07592360.5
>>
>> $e2
>> [1] 74.84273
>>
>> $conv
>> [1] 0
>>
>> $v
>> [1] 74.84273
>>
>> Solution2:
>> $par
>> beta1   beta2  beta3 lambda
>> 1 0.06537061 0.001474822 -0.07592360.5
>>
>> $e2
>> [1] 74.84273
>>
>> $conv
>> [1] 10
>>
>> $v
>> [1] 74.84273
>>
>> My intuition tells me the correct solution is no convergence. Does anybody
>> know why this might be happening.
>>
>> Thank you
>>
>> Felipe Parra
>>
>> [[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.
>>
>>


-- 

Este mensaje de correo electrónico es enviado por Quantil S.A.S y puede
contener información confidencial o privilegiada.

This e-mail is sent by Quantil S.A.S and may contain confidential or
privileged information

[[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] Problem with convergence in optim

2013-05-15 Thread Rui Barradas

Hello,

It's impossible to tell what is happening without the function and the 
values for the other variables (including the initial parameters) but 
your setting of reltol is too small. Try using the default. It's 
sqrt(.Machine$double.eps), about 1e-8, you are using 1e-16.


Hope this helps,

Rui Barradas

Em 15-05-2013 17:02, Luis Felipe Parra escreveu:

Hello to all,

I have been using an optim with the following call:

optim(param_ini,fun_errores2,Precio_mercado=Precio,anos_pagosE2=anos_pagos,control=list(maxit=1,reltol=1e-16))

depending on the intial values I'm getting the same solution but once I get
the convergence message=10 (no convergence) and  for the others I get
convergence message = 0

Solution1:
$par
beta1   beta2  beta3 lambda
beta1 0.06537061 0.001474821 -0.07592360.5

$e2
[1] 74.84273

$conv
[1] 0

$v
[1] 74.84273

Solution2:
$par
beta1   beta2  beta3 lambda
1 0.06537061 0.001474822 -0.07592360.5

$e2
[1] 74.84273

$conv
[1] 10

$v
[1] 74.84273

My intuition tells me the correct solution is no convergence. Does anybody
know why this might be happening.

Thank you

Felipe Parra

[[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] animating plots over time with a slider

2013-05-15 Thread Gavin Rudge
I have a population of subjects each with a variable which has been captured at 
a baseline date.  Then for many subjects (but not all) an intervention has 
occurred and the variable has changed at one or more time points after the 
baseline date.  So my dataset consists of a subject ID (x), which may appear 
several times or just once, a measure (y), and a date of observation (z).  I 
would like to be able to have some sort of animated plot with a slider 
representing time so I can show how the distribution of the variable has 
altered (say in a histogram or a box plot) from baseline up to the end of a 
period. I need each subject only to be counted once in this distribution using 
the measure recorded up to or including the current data on the slider.

I have created a synthetic data set using the code below which kind of 
replicates the problem for a just a few data points over a couple of months.  
My real data set has about 30,000 subjects with multiple measures captured over 
10 years. What I need for each date point is a summary chart such as a 
histogram,  which shows me the distribution of my variable (in this case y) 
with just one observation per subject, that observation being the most up to 
date at the point at which the slider.

I have tried to use the manipulate package, which I've used successfully for 
other simple applications, but hit two problems - firstly it doesn't like dates 
as a slider variable. I can work around this by making them numeric, but would 
like to work with dates if possible.  Secondly I don't know how to restrict 
observations to the date on the slider - eg. Subject 100 has a baseline of 
45.26, but on or after 26th April it becomes 56.96. So where the slider is set 
beyond this date I would want the earlier value for this subject to be excluded 
from the distribution.   I'm not sure that manipulate was really made for this 
problem and perhaps I should be looking elsewhere.

I guess a solution involves using the aggregate command to get the unique 
values at various time points and then using something like the TeachingDemos 
package?   Not sure I'm on the right path with this though and as an R beginner 
I can't get to first base with this.  I can't figure how to use aggregate to 
give me the value of y corresponding to the latest date z.  I know this is 
basic stuff but I really can't see how to do it.

My synthetic data can be generated like this (clunky I know, but I can't do 
this any slicker)

#make my baseline observations for 100 subjects on 1st April 2013
set.seed(1)
a<-data.frame(x=seq(1:100),y=rnorm(100,mean=50,sd=10),z=as.Date("2013-04-01"))
#simulate 50 subsequent observations in the next 2 months resulting in some 
subjects having different future measurements of y
Start <- as.Date("2013-04-02")
End <- as.Date("2013-06-30")
dates <- seq(from = Start, to = End, by = 1)
set.seed(1)
b<-data.frame(x=sample(0:100,50,replace=TRUE),y=rnorm(50,mean=50,sd=10),z=sample(dates,50,replace=FALSE))
#make one table of observations
c<-merge(a,b,all=TRUE)

Any suggestions much appreciated.

Gavin.



[[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] x and y lengths differ

2013-05-15 Thread catalin roibu
I have a problem with R. I try to compute the confidence interval for my
df. When I want to create the plot I have this problem: Error in
xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ.
I try this code:
library(dplR)
df.rwi <- detrend(rwl = df, method = "Spline",nyrs=NULL)
write.table(df.rwi,file="rwi.txt",quote=FALSE,row.names=TRUE)

df.crn <- chron(df.rwi, prefix = "RGE",prewhiten = TRUE)
write.table(df.crn,file="crn.txt",quote=FALSE,row.names=TRUE)
##confidence interval
library(boot)
ci.func <- function(y) {
  y <- y[!is.na(y)]
  mean.fun <- function(y,i)
  {
m <- mean(y[i])
n <- length(i)
v <- (n-1)*var(y[i])/n^2
c(m,v)
  }
  y.boot <- boot (y, mean.fun, R=1000)
  y.ci=boot.ci (y.boot, conf=0.99, type = 'basic')
  y.ci=y.ci$basic[c(4,5)]
  names(y.ci)=c('lower','upper')
  y.ci
}
df.trunc<-subset(df.crn,samp.depth>5)
df.rwi.trunc <- subset(df.rwi, df.crn$samp.depth > 5)
df.ci <- data.frame(t(apply(df.rwi.trunc,1,ci.func)))
base<-cbind(df.trunc,df.ci)

op=par(no.readonly=TRUE) # save par to reset
par(mar=c(3,2,2,3)+0.1,mgp=c(1.25,0.25,0),tcl=0.25,tck=0.0125)
yr.vec=as.numeric(rownames(df.trunc))
samp.depth=df.trunc[,2]
crn2=df.trunc[,-2]

plot(yr.vec,crn2,type='n',xlab='Years',ylab='RWT',
 main='Gemenele')
axis(1,at=seq(1900,2012,by=4))
polygon(c(yr.vec,rev(yr.vec)), c(df.ci$lower,rev(df.ci#upper)),
col='grey80',border=NA)
 lines(yr.vec,crn2,col='black')
 abline(h=1)
 par(new=TRUE)

 plot(yr.vec,samp.depth,type='1',col='black',xlab='',ylab='',axes=FALSE,
  lty=2)
 axis(4,at=pretty(samp.depth))
 mtext('Sample Depth',side=4,line=1.25)
 legend("topleft", c('Chronology', '99%
CI', 'Samples'),

col=c('black','grey50','black'),lwd=rep(2,3))

My data is like this:
structure(list(RGE01 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1.47, 3.11,
2.87, 2.69, 1.98, 2.22, 1.93, 1, 0.61, 0.57, 0.55, 1, 1.41, 0.98,
2.32, 1.86, 1.81, 1.48, 2.18, 2.29, 2.31, 2.28, 1.72, 1.8, 1.71,
1.59, 1.11, 1.24, 1.1, 1.83, 0.43, 0.98, 0.71, 1.09, 0.79, 1.11,
0.55, 0.44, 0.36, 0.5, 0.5, 0.51, 0.48, 0.42, 0.44, 0.44), RGE02 = c(NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
1.97, 0.94, 1.95, 1.95, 1.92, 1.14, 1.84, 1.45, 1.63, 1.81, 1.24,
1.29, 1.31, 1.41, 1.2, 2.04, 2.23, 2.44, 2.11, 2.24, 0.93, 1.89,
1.93, 1.58, 2.36, 2.07, 1.79, 1.4, 1.05, 2.14, 2.14, 2.65, 3.47,
2.93, 1.52), RGE03 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1.62,
0.83, 0.81, 0.84, 0.83, 1.06, 0.13, 0.72, 0.98, 0.54, 0.8, 0.6,
0.44, 0.59, 0.78, 0.62, 0.7, 0.98, 0.68, 0.58, 0.5, 0.45, 0.37,
0.26, 0.44, 0.6, 0.48, 0.55, 0.88, 0.4, 0.4, 0.45, 0.46, 0.52,
0.46, 0.36, 0.43, 0.36, 0.29, 0.36, 0.64, 0.49, 0.92, 0.9, 0.54,
0.7, 0.84, 0.52, 0.81, 0.95, 0.8, 0.64, 0.84, 0.6, 0.78, 0.76,
0.88, 0.74, 0.9), RGE04 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, 2.29, 2.4, 1.74, 1.56, 2.06,
1.11, 1.63, 1.83, 1.41, 1.37, 1.34, 1.18, 0.92, 1.64, 1.21, 1.5,
1.12, 0.7, 1.05, 1.19, 1.17, 0.68, 0.62, 0.97, 0.71, 0.73, 0.92,
0.64, 0.48, 0.45, 0.96, 0.84, 0.97, 0.33, 0.26, 0.31, 0.6, 0.71,
0.5, 0.46, 0.24, 0.26, 0.65, 0.85, 0.9, 0.27, 0.3, 0.86, 0.82,
0.6), RGE05 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 2.36,
2.65, 1.78, 1.29, 1.08, 1.9, 2.33, 1.72, 1.45, 0.32, 1.42, 1.06,
1.46, 1.61, 1.24, 1.56, 1.58, 1.66, 1.49, 0.55, 1.58, 1.96, 1.26,
0.82, 0.92, 0.84, 0.72, 0.72, 0.68, 0.98, 0.5, 0.84, 0.4, 0.3,
1.22, 0.74, 0.97, 0.52, 0.88, 0.63, 0.58, 0.56, 0.62, 0.47, 0.46,
0.72, 1.2, 1.01, 0.88, 0.87, 1.58, 0.82, 0.67, 1.27, 0.96, 0.54,
0.48, 1.14), RGE06 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, 2.37, 2.32, 1.39, 1.2, 0.97, 1.01, 0.83, 0.86, 0.74,
0.65, 1.04, 0.79, 0.52, 0.54, 0.57, 0.45, 0.44, 0.42, 0.47, 0.75,
0.86, 0.61, 0.79, 0.73, 0.53, 0.61, 0.55, 0.63, 0.7, 0.62, 0.64,
0.64, 0.58, 0.5, 0.46, 0.65, 0.76, 0.44, 0.81, 0.88, 0.48, 0.38,
0.4, 0.57, 0.39, 0.45, 0.41, 0.44, 0.6, 0.37, 0.2, 0.23, 0.49,
0.31, 0.24, 0.38, 0.37, 0.4, 0.48, 0.46, 0.39, 0.26, 0.4, 0.38,
0.52, 0.51, 0.78, 0.68, 0.52,

Re: [R] R update problem

2013-05-15 Thread carol white
yes, and here is the output


Executing: gpg --ignore-time-conflict --no-options --no-default-keyring 
--secret-keyring /tmp/tmp.DhD6e2Q3Xb --trustdb-name /etc/apt/trustdb.gpg 
--keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg 
--keyserver keyserver.ubuntu.com --recv-keys E084DAB9
gpg: requesting key E084DAB9 from hkp server keyserver.ubuntu.com
gpg: key E084DAB9: public key "Michael Rutter " imported
gpg: Total number processed: 1
gpg:   imported: 1  (RSA: 1)




 From: Emre Sahin 

Cc: "r-h...@stat.math.ethz.ch"  
Sent: Wednesday, May 15, 2013 5:35 PM
Subject: Re: [R] R update problem


On Wed, May 15, 2013 at 07:59:32AM -0700, carol white wrote:
> Hi,
> I try to update R on Ubuntu
> 
> I added deb http://cran.cnr.Berkeley.edu/bin/linux/ubuntu precise/ in 
> /etc/apt/sources.list but any mirror site that I take, I get the following 
> error msg:
> 
> W: GPG error: http://cran.cnr.Berkeley.edu precise/ Release: The following 
> signatures couldn't be verified because the public key is not available: 
> NO_PUBKEY 51716619E084DAB9
> 

Hi, 

In a terminal, could you type

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9

HTH. 

E. 
[[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] Problem with convergence in optim

2013-05-15 Thread Luis Felipe Parra
Hello to all,

I have been using an optim with the following call:

optim(param_ini,fun_errores2,Precio_mercado=Precio,anos_pagosE2=anos_pagos,control=list(maxit=1,reltol=1e-16))

depending on the intial values I'm getting the same solution but once I get
the convergence message=10 (no convergence) and  for the others I get
convergence message = 0

Solution1:
$par
   beta1   beta2  beta3 lambda
beta1 0.06537061 0.001474821 -0.07592360.5

$e2
[1] 74.84273

$conv
[1] 0

$v
[1] 74.84273

Solution2:
$par
   beta1   beta2  beta3 lambda
1 0.06537061 0.001474822 -0.07592360.5

$e2
[1] 74.84273

$conv
[1] 10

$v
[1] 74.84273

My intuition tells me the correct solution is no convergence. Does anybody
know why this might be happening.

Thank you

Felipe Parra

[[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] stack object layer names not visible

2013-05-15 Thread Fabio Berzaghi
I use to be able to see the layer names of a RasterStack by just typing 
its name but now I only get this


class   : RasterStack
dimensions  : 70, 180, 12600  (nrow, ncol, ncell)
resolution  : 0.5, 0.5  (x, y)
extent  : -80, 10, 50, 85  (xmin, xmax, ymin, ymax)
coord. ref. : NA

If I do plot(s) then I can see all the layers and their names.

Why is this happening?

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


Re: [R] R update problem

2013-05-15 Thread Emre Sahin
On Wed, May 15, 2013 at 07:59:32AM -0700, carol white wrote:
> Hi,
> I try to update R on Ubuntu
> 
> I added deb http://cran.cnr.Berkeley.edu/bin/linux/ubuntu precise/ in 
> /etc/apt/sources.list but any mirror site that I take, I get the following 
> error msg:
> 
> W: GPG error: http://cran.cnr.Berkeley.edu precise/ Release: The following 
> signatures couldn't be verified because the public key is not available: 
> NO_PUBKEY 51716619E084DAB9
> 

Hi, 

In a terminal, could you type

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9

HTH. 

E.

__
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 show a dataset in 3d?

2013-05-15 Thread Chris Campbell
# Hi Maggy
# Try the rgl package

con <- textConnection("  
  Subject  Time1  Time2  Time3  
 1  0.385  0.103 -0.488  
 2 -1.939  0.569  1.370  
 3 -1.196 -0.051  1.247  
 4  0.174 -1.163  0.989  
 5  1.246  0.558 -1.804  
 6 -1.108 -0.057  1.165  
 7 -0.609 -0.344  0.953  
")  
  
dat1 <- read.table(con, header = TRUE)  
  
require(rgl)  
cols <- rainbow(n = length(dat1$Subject))  
plot3d(dat1[, 2:4], col = cols)  
  

Chris Campbell
Tel. +44 (0) 1249 705 450 | Mobile. +44 (0) 7929 628349
mailto:ccampb...@mango-solutions.com | http://www.mango-solutions.com
Mango Solutions
2 Methuen Park, Chippenham, Wiltshire , SN14 OGB UK

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of maggy yan
Sent: 15 May 2013 15:34
To: R-help@r-project.org
Subject: [R] how to show a dataset in 3d?

my dataset looks like this in the beginning:

  Subject  Time1  Time2  Time3
1 1  0.385  0.103 -0.488
2 2 -1.939  0.569  1.370
3 3 -1.196 -0.051  1.247
4 4  0.174 -1.163  0.989
5 5  1.246  0.558 -1.804
6 6 -1.108 -0.057  1.165
7 7 -0.609 -0.344  0.953

so each subject has three observations. now I need to show the dataset in 3d 
with scatterplot3d and plot3d together, that's what I don't know how it works.

I tried:
scatterplot3d(data, type="p", highlight.3d=T, pch=16)

the graph looks like 3D but is not reall 3D, I mean I can't e.g. rotate it.
but how can combine both functions?

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

--

LEGAL NOTICE\ \ This message is intended for the use of ...{{dropped:18}}

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


[R] R update problem

2013-05-15 Thread carol white
Hi,
I try to update R on Ubuntu

I added deb http://cran.cnr.Berkeley.edu/bin/linux/ubuntu precise/ in 
/etc/apt/sources.list but any mirror site that I take, I get the following 
error msg:

W: GPG error: http://cran.cnr.Berkeley.edu precise/ Release: The following 
signatures couldn't be verified because the public key is not available: 
NO_PUBKEY 51716619E084DAB9


What is the solution?

Thanks

Carol

[[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] Vegan package treatment of zeros

2013-05-15 Thread Gavin Simpson
On Wed, 2013-05-15 at 09:04 -0500, Michael Rentz wrote:
> Hello:  I have a good size database of plant cover measurements I was
> running a Shannon Diversity on.  I have every cell as a default of "0" if
> it is not present.  The tutorials I have looked at all had blanks in cases
> of absence.  I just wanted some kind of verification that VEGAN will
> recognize 0s as absent
> 
> I just wanted to make sure I was not inadvertently setting myself up for
> problems.

Blanks would be interpreted as `NA` in R when you read the data in.
Vegan would respect that and most likely fail because of the missing
data as not all methods are appropriate when there are `NA` values.

Hence a common first step is to replace `NA` with 0. As you have already
have this indicated in your file external to R then you won;t need to do
this extra step *in* R.

How zeros are then treated will depend largely on the method employed
and/or the dissimilarity coefficient used, but that is not an R
question. A recent posting to the R-Sig-Ecology list by Brian Cade
presents some interesting observations on the double zero issue:

https://stat.ethz.ch/pipermail/r-sig-ecology/attachments/20130419/114d1e5f/attachment.pl

HTH

G

-- 
Gavin Simpson, PhD  [t] +1 306 337 8863
Adjunct Professor, Department of Biology[f] +1 306 337 2410
Institute of Environmental Change & Society [e] gavin.simp...@uregina.ca
523 Research and Innovation Centre  [tw] @ucfagls
University of Regina
Regina, SK S4S 0A2, Canada

__
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] NMDS using Vegan

2013-05-15 Thread Gavin Simpson
On Wed, 2013-05-15 at 12:06 +0800, Suparna Mitra wrote:
> Hello R experts,
>   I am new to Vegan and use trying to follow the tutorial to perform NMDS
> for my data. But after performing the metaMDS, when I plotted my results
> the default plot shows MDS1 vs MDS2. Thought according to the
> tutorial Default ordination plot should display NMDS1vs NMDS2. Why is this
> difference? Accourding to tutorial it says: Function metaMDS
> is a wrapper to perform NMDS.
> Can anybody please help me to understand this?
> Thanks,
> Mitra

They are just labels and metaMDS **has** performed an NMDS. Not sure why
Jari labelled these as "MDSx". If this bothers you so, add your own
labels:

require("vegan")
data(dune)
sol <- metaMDS(dune)
plot(sol, xlab = "NMDS1", ylab = "NMDS2")

HTH

G

-- 
Gavin Simpson, PhD  [t] +1 306 337 8863
Adjunct Professor, Department of Biology[f] +1 306 337 2410
Institute of Environmental Change & Society [e] gavin.simp...@uregina.ca
523 Research and Innovation Centre  [tw] @ucfagls
University of Regina
Regina, SK S4S 0A2, Canada

__
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 show a dataset in 3d?

2013-05-15 Thread maggy yan
my dataset looks like this in the beginning:

  Subject  Time1  Time2  Time3
1 1  0.385  0.103 -0.488
2 2 -1.939  0.569  1.370
3 3 -1.196 -0.051  1.247
4 4  0.174 -1.163  0.989
5 5  1.246  0.558 -1.804
6 6 -1.108 -0.057  1.165
7 7 -0.609 -0.344  0.953

so each subject has three observations. now I need to show the dataset in
3d with scatterplot3d and plot3d together, that's what I don't know how it
works.

I tried:
scatterplot3d(data, type="p", highlight.3d=T, pch=16)

the graph looks like 3D but is not reall 3D, I mean I can't e.g. rotate it.
but how can combine both functions?

[[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 package treatment of zeros

2013-05-15 Thread Michael Rentz
Hello:  I have a good size database of plant cover measurements I was
running a Shannon Diversity on.  I have every cell as a default of "0" if
it is not present.  The tutorials I have looked at all had blanks in cases
of absence.  I just wanted some kind of verification that VEGAN will
recognize 0s as absent

I just wanted to make sure I was not inadvertently setting myself up for
problems.

Mike.

PS: I am set up to just receive the daily digest, if you do not mind
replying to both me and the list (or just me if the question is that dumb)
I would be appreciative.

-- 
Michael Rentz
PhD Candidate, University of Minnesota, Conservation Biology
Fixed-Term professor: St. Cloud State University
5122 Idlewild Street
Duluth, MN 55804
218 525 3299 (h)

[[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] K Fold CrossValidation

2013-05-15 Thread Kevin Hao
Maybe the following code is helpful for you.  At the same time, you can
check the 
ChemometricsWithR
package
from http://cran.r-project.org/web/packages/available_packages_by_date.html.

# product crossvalidation index
crossvalind <- function(N, kfold) {
len.seg <- ceiling(N/kfold)
incomplete <- kfold*len.seg - N
complete <- kfold - incomplete
ind <- matrix(c(sample(1:N), rep(NA, incomplete)), nrow = len.seg, byrow =
TRUE)
cvi <- lapply(as.data.frame(ind), function(x) c(na.omit(x))) # a list
return(cvi)
}

N <- length(y)
kfold <- 10
cvi <- crossvalind(N, kfold)
for (i in 1:length(cvi)) {
idx.tr <- unlist(cvi[-i])
idx.te <- unlist(cvi[i])
xc <- x[idx.tr, ]
yc <- y[idx.tr]
xt <- x[idx.te, ]
yt <- y[idx.te]
lm.mod <- lm(yc ~ xc)
yt.pred <- predict(lm.mod, xt)
mse[i] <- sum((yt - yt.pred)^2)/length(yt)
}

plot(mse)

You can pick it out which is the minimu mse.

Best,

Kevin


On Wed, May 15, 2013 at 5:51 AM, Preetam Pal  wrote:

> Hi all,
> I want to run the following Cross-validation technique on my data set:
>
>
> Variables: X, Y (each having 50 observations)
> I want to run a least-squares regression of Y on X.
> I need to divide the entire data set into 10 groups of size 5 each, keep
> one of them out as 'test' set and build the model on the basis of the
> remaining 9 groups (the 'training set').Then i calculate the MSE of the
> fitted model by applying it on the 'test set'.
>
> So, for each choice of the 'test set', I get a MSE value.
> I select that model as final which corresponds to the minimum of these 10
> MSE values.
>
> How do i get the coefficients for this model.
>
> I am a beginner in R and the help page on CROSSVAL appeared a bit confusing
> to me.
>
> Thanks for any help.
> Regards,
> Preetam
>
> --
> Preetam Pal
> (+91)-9432212774
> M-Stat 2nd Year, Room No. N-114
> Statistics Division,   C.V.Raman
> Hall
> Indian Statistical Institute, B.H.O.S.
> Kolkata.
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


Re: [R] Help me please: gplot, facets_wrap and ordering of x axis dates

2013-05-15 Thread David Lyon
Thanks John for your reply.
I did include the data if you scroll down to the end of my original email.

Can someone help me on this? 

Thanks




- Original Message -
From: John Kane 
To: David Lyon ; r-help 
Cc: 
Sent: Tuesday, May 14, 2013 4:11 PM
Subject: RE: [R] Help me please: gplot, facets_wrap and ordering of x axis
  dates

Thank you for supplying the code. It would be easier to help you  if we also 
had some data to work with.  ?dput

https://github.com/hadley/devtools/wiki/Reproducibility

I think reorder() is likely to do the trick but I don't have enough time to 
mock up some data and check at the moment.

Have a look at  
http://stackoverflow.com/questions/3744178/ggplot2-sorting-a-plot

Good luck.
John Kane
Kingston ON Canada


> -Original Message-
> From: david_ly...@yahoo.com
> Sent: Tue, 14 May 2013 12:59:07 -0700 (PDT)
> To: r-help@r-project.org
> Subject: [R] Help me please: gplot, facets_wrap and ordering of x axis
> dates
> 
> I have a text file of data as below and doing a ggplot line plot of all
> the ids as separate mini line plots which works with the following code.
> 
> Problem how do I order the dates for each id plot on the x axis so that
> the dates are going from oldest to most recent
> 
> 
> Thanks in advance
> 
> Dave
> 
> 
> 
> 
> 
> CODE:
> 
> a<-read.table("DATA",header=TRUE);
> b<-a[order(as.Date(a$date, format="%m/%d/%Y")),]
> 
> ggplot(data=b) + geom_line(aes(x=date, y=value, group=id, colour=
> factor(id))) + facet_wrap(~id, scales = "free")
> 
> 
> 
> 
> 
> 
> DATA:
> 
> 
> id  date    value
> 001 8/16/10 <0.16
> 001 10/25/10    <0.16
> 001 11/8/10 0.42
> 001 11/22/10    0.81
> 001 12/6/10 <0.16
> 002 8/18/10 2.93
> 002 10/25/10    2.4
> 002 11/8/10 1.36
> 002 11/22/10    1.22
> 004 8/20/10 0.77
> 004 10/25/10    0.85
> 004 11/8/10 1.22
> 004 11/22/10    0.21
> 004 12/6/10 1.81
> 004 10/26/11    0.54
> 005 6/4/09  1.33
> 005 6/18/10 1.32
> 005 8/25/10 2.5
> 005 9/15/10 1.3
> 005 10/25/10    1.1
> 005 11/8/10 0.66
> 005 11/22/10    0.84
> 005 12/6/10 7.42
> 005 11/4/11 1.21
> 006 9/23/10 0.97
> 006 10/25/10    2.25
> 006 11/8/10 0.51
> 006 11/22/10    0.53
> 006 12/6/10 0.41
> 008 8/25/10 3.14
> 008 10/25/10    3.58
> 008 11/8/10 2.41
> 008 12/6/10 2.08
> 008 6/11/12 3.2
> 009 10/6/10 0.24
> 009 11/22/10    0.34
> 009 2/2/11  0.58
> 009 2/16/11 0.54
> 009 3/2/11  0.25
> 009 3/16/11 0.39
> 010 9/14/10 0.28
> 010 2/2/11  0.19
> 010 2/16/11 0.42
> 010 3/2/11  0.39
> 010 3/16/11 0.26
> 011 8/20/10 <0.16
> 011 2/2/11  <0.16
> 011 2/16/11 <0.16
> 011 3/2/11  <0.16
> 011 3/16/11 1.76
> 011 10/26/11    <0.16
> 012 12/14/10    0.48
> 012 2/2/11  1.2
> 012 2/16/11 0.44
> 012 3/2/11  0.32
> 012 3/16/11 0.34
> 013 11/13/09    0.73
> 013 8/19/10 3.32
> 013 2/2/11  13.7
> 014 2/6/13  1.35
> 014 4/24/13 0.85
> 014 8/18/10 0.66
> 014 10/5/10 0.68
> 014 10/27/10    0.53
> 014 2/2/11  0.54
> 014 2/16/11 0.49
> 014 3/2/11  0.31
> 014 3/16/11 0.4
> 014 6/29/11 0.53
> 014 8/15/11 0.55
> 014 8/15/12 0.94
> 014 10/31/12    0.74
> 015 12/10/10    0.4
> 015 2/2/11  0.44
> 015 3/2/11  0.38
> 015 3/16/11 0.43
> 016 12/17/10    0.18
> 016 1/25/11 <0.16
> 016 2/2/11  0.53
> 016 2/2/11  0.54
> 016 2/16/11 0.46
> 016 3/2/11  0.29
> 016 3/16/11 0.2
> 016 3/20/12 0.18
> 016 3/26/12 0.23
> 016 3/30/12 0.52
> 016 4/2/12  0.33
> 016 4/23/12 0.3
> 017 11/17/11    3.35
> 017 12/9/11 2.56
> 018 2/25/13 18.1
> 018 3/11/13 14.9
> 018 3/25/13 11.1
> 018 4/10/13 8.47
> 018 4/22/13 15.9
> 
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!
Check it out at http://www.inbox.com/earth

__
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] Empty clusters in k-means - possible solution

2013-05-15 Thread Simon Chamaillé

Hello all,

k-means algorithms can at times fail because one of the cluster become 
emmpty. In this case, the kmeans R function returns:

"empty cluster: try a better set of initial centers"

This has been discussed several times on several R-lists, and is NOT a 
bug, but can be annoying when using k-means in complex simulation where 
this error brings everything to a stop. One can use try() or tryCatch() 
to avoid this, but this is just a programming trick.


I was wondering if anyone knows about a R implementation of k-means that 
prevent this problem to happen. An very simple algorithm is proposed in 
(Pakhira, A Modified k-means Algorithm to Avoid Empty
Clusters; International Journal of Recent Trends in Engineering, Vol 1, 
No. 1, May 2009), in which the solution is simply to add the current 
cluster centers to the datapoints when computing new cluster centers at 
the next iteration. I could code that in pure R but that would be really 
slow, and I'm too dumb to modify the current internal implementation. If 
guys in R-dev think it is worth it, maybe this could be an option 
available in a future version of kmeans?


Any suggestion would be appreciated.

simon

__
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] K Fold CrossValidation

2013-05-15 Thread Kevin Hao
Below is the some code, may be helpful for you. [maybe have the finished
package which includes mlr with crossvaliation], you can check
http://cran.r-project.org/web/packages/available_packages_by_date.html.
 you can check this
"ChemometricsWithR"
package.

# product crossvalidation index
crossvalind <- function(N, kfold) {
len.seg <- ceiling(N/kfold)
incomplete <- kfold*len.seg - N
complete <- kfold - incomplete
ind <- matrix(c(sample(1:N), rep(NA, incomplete)), nrow = len.seg, byrow =
TRUE)
cvi <- lapply(as.data.frame(ind), function(x) c(na.omit(x))) # a list
return(cvi)
}

N <- length(y)
kfold <- 10
cvi <- crossvalind(N, kfold)
for (i in 1:length(cvi)) {
xc <- x[cvi[-i], ]# x in training set
yc <- y[cvi[-i]] # y in training set
xt <- x[cvi[i], ]# x in test set
yt <- y[cvi[i]] # y in test set
lm.mod <- lm(yc ~ xc)
yt.pred <- predict(lm.mod, xt)
mse[i] <- sum((yt - yt.pred)^2)/length(yt)
}

plot(mse)

you can see the minimum mse and point it out.

Maybe this is what you want.

Best,

Kevin



On Wed, May 15, 2013 at 5:51 AM, Preetam Pal  wrote:

> Hi all,
> I want to run the following Cross-validation technique on my data set:
>
>
> Variables: X, Y (each having 50 observations)
> I want to run a least-squares regression of Y on X.
> I need to divide the entire data set into 10 groups of size 5 each, keep
> one of them out as 'test' set and build the model on the basis of the
> remaining 9 groups (the 'training set').Then i calculate the MSE of the
> fitted model by applying it on the 'test set'.
>
> So, for each choice of the 'test set', I get a MSE value.
> I select that model as final which corresponds to the minimum of these 10
> MSE values.
>
> How do i get the coefficients for this model.
>
> I am a beginner in R and the help page on CROSSVAL appeared a bit confusing
> to me.
>
> Thanks for any help.
> Regards,
> Preetam
>
> --
> Preetam Pal
> (+91)-9432212774
> M-Stat 2nd Year, Room No. N-114
> Statistics Division,   C.V.Raman
> Hall
> Indian Statistical Institute, B.H.O.S.
> Kolkata.
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


Re: [R] Help me please: gplot, facets_wrap and ordering of x axis dates

2013-05-15 Thread John Kane
My appologies, I was in a rush yesterday and a) completely misread the post  
and b) did not scroll down far enough.  David W is correct that you need to do 
something with the data set. <.6 is not a number. 

Also, as David says,  it  sounds like your coversion using as.Date did not work 
out.  The difficulty from here is that if is graphs then it sounds like your 
actual data.frame is not exactly the same as what I get if I try to read in the 
data you included. hat is why supplying the data using something like dput() is 
important.

I don't see how got something to plot.  However if I get rid of the < in the 
text file and read in the data , etc I get something that may look like what 
you want.  See code below.  I renamed the data.frame to dat1, just because it 
was handy and renamed the variable date to date1 since date is a reserved word 
in R . Type date() to see what I mean.

Again my applogies for completely misreading the problem
John Kane
Kingston ON Canada
#
library(lubridate)
library(ggplot2)
  
 dat1  <-   structure(list(id = c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 4L, 
4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 
6L, 6L, 6L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 
10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 
12L, 12L, 13L, 13L, 13L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 
14L, 14L, 14L, 14L, 14L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 16L, 
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 17L, 17L, 18L, 18L, 18L, 
18L, 18L), date1 = c("8/16/10", "10/25/10", "11/8/10", "11/22/10", 
"12/6/10", "8/18/10", "10/25/10", "11/8/10", "11/22/10", "8/20/10", 
"10/25/10", "11/8/10", "11/22/10", "12/6/10", "10/26/11", "6/4/09", 
"6/18/10", "8/25/10", "9/15/10", "10/25/10", "11/8/10", "11/22/10", 
"12/6/10", "11/4/11", "9/23/10", "10/25/10", "11/8/10", "11/22/10", 
"12/6/10", "8/25/10", "10/25/10", "11/8/10", "12/6/10", "6/11/12", 
"10/6/10", "11/22/10", "2/2/11", "2/16/11", "3/2/11", "3/16/11", 
"9/14/10", "2/2/11", "2/16/11", "3/2/11", "3/16/11", "8/20/10", 
"2/2/11", "2/16/11", "3/2/11", "3/16/11", "10/26/11", "12/14/10", 
"2/2/11", "2/16/11", "3/2/11", "3/16/11", "11/13/09", "8/19/10", 
"2/2/11", "2/6/13", "4/24/13", "8/18/10", "10/5/10", "10/27/10", 
"2/2/11", "2/16/11", "3/2/11", "3/16/11", "6/29/11", "8/15/11", 
"8/15/12", "10/31/12", "12/10/10", "2/2/11", "3/2/11", "3/16/11", 
"12/17/10", "1/25/11", "2/2/11", "2/2/11", "2/16/11", "3/2/11", 
"3/16/11", "3/20/12", "3/26/12", "3/30/12", "4/2/12", "4/23/12", 
"11/17/11", "12/9/11", "2/25/13", "3/11/13", "3/25/13", "4/10/13", 
"4/22/13"), value = c(0.16, 0.16, 0.42, 0.81, 0.16, 2.93, 2.4, 
1.36, 1.22, 0.77, 0.85, 1.22, 0.21, 1.81, 0.54, 1.33, 1.32, 2.5, 
1.3, 1.1, 0.66, 0.84, 7.42, 1.21, 0.97, 2.25, 0.51, 0.53, 0.41, 
3.14, 3.58, 2.41, 2.08, 3.2, 0.24, 0.34, 0.58, 0.54, 0.25, 0.39, 
0.28, 0.19, 0.42, 0.39, 0.26, 0.16, 0.16, 0.16, 0.16, 1.76, 0.16, 
0.48, 1.2, 0.44, 0.32, 0.34, 0.73, 3.32, 13.7, 1.35, 0.85, 0.66, 
0.68, 0.53, 0.54, 0.49, 0.31, 0.4, 0.53, 0.55, 0.94, 0.74, 0.4, 
0.44, 0.38, 0.43, 0.18, 0.16, 0.53, 0.54, 0.46, 0.29, 0.2, 0.18, 
0.23, 0.52, 0.33, 0.3, 3.35, 2.56, 18.1, 14.9, 11.1, 8.47, 15.9
)), .Names = c("id", "date1", "value"), class = "data.frame", row.names = c(NA, 
-95L))
  
str(dat1)
dat1$date1  <-  mdy(dat1$date1) # using lubridate 
str(dat1) #  POSIXct object not date object as in your original code

 ggplot(data=dat1) + geom_line(aes(x=date1, y=value, group=id, colour=
 factor(id))) + facet_wrap(~id, scales = "free")
#

> -Original Message-
> From: david_ly...@yahoo.com
> Sent: Wed, 15 May 2013 05:49:18 -0700 (PDT)
> To: jrkrid...@inbox.com, r-help@r-project.org
> Subject: Re: [R] Help me please: gplot, facets_wrap and ordering of x
> axis dates
> 
> Thanks John for your reply.
> I did include the data if you scroll down to the end of my original
> email.
> 
> Can someone help me on this?
> 
> Thanks
> 
> 
> 
> 
> - Original Message -
> From: John Kane 
> To: David Lyon ; r-help 
> Cc:
> Sent: Tuesday, May 14, 2013 4:11 PM
> Subject: RE: [R] Help me please: gplot, facets_wrap and ordering of x
> axis
>   dates
> 
> Thank you for supplying the code. It would be easier to help you  if we
> also had some data to work with.  ?dput
> 
> https://github.com/hadley/devtools/wiki/Reproducibility
> 
> I think reorder() is likely to do the trick but I don't have enough time
> to mock up some data and check at the moment.
> 
> Have a look at
> http://stackoverflow.com/questions/3744178/ggplot2-sorting-a-plot
> 
> Good luck.
> John Kane
> Kingston ON Canada
> 
> 
>> -Original Message-
>> From: david_ly...@yahoo.com
>> Sent: Tue, 14 May 2013 12:59:07 -0700 (PDT)
>> To: r-help@r-project.org
>> Subject: [R] Help me please: gplot, facets_wrap and ordering of x axis
>> dates
>> 
>> I have a text file of data as below and doing a ggplot line plot of all
>> the ids as separate mini line

Re: [R] Error in colMeans with multiple column data.frame

2013-05-15 Thread arun
Hi,
#dput()
dat1<- 

structure(list(a1 = c(432L, 0L, 1295L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 432L, 0L, 432L, 0L, 0L, 0L, 0L, 432L, 0L, 432L, 0L, 0L, 0L, 
0L, 0L, 864L, 0L, 432L, 432L, 1296L, 0L, 432L, 0L, 0L, 432L, 
0L, 863L, 432L, 0L, 432L, 432L, 0L, 432L, 0L, 0L, 432L, 864L, 
0L, 432L, 0L, 432L, 0L, 0L, 432L, 0L, 432L, 0L, 0L, 0L, 0L, 432L, 
0L, 432L, 0L, 0L, 0L, 432L, 2159L, 432L, 864L, 863L, 432L, 2160L, 
3456L, 432L, 0L, 863L, 2159L, 0L, 864L, 1727L, 1728L, 5616L, 
4318L), a2 = c(355L, 184L, 2L, 100L, 170L, 170L, 723L, 184L, 
539L, 341L, 403L, 218L, 67L, 0L, 67L, 0L, 605L, 1L, 204L, 1221L, 
0L, 170L, 184L, 170L, 67L, 356L, 0L, 67L, 355L, 513L, 369L, 402L, 
184L, 170L, 34L, 355L, 526L, 374L, 355L, 271L, 67L, 639L, 185L, 
388L, 756L, 67L, 205L, 170L, 34L, 100L, 526L, 170L, 606L, 67L, 
184L, 696L, 0L, 170L, 0L, 184L, 34L, 0L, 403L, 0L, 341L, 0L, 
355L, 1214L, 1901L, 1567L, 1382L, 1282L, 1811L, 394L, 843L, 828L, 
743L, 581L, 979L, 783L, 2210L, 2427L, 3623L, 2887L), a3 = c(159L, 
157L, 0L, 572L, 95L, 2L, 380L, 111L, 223L, 4L, 412L, 395L, 428L, 
47L, 382L, 47L, 698L, 0L, 193L, 371L, 0L, 49L, 111L, 142L, 428L, 
112L, 47L, 475L, 112L, 52L, 221L, 412L, 111L, 2L, 285L, 159L, 
114L, 194L, 159L, 714L, 428L, 795L, 204L, 303L, 571L, 522L, 286L, 
95L, 284L, 666L, 114L, 142L, 698L, 428L, 111L, 303L, 0L, 2L, 
0L, 157L, 191L, 94L, 506L, 0L, 50L, 0L, 253L, 1302L, 1679L, 1368L, 
1398L, 779L, 2099L, 444L, 1034L, 1066L, 509L, 480L, 799L, 626L, 
1680L, 3859L, 3227L, 2478L), a4 = c(9304L, 9182L, 8861L, 9102L, 
8421L, 8963L, 8483L, 8206L, 8670L, 8044L, 6938L, 7661L, 7176L, 
7508L, 6978L, 8537L, 8651L, 8114L, 8904L, 8997L, 8454L, 8232L, 
9251L, 8227L, 8147L, 8570L, 8285L, 8326L, 8379L, 8041L, 8253L, 
8840L, 9085L, 8381L, 8744L, 8564L, 8479L, 8130L, 7785L, 9065L, 
8621L, 8294L, 9243L, 8938L, 9574L, 8733L, 7760L, 8089L, 8132L, 
7704L, 7414L, 8039L, 8443L, 9334L, 8313L, 8280L, 8578L, 7820L, 
7738L, 8867L, 7664L, 8368L, 8601L, 9330L, 8782L, 7676L, 7033L, 
8068L, 8230L, 8813L, 8329L, 8162L, 8465L, 8263L, 8195L, 7338L, 
8134L, 7325L, 7999L, 8337L, 7633L, 8248L, 7566L, 7520L), a5 = c(9949L, 
10120L, 10410L, 9836L, 9044L, 9261L, 8923L, 9373L, 8714L, 7977L, 
7755L, 7898L, 7957L, 8160L, 7811L, 8486L, 9421L, 8923L, 9324L, 
9681L, 8838L, 8994L, 10790L, 9616L, 8359L, 8578L, 8859L, 8915L, 
9061L, 9023L, 9262L, 8704L, 9718L, 9335L, 8999L, 9387L, 10050L, 
7840L, 8728L, 9168L, 9906L, 8697L, 9206L, 9789L, 9090L, 8931L, 
8340L, 8597L, 8702L, 8686L, 8370L, 8385L, 9366L, 9000L, 8312L, 
8597L, 9124L, 9355L, 7975L, 8843L, 8629L, 9230L, 9095L, 8670L, 
8562L, 8191L, 8274L, 8903L, 9152L, 8729L, 9207L, 8644L, 7745L, 
8833L, 8508L, 7591L, 8734L, 8426L, 8233L, 9256L, 8735L, 8895L, 
8268L, 8146L), interval = c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 
2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 
5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 
7L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 
10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 
12L, 12L, 12L, 13L, 13L, 13L, 13L, 13L, 13L, 14L, 14L, 14L, 14L, 
14L, 14L)), .Names = c("a1", "a2", "a3", "a4", "a5", "interval"
), class = "data.frame", row.names = c(NA, -84L))

library(plyr)
 res1<-ddply(dat1,.(interval),colMeans)
 res2<-ddply(dat1,.(interval),numcolwise(mean))
head(res1)
#    a1   a2   a3   a4   a5 interval
#1 287.8333 163.5000 164.1667 8972.167 9770.000    1
#2  72. 401. 254.1667 8000.333 8440.000    2
#3 144. 123. 267. 7827.333 8459.667    3
#4  72. 324.8333 144. 8677.500 9540.500    4
#5 504. 226. 204. 8291.333 8799.167    5
#6 144. 252. 198. 8644.500 9234.167    6

identical(res2,cbind(interval=as.integer(res1[,6]),res1[,-6]))
#[1] TRUE
res3<- aggregate(. ~ interval, data = dat1, mean)
 identical(res2,res3)
#[1] TRUE
A.K.



- Original Message -
From: Simonas Kecorius 
To: r-help@r-project.org
Cc: 
Sent: Wednesday, May 15, 2013 5:46 AM
Subject: [R] Error in colMeans with multiple column data.frame

Dear R users,

Here is my data:

"a1"    "a2"    "a3"    "a4"    "a5"    "interval"
432    355    159    9304    9949    1
0    184    157    9182    10120    1
1295    2    0    8861    10410    1
0    100    572    9102    9836    1
0    170    95    8421    9044    1
0    170    2    8963    9261    1
0    723    380    8483    8923    2
0    184    111    8206    9373    2
0    539    223    8670    8714    2
0    341    4    8044    7977    2
432    403    412    6938    7755    2
0    218    395    7661    7898    2
432    67    428    7176    7957    3
0    0    47    7508    8160    3
0    67    382    6978    7811    3
0    0    47    8537    8486    3
0    605    698    8651    9421    3
432    1    0    8114    8923    3
0    204    193    8904    9324    4
432    1221    371    8997    9681    4
0    0    0    8454    8838    4
0    170    49    8232    8994    4
0    184    111    9251    10790    4
0    170    142    8227    961

Re: [R] data manipulation

2013-05-15 Thread Jim Lemon

On 05/15/2013 04:15 PM, catalin roibu wrote:

Hello all!
I have a problem with my data.
My initial data is a list years and months (see below). I want to transpose
my data (12 rows (months) and year values as column). I try t(spi3), but
the year values do not appear as column names, but as values. Please help
me to solve this problem!


Hi catalin,
Try this:

spi4<-data.frame(t(spi3[,-1]))
names(spi4)<-spi3$year

Jim

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


Re: [R] Error in colMeans with multiple column data.frame

2013-05-15 Thread Simonas Kecorius
Thank you for your help. Appreciate it a lot! I am using appropriate names,
just here as an example I used data :)





2013/5/15 Rui Barradas 

> Hello,
>
> Try the following.
>
> aggregate(. ~ interval, data = data, mean)
>
>
> Also, 'data' is an R function, you should use some other name, such as
> 'dat'.
>
> Hope this helps,
>
> Rui Barradas
>
> Em 15-05-2013 10:46, Simonas Kecorius escreveu:
>
>  Dear R users,
>>
>> Here is my data:
>>
>> "a1""a2""a3""a4""a5""interval"
>> 432355159930499491
>> 01841579182101201
>> 1295208861104101
>> 0100572910298361
>> 017095842190441
>> 01702896392611
>> 0723380848389232
>> 0184111820693732
>> 0539223867087142
>> 03414804479772
>> 432403412693877552
>> 0218395766178982
>> 43267428717679573
>> 0047750881603
>> 067382697878113
>> 0047853784863
>> 0605698865194213
>> 43210811489233
>> 0204193890493244
>> 4321221371899796814
>> 000845488384
>> 017049823289944
>> 01841119251107904
>> 0170142822796164
>> 067428814783595
>> 864356112857085785
>> 0047828588595
>> 43267475832689155
>> 432355112837990615
>> 129651352804190235
>> 0369221825392626
>> 432402412884087046
>> 0184111908597186
>> 01702838193356
>> 43234285874489996
>> 0355159856493876
>> 8635261148479100507
>> 432374194813078407
>> 0355159778587287
>> 432271714906591687
>> 43267428862199067
>> 0639795829486977
>> 432185204924392068
>> 0388303893897898
>> 0756571957490908
>> 43267522873389318
>> 864205286776083408
>> 017095808985978
>> 43234284813287029
>> 0100666770486869
>> 432526114741483709
>> 0170142803983859
>> 0606698844393669
>> 43267428933490009
>> 01841118313831210
>> 4326963038280859710
>> 0008578912410
>> 017027820935510
>> 0007738797510
>> 01841578867884310
>> 432341917664862911
>> 00948368923011
>> 4324035068601909511
>> 0009330867011
>> 0341508782856211
>> 0007676819111
>> 4323552537033827412
>> 2159121413028068890312
>> 432190116798230915212
>> 864156713688813872912
>> 863138213988329920712
>> 43212827798162864412
>> 2160181120998465774513
>> 34563944448263883313
>> 43284310348195850813
>> 082810667338759113
>> 8637435098134873413
>> 21595814807325842613
>> 09797997999823314
>> 8647836268337925614
>> 1727221016807633873514
>> 1728242738598248889514
>> 5616362332277566826814
>> 4318288724787520814614
>>
>> I read it from a file:
>>
>> data<-read.table("data.txt", head=T, sep="\t")
>>
>> When I try count column mean by interval:
>>
>> newData <- do.call(rbind, tapply(data[1:5], data$interval, colMeans))
>>
>>
>> I get an error: Error in tapply(data[1:5], data$interval, colMeans) :
>>arguments must have same length
>>
>> Has anyone any clue what is wrong?
>> Thank you in advance.
>>
>>


-- 
Simonas Kecorius
**

[[alternative HTML version deleted]]

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


Re: [R] Error in colMeans with multiple column data.frame

2013-05-15 Thread Rui Barradas

Hello,

Try the following.

aggregate(. ~ interval, data = data, mean)


Also, 'data' is an R function, you should use some other name, such as 
'dat'.


Hope this helps,

Rui Barradas

Em 15-05-2013 10:46, Simonas Kecorius escreveu:

Dear R users,

Here is my data:

"a1""a2""a3""a4""a5""interval"
432355159930499491
01841579182101201
1295208861104101
0100572910298361
017095842190441
01702896392611
0723380848389232
0184111820693732
0539223867087142
03414804479772
432403412693877552
0218395766178982
43267428717679573
0047750881603
067382697878113
0047853784863
0605698865194213
43210811489233
0204193890493244
4321221371899796814
000845488384
017049823289944
01841119251107904
0170142822796164
067428814783595
864356112857085785
0047828588595
43267475832689155
432355112837990615
129651352804190235
0369221825392626
432402412884087046
0184111908597186
01702838193356
43234285874489996
0355159856493876
8635261148479100507
432374194813078407
0355159778587287
432271714906591687
43267428862199067
0639795829486977
432185204924392068
0388303893897898
0756571957490908
43267522873389318
864205286776083408
017095808985978
43234284813287029
0100666770486869
432526114741483709
0170142803983859
0606698844393669
43267428933490009
01841118313831210
4326963038280859710
0008578912410
017027820935510
0007738797510
01841578867884310
432341917664862911
00948368923011
4324035068601909511
0009330867011
0341508782856211
0007676819111
4323552537033827412
2159121413028068890312
432190116798230915212
864156713688813872912
863138213988329920712
43212827798162864412
2160181120998465774513
34563944448263883313
43284310348195850813
082810667338759113
8637435098134873413
21595814807325842613
09797997999823314
8647836268337925614
1727221016807633873514
1728242738598248889514
5616362332277566826814
4318288724787520814614

I read it from a file:

data<-read.table("data.txt", head=T, sep="\t")

When I try count column mean by interval:

newData <- do.call(rbind, tapply(data[1:5], data$interval, colMeans))


I get an error: Error in tapply(data[1:5], data$interval, colMeans) :
   arguments must have same length

Has anyone any clue what is wrong?
Thank you in advance.



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


Re: [R] Error in colMeans with multiple column data.frame

2013-05-15 Thread Simonas Kecorius
Thank you so much, it did what I need!


2013/5/15 Pascal Oettli 

> Hi,
>
> I renamed your data.frame "df", as "data" is a built-in function.
>
> You can achieve what you are looking for with:
>
> > datf.mean <- with(datf, aggregate(datf[,-6], list(interval=interval),
> mean))
>
> Advice:
> Next time, use "dput" when you submit a data set to R-help.
>
> Hope this helps,
> Pascal
>
>
>
>
> On 05/15/2013 06:46 PM, Simonas Kecorius wrote:
>
>> Dear R users,
>>
>> Here is my data:
>>
>> "a1""a2""a3""a4""a5""interval"
>> 432355159930499491
>> 01841579182101201
>> 1295208861104101
>> 0100572910298361
>> 017095842190441
>> 01702896392611
>> 0723380848389232
>> 0184111820693732
>> 0539223867087142
>> 03414804479772
>> 432403412693877552
>> 0218395766178982
>> 43267428717679573
>> 0047750881603
>> 067382697878113
>> 0047853784863
>> 0605698865194213
>> 43210811489233
>> 0204193890493244
>> 4321221371899796814
>> 000845488384
>> 017049823289944
>> 01841119251107904
>> 0170142822796164
>> 067428814783595
>> 864356112857085785
>> 0047828588595
>> 43267475832689155
>> 432355112837990615
>> 129651352804190235
>> 0369221825392626
>> 432402412884087046
>> 0184111908597186
>> 01702838193356
>> 43234285874489996
>> 0355159856493876
>> 8635261148479100507
>> 432374194813078407
>> 0355159778587287
>> 432271714906591687
>> 43267428862199067
>> 0639795829486977
>> 432185204924392068
>> 0388303893897898
>> 0756571957490908
>> 43267522873389318
>> 864205286776083408
>> 017095808985978
>> 43234284813287029
>> 0100666770486869
>> 432526114741483709
>> 0170142803983859
>> 0606698844393669
>> 43267428933490009
>> 01841118313831210
>> 4326963038280859710
>> 0008578912410
>> 017027820935510
>> 0007738797510
>> 01841578867884310
>> 432341917664862911
>> 00948368923011
>> 4324035068601909511
>> 0009330867011
>> 0341508782856211
>> 0007676819111
>> 4323552537033827412
>> 2159121413028068890312
>> 432190116798230915212
>> 864156713688813872912
>> 863138213988329920712
>> 43212827798162864412
>> 2160181120998465774513
>> 34563944448263883313
>> 43284310348195850813
>> 082810667338759113
>> 8637435098134873413
>> 21595814807325842613
>> 09797997999823314
>> 8647836268337925614
>> 1727221016807633873514
>> 1728242738598248889514
>> 5616362332277566826814
>> 4318288724787520814614
>>
>> I read it from a file:
>>
>> data<-read.table("data.txt", head=T, sep="\t")
>>
>> When I try count column mean by interval:
>>
>> newData <- do.call(rbind, tapply(data[1:5], data$interval, colMeans))
>>
>>
>> I get an error: Error in tapply(data[1:5], data$interval, colMeans) :
>>arguments must have same length
>>
>> Has anyone any clue what is wrong?
>> Thank you in advance.
>>
>>


-- 
Simonas Kecorius
**

[[alternative HTML version deleted]]

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


Re: [R] Error in colMeans with multiple column data.frame

2013-05-15 Thread Blaser Nello
It  looks like you should use "by" instead of "tapply". 
Anyway, if you use dput(data) for sharing your data, it is much easier
to get help. 

Best, 
Nello



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of Simonas Kecorius
Sent: Mittwoch, 15. Mai 2013 11:46
To: r-help@r-project.org
Subject: [R] Error in colMeans with multiple column data.frame

Dear R users,

Here is my data:

"a1""a2""a3""a4""a5""interval"
432355159930499491
01841579182101201
1295208861104101
0100572910298361
017095842190441
01702896392611
0723380848389232
0184111820693732
0539223867087142
03414804479772
432403412693877552
0218395766178982
43267428717679573
0047750881603
067382697878113
0047853784863
0605698865194213
43210811489233
0204193890493244
4321221371899796814
000845488384
017049823289944
01841119251107904
0170142822796164
067428814783595
864356112857085785
0047828588595
43267475832689155
432355112837990615
129651352804190235
0369221825392626
432402412884087046
0184111908597186
01702838193356
43234285874489996
0355159856493876
8635261148479100507
432374194813078407
0355159778587287
432271714906591687
43267428862199067
0639795829486977
432185204924392068
0388303893897898
0756571957490908
43267522873389318
864205286776083408
017095808985978
43234284813287029
0100666770486869
432526114741483709
0170142803983859
0606698844393669
43267428933490009
01841118313831210
4326963038280859710
0008578912410
017027820935510
0007738797510
01841578867884310
432341917664862911
00948368923011
4324035068601909511
0009330867011
0341508782856211
0007676819111
4323552537033827412
2159121413028068890312
432190116798230915212
864156713688813872912
863138213988329920712
43212827798162864412
2160181120998465774513
34563944448263883313
43284310348195850813
082810667338759113
8637435098134873413
21595814807325842613
09797997999823314
8647836268337925614
1727221016807633873514
1728242738598248889514
5616362332277566826814
4318288724787520814614

I read it from a file:

data<-read.table("data.txt", head=T, sep="\t")

When I try count column mean by interval:

newData <- do.call(rbind, tapply(data[1:5], data$interval, colMeans))


I get an error: Error in tapply(data[1:5], data$interval, colMeans) :
  arguments must have same length

Has anyone any clue what is wrong?
Thank you in advance.

-- 
Simonas Kecorius
**

[[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 in colMeans with multiple column data.frame

2013-05-15 Thread Pascal Oettli

Hi,

I renamed your data.frame "df", as "data" is a built-in function.

You can achieve what you are looking for with:

> datf.mean <- with(datf, aggregate(datf[,-6], list(interval=interval), 
mean))


Advice:
Next time, use "dput" when you submit a data set to R-help.

Hope this helps,
Pascal



On 05/15/2013 06:46 PM, Simonas Kecorius wrote:

Dear R users,

Here is my data:

"a1""a2""a3""a4""a5""interval"
432355159930499491
01841579182101201
1295208861104101
0100572910298361
017095842190441
01702896392611
0723380848389232
0184111820693732
0539223867087142
03414804479772
432403412693877552
0218395766178982
43267428717679573
0047750881603
067382697878113
0047853784863
0605698865194213
43210811489233
0204193890493244
4321221371899796814
000845488384
017049823289944
01841119251107904
0170142822796164
067428814783595
864356112857085785
0047828588595
43267475832689155
432355112837990615
129651352804190235
0369221825392626
432402412884087046
0184111908597186
01702838193356
43234285874489996
0355159856493876
8635261148479100507
432374194813078407
0355159778587287
432271714906591687
43267428862199067
0639795829486977
432185204924392068
0388303893897898
0756571957490908
43267522873389318
864205286776083408
017095808985978
43234284813287029
0100666770486869
432526114741483709
0170142803983859
0606698844393669
43267428933490009
01841118313831210
4326963038280859710
0008578912410
017027820935510
0007738797510
01841578867884310
432341917664862911
00948368923011
4324035068601909511
0009330867011
0341508782856211
0007676819111
4323552537033827412
2159121413028068890312
432190116798230915212
864156713688813872912
863138213988329920712
43212827798162864412
2160181120998465774513
34563944448263883313
43284310348195850813
082810667338759113
8637435098134873413
21595814807325842613
09797997999823314
8647836268337925614
1727221016807633873514
1728242738598248889514
5616362332277566826814
4318288724787520814614

I read it from a file:

data<-read.table("data.txt", head=T, sep="\t")

When I try count column mean by interval:

newData <- do.call(rbind, tapply(data[1:5], data$interval, colMeans))


I get an error: Error in tapply(data[1:5], data$interval, colMeans) :
   arguments must have same length

Has anyone any clue what is wrong?
Thank you in advance.



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


[R] K Fold CrossValidation

2013-05-15 Thread Preetam Pal
Hi all,
I want to run the following Cross-validation technique on my data set:


Variables: X, Y (each having 50 observations)
I want to run a least-squares regression of Y on X.
I need to divide the entire data set into 10 groups of size 5 each, keep
one of them out as 'test' set and build the model on the basis of the
remaining 9 groups (the 'training set').Then i calculate the MSE of the
fitted model by applying it on the 'test set'.

So, for each choice of the 'test set', I get a MSE value.
I select that model as final which corresponds to the minimum of these 10
MSE values.

How do i get the coefficients for this model.

I am a beginner in R and the help page on CROSSVAL appeared a bit confusing
to me.

Thanks for any help.
Regards,
Preetam

-- 
Preetam Pal
(+91)-9432212774
M-Stat 2nd Year, Room No. N-114
Statistics Division,   C.V.Raman
Hall
Indian Statistical Institute, B.H.O.S.
Kolkata.

[[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] Error in colMeans with multiple column data.frame

2013-05-15 Thread Simonas Kecorius
Dear R users,

Here is my data:

"a1""a2""a3""a4""a5""interval"
432355159930499491
01841579182101201
1295208861104101
0100572910298361
017095842190441
01702896392611
0723380848389232
0184111820693732
0539223867087142
03414804479772
432403412693877552
0218395766178982
43267428717679573
0047750881603
067382697878113
0047853784863
0605698865194213
43210811489233
0204193890493244
4321221371899796814
000845488384
017049823289944
01841119251107904
0170142822796164
067428814783595
864356112857085785
0047828588595
43267475832689155
432355112837990615
129651352804190235
0369221825392626
432402412884087046
0184111908597186
01702838193356
43234285874489996
0355159856493876
8635261148479100507
432374194813078407
0355159778587287
432271714906591687
43267428862199067
0639795829486977
432185204924392068
0388303893897898
0756571957490908
43267522873389318
864205286776083408
017095808985978
43234284813287029
0100666770486869
432526114741483709
0170142803983859
0606698844393669
43267428933490009
01841118313831210
4326963038280859710
0008578912410
017027820935510
0007738797510
01841578867884310
432341917664862911
00948368923011
4324035068601909511
0009330867011
0341508782856211
0007676819111
4323552537033827412
2159121413028068890312
432190116798230915212
864156713688813872912
863138213988329920712
43212827798162864412
2160181120998465774513
34563944448263883313
43284310348195850813
082810667338759113
8637435098134873413
21595814807325842613
09797997999823314
8647836268337925614
1727221016807633873514
1728242738598248889514
5616362332277566826814
4318288724787520814614

I read it from a file:

data<-read.table("data.txt", head=T, sep="\t")

When I try count column mean by interval:

newData <- do.call(rbind, tapply(data[1:5], data$interval, colMeans))


I get an error: Error in tapply(data[1:5], data$interval, colMeans) :
  arguments must have same length

Has anyone any clue what is wrong?
Thank you in advance.

-- 
Simonas Kecorius
**

[[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] Possible bug in 'data.table'

2013-05-15 Thread Manta
As somebody else replied (but for some reason did not get through it) the
solution to this is to convert the variable TIME3 from POSIXlt to POSIXct.
It works like a charm.

Nevertheless, there is a bug in that R should give me a warning/error
message, and not simply crash. I reported the bug to the relevant team.

Thank you,
Marco



--
View this message in context: 
http://r.789695.n4.nabble.com/Possible-bug-in-data-table-tp4667025p4667096.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] BASEL II Validation Tests

2013-05-15 Thread Preetam Pal
Hi,


I would like to know whether there is any in-built code for the following
BASEL II related validation tests:


1>Level Test

2> K-Fold Test

3>Mobility Test



Kindly let me know if I need to supply any more information.


Thanks,

Preetam
-- 
Preetam Pal
(+91)-9432212774
M-Stat 2nd Year, Room No. N-114
Statistics Division,   C.V.Raman
Hall
Indian Statistical Institute, B.H.O.S.
Kolkata.

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