Re: [R] Help with a code in R

2016-09-05 Thread PIKAL Petr
Hi

Well, it seems to me that it is coded in different language like C++.
The code is not reproducible but the error seems to be from your call of ts

You can check it line by line with setting i to arbitrary value and inspect how 
your objects look like, however some of your constructions seems to me quite 
weird.

e.g.
forecast_nal<-data.frame()

leads to mempty data frame with no column named mean
> forecast_nal
data frame with 0 columns and 0 rows
> forecast_nal$mean
NULL

and I am rather surprised how this column come into existence.

BTW, are you sure that in each cycle your rbinded or cbinded objects have the 
same size?

Cheers
Petr


> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Erika Rocío
> Espinosa Balbuena
> Sent: Monday, September 5, 2016 8:26 PM
> To: r-help@r-project.org
> Subject: [R] Help with a code in R
>
> Hi,
>
> I am working with this code:
>
> forecast_nal<-data.frame()
> out<-vector()
> x<-foreach(i=1:nrow(comb)) %do%
> {
>
> s<-comb[i,'prod_id']
>
> #Familia+Sumbarca+prod_id
> #Serie
>
> bcomb1<-b
> bcomb1<-subset(bcomb1,bcomb1$prod_id == s & bcomb1$year <= 2015)
> bcomb1<-arrange(bcomb1,year,week)
> a<-bcomb1[1:1,'week']
> d<-bcomb1[1:1,'year']
> f<-nrow(bcomb1)
> h<-bcomb1[f:f,'year']
> j<-bcomb1[f:f,'week']
> bcomb1<-bcomb1[,c(6)]
>
> if (length(bcomb1)<=10 || h=="2014" || (h=="2015" && j<=48)) { out[i]<-s }
> else {
>y <- ts(bcomb1, frequency=52, start=c(d, a)) ##Casos
>
> if (length(y)<=60)
> {
>
> v<-auto.arima(y)
> v<-arimaorder(v)
> fit <- arima(y, order = v ,method="ML")
>   fca <- forecast(fit, h = 16)
> dates <- attr(forecast_nal$mean, "tsp")
> datecol <- seq(from=dates[1], to=dates[2], by=1/dates[3])
> fct<-cbind.data.frame(s,datecol,Point=fca$mean)
> forecast_nal<- rbind.data.frame(forecast_nal,fct)
> }
> else
> {
>
> fit <- tbats(y)
> fcb <- forecast(fit, h = 16)
> dates <- attr(forecast_nal$mean, "tsp")
> datecol <- seq(from=dates[1], to=dates[2], by=1/dates[3])
> fct<-cbind.data.frame(s,datecol,Point=fcb$mean)
> forecast_nal<- rbind.data.frame(forecast_nal,fct)
> }
> }
> }
>  But I am getting this error:
>
> Error in `[<-.ts`(`*tmp*`, ri, value = c(26656.136365833, 26750.9374514082,
>  :
>   only replacement of elements is allowed
>
> Can someone help me with this?
>
> Thanks
>
>
> --
> Erika Rocío Espinosa Balbuena
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.


Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny 
pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně 
jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze 
svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email 
jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či 
zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a 
to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; 
Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce 
s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným 
dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost 
žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně 
pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně 
osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi 
či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are 
intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. 
Delete the contents of this e-mail with all attachments and its copies from 
your system.
If you are not the intended recipient of this e-mail, you are not authorized to 
use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by 
modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a 
contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately 
accept such offer;

Re: [R] Help with a code in R

2016-09-05 Thread Mark Sharp
Erika,

You have failed to supply reproducible code. I do not all that is missing, but 
a glance shows that you did not include the code to load the foreach package or 
a definition of the objects named comb and b.

It is very likely you will receive assistance if you can follow the posting 
guide http://www.R-project.org/posting-guide.html


Mark

R. Mark Sharp, Ph.D.
Director of Primate Records Database
Southwest National Primate Research Center
Texas Biomedical Research Institute
P.O. Box 760549
San Antonio, TX 78245-0549
Telephone: (210)258-9476
e-mail: msh...@txbiomed.org







> On Sep 5, 2016, at 1:25 PM, Erika Rocío Espinosa Balbuena 
>  wrote:
>
> Hi,
>
> I am working with this code:
>
> forecast_nal<-data.frame()
> out<-vector()
> x<-foreach(i=1:nrow(comb)) %do%
> {
>
> s<-comb[i,'prod_id']
>
> #Familia+Sumbarca+prod_id
> #Serie
>
> bcomb1<-b
> bcomb1<-subset(bcomb1,bcomb1$prod_id == s & bcomb1$year <= 2015)
> bcomb1<-arrange(bcomb1,year,week)
> a<-bcomb1[1:1,'week']
> d<-bcomb1[1:1,'year']
> f<-nrow(bcomb1)
> h<-bcomb1[f:f,'year']
> j<-bcomb1[f:f,'week']
> bcomb1<-bcomb1[,c(6)]
>
> if (length(bcomb1)<=10 || h=="2014" || (h=="2015" && j<=48))
> {
> out[i]<-s
> }
> else
> {
>   y <- ts(bcomb1, frequency=52, start=c(d, a))
> ##Casos
>
> if (length(y)<=60)
> {
>
> v<-auto.arima(y)
> v<-arimaorder(v)
> fit <- arima(y, order = v ,method="ML")
>  fca <- forecast(fit, h = 16)
> dates <- attr(forecast_nal$mean, "tsp")
> datecol <- seq(from=dates[1], to=dates[2], by=1/dates[3])
> fct<-cbind.data.frame(s,datecol,Point=fca$mean)
> forecast_nal<- rbind.data.frame(forecast_nal,fct)
> }
> else
> {
>
> fit <- tbats(y)
> fcb <- forecast(fit, h = 16)
> dates <- attr(forecast_nal$mean, "tsp")
> datecol <- seq(from=dates[1], to=dates[2], by=1/dates[3])
> fct<-cbind.data.frame(s,datecol,Point=fcb$mean)
>forecast_nal<- rbind.data.frame(forecast_nal,fct)
> }
> }
> }
> But I am getting this error:
>
> Error in `[<-.ts`(`*tmp*`, ri, value = c(26656.136365833, 26750.9374514082,
> :
>  only replacement of elements is allowed
>
> Can someone help me with this?
>
> Thanks
>
>
> --
> Erika Rocío Espinosa Balbuena
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


CONFIDENTIALITY NOTICE: This e-mail and any files and/or attachments 
transmitted, may contain privileged and confidential information and is 
intended solely for the exclusive use of the individual or entity to whom it is 
addressed. If you are not the intended recipient, you are hereby notified that 
any review, dissemination, distribution or copying of this e-mail and/or 
attachments is strictly prohibited. If you have received this e-mail in error, 
please immediately notify the sender stating that this transmission was 
misdirected; return the e-mail to sender; destroy all paper copies and delete 
all electronic copies from your system without disclosing its contents.
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] outliers in Box Plot

2016-09-05 Thread Jim Lemon
Hi Rosa,
Your data never seem to get through. Nevertheless, here is a suggestion:

rodat<-data.frame(id=1:20,age=sample(c("10-20","21-30","31-40"),20,TRUE),
 weight=c(sample(40:70,18),110,120))
robp<-boxplot(weight~age,rodat)
rodat$id[which(rodat$weight %in% robp$out)]

Jim


On Mon, Sep 5, 2016 at 9:38 PM, Rosa Oliveira  wrote:
> Dear all,
>
> I have searched all over and didn´t found an answer :(
>
> I need urgently to "extract" de identification of the weight outliers of
> the participants of a study.
>
> So, I have a data base with several variables:
> id
> weight
> are 2 off them.
>
> So, I've done a boxplot and found the weight have outliers. Now I need to
> identify the id's of those participants.
> I can get the outliers values, nonetheless lots os them are not correct for
> some vriables.
>
> Can you please help me?
>
> boxplot(WEIGHT~AGE,baseR,range=3) #print WEIGHT boxplot
> boxplot(WEIGHT~AGE==1,,baseR,range=3, plot=FALSE)$out  # find outliers
> values to age 1 (example)
>
>
> I attach the data.
>
> Best,
> Rosa Oliveira
>
> __
>
> Antes de imprimir este e-mail pense bem se tem mesmo que o fazer.
> Há cada vez menos árvores.
> Não imprima, pense na sua responsabilidade e compromisso com o MEIO
> AMBIENTE!
> 
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

[R] how to transform db query result into a set of timeseries ?

2016-09-05 Thread Stef Mientki

hello,

I've a number of timeseries into a database and want to display these 
timeseries into graph.


Now the code below works well, but as the user can select which 
timeseries should be shown (up to 20 timeseries) the code below should 
be dynamic and can be quiet large and complex.


Is there an easier way to convert a database result into timeseries 
accepted by dygraph ?


SQL <- "select Date, M, G, N from Compare_Model"
df <- dbGetQuery ( con, statement = SQL )

zon1 <- xts ( df$M,  as.POSIXct ( df$Date, format="%Y-%m-%d 
%H:%M:%S") )
zon2 <- xts ( df$G,  as.POSIXct ( df$Date, format="%Y-%m-%d 
%H:%M:%S") )
zon3 <- xts ( df$N,  as.POSIXct ( df$Date, format="%Y-%m-%d 
%H:%M:%S") )


zonnen <- Reduce ( function(...) merge(..., all=TRUE ), list ( zon, 
zon2, zon3 ))


dygraph ( zonnen )


thanks,

Stef

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] evaluating expressions as R console

2016-09-05 Thread Bert Gunter
I'm sharing this with r-help, as your detailed response might help
others help you.

-- Bert
Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sun, Sep 4, 2016 at 11:45 PM, Adrian Dușa  wrote:
> On Mon, Sep 5, 2016 at 2:52 AM, Bert Gunter  wrote:
>>
>> You might want to look at the "evaluate" package.
>
>
> Of course, forgot to mention. I did try it, but got:
>
>> bar <- readLines("foo.R", warn = FALSE)
>> bar <- paste(bar, collapse = "\n")
>> evaluate::evaluate(input = bar)
> [[1]]
> $src
> [1] "foo <- function(x) {\nprint(x)\n}\nprint)foo)\nfoo(2)"
>
> attr(,"class")
> [1] "source"
>
> [[2]]
> :4:6: unexpected ')'
> 3: }
> 4: print)
> ^>
>
> I ran into the same problem as source(): it works only if it doesn't have
> any errors. In addition, the error message is also different because it
> evaluates the entire chunk, whereas the R console evaluates one command
> (line) at a time.
>
> Fixing the command:
> bar2 <- "foo <- function(x) {\nprint(x)\n}\nprint(foo)\nfoo(2)"
>
> will fix the workflow in evaluate():
>
> evaluate::evaluate(input = bar2)
>
>
> But it will also fix it with source():
>
>> source("foo2.R", echo = TRUE, keep.source = TRUE)
>
>> foo <- function(x) {
> + print(x)
> + }
>
>> print(foo)
> function(x) {
> print(x)
> }
>
>> foo(2)
> [1] 2
>
>
> So evaluate() has more detail than source(), but essentially they do the
> same thing in evaluating the whole chunk. From the help of source():
> "Since the complete file is parsed before any of it is run, syntax errors
> result in none of the code being run."
>
> So far, it seems that only R CMD BATCH is able to run one command at a time:
>
> $ R CMD BATCH -q foo.R
> $ cat foo.Rout
>> foo <- function(x) {
> + print(x)
> + }
>> print)foo)
> Error: unexpected ')' in "print)"
> Execution halted
>
> This error is exactly the same as in the R console, and the function foo()
> is created before the error occurs. One possible solution is to get the
> workspace saved, and run R CMD BATCH again on the rest of commands after the
> error.
>
> But it still needs additional objects if the chunk is to be evaluated in a
> specific environment. This is the point where I've got, and I don't know if
> this is the best approach.
>
> Thank you,
> Adrian
>
> --
> Adrian Dusa
> University of Bucharest
> Romanian Social Data Archive
> Soseaua Panduri nr.90
> 050663 Bucharest sector 5
> Romania

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 reading subset of data from CSV file

2016-09-05 Thread Florian Schwendinger

There are several issues,

1. I think
ReadName = '133261'
read.csv.sql("Dat.csv", sql = "select * from file where 'col 1' = ReadName")

should be replaced by something like this

ReadName = '133261'
sql_cmd <- sprintf("select * from file where col_1='%s'", ReadName)
sql_cmd
read.csv.sql("Dat.csv", sql = sql_cmd, sep="|")

2. I wouldn't use spaces in the column names.
3. Since you have in column 2 also your separator, you cloud switch the 
separator to "|" or ";" if possible.



colnames(Dat) <- gsub("\\s+", "_", colnames(Dat))
colnames(Dat)
write.table(Dat, "Dat.csv", quote = FALSE, row.names = FALSE, sep="|")

ReadName = '133261'
sql_cmd <- sprintf("select * from file where col_1='%s'", ReadName)
sql_cmd
read.csv.sql("Dat.csv", sql = sql_cmd, sep="|")


So the following works at my pc, but if you cant change the separator 
things will get more difficult.


colnames(Dat) <- gsub("\\s+", "_", colnames(Dat))
colnames(Dat)
write.table(Dat, "Dat.csv", quote = FALSE, row.names = FALSE, sep="|")

ReadName = '133261'
sql_cmd <- sprintf("select * from file where col_1='%s'", ReadName)
sql_cmd
read.csv.sql("Dat.csv", sql = sql_cmd, sep="|")

Best,
Florian


On 2016-09-04 13:29, Christofer Bogaso wrote:

Didnt work getting unused argument error.

On Sun, Sep 4, 2016 at 4:47 PM, Jim Lemon  wrote:

I suppose you could try quote=TRUE

Jim


On Sun, Sep 4, 2016 at 8:13 PM, Christofer Bogaso
 wrote:

Thanks Jim. But my data is like that and I have to live with that. Any
idea on workaround. Thanks,

On Sun, Sep 4, 2016 at 3:40 PM, Jim Lemon  wrote:

Hi Christofer,
You have embedded commas in your data structure. This is guaranteed to
mess up a CSV read.

Jim


On Sun, Sep 4, 2016 at 5:54 PM, Christofer Bogaso
 wrote:

Hi again,

I was trying to read a subset of Data from a CSV file using below code
as example :

library(sqldf)

Dat = structure(list(`col 1` = c(133261L, 133261L, 133262L, 133262L
), `col 2` = structure(1:4, .Label = c("aaa1", "aaa2", "bbb1, bbb",
"bbb3, bbb"), class = "factor"), `col 3` = c(10.59, 10.56, 10.59,
10.56), `col 4` = c(10.59, 10.56, 10.59, 10.56), `col 5` = c(10.59,
10.56, 10.59, 10.56), `col 6` = structure(c(1L, 2L, 1L, 2L), .Label =
c("04-Jul-16",
"05-Jul-16"), class = "factor")), .Names = c("col 1", "col 2",
"col 3", "col 4", "col 5", "col 6"), class = "data.frame", row.names = c(NA,
-4L))
Dat

write.csv(Dat, "Dat.csv", quote = FALSE, row.names = FALSE)

ReadName = '133261'
read.csv.sql("Dat.csv", sql = "select * from file where 'col 1' = ReadName")

Loading required package: tcltk
Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  :
   line 1 did not have 7 elements

This code generates above Error. Could you please help me with a
pointer where something went wrong? My actual CSV file is quite huge
so I cant read it as whole. However basic structure of my original
file is similar as above "Dat"

Thanks for your time.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Seasonal package: "Error in x[[2]] : subscript out of bounds"

2016-09-05 Thread Juan Ceccarelli Arias
Hi
Im running X13 with the seasonal package. However, in some series i get
this error after specifying the x11 options:

o_1=ts(o1,frequency=12,start=c(2010,2))
so_1=seas(o_1, x11="",transform.function ="log",arima.model="([3] 1 1)(1 1
0)", x11.seasonalma="S3x5",x11.trendma=13)
Error in x[[2]] : subscript out of bounds

I have four series with almost the same code. Only in one of them the
process is applied correctly.  If i type so_1, i see this:

Error: object 'so_1' not found

The series that im working with are declared as time series. I mean, all of
them look exactly the same if i do a simple View(cbind(series1,
series2,...series4))
Can some one guide me ?
Thanks for your time and interest.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] outliers in Box Plot

2016-09-05 Thread Rosa Oliveira
Dear all,

I have searched all over and didn´t found an answer :(

I need urgently to "extract" de identification of the weight outliers of
the participants of a study.

So, I have a data base with several variables:
id
weight
are 2 off them.

So, I've done a boxplot and found the weight have outliers. Now I need to
identify the id's of those participants.
I can get the outliers values, nonetheless lots os them are not correct for
some vriables.

Can you please help me?

boxplot(WEIGHT~AGE,baseR,range=3) #print WEIGHT boxplot
boxplot(WEIGHT~AGE==1,,baseR,range=3, plot=FALSE)$out  # find outliers
values to age 1 (example)


I attach the data.

Best,
Rosa Oliveira

__

Antes de imprimir este e-mail pense bem se tem mesmo que o fazer.
Há cada vez menos árvores.
Não imprima, pense na sua responsabilidade e compromisso com o MEIO
AMBIENTE!


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 with a code in R

2016-09-05 Thread Erika Rocío Espinosa Balbuena
Hi,

I am working with this code:

forecast_nal<-data.frame()
out<-vector()
x<-foreach(i=1:nrow(comb)) %do%
{

s<-comb[i,'prod_id']

#Familia+Sumbarca+prod_id
#Serie

bcomb1<-b
bcomb1<-subset(bcomb1,bcomb1$prod_id == s & bcomb1$year <= 2015)
bcomb1<-arrange(bcomb1,year,week)
a<-bcomb1[1:1,'week']
d<-bcomb1[1:1,'year']
f<-nrow(bcomb1)
h<-bcomb1[f:f,'year']
j<-bcomb1[f:f,'week']
bcomb1<-bcomb1[,c(6)]

if (length(bcomb1)<=10 || h=="2014" || (h=="2015" && j<=48))
{
out[i]<-s
}
else
{
   y <- ts(bcomb1, frequency=52, start=c(d, a))
##Casos

if (length(y)<=60)
{

v<-auto.arima(y)
v<-arimaorder(v)
fit <- arima(y, order = v ,method="ML")
  fca <- forecast(fit, h = 16)
dates <- attr(forecast_nal$mean, "tsp")
datecol <- seq(from=dates[1], to=dates[2], by=1/dates[3])
fct<-cbind.data.frame(s,datecol,Point=fca$mean)
forecast_nal<- rbind.data.frame(forecast_nal,fct)
}
else
{

fit <- tbats(y)
fcb <- forecast(fit, h = 16)
dates <- attr(forecast_nal$mean, "tsp")
datecol <- seq(from=dates[1], to=dates[2], by=1/dates[3])
fct<-cbind.data.frame(s,datecol,Point=fcb$mean)
forecast_nal<- rbind.data.frame(forecast_nal,fct)
}
}
}
 But I am getting this error:

Error in `[<-.ts`(`*tmp*`, ri, value = c(26656.136365833, 26750.9374514082,
 :
  only replacement of elements is allowed

Can someone help me with this?

Thanks


-- 
Erika Rocío Espinosa Balbuena

[[alternative HTML version deleted]]

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

[R] Fwd: problem writing .bil files in netcdf

2016-09-05 Thread Abdoulaye Sarr
-- Forwarded message --
From: Abdoulaye SARR 
Date: Mon, Jan 1, 2001 at 4:02 AM
Subject: Re: [R] problem writing .bil files in netcdf
To: Michael Sumner 
Cc: r-help@r-project.org


Hi Michael,

I had a problem with my mac hopefully solve now.


For the  issue i submitted, I tried your suggestion with writeRaster which
creates a netcdf file. The problem when I look the results by displaying as
graph I seen the
values starting by -9000 and mainly are located in the continent
boundaries, so how to add in write taste the undef values and have precip
from 0 to x.


For the loop if successful is toe write each day in a separate netcdf file,
if done it will be easy to concatenate using nco or cdo.
To convert each day in netcdf I need to have an appropriate loop in a
script. I have to process many years.

Cheers,


Le 2 sept. 2016 à 15:09, Michael Sumner  a écrit :



On Fri, 2 Sep 2016 at 00:43 Abdoulaye SARR  wrote:

> Dear List,
>
> I have daily rainfall data in .bil format and can get info of the file
> using rgdal:
>
> > library(rgdal)
> > GDALinfo("/1981/v2p19810101.bil")
> rows1600
> columns 1500
> bands   1
> lower left origin.x-20
> lower left origin.y-40
> res.x   0.05
> res.y   0.05
> ysign   -1
> oblique.x   0
> oblique.y   0
> driver  EHdr
> projection  NA
>
> How can I read all daily file and write them as netcdf files and
> concatenate as one yearly file and also avoid boundary pixels alter
> rainfall values.
>
>
Hi,

You can read the single .bil and write it to NetCDF with raster (and the
rgdal and ncdf4) package:

 library(raster)
r <- raster("/1981/v2p19810101.bil")
writeRaster(r, "v2p19810101.nc")

But, if you read in multi .bil files and build a multilayer raster, i.e.

st <- stack(list.files("/1981", pattern = "bil$", full.names = TRUE))

you *can* write it out to NetCDF, very similar to above with writeRaster,
but I think it will generate a variable (an netcdf array) for each layer.

To really write to .nc in a specific way you'll need to delve into the
standard tools in ncdf4, to create a file, create
variables/dimensions/attributes,
and then populate the variable, in this case probably one 3rd-level slice
for each .bil. That might be better done at the command line, say with nco
(the "nc operators"). There are copy-create idioms which is probably the
way to go if you have a template data file or CDF specification.

There may be some higher level tools in other packages on CRAN, check the
reverse depends/imports/suggests on CRAN for ncdf4. Also you should explore
RNetCDF which has an independent implementation.

 (raster really blitzes the field in terms of high-level tools here, but it
has limits, with writing NetCDF *in specific ways* being one of them. GDAL
has similar limitations, since it sees the world in this
"array-as-2d-bands" way).

HTH, at least a little.

Cheers, Mike.

Best regards,
>
> Eus
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.
> org/posting-guide.html 
> and provide commented, minimal, self-contained, reproducible code.
>
-- 
Dr. Michael Sumner
Software and Database Engineer
Australian Antarctic Division
203 Channel Highway
Kingston Tasmania 7050 Australia

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] evaluating expressions as R console

2016-09-05 Thread Adrian Dușa
I think I have found a working solution. Rather ugly, but working and will
keep looking for better alternatives, though.

The procedure involves:

- parsing one line at a time
- if incomplete, parse as many lines as necessary to form an expression
- determine all expressions in the original input
- evaluate each expression, one at a time
  (which shows individual errors and warnings)
- print each pair of:
- expression
- error, or result with possible warning(s)

It works reasonably quick for small chunks, but that is ok for my purposes.

I hope it helps anyone. Should there be better alternatives, I would be
more than grateful for a hint.

Best,
Adrian

On Mon, Sep 5, 2016 at 5:33 PM, Bert Gunter  wrote:

> I'm sharing this with r-help, as your detailed response might help
> others help you.
>
> -- Bert
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along
> and sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Sun, Sep 4, 2016 at 11:45 PM, Adrian Dușa 
> wrote:
> > On Mon, Sep 5, 2016 at 2:52 AM, Bert Gunter 
> wrote:
> >>
> >> You might want to look at the "evaluate" package.
> >
> >
> > Of course, forgot to mention. I did try it, but got:
> >
> >> bar <- readLines("foo.R", warn = FALSE)
> >> bar <- paste(bar, collapse = "\n")
> >> evaluate::evaluate(input = bar)
> > [[1]]
> > $src
> > [1] "foo <- function(x) {\nprint(x)\n}\nprint)foo)\nfoo(2)"
> >
> > attr(,"class")
> > [1] "source"
> >
> > [[2]]
> > :4:6: unexpected ')'
> > 3: }
> > 4: print)
> > ^>
> >
> > I ran into the same problem as source(): it works only if it doesn't have
> > any errors. In addition, the error message is also different because it
> > evaluates the entire chunk, whereas the R console evaluates one command
> > (line) at a time.
> >
> > Fixing the command:
> > bar2 <- "foo <- function(x) {\nprint(x)\n}\nprint(foo)\nfoo(2)"
> >
> > will fix the workflow in evaluate():
> >
> > evaluate::evaluate(input = bar2)
> >
> >
> > But it will also fix it with source():
> >
> >> source("foo2.R", echo = TRUE, keep.source = TRUE)
> >
> >> foo <- function(x) {
> > + print(x)
> > + }
> >
> >> print(foo)
> > function(x) {
> > print(x)
> > }
> >
> >> foo(2)
> > [1] 2
> >
> >
> > So evaluate() has more detail than source(), but essentially they do the
> > same thing in evaluating the whole chunk. From the help of source():
> > "Since the complete file is parsed before any of it is run, syntax errors
> > result in none of the code being run."
> >
> > So far, it seems that only R CMD BATCH is able to run one command at a
> time:
> >
> > $ R CMD BATCH -q foo.R
> > $ cat foo.Rout
> >> foo <- function(x) {
> > + print(x)
> > + }
> >> print)foo)
> > Error: unexpected ')' in "print)"
> > Execution halted
> >
> > This error is exactly the same as in the R console, and the function
> foo()
> > is created before the error occurs. One possible solution is to get the
> > workspace saved, and run R CMD BATCH again on the rest of commands after
> the
> > error.
> >
> > But it still needs additional objects if the chunk is to be evaluated in
> a
> > specific environment. This is the point where I've got, and I don't know
> if
> > this is the best approach.
> >
> > Thank you,
> > Adrian
>


-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] element wise pattern recognition and string substitution

2016-09-05 Thread Bert Gunter
Jun:

You need to provide a clear specification via regular expressions of
the patterns you wish to match -- at least for me to decipher it.
Others may be smarter than I, though...

Jeff: Thanks. I have now convinced myself that it can be done (a
"proof" of sorts): If pat1, pat2,..., patn are m different patterns
(in a vector of patterns)  to be matched in a vector of n strings,
where only one of the patterns will match in any string,  then use
paste() (probably via do.call()) or otherwise to paste them together
separated by "|" to form the concatenated pattern, pat. Then

sub(paste0("^.*(",pat, ").*$"),"\\1",thevector)

should extract the matching pattern in each (perhaps with a little
fiddling due to precedence rules); e.g.

> z <-c(".fg.h.g.a.a", "bb..dd.ef.tgf.", "foo...b.bbb.tgy")

> pat1 <- "a+\\.*a+"
> pat2 <-"b+\\.*b+"
> pat <- c(pat1,pat2)

> pat <- do.call(paste,c(as.list(pat), sep="|"))
> pat
[1] "a+\\.*a+|b+\\.*b+"

> sub(paste0("^[^b]*(",pat,").*$"), "\\1", z)
[1] "a.a"   "bb""b.bbb"

Cheers,
Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Mon, Sep 5, 2016 at 9:56 AM, Jun Shen  wrote:
> Thanks for the reply, Bert.
>
> Your solution solves the example. I actually have a more general situation
> where I have this dot concatenated string from multiple variables. The
> problem is those variables may have values with dots in there. The number of
> dots are not consistent for all values of a variable. So I am thinking to
> define a vector of patterns for the vector of the string and hopefully to
> find a way to use a pattern from the pattern vector for each value of the
> string vector. The only way I can think of is "for" loop, which can be slow.
> Also these are happening in a function I am writing. Just wonder if there is
> another more efficient way. Thanks a lot.
>
> Jun
>
> On Mon, Sep 5, 2016 at 1:41 AM, Bert Gunter  wrote:
>>
>> Well, he did provide an example, and...
>>
>>
>> > z <- c('TX.WT.CUT.mean','mg.tx.cv')
>>
>> > sub("^.+?\\.(.+)\\.[^.]+$","\\1",z)
>> [1] "WT.CUT" "tx"
>>
>>
>> ## seems to do what was requested.
>>
>> Jeff would have to amplify on his initial statement however: do you
>> mean that separate patterns can always be combined via "|" ?  Or
>> something deeper?
>>
>> Cheers,
>> Bert
>> Bert Gunter
>>
>> "The trouble with having an open mind is that people keep coming along
>> and sticking things into it."
>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>>
>>
>> On Sun, Sep 4, 2016 at 9:30 PM, Jeff Newmiller 
>> wrote:
>> > Your opening assertion is false.
>> >
>> > Provide a reproducible example and someone will demonstrate.
>> > --
>> > Sent from my phone. Please excuse my brevity.
>> >
>> > On September 4, 2016 9:06:59 PM PDT, Jun Shen 
>> > wrote:
>> >>Dear list,
>> >>
>> >>I have a vector of strings that cannot be described by one pattern. So
>> >>let's say I construct a vector of patterns in the same length as the
>> >>vector
>> >>of strings, can I do the element wise pattern recognition and string
>> >>substitution.
>> >>
>> >>For example,
>> >>
>> >>pattern1 <- "([^.]*)\\.([^.]*\\.[^.]*)\\.(.*)"
>> >>pattern2 <- "([^.]*)\\.([^.]*)\\.(.*)"
>> >>
>> >>patterns <- c(pattern1,pattern2)
>> >>strings <- c('TX.WT.CUT.mean','mg.tx.cv')
>> >>
>> >>Say I want to extract "WT.CUT" from the first string and "tx" from the
>> >>second string. If I do
>> >>
>> >>sub(patterns, '\\2', strings), only the first pattern will be used.
>> >>
>> >>looping the patterns doesn't work the way I want. Appreciate any
>> >>comments.
>> >>Thanks.
>> >>
>> >>Jun
>> >>
>> >>   [[alternative HTML version deleted]]
>> >>
>> >>__
>> >>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> >>https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
>> > https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] element wise pattern recognition and string substitution

2016-09-05 Thread Jun Shen
Thanks for the reply, Bert.

Your solution solves the example. I actually have a more general situation
where I have this dot concatenated string from multiple variables. The
problem is those variables may have values with dots in there. The number
of dots are not consistent for all values of a variable. So I am thinking
to define a vector of patterns for the vector of the string and hopefully
to find a way to use a pattern from the pattern vector for each value of
the string vector. The only way I can think of is "for" loop, which can be
slow. Also these are happening in a function I am writing. Just wonder if
there is another more efficient way. Thanks a lot.

Jun

On Mon, Sep 5, 2016 at 1:41 AM, Bert Gunter  wrote:

> Well, he did provide an example, and...
>
>
> > z <- c('TX.WT.CUT.mean','mg.tx.cv')
>
> > sub("^.+?\\.(.+)\\.[^.]+$","\\1",z)
> [1] "WT.CUT" "tx"
>
>
> ## seems to do what was requested.
>
> Jeff would have to amplify on his initial statement however: do you
> mean that separate patterns can always be combined via "|" ?  Or
> something deeper?
>
> Cheers,
> Bert
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along
> and sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Sun, Sep 4, 2016 at 9:30 PM, Jeff Newmiller 
> wrote:
> > Your opening assertion is false.
> >
> > Provide a reproducible example and someone will demonstrate.
> > --
> > Sent from my phone. Please excuse my brevity.
> >
> > On September 4, 2016 9:06:59 PM PDT, Jun Shen 
> wrote:
> >>Dear list,
> >>
> >>I have a vector of strings that cannot be described by one pattern. So
> >>let's say I construct a vector of patterns in the same length as the
> >>vector
> >>of strings, can I do the element wise pattern recognition and string
> >>substitution.
> >>
> >>For example,
> >>
> >>pattern1 <- "([^.]*)\\.([^.]*\\.[^.]*)\\.(.*)"
> >>pattern2 <- "([^.]*)\\.([^.]*)\\.(.*)"
> >>
> >>patterns <- c(pattern1,pattern2)
> >>strings <- c('TX.WT.CUT.mean','mg.tx.cv')
> >>
> >>Say I want to extract "WT.CUT" from the first string and "tx" from the
> >>second string. If I do
> >>
> >>sub(patterns, '\\2', strings), only the first pattern will be used.
> >>
> >>looping the patterns doesn't work the way I want. Appreciate any
> >>comments.
> >>Thanks.
> >>
> >>Jun
> >>
> >>   [[alternative HTML version deleted]]
> >>
> >>__
> >>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >>https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] element wise pattern recognition and string substitution

2016-09-05 Thread Jeff Newmiller
I am not the one who proved this... I can only respond to your suggested 
counterexamples.
-- 
Sent from my phone. Please excuse my brevity.

On September 5, 2016 9:01:12 AM PDT, Bert Gunter  wrote:
>Jeff:
>
>It is not obvious to me that the ability to *match* an arbitrary
>pattern (including one of several different ones via "|" , per the
>link you included) implies that sub() and friends can extract it, e.g.
>via the /N construct or otherwise.  I would appreciate it if you or
>someone else could show me how this can be done.
>
>Cheers,
>Bert
>
>
>Bert Gunter
>
>"The trouble with having an open mind is that people keep coming along
>and sticking things into it."
>-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
>On Mon, Sep 5, 2016 at 8:37 AM, Jeff Newmiller
> wrote:
>> Yes, sorry I did not look closer... regex can match any finite
>language, so there are no data sets you can feed to R that cannot be
>matched. [1] You may find it hard to see the pattern, or you may want
>to build the pattern programmatically to alleviate tedium for yourself,
>but regexes are not the constraint.
>>
>> http://www.cs.nuim.ie/~jpower/Courses/Previous/parsing/node18.html
>> --
>> Sent from my phone. Please excuse my brevity.
>>
>> On September 4, 2016 10:41:45 PM PDT, Bert Gunter
> wrote:
>>>Well, he did provide an example, and...
>>>
>>>
 z <- c('TX.WT.CUT.mean','mg.tx.cv')
>>>
 sub("^.+?\\.(.+)\\.[^.]+$","\\1",z)
>>>[1] "WT.CUT" "tx"
>>>
>>>
>>>## seems to do what was requested.
>>>
>>>Jeff would have to amplify on his initial statement however: do you
>>>mean that separate patterns can always be combined via "|" ?  Or
>>>something deeper?
>>>
>>>Cheers,
>>>Bert
>>>Bert Gunter
>>>
>>>"The trouble with having an open mind is that people keep coming
>along
>>>and sticking things into it."
>>>-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>>>
>>>
>>>On Sun, Sep 4, 2016 at 9:30 PM, Jeff Newmiller
>>> wrote:
 Your opening assertion is false.

 Provide a reproducible example and someone will demonstrate.
 --
 Sent from my phone. Please excuse my brevity.

 On September 4, 2016 9:06:59 PM PDT, Jun Shen
>
>>>wrote:
>Dear list,
>
>I have a vector of strings that cannot be described by one pattern.
>>>So
>let's say I construct a vector of patterns in the same length as
>the
>vector
>of strings, can I do the element wise pattern recognition and
>string
>substitution.
>
>For example,
>
>pattern1 <- "([^.]*)\\.([^.]*\\.[^.]*)\\.(.*)"
>pattern2 <- "([^.]*)\\.([^.]*)\\.(.*)"
>
>patterns <- c(pattern1,pattern2)
>strings <- c('TX.WT.CUT.mean','mg.tx.cv')
>
>Say I want to extract "WT.CUT" from the first string and "tx" from
>>>the
>second string. If I do
>
>sub(patterns, '\\2', strings), only the first pattern will be used.
>
>looping the patterns doesn't work the way I want. Appreciate any
>comments.
>Thanks.
>
>Jun
>
>   [[alternative HTML version deleted]]
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] element wise pattern recognition and string substitution

2016-09-05 Thread Bert Gunter
Jeff:

It is not obvious to me that the ability to *match* an arbitrary
pattern (including one of several different ones via "|" , per the
link you included) implies that sub() and friends can extract it, e.g.
via the /N construct or otherwise.  I would appreciate it if you or
someone else could show me how this can be done.

Cheers,
Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Mon, Sep 5, 2016 at 8:37 AM, Jeff Newmiller  wrote:
> Yes, sorry I did not look closer... regex can match any finite language, so 
> there are no data sets you can feed to R that cannot be matched. [1] You may 
> find it hard to see the pattern, or you may want to build the pattern 
> programmatically to alleviate tedium for yourself, but regexes are not the 
> constraint.
>
> http://www.cs.nuim.ie/~jpower/Courses/Previous/parsing/node18.html
> --
> Sent from my phone. Please excuse my brevity.
>
> On September 4, 2016 10:41:45 PM PDT, Bert Gunter  
> wrote:
>>Well, he did provide an example, and...
>>
>>
>>> z <- c('TX.WT.CUT.mean','mg.tx.cv')
>>
>>> sub("^.+?\\.(.+)\\.[^.]+$","\\1",z)
>>[1] "WT.CUT" "tx"
>>
>>
>>## seems to do what was requested.
>>
>>Jeff would have to amplify on his initial statement however: do you
>>mean that separate patterns can always be combined via "|" ?  Or
>>something deeper?
>>
>>Cheers,
>>Bert
>>Bert Gunter
>>
>>"The trouble with having an open mind is that people keep coming along
>>and sticking things into it."
>>-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>>
>>
>>On Sun, Sep 4, 2016 at 9:30 PM, Jeff Newmiller
>> wrote:
>>> Your opening assertion is false.
>>>
>>> Provide a reproducible example and someone will demonstrate.
>>> --
>>> Sent from my phone. Please excuse my brevity.
>>>
>>> On September 4, 2016 9:06:59 PM PDT, Jun Shen 
>>wrote:
Dear list,

I have a vector of strings that cannot be described by one pattern.
>>So
let's say I construct a vector of patterns in the same length as the
vector
of strings, can I do the element wise pattern recognition and string
substitution.

For example,

pattern1 <- "([^.]*)\\.([^.]*\\.[^.]*)\\.(.*)"
pattern2 <- "([^.]*)\\.([^.]*)\\.(.*)"

patterns <- c(pattern1,pattern2)
strings <- c('TX.WT.CUT.mean','mg.tx.cv')

Say I want to extract "WT.CUT" from the first string and "tx" from
>>the
second string. If I do

sub(patterns, '\\2', strings), only the first pattern will be used.

looping the patterns doesn't work the way I want. Appreciate any
comments.
Thanks.

Jun

   [[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Fwd: Splines

2016-09-05 Thread Jeff Newmiller
This is not the kind of thing people know off the top of their heads, and even 
if they do it is an ideal application of text search tools. Download the source 
and start looking. Don't neglect the licencing terms... your use of that code 
implies responsibilities on your part. 
-- 
Sent from my phone. Please excuse my brevity.

On September 5, 2016 3:11:53 AM PDT, Filippo Monari  wrote:
>Hi,
>does anybody know what header file includes the bspline functions used
>in R?
>
>Regards,
>Filippo
>
>
> Forwarded Message 
>Subject:   Splines
>Date:  Sun, 04 Sep 2016 09:12:37 +0100
>From:  Filippo Monari 
>To:R-help@r-project.org
>
>
>
>Hi,
>I would like to use the C spline functions if R for a FORTRAN
>subroutine. What header file should I refer to?
>
>Regards
>Filippo Monari
>
>
>
>
>   [[alternative HTML version deleted]]
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Antw: Re: robumeta package - error

2016-09-05 Thread Kristina Loderer
Dear Michael,

thank you for your reply! I managed to solve the problem in the
meantime, there was an issue in the effect size conversion (correlations
to Fisher's z) that lead to zero values for some effect size variances. 

Regards,
Kristina


-
Kristina Loderer
Ludwig-Maximilians-Universität München
Department Psychologie
Leopoldstr. 13
D-80802 München

Telefon: +49 (89) 2180-6047
Email: kristina.lode...@psy.lmu.de

-
>>> Michael Dewey  02.09.16 13.38 Uhr >>>
Dear Kristina

I do not use that package so cannot offer any direct help but

1 - can you fit the model with any other combination of parameters?
2 - what happens if you vary rho?
3 - if your data-set is small and not confidential can you share it, 
otherwise can you show us str(anxiety_control) or 
summary(anxiety_control) preferable without any variables you are not 
using in this model?
4 - there is a robust option in Wolfgang Viechtbauer's metafor package 
which might help although I am not sure how equivalent the analysis 
approaches are.

On 01/09/2016 17:52, Kristina Loderer wrote:
> Dear all,
>
> I am trying to fit a simple (intercept-only) meta-analytic model using
> the robumeta package using the following code:
>  anx_cont_mean<-robu(formula = es_fisher ~ 1, var.eff.size =
> variance_fisher, studynum = study_ID, modelweights = "CORR", rho =
0.8,
> small=TRUE, data = anxiety_control)
>
> When I try to run this model, the following error message pops up:
> Error in solve.default(sumXWX) :
>   system is computationally singular: reciprocal condition number = 0
>
> What exactly does this mean in the context of meta-analysis? I haven't
> been able to find any answers.
>
> Thank you,
> Kristina
>
>
> -
> Kristina Loderer
> Ludwig-Maximilians-Universität München
> Department Psychologie
> Leopoldstr. 13
> D-80802 München
>
> Telefon: +49 (89) 2180-6047
> Email: kristina.lode...@psy.lmu.de
>
> -
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Michael
http://www.dewey.myzen.co.uk/home.html


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] evaluating expressions as R console

2016-09-05 Thread Adrian Dușa
On Mon, Sep 5, 2016 at 5:33 PM, Bert Gunter  wrote:
>
> I'm sharing this with r-help, as your detailed response might help
> others help you.


Oh, my bad (thought I had replied to all).
I wanted to add anyways the intended result seems to be possible. If
pasting the code here...:
http://www.tutorialspoint.com/r_terminal_online.php

... the result is exactly as in the R console.

Maybe this is a different technology (direct websocket?), but if they are
evaluating the text they're doing a very good job.

Best,
Adrian

--
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr.90
050663 Bucharest sector 5
Romania

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] element wise pattern recognition and string substitution

2016-09-05 Thread Jeff Newmiller
Yes, sorry I did not look closer... regex can match any finite language, so 
there are no data sets you can feed to R that cannot be matched. [1] You may 
find it hard to see the pattern, or you may want to build the pattern 
programmatically to alleviate tedium for yourself, but regexes are not the 
constraint. 

http://www.cs.nuim.ie/~jpower/Courses/Previous/parsing/node18.html
-- 
Sent from my phone. Please excuse my brevity.

On September 4, 2016 10:41:45 PM PDT, Bert Gunter  
wrote:
>Well, he did provide an example, and...
>
>
>> z <- c('TX.WT.CUT.mean','mg.tx.cv')
>
>> sub("^.+?\\.(.+)\\.[^.]+$","\\1",z)
>[1] "WT.CUT" "tx"
>
>
>## seems to do what was requested.
>
>Jeff would have to amplify on his initial statement however: do you
>mean that separate patterns can always be combined via "|" ?  Or
>something deeper?
>
>Cheers,
>Bert
>Bert Gunter
>
>"The trouble with having an open mind is that people keep coming along
>and sticking things into it."
>-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
>On Sun, Sep 4, 2016 at 9:30 PM, Jeff Newmiller
> wrote:
>> Your opening assertion is false.
>>
>> Provide a reproducible example and someone will demonstrate.
>> --
>> Sent from my phone. Please excuse my brevity.
>>
>> On September 4, 2016 9:06:59 PM PDT, Jun Shen 
>wrote:
>>>Dear list,
>>>
>>>I have a vector of strings that cannot be described by one pattern.
>So
>>>let's say I construct a vector of patterns in the same length as the
>>>vector
>>>of strings, can I do the element wise pattern recognition and string
>>>substitution.
>>>
>>>For example,
>>>
>>>pattern1 <- "([^.]*)\\.([^.]*\\.[^.]*)\\.(.*)"
>>>pattern2 <- "([^.]*)\\.([^.]*)\\.(.*)"
>>>
>>>patterns <- c(pattern1,pattern2)
>>>strings <- c('TX.WT.CUT.mean','mg.tx.cv')
>>>
>>>Say I want to extract "WT.CUT" from the first string and "tx" from
>the
>>>second string. If I do
>>>
>>>sub(patterns, '\\2', strings), only the first pattern will be used.
>>>
>>>looping the patterns doesn't work the way I want. Appreciate any
>>>comments.
>>>Thanks.
>>>
>>>Jun
>>>
>>>   [[alternative HTML version deleted]]
>>>
>>>__
>>>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>>https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] sim() not working in example given in lava() documentation - please help.

2016-09-05 Thread PIKAL Petr
Hi

First I thought that it could be due to variables which can be defined in your 
workspace however I had also x and y defined and did not experience error. I 
tried with the code with m, z, logit and lvm silly defined as variables but I 
did not experience any error too.

So I have no clue how you managed to get such error.

Cheers
Petr



From: John Hillier [mailto:j.hill...@lboro.ac.uk]
Sent: Monday, September 5, 2016 3:35 PM
To: PIKAL Petr ; r-help mailing list 

Subject: Re: [R] sim() not working in example given in lava() documentation - 
please help.


Thank you very much Petr! An external check like you did really helps.



After shutting down, I've started new session and project in a different 
directory and it's working.



I will know next time that with R a full "turn it off and turn it on again" can 
make a difference even when I can't see why it should :-)



John


-
Dr John Hillier
Senior Lecturer - Physical Geography
Loughborough University
01509 223727

From: PIKAL Petr mailto:petr.pi...@precheza.cz>>
Sent: 05 September 2016 14:01:52
To: John Hillier; r-help mailing list
Subject: RE: [R] sim() not working in example given in lava() documentation - 
please help.

Hi

I do not know anything about lava, however this

m <- lvm(y~x+z)
regression(m) <- x~z
distribution(m,~y+z) <- binomial.lvm("logit")
d <- sim(m,1e3)
head(d)
  y  x z
1 1  1.0033540 1
2 0  0.3834120 0
3 1 -0.3737790 1
4 1 -1.2927288 0
5 0 -0.4242461 1
6 0 -1.8349548 0
>

gives me some result without any error.

So obviosly something is broken in your side. Try to start clean R session and 
try this code again.

Cheers
Petr

> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of John Hillier
> Sent: Monday, September 5, 2016 2:19 PM
> To: r-help mailing list mailto:R-help@r-project.org>>
> Subject: [R] sim() not working in example given in lava() documentation -
> please help.
>
> Dear All,
>
> I am trying to simulate using a statistical model created in the lava() 
> package.
> My model gave the error message "Error in rep(0, ncol(fx)) : invalid 'times'
> argument". So, I used the example in the documentation for the lava()
> package - v1.4.4, on page 79; this is copied below with the output.  It did 
> the
> same thing.
>
> I can plot and view the model, so it appears to have been created correctly.
>
> I am relative new to this, so don't have a good idea of where to start when a
> standard example fails like this. I have tried naive fiddling with the code, 
> and
> Googling.  Any advice would be much appreciated.
>
> Thank you
>
> John
>
> > ##
> > ## Logistic regression
> > ##
> > m <- lvm(y~x+z)
> > regression(m) <- x~z
> > distribution(m,~y+z) <- binomial.lvm("logit")
> > d <- sim(m,1e3)
> Error in rep(0, ncol(fx)) : invalid 'times' argument
>
>
>
>
> -
> Dr John Hillier
> Senior Lecturer - Physical Geography
> Loughborough University
> 01509 223727
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To 
> UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.


Tento e-mail a jak�koliv k n�mu p�ipojen� dokumenty jsou d�v�rn� a jsou ur�eny 
pouze jeho adres�t�m.
Jestli�e jste obdr�el(a) tento e-mail omylem, informujte laskav� neprodlen� 
jeho odes�latele. Obsah tohoto emailu i s p��lohami a jeho kopie vyma�te ze 
sv�ho syst�mu.
Nejste-li zam��len�m adres�tem tohoto emailu, nejste opr�vn�ni tento email 
jakkoliv u��vat, roz�i�ovat, kop�rovat �i zve�ej�ovat.
Odes�latel e-mailu neodpov�d� za eventu�ln� �kodu zp�sobenou modifikacemi �i 
zpo�d�n�m p�enosu e-mailu.

V p��pad�, �e je tento e-mail sou��st� obchodn�ho jedn�n�:
- vyhrazuje si odes�latel pr�vo ukon�it kdykoliv jedn�n� o uzav�en� smlouvy, a 
to z jak�hokoliv d�vodu i bez uveden� d�vodu.
- a obsahuje-li nab�dku, je adres�t opr�vn�n nab�dku bezodkladn� p�ijmout; 
Odes�latel tohoto e-mailu (nab�dky) vylu�uje p�ijet� nab�dky ze strany p��jemce 
s dodatkem �i odchylkou.
- trv� odes�latel na tom, �e p��slu�n� smlouva je uzav�ena teprve v�slovn�m 
dosa�en�m shody na v�ech jej�ch n�le�itostech.
- odes�latel tohoto emailu informuje, �e nen� opr�vn�n uzav�rat za spole�nost 
��dn� smlouvy s v�jimkou p��pad�, kdy k tomu byl p�semn� zmocn�n nebo p�semn� 
pov��en a takov� pov��en� nebo pln� moc byly adres�tovi tohoto emailu p��padn� 
osob�, kterou adres�t zastupuje, p�edlo�eny nebo jejich existence je adres�tovi 
�i osob� j�m zastoupen� zn�m�.

This e-mail and any documents attached to it may be confidential and are 
intended only for its intended rec

Re: [R] Error in reading subset of data from CSV file

2016-09-05 Thread David L Carlson
Try changing the separator to ;

# write.table() instead of write.csv()
> write.table(Dat, "Dat.csv", quote = FALSE, sep=";", row.names = FALSE)
> readLines("Dat.csv")
[1] "col 1;col 2;col 3;col 4;col 5;col 6" 
[2] "133261;aaa1;10.59;10.59;10.59;04-Jul-16" 
[3] "133261;aaa2;10.56;10.56;10.56;05-Jul-16" 
[4] "133262;bbb1, bbb;10.59;10.59;10.59;04-Jul-16"
[5] "133262;bbb3, bbb;10.56;10.56;10.56;05-Jul-16"
# Note read.csv2.sql() not read.csv.sql()
> read.csv2.sql("Dat.csv", sql = "select * from file where 'col 1' = ReadName", 
> header=TRUE)
Error in sqliteSendQuery(con, statement, bind.data) : 
  error in statement: no such column: ReadName
In addition: Warning message:
closing unused connection 3 (Dat.csv)

-
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Jim Lemon
Sent: Sunday, September 4, 2016 6:39 AM
To: Christofer Bogaso
Cc: r-help
Subject: Re: [R] Error in reading subset of data from CSV file

Shouldn't get that with write.csv.

Jim


On Sun, Sep 4, 2016 at 9:29 PM, Christofer Bogaso
 wrote:
> Didnt work getting unused argument error.
>
> On Sun, Sep 4, 2016 at 4:47 PM, Jim Lemon  wrote:
>> I suppose you could try quote=TRUE
>>
>> Jim
>>
>>
>> On Sun, Sep 4, 2016 at 8:13 PM, Christofer Bogaso
>>  wrote:
>>> Thanks Jim. But my data is like that and I have to live with that. Any
>>> idea on workaround. Thanks,
>>>
>>> On Sun, Sep 4, 2016 at 3:40 PM, Jim Lemon  wrote:
 Hi Christofer,
 You have embedded commas in your data structure. This is guaranteed to
 mess up a CSV read.

 Jim


 On Sun, Sep 4, 2016 at 5:54 PM, Christofer Bogaso
  wrote:
> Hi again,
>
> I was trying to read a subset of Data from a CSV file using below code
> as example :
>
> library(sqldf)
>
> Dat = structure(list(`col 1` = c(133261L, 133261L, 133262L, 133262L
> ), `col 2` = structure(1:4, .Label = c("aaa1", "aaa2", "bbb1, bbb",
> "bbb3, bbb"), class = "factor"), `col 3` = c(10.59, 10.56, 10.59,
> 10.56), `col 4` = c(10.59, 10.56, 10.59, 10.56), `col 5` = c(10.59,
> 10.56, 10.59, 10.56), `col 6` = structure(c(1L, 2L, 1L, 2L), .Label =
> c("04-Jul-16",
> "05-Jul-16"), class = "factor")), .Names = c("col 1", "col 2",
> "col 3", "col 4", "col 5", "col 6"), class = "data.frame", row.names = 
> c(NA,
> -4L))
> Dat
>
> write.csv(Dat, "Dat.csv", quote = FALSE, row.names = FALSE)
>
> ReadName = '133261'
> read.csv.sql("Dat.csv", sql = "select * from file where 'col 1' = 
> ReadName")
>
> Loading required package: tcltk
> Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, 
> na.strings,  :
>   line 1 did not have 7 elements
>
> This code generates above Error. Could you please help me with a
> pointer where something went wrong? My actual CSV file is quite huge
> so I cant read it as whole. However basic structure of my original
> file is similar as above "Dat"
>
> Thanks for your time.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] sim() not working in example given in lava() documentation - please help.

2016-09-05 Thread John Hillier
Thank you very much Petr! An external check like you did really helps.


After shutting down, I've started new session and project in a different 
directory and it's working.


I will know next time that with R a full "turn it off and turn it on again" can 
make a difference even when I can't see why it should :-)


John


-
Dr John Hillier
Senior Lecturer - Physical Geography
Loughborough University
01509 223727

From: PIKAL Petr 
Sent: 05 September 2016 14:01:52
To: John Hillier; r-help mailing list
Subject: RE: [R] sim() not working in example given in lava() documentation - 
please help.

Hi

I do not know anything about lava, however this

m <- lvm(y~x+z)
regression(m) <- x~z
distribution(m,~y+z) <- binomial.lvm("logit")
d <- sim(m,1e3)
head(d)
  y  x z
1 1  1.0033540 1
2 0  0.3834120 0
3 1 -0.3737790 1
4 1 -1.2927288 0
5 0 -0.4242461 1
6 0 -1.8349548 0
>

gives me some result without any error.

So obviosly something is broken in your side. Try to start clean R session and 
try this code again.

Cheers
Petr

> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of John Hillier
> Sent: Monday, September 5, 2016 2:19 PM
> To: r-help mailing list 
> Subject: [R] sim() not working in example given in lava() documentation -
> please help.
>
> Dear All,
>
> I am trying to simulate using a statistical model created in the lava() 
> package.
> My model gave the error message "Error in rep(0, ncol(fx)) : invalid 'times'
> argument". So, I used the example in the documentation for the lava()
> package - v1.4.4, on page 79; this is copied below with the output.  It did 
> the
> same thing.
>
> I can plot and view the model, so it appears to have been created correctly.
>
> I am relative new to this, so don't have a good idea of where to start when a
> standard example fails like this. I have tried naive fiddling with the code, 
> and
> Googling.  Any advice would be much appreciated.
>
> Thank you
>
> John
>
> > ##
> > ## Logistic regression
> > ##
> > m <- lvm(y~x+z)
> > regression(m) <- x~z
> > distribution(m,~y+z) <- binomial.lvm("logit")
> > d <- sim(m,1e3)
> Error in rep(0, ncol(fx)) : invalid 'times' argument
>
>
>
>
> -
> Dr John Hillier
> Senior Lecturer - Physical Geography
> Loughborough University
> 01509 223727
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.


Tento e-mail a jak�koliv k n�mu p�ipojen� dokumenty jsou d�v�rn� a jsou ur�eny 
pouze jeho adres�t�m.
Jestli�e jste obdr�el(a) tento e-mail omylem, informujte laskav� neprodlen� 
jeho odes�latele. Obsah tohoto emailu i s p��lohami a jeho kopie vyma�te ze 
sv�ho syst�mu.
Nejste-li zam��len�m adres�tem tohoto emailu, nejste opr�vn�ni tento email 
jakkoliv u��vat, roz�i�ovat, kop�rovat �i zve�ej�ovat.
Odes�latel e-mailu neodpov�d� za eventu�ln� �kodu zp�sobenou modifikacemi �i 
zpo�d�n�m p�enosu e-mailu.

V p��pad�, �e je tento e-mail sou��st� obchodn�ho jedn�n�:
- vyhrazuje si odes�latel pr�vo ukon�it kdykoliv jedn�n� o uzav�en� smlouvy, a 
to z jak�hokoliv d�vodu i bez uveden� d�vodu.
- a obsahuje-li nab�dku, je adres�t opr�vn�n nab�dku bezodkladn� p�ijmout; 
Odes�latel tohoto e-mailu (nab�dky) vylu�uje p�ijet� nab�dky ze strany p��jemce 
s dodatkem �i odchylkou.
- trv� odes�latel na tom, �e p��slu�n� smlouva je uzav�ena teprve v�slovn�m 
dosa�en�m shody na v�ech jej�ch n�le�itostech.
- odes�latel tohoto emailu informuje, �e nen� opr�vn�n uzav�rat za spole�nost 
��dn� smlouvy s v�jimkou p��pad�, kdy k tomu byl p�semn� zmocn�n nebo p�semn� 
pov��en a takov� pov��en� nebo pln� moc byly adres�tovi tohoto emailu p��padn� 
osob�, kterou adres�t zastupuje, p�edlo�eny nebo jejich existence je adres�tovi 
�i osob� j�m zastoupen� zn�m�.

This e-mail and any documents attached to it may be confidential and are 
intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. 
Delete the contents of this e-mail with all attachments and its copies from 
your system.
If you are not the intended recipient of this e-mail, you are not authorized to 
use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by 
modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a 
contract in any time, for any reason, and without stating a

Re: [R] sim() not working in example given in lava() documentation - please help.

2016-09-05 Thread PIKAL Petr
Hi

I do not know anything about lava, however this

m <- lvm(y~x+z)
regression(m) <- x~z
distribution(m,~y+z) <- binomial.lvm("logit")
d <- sim(m,1e3)
head(d)
  y  x z
1 1  1.0033540 1
2 0  0.3834120 0
3 1 -0.3737790 1
4 1 -1.2927288 0
5 0 -0.4242461 1
6 0 -1.8349548 0
>

gives me some result without any error.

So obviosly something is broken in your side. Try to start clean R session and 
try this code again.

Cheers
Petr

> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of John Hillier
> Sent: Monday, September 5, 2016 2:19 PM
> To: r-help mailing list 
> Subject: [R] sim() not working in example given in lava() documentation -
> please help.
>
> Dear All,
>
> I am trying to simulate using a statistical model created in the lava() 
> package.
> My model gave the error message "Error in rep(0, ncol(fx)) : invalid 'times'
> argument". So, I used the example in the documentation for the lava()
> package - v1.4.4, on page 79; this is copied below with the output.  It did 
> the
> same thing.
>
> I can plot and view the model, so it appears to have been created correctly.
>
> I am relative new to this, so don't have a good idea of where to start when a
> standard example fails like this. I have tried naive fiddling with the code, 
> and
> Googling.  Any advice would be much appreciated.
>
> Thank you
>
> John
>
> > ##
> > ## Logistic regression
> > ##
> > m <- lvm(y~x+z)
> > regression(m) <- x~z
> > distribution(m,~y+z) <- binomial.lvm("logit")
> > d <- sim(m,1e3)
> Error in rep(0, ncol(fx)) : invalid 'times' argument
>
>
>
>
> -
> Dr John Hillier
> Senior Lecturer - Physical Geography
> Loughborough University
> 01509 223727
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.


Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny 
pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně 
jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze 
svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email 
jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či 
zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a 
to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; 
Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce 
s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným 
dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost 
žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně 
pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně 
osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi 
či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are 
intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. 
Delete the contents of this e-mail with all attachments and its copies from 
your system.
If you are not the intended recipient of this e-mail, you are not authorized to 
use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by 
modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a 
contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately 
accept such offer; The sender of this e-mail (offer) excludes any acceptance of 
the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an 
express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into 
any contracts on behalf of the company except for cases in which he/she is 
expressly authorized to do so in writing, and such authorization or power of 
attorney is submitted to the recipient or the 

Re: [R] substring simultaneous conditions

2016-09-05 Thread ruipbarradas

Hello,

Try placing the & immediately after the substr() conditions, like this:


base <- baseR[substr(baseR[['ID']],3,4)!='03' &
substr(baseR[['ID']],11,12)!='01' &
substr(baseR[['ID']],11,12)!='11',]


Maybe I'm wrong but R might have decided that the instructions were  
complete before the next lines were reached.

And your attachment didn't make through. Use dput to post a data example.

dput(head(baseR, 30))  #paste the output of this in a mail


Hope this helps,

Rui Barradas




Citando Rosa Oliveira :


Dear all,

I have searched all over and didn´t found an answer :( Sorry, I'm new.

I need urgently to "not analyse"the weight the ID's that have 07 in the
position 3 and 4 respectively, 01 or 11 in positions 11 and 12 of ID
variable. .

I used the following code:

base<--baseR[substr(baseR$'ID',3,4)!='03'
  &substr(baseR$'ID',11,12)!='01'
   &substr(baseR$'ID',11,12)!='11',]

But, instead of removing just the id's that respect the 3 conditions
simultaneously, base don't have all the id's that have 03 in the 3 and 4
positions os id variable, neither 01  in positions 11 and 12 of ID,  
neither 11

in positions 11 and 12 of ID variable.variable.

So, it seems, that the code exclude all the conditions, as it was a OR (|)
condition in spite of AND (&) condition.

Can anyone help me please?

I attach the data.

Best,
Rosa Oliveira

__

Antes de imprimir este e-mail pense bem se tem mesmo que o fazer.
Há cada vez menos árvores.
Não imprima, pense na sua responsabilidade e compromisso com o MEIO
AMBIENTE!


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] substring simultaneous conditions

2016-09-05 Thread Ulrik Stervbo
Dear Rosa,

you can use grep for pattern matching along the lines of:

x <- c("00071101", "0007", "00071112","123456789123")

grep("^[0-9]{2}07[0-9]{6}(01|11)", x)

Here I assume that your real IDs consist of integers only. The pattern
matches two integers followed by 07 followed by 6 integers and finally 01
or 11

Hope this helps,
Ulrik

On Mon, 5 Sep 2016 at 13:54 Rosa Oliveira  wrote:

> Dear all,
>
> I have searched all over and didn´t found an answer :( Sorry, I'm new.
>
> I need urgently to "not analyse"the weight the ID's that have 07 in the
> position 3 and 4 respectively, 01 or 11 in positions 11 and 12 of ID
> variable. .
>
> I used the following code:
>
> base<--baseR[substr(baseR$'ID',3,4)!='03'
>   &substr(baseR$'ID',11,12)!='01'
>&substr(baseR$'ID',11,12)!='11',]
>
> But, instead of removing just the id's that respect the 3 conditions
> simultaneously, base don't have all the id's that have 03 in the 3 and 4
> positions os id variable, neither 01  in positions 11 and 12 of ID,
> neither 11
> in positions 11 and 12 of ID variable.variable.
>
> So, it seems, that the code exclude all the conditions, as it was a OR (|)
> condition in spite of AND (&) condition.
>
> Can anyone help me please?
>
> I attach the data.
>
> Best,
> Rosa Oliveira
>
> __
>
> Antes de imprimir este e-mail pense bem se tem mesmo que o fazer.
> Há cada vez menos árvores.
> Não imprima, pense na sua responsabilidade e compromisso com o MEIO
> AMBIENTE!
> <
> http://pt.dreamstime.com/cora-ccedil-atildeo-criado-das-folhas-de-aacutervores-diferentes-thumb12275776.jpg
> >
> <
> http://pt.dreamstime.com/cora-ccedil-atildeo-criado-das-folhas-de-aacutervores-diferentes-thumb12275776.jpg
> >
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] sim() not working in example given in lava() documentation - please help.

2016-09-05 Thread John Hillier
Dear All,

I am trying to simulate using a statistical model created in the lava() 
package.  My model gave the error message "Error in rep(0, ncol(fx)) : invalid 
'times' argument". So, I used the example in the documentation for the lava() 
package - v1.4.4, on page 79; this is copied below with the output.  It did the 
same thing.

I can plot and view the model, so it appears to have been created correctly.

I am relative new to this, so don't have a good idea of where to start when a 
standard example fails like this. I have tried naive fiddling with the code, 
and Googling.  Any advice would be much appreciated.

Thank you

John

> ##
> ## Logistic regression
> ##
> m <- lvm(y~x+z)
> regression(m) <- x~z
> distribution(m,~y+z) <- binomial.lvm("logit")
> d <- sim(m,1e3)
Error in rep(0, ncol(fx)) : invalid 'times' argument




-
Dr John Hillier
Senior Lecturer - Physical Geography
Loughborough University
01509 223727

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] substring simultaneous conditions

2016-09-05 Thread Rosa Oliveira
Dear all,

I have searched all over and didn´t found an answer :( Sorry, I'm new.

I need urgently to "not analyse"the weight the ID's that have 07 in the
position 3 and 4 respectively, 01 or 11 in positions 11 and 12 of ID
variable. .

I used the following code:

base<--baseR[substr(baseR$'ID',3,4)!='03'
  &substr(baseR$'ID',11,12)!='01'
   &substr(baseR$'ID',11,12)!='11',]

But, instead of removing just the id's that respect the 3 conditions
simultaneously, base don't have all the id's that have 03 in the 3 and 4
positions os id variable, neither 01  in positions 11 and 12 of ID, neither 11
in positions 11 and 12 of ID variable.variable.

So, it seems, that the code exclude all the conditions, as it was a OR (|)
condition in spite of AND (&) condition.

Can anyone help me please?

I attach the data.

Best,
Rosa Oliveira

__

Antes de imprimir este e-mail pense bem se tem mesmo que o fazer.
Há cada vez menos árvores.
Não imprima, pense na sua responsabilidade e compromisso com o MEIO
AMBIENTE!


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

[R] Fwd: Splines

2016-09-05 Thread Filippo Monari
Hi,
does anybody know what header file includes the bspline functions used in R?

Regards,
Filippo


 Forwarded Message 
Subject:Splines
Date:   Sun, 04 Sep 2016 09:12:37 +0100
From:   Filippo Monari 
To: R-help@r-project.org



Hi,
I would like to use the C spline functions if R for a FORTRAN subroutine. What 
header file should I refer to?

Regards
Filippo Monari




[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] conditional gap time frailty cox model for recurrent events

2016-09-05 Thread Göran Broström

Dear Elisabetta,

I have no direct answer to your question, but a suggestion: Use the 
'coxme' function (in the package with the same name). In the help page 
for 'frailty' (survival) you will find: "The coxme package has 
superseded this method. It is faster, more stable, and more flexible."


Hth, Göran

On 2016-09-05 11:42, Elisabetta Petracci wrote:

Dear users,

I am fitting a conditional gap time frailty cox model weighting
observations by means of inverse probability time dependent weigths.
Attached find the self-explaining dataset.

I have used the following sintax:

coxph(Surv(gaptstart,gaptstop,status)~treat+strata(nrecord01)+frailty(id,distribution="gamma",method="em"),
data=dataNOTDrr,weights=dataNOTDrr$weight)


And I get the following warning:

Warning message:
In coxpenal.fit(X, Y, strats, offset, init = init, control, weights =
weights,  :
  Inner loop failed to coverge for iterations 3 4


I have tried to:
- leave out the weights but I get the error anyway
- to randomly select a subset of patients and I don't get the error. This
seems to suggest that the problem is with some observations.

Any suggestion?

Many thanks,

Elisabetta
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] conditional gap time frailty cox model for recurrent events

2016-09-05 Thread Elisabetta Petracci
Dear users,

I am fitting a conditional gap time frailty cox model weighting
observations by means of inverse probability time dependent weigths.
Attached find the self-explaining dataset.

I have used the following sintax:

coxph(Surv(gaptstart,gaptstop,status)~treat+strata(nrecord01)+frailty(id,distribution="gamma",method="em"),
data=dataNOTDrr,weights=dataNOTDrr$weight)


And I get the following warning:

Warning message:
In coxpenal.fit(X, Y, strats, offset, init = init, control, weights =
weights,  :
  Inner loop failed to coverge for iterations 3 4


I have tried to:
- leave out the weights but I get the error anyway
- to randomly select a subset of patients and I don't get the error. This
seems to suggest that the problem is with some observations.

Any suggestion?

Many thanks,

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