Re: [R] dput(treat)

2017-10-11 Thread roslinazairimah zakaria
Hi,

If you have a data, run dput(data), then in the console you will see the
output.  Copy the output and place it in your email.

HTH.

On Wed, Oct 11, 2017 at 6:59 PM, Ted Beginner (RStudio) via R-help <
r-help@r-project.org> wrote:

>
> I got advice here that I didn't understand! Can I ask to explain me the
> meaning of this procedure: first get the structure, and then assign it
> back. For what? Thanks!  (Great thanks to Moderator/Admin!)
>
> You should learn to post in plain text and use dput to present your data
> structures. At your console do this
> dput(treat)
> # and this will appear. Copy it to your plain-text message:
> structure(list(ID = 1:5, start = c(0L, 0L, 0L, 0L, 0L), stop = c(66L,
> 18L, 43L, 47L, 26L), censor = c(0L, 0L, 1L, 1L, 0L), sex = c(2L,
> 1L, 2L, 2L, 1L), age = c(1L, 2L, 3L, 3L, 4L), stage = c(3L, 4L,
> 3L, NA, 3L), treatment = c(1L, 2L, 1L, 2L, NA)), .Names = c("ID",
> "start", "stop", "censor", "sex", "age", "stage", "treatment"
> ), class = "data.frame", row.names = c("1", "2", "3", "4", "5"
> )):
> Then we can just do this:
>  treat <- structure(list(ID = 1:5, start = c(0L, 0L, 0L, 0L, 0L), stop =
> c(66L,
> 18L, 43L, 47L, 26L), censor = c(0L, 0L, 1L, 1L, 0L), sex = c(2L,
> 1L, 2L, 2L, 1L), age = c(1L, 2L, 3L, 3L, 4L), stage = c(3L, 4L,
> 3L, NA, 3L), treatment = c(1L, 2L, 1L, 2L, NA)), .Names = c("ID",
> "start", "stop", "censor", "sex", "age", "stage", "treatment"
> ), class = "data.frame", row.names = c("1", "2", "3", "4", "5"
> ))
>
> [[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.




-- 
*Roslinazairimah Zakaria*
*Tel: +609-5492370; Fax. No.+609-5492766*

*Email: roslinazairi...@ump.edu.my ;
roslina...@gmail.com *
Faculty of Industrial Sciences & Technology
University Malaysia Pahang
Lebuhraya Tun Razak, 26300 Gambang, Pahang, Malaysia

[[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-es] ggplot ayuda con argumento

2017-10-11 Thread Freddy Omar López Quintero
Hola.

Plagiando parte de lo que está en:

>
>
> https://stackoverflow.com/questions/12018499/how-to-put-labels-over-geom-bar-for-each-bar-in-r-with-ggplot2
>

se puede usar algo como:

dat <- read.table(text = "sample Types Number
> sample1 A   3641
> sample2 A   3119
> sample1 B   15815
> sample2 B   12334
> sample1 C   2706
> sample2 C   3147", header=TRUE)
>
> ggplot(data=dat, aes(x=Types, y=Number, fill=sample)) +  geom_bar(position
> = "dodge", stat="identity") + geom_text(aes(label=Number),
> position=position_dodge(width=0.9), vjust=-0.25)
>

Esto fue hecho para una tabla que ya tenía agrupadas las cantidades. En
cualquier caso, las modificaciones que debes hacer parece que son remover
los elementos del dodge y acomodar el vjust.

Otro ejemplo hay en

https://stackoverflow.com/questions/32986651/display-frequency-and-count-on-a-bar-chart
>
​
Ojalá este plagio casi absoluto sirva de algo.

¡Salud!

2017-10-11 22:19 GMT-03:00 Kelly Johanna Monroy Malagon <
kjmonr...@unal.edu.co>:

> Buenas Noches
>
> Estoy trabajando con R, con ggplot
> y deseo insertar el valor en la parte superior de cada uno de los
> rectángulos del gráfico, pero no se que argumento debo implementar,,
> cualquier ayuda o concejo sera bien recibido
>
> Muchas Gracias
>
>
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>



-- 
«...homines autem hominum causa esse generatos...»

Cicero

[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

Re: [R] issues with the WD

2017-10-11 Thread Jim Lemon
Hi Peter,
What is the command that you used in R-3.1.1? If this is embedded in
code, do you still have the same directory structure that you had
then?

Jim


On Thu, Oct 12, 2017 at 1:48 AM, Peter Wight  wrote:
> ood morning,
>
> I am reaching out to discus an issue I am having with setting a working
> directing.
>
> I have tried github, stack overload, setwd, getwd, all to no avail. I am
> used to setting a working directory in 3.1.1 and have yet to get 3.4.1 to
> work properly.
>
> Let me know if there is anyone who I can talk to about this.
>
> Thank you so much,
>
> My best,
>
> Peter Wight, MPA
>
> [[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.


Re: [R] RFM analysis

2017-10-11 Thread Jim Lemon
Hi Hemant,
Let's take it one step at a time. Save this code as "qdrfm.R" in your
R working directory: It includes the comments I added last time and
fixes a bug in the recency scoring.

qdrfm<-function(x,rbreaks=3,fbreaks=3,mbreaks=3,
 date.format="%Y-%m-%d",weights=c(1,1,1),finish=NA) {

 # if no finish date is specified, use current date
 if(is.na(finish)) finish<-as.Date(date(), "%a %b %d %H:%M:%S %Y")
 x$rscore<-as.numeric(finish-as.Date(x[,3],date.format))
 cat("Range of purchase recency",range(x$rscore),"\n")
 cat("Range of purchase freqency",range(table(x[,1])),"\n")
 cat("Range of purchase amount",range(by(x[,2],x[,1],sum)),"\n")
 custIDs<-unique(x[,1])
 ncust<-length(custIDs)
 # initialize a data frame to hold the output
 rfmout<-data.frame(custID=custIDs,rscore=rep(0,ncust),
  fscore=rep(0,ncust),mscore=rep(0,ncust))
 # categorize the minimum number of days
 # since last purchase for each customer
 rfmout$rscore<-cut(by(x$rscore,x[,1],min),breaks=rbreaks,labels=FALSE)
 # categorize the number of purchases
 # recorded for each customer
 rfmout$fscore<-cut(table(x[,1]),breaks=fbreaks,labels=FALSE)
 # categorize the amount purchased
 # by each customer
 rfmout$mscore<-cut(by(x[,2],x[,1],sum),breaks=mbreaks,labels=FALSE)
 # calculate the RFM score from the
 # optionally weighted average of the above
 rfmout$cscore<-round((weights[1]*rfmout$rscore+
  weights[2]*rfmout$fscore+
  weights[3]*rfmout$mscore)/sum(weights),2)
 return(rfmout[order(rfmout$cscore),])
}

Now you can load the function into your workspace like this:

source("qdrfm.R")

Load your data:

df<-read.csv("df.csv")

Run the function with the defaults except for the finish date:

df.rfm<-qdrfm(df,finish=as.Date("2017-08-31"))
Range of purchase recency 31 122
Range of purchase freqency 1 4
Range of purchase amount 5.97 127.65

Your problem is now apparent. If I use the following breaks, I will
generate NA values in all three scores:

df.rfm2<-qdrfm(df,rbreaks=c(10,30,50),fbreaks=c(1,2,3),
 mbreaks=c(8,14,400),finish=as.Date("2017-08-31"))
head(df.rfm2)

As I wrote before, the breaks _must_ cover the range of values if you
want a sensible analysis:

df.rfm3<-qdrfm(df,rbreaks=c(0,75,150),fbreaks=c(0,2,5),
 mbreaks=c(0,75,150),finish=as.Date("2017-08-31"))
head(df.rfm3)

Looking at df.rfm3, it seems that the recency score is the only one
discriminating users. This suggests to me that the data distributions
are causing a problem.  First, you have 946 users in a dataset of 1000
rows, meaning that almost all made only one transaction. Second, your
purchase amounts are concentrated in the 0-20 range. Therefore if I
change the breaks to reflect this, I get a much better separation of
customers:

df.rfm4<-qdrfm(df,rbreaks=c(0,75,150),fbreaks=c(0,1,5),
 mbreaks=c(0,10,150),finish=as.Date("2017-08-31"))

Maybe this will get you going.

Jim

On Wed, Oct 11, 2017 at 4:43 PM, Hemant Sain  wrote:
> Also try to put finish date as 2017-08-31.
> and help me with the complete running r code.
>
> On 11 October 2017 at 10:36, Hemant Sain  wrote:
>>
>> Hey Jim,
>> i'm attaching you the actual dataset i'm working on and i want RFM breaks
>> as
>> r=(10,30,50), f=(1,2,3),m=(8,14,400).
>>

__
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] about taylor.diagram

2017-10-11 Thread Jim Lemon
Hi lily,
I assume that you are using the taylor.diagram function from the
plotrix package. You have most likely started a plot window that is
not square or specified margins that distort the plot. As your image
did not come through, we can't see what has gone wrong.

Jim

On Wed, Oct 11, 2017 at 3:22 PM, lily li  wrote:
> Hi R users,
>
> I don't know if you have used taylor.diagram function. Why my diagram is
> not like 1/4th of a round shape, but more flat, like 1/4th of an oval?
> Thanks.
>
> [[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.


Re: [R] Converting SAS Code

2017-10-11 Thread Mitchell Maltenfort
I believe the lmerTest package's "difflsmeans" is what you need.

On Wed, Oct 11, 2017 at 2:33 PM, Andrew Harmon 
wrote:

> I have no problem setting up my mixed model, or performing anova or lsmeans
> on my model’s outputs. However, performing lsd mean separation is giving me
> fits.
>
>
>
> So I do not have a problem when using two-way anova model. When using the
> code:
>
> fit.yield.add <- lm(data = ryzup, Yield ~ Rep + Nitrogen + Treatment)
>
> LSD.test(fit.yield.add, trt = "Nitrogen", alpha = 0.1, console = TRUE)
>
>
>
> It works beautifully. However when I run a mixed model:
>
>
>
> yield.lmer <- lmer(data = ryzup, Yield ~ Nitrogen + Treatment +
> (1|Rep/Nitrogen), REML = FALSE)
>
> LSD.test(yield.lmer, trt = "Nitrogen", alpha = 0.1, console = TRUE)
>
>
>
> It gives me fits. It produces errors like:
>
>
>
> Error in as.data.frame.default(x[[i]], optional = TRUE) :
>
>   cannot coerce class "structure("merModLmerTest", package = "lmerTest")"
> to a data.frame
>
>
> Do you have any suggestions for that?
>
> Thanks
>
> [[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.
>

[[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] Converting SAS Code

2017-10-11 Thread Andrew Harmon
I have no problem setting up my mixed model, or performing anova or lsmeans
on my model’s outputs. However, performing lsd mean separation is giving me
fits.



So I do not have a problem when using two-way anova model. When using the
code:

fit.yield.add <- lm(data = ryzup, Yield ~ Rep + Nitrogen + Treatment)

LSD.test(fit.yield.add, trt = "Nitrogen", alpha = 0.1, console = TRUE)



It works beautifully. However when I run a mixed model:



yield.lmer <- lmer(data = ryzup, Yield ~ Nitrogen + Treatment +
(1|Rep/Nitrogen), REML = FALSE)

LSD.test(yield.lmer, trt = "Nitrogen", alpha = 0.1, console = TRUE)



It gives me fits. It produces errors like:



Error in as.data.frame.default(x[[i]], optional = TRUE) :

  cannot coerce class "structure("merModLmerTest", package = "lmerTest")"
to a data.frame


Do you have any suggestions for that?

Thanks

[[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] issues with the WD

2017-10-11 Thread Peter Wight
ood morning,

I am reaching out to discus an issue I am having with setting a working
directing.

I have tried github, stack overload, setwd, getwd, all to no avail. I am
used to setting a working directory in 3.1.1 and have yet to get 3.4.1 to
work properly.

Let me know if there is anyone who I can talk to about this.

Thank you so much,

My best,

Peter Wight, MPA

[[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] about taylor.diagram

2017-10-11 Thread David Winsemius

> On Oct 10, 2017, at 9:22 PM, lily li  wrote:
> 
> Hi R users,
> 
> I don't know if you have used taylor.diagram function. Why my diagram is
> not like 1/4th of a round shape, but more flat, like 1/4th of an oval?
> Thanks.

Posters to rhelp are asked in the posting guide to include a call to the 
library function at the start of an example involving a function that will not 
be in the base packages. And they are asked to include code that creates a 
dataset suitable for passing to that function. My personal opinion is htat the 
audience shoudl ignore postings that fail to do this.


> 
>   [[alternative HTML version deleted]]

And HTML mail is not the proper mode for sending postings.

> PLEASE,PLEASE, 
> PLEASE,PLEASE
>  do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA

'Any technology distinguishable from magic is insufficiently advanced.'   
-Gehm's Corollary to Clarke's Third Law

__
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] Iterate in a Spatial Polygon Dataframe in R?

2017-10-11 Thread Jon.SKOIEN

Ashraf,

What do you want your function to do?
Currently you are overwriting p each time you go through your for-loop, and you 
finally return p = x[nrow(x), ]

It is similar to

y = 101:200
for (i in 1:100) {
  x = y[i]
}
x


Best,
Jon


--
Jon Olav Skøien
European Commission
Joint Research Centre – JRC.E.1
Disaster Risk Management Unit
Building 26b 1/144 | Via E.Fermi 2749, I-21027 Ispra (VA) Italy, TP 267
Disclaimer: Views expressed in this email are those of the individual and do 
not necessarily represent official views of the European Commission.



From: R-help [r-help-boun...@r-project.org] on behalf of Ashraf Afana via 
R-help [r-help@r-project.org]
Sent: 11 October 2017 13:55
To: r-help@r-project.org
Subject: [R] Iterate in a Spatial Polygon Dataframe in R?

Hi all,

 I'm trying to iterate in a SpatialPolygonDataFrame thatcontains 110 features. 
I tried to use the following code
iterate.spdf =function(x){ for (i in 1:nrow(x)){ p = x[i, ]} return(p)}
but with no success as it returns with aSpatialPolygonDataFrame that contains 
onlyone feature. The code seems to overwrite the polygons to end up with only 
onefeature.
 Any suggestions?Ashraf, cheers


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


Re: [R] changing "," to "." in data.frame

2017-10-11 Thread David L Carlson
Minor modification:

fff <- function(x) as.numeric(chartr(",", ".", x))
BX <- sapply(AX, fff)

Or this keeps the original data frame:

AX[, 1:2] <- sapply(AX[, 1:2], fff)


David L Carlson
Department of Anthropology
Texas A University
College Station, TX 77843-4352


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of PIKAL Petr
Sent: Wednesday, October 11, 2017 3:00 AM
To: Troels Ring ; r-help@r-project.org
Subject: Re: [R] changing "," to "." in data.frame

And as follow up,

fff<-function(x) gsub(",", ".", x)

BX <- apply(apply(AX, 2, fff), 2, as.numeric)

this seems to be easier.

Cheers
Petr




S pozdravem | Best Regards
RNDr. Petr PIKAL
Vedoucí Výzkumu a vývoje | Research Manager PRECHEZA a.s.
nábř. Dr. Edvarda Beneše 1170/24 | 750 02 Přerov | Czech Republic
Tel: +420 581 252 256 | GSM: +420 724 008 364 petr.pi...@precheza.cz | 
www.precheza.cz

> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Troels 
> Ring
> Sent: Wednesday, October 11, 2017 9:46 AM
> To: r-help@r-project.org
> Subject: [R] changing "," to "." in data.frame
>
> Dear friends - I have a data.frame with "," instead of "." and found 
> the discussion
>
> http://r.789695.n4.nabble.com/How-to-replace-all-commas-with-semicolon
> -in-
> a-string-tt4721187.html#a4721192
>
> so copying the code of Ulrik(I hope:-)) I tried
>
> (making some data)
>
> AX <-
> data.frame(a=chartr(".",",",rnorm(5)),b=chartr(".",",",rnorm(5)),c=rno
> rm(5))
>
>
> library(plyr)
>
> adply(AX, 2, function(x){
> if(!is.numeric(x[[1]]){
> gsub(",", ".", x[[1]])
> }else{
> x[[1]]
> }
> })
>
> and got the unwelcome error
>
> Error: unexpected '{' in:
> "adply(AX, 2, function(x){
> if(!is.numeric(x[[1]]){"
>
> Here is:
>
>  > sessionInfo()
> R version 3.4.1 (2017-06-30)
> Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 7 x64 
> (build 7601) Service Pack 1
>
> Matrix products: default
>
> locale:
> [1] LC_COLLATE=Danish_Denmark.1252  LC_CTYPE=Danish_Denmark.1252 [3]
> LC_MONETARY=Danish_Denmark.1252 LC_NUMERIC=C [5] 
> LC_TIME=Danish_Denmark.1252
>
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods base
>
> other attached packages:
> [1] plyr_1.8.4  TinnRcom_1.0.20 formatR_1.5 svSocket_0.9-57
>
> loaded via a namespace (and not attached):
> [1] compiler_3.4.1 tools_3.4.1svMisc_0.9-70  Rcpp_0.12.13 tcltk_3.4.1
>
> All best wishes
>
> Troels Ring, Aalborg, Denmark
>
> __
> 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, 

[R] Iterate in a Spatial Polygon Dataframe in R?

2017-10-11 Thread Ashraf Afana via R-help

Hi all,

 I'm trying to iterate in a SpatialPolygonDataFrame thatcontains 110 features. 
I tried to use the following code 
iterate.spdf =function(x){ for (i in 1:nrow(x)){ p = x[i, ]} return(p)}
but with no success as it returns with aSpatialPolygonDataFrame that contains 
onlyone feature. The code seems to overwrite the polygons to end up with only 
onefeature.
 Any suggestions?Ashraf, cheers


[[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] dput(treat)

2017-10-11 Thread Rui Barradas

Hello,

The best way to post data is to use dput. The moderator/admin (?) did 
NOT say that you should "first get the structure, and then assign it 
back", they gave you an example of the use of dput and then what us, 
when reading your post would do with that output.


They wrote that "Then we can just do this".

We can simply assign that output to a variable and create an exact copy 
of what you have in your R session, that's why dput is so usefull.


When you post data, always post the output of dput. If it's a large 
dataset, such as a data.frame with many rows, you can post a small 
subset with


dput(head(df, 20))  # or 30 or 50

This will only give the structure of the first 20 (or 30 or 50) rows.


Hope this helps,

Rui Barradas

Em 11-10-2017 11:59, Ted Beginner (RStudio) via R-help escreveu:


I got advice here that I didn't understand! Can I ask to explain me the meaning 
of this procedure: first get the structure, and then assign it back. For what? 
Thanks!  (Great thanks to Moderator/Admin!)

You should learn to post in plain text and use dput to present your data 
structures. At your console do this
dput(treat)
# and this will appear. Copy it to your plain-text message:
structure(list(ID = 1:5, start = c(0L, 0L, 0L, 0L, 0L), stop = c(66L,
18L, 43L, 47L, 26L), censor = c(0L, 0L, 1L, 1L, 0L), sex = c(2L,
1L, 2L, 2L, 1L), age = c(1L, 2L, 3L, 3L, 4L), stage = c(3L, 4L,
3L, NA, 3L), treatment = c(1L, 2L, 1L, 2L, NA)), .Names = c("ID",
"start", "stop", "censor", "sex", "age", "stage", "treatment"
), class = "data.frame", row.names = c("1", "2", "3", "4", "5"
)):
Then we can just do this:
  treat <- structure(list(ID = 1:5, start = c(0L, 0L, 0L, 0L, 0L), stop = c(66L,
18L, 43L, 47L, 26L), censor = c(0L, 0L, 1L, 1L, 0L), sex = c(2L,
1L, 2L, 2L, 1L), age = c(1L, 2L, 3L, 3L, 4L), stage = c(3L, 4L,
3L, NA, 3L), treatment = c(1L, 2L, 1L, 2L, NA)), .Names = c("ID",
"start", "stop", "censor", "sex", "age", "stage", "treatment"
), class = "data.frame", row.names = c("1", "2", "3", "4", "5"
))

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


Re: [R] dput(treat)

2017-10-11 Thread Michael Dewey

Dear Ted

Comments in line

On 11/10/2017 11:59, Ted Beginner (RStudio) via R-help wrote:


I got advice here that I didn't understand! Can I ask to explain me the meaning 
of this procedure: first get the structure, and then assign it back. For what? 
Thanks!  (Great thanks to Moderator/Admin!)

You should learn to post in plain text and use dput to present your data 
structures. At your console do this


So this is what you do to display your data-frame in a plain text way.


dput(treat)
# and this will appear. Copy it to your plain-text message:
structure(list(ID = 1:5, start = c(0L, 0L, 0L, 0L, 0L), stop = c(66L,
18L, 43L, 47L, 26L), censor = c(0L, 0L, 1L, 1L, 0L), sex = c(2L,
1L, 2L, 2L, 1L), age = c(1L, 2L, 3L, 3L, 4L), stage = c(3L, 4L,
3L, NA, 3L), treatment = c(1L, 2L, 1L, 2L, NA)), .Names = c("ID",
"start", "stop", "censor", "sex", "age", "stage", "treatment"
), class = "data.frame", row.names = c("1", "2", "3", "4", "5"
)):


Then this is what we, the readers, do to read in your data-frame so we 
are sure we have exactly the same as you had.



Then we can just do this:
  treat <- structure(list(ID = 1:5, start = c(0L, 0L, 0L, 0L, 0L), stop = c(66L,
18L, 43L, 47L, 26L), censor = c(0L, 0L, 1L, 1L, 0L), sex = c(2L,
1L, 2L, 2L, 1L), age = c(1L, 2L, 3L, 3L, 4L), stage = c(3L, 4L,
3L, NA, 3L), treatment = c(1L, 2L, 1L, 2L, NA)), .Names = c("ID",
"start", "stop", "censor", "sex", "age", "stage", "treatment"
), class = "data.frame", row.names = c("1", "2", "3", "4", "5"
))



If you carry on posting in HTML it is possible that your e-mails will 
get scrambled so it would be best to post in plain text. It does not 
seem to have had a bad effect this time.



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

---
This email has been checked for viruses by AVG.
http://www.avg.com



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

[R] dput(treat)

2017-10-11 Thread RStudio

I got advice here that I didn't understand! Can I ask to explain me the meaning 
of this procedure: first get the structure, and then assign it back. For what? 
Thanks!  (Great thanks to Moderator/Admin!)

You should learn to post in plain text and use dput to present your data 
structures. At your console do this
dput(treat)
# and this will appear. Copy it to your plain-text message:
structure(list(ID = 1:5, start = c(0L, 0L, 0L, 0L, 0L), stop = c(66L,
18L, 43L, 47L, 26L), censor = c(0L, 0L, 1L, 1L, 0L), sex = c(2L,
1L, 2L, 2L, 1L), age = c(1L, 2L, 3L, 3L, 4L), stage = c(3L, 4L,
3L, NA, 3L), treatment = c(1L, 2L, 1L, 2L, NA)), .Names = c("ID",
"start", "stop", "censor", "sex", "age", "stage", "treatment"
), class = "data.frame", row.names = c("1", "2", "3", "4", "5"
)):
Then we can just do this:
 treat <- structure(list(ID = 1:5, start = c(0L, 0L, 0L, 0L, 0L), stop = c(66L,
18L, 43L, 47L, 26L), censor = c(0L, 0L, 1L, 1L, 0L), sex = c(2L,
1L, 2L, 2L, 1L), age = c(1L, 2L, 3L, 3L, 4L), stage = c(3L, 4L,
3L, NA, 3L), treatment = c(1L, 2L, 1L, 2L, NA)), .Names = c("ID",
"start", "stop", "censor", "sex", "age", "stage", "treatment"
), class = "data.frame", row.names = c("1", "2", "3", "4", "5"
))

[[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] Notes for new R version 3.4.2

2017-10-11 Thread Uwe Ligges
Sounds like you have some base packages from an old version of R. 
Perhaps copy in another library tree that comes firt on the search path?


Best,
Uwe Ligges





On 11.10.2017 02:58, kevin luo wrote:

Dear officers,

Sorry to bother you.
Recently, I have installed the R version 3.4.2. But some cautions appear in
the console as the following:
Note: no visible global function definition for 'radixsort'
This note didn't affect the normal operation of some statistical packages.
BUT it does great affect the ggplot2 and the other graphics systems in my
PC.
So, what can I do to fix this bugs or is there any remedy to make things ok?

Thanks for your reading!

Best!

Kai Luo

Ph.D. candidate
Peking Union Medical College
Beijing,China
zip: 100730

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


Re: [R] Unbalanced data in split-plot analysis with aov()

2017-10-11 Thread peter dalgaard

> On 11 Oct 2017, at 00:07 , Samuel Knapp  wrote:
> 
> Dear all,
> 
> I'm analysing a split-plot experiment, where there are sometimes one or 
> two values missing. I realized that if the data is slightly unbalanced, 
> the effect of the subplot-treatment will also appear and be tested 
> against the mainplot-error term.
> 
> I replicated this with the Oats dataset from Yates (1935), contained in 
> the nlme package, where Variety is on mainplot, and nitro on subplot.
> 
>> # Oats dataset (Yates 1935) from the nlme package
>> require(nlme); data <- get(data(Oats))
>> data$nitro <- factor(data$nitro);data$Block <- 
> as.factor(as.character(data$Block))
>> nrow(data) # 6 Blocks * 4 N-levels * 3 Varieties = 72 obs -> 
> orthogonal and balanced
> [1] 72
>> # split-plot anova
>> summary(aov(yield ~ Block+Variety*nitro + Error(Block/Variety),data))
> 
> Error: Block
>   Df Sum Sq Mean Sq
> Block  5  158753175
> 
> Error: Block:Variety
>   Df Sum Sq Mean Sq F value Pr(>F)
> Variety2   1786   893.2   1.485  0.272
> Residuals 10   6013   601.3
> 
> Error: Within
>   Df Sum Sq Mean Sq F value   Pr(>F)
> nitro  3  200206674  37.686 2.46e-12 ***
> Variety:nitro  6322  54   0.3030.932
> Residuals 45   7969 177
> ---
> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>> reduceddata <- data[-5,] # delete one observation
>> summary(aov(yield ~ Block+Variety*nitro + 
> Error(Block/Variety),reduceddata))
> 
> Error: Block
>   Df Sum Sq Mean Sq
> Block  5  160703214
> 
> Error: Block:Variety
>   Df Sum Sq Mean Sq F value Pr(>F)
> Variety2   1820   910.0   1.373  0.302
> nitro  1  1 1.0   0.001  0.970
> Residuals  9   5964   662.7
> 
> Error: Within
>   Df Sum Sq Mean Sq F value   Pr(>F)
> nitro  3  197666589   36.88 4.49e-12 ***
> Variety:nitro  6333  550.310.928
> Residuals 44   7860 179
> 
> Although I fully understand, that mixed-models should be preferred for 
> non-orthogonal/unbalanced data, I think it's still valid to use the 
> aov() approach, when only 1 or 2 datapoints are missing. Also, I don't 
> really understand, why the structure of the ANOVA changes suddenly. Is 
> there any argument, I could supply to change this behaviour?

The answer to this is in the math, and not really possible to cover here. 

If things are non-orthogonal, you don't have the pretty separation of effects 
into error strata and one effect of that is that you can see the same effect 
occurring multiple time with different error terms. (In a plain block design, 
if not all treatments occur equally often in each block, the block means 
contain information about the treatment effects if block effects are considered 
random). 

Worse, if the balanced structure of the design is broken, the orthogonal 
decomposition of random effects does not correspond to the covariance structure 
that you think you are assuming. The consequences of this require considerable 
expertise to figure out. (I forget the details, but the nature is like having 
to assume variance of random effects to depend on block size.)

One known-valid way of dealing with a small number of missing values, is to 
retain the design, set the value of the missing values to something arbitrary, 
and include a dummy variable for each missing observation which is 1 for the 
position of that value and zero elsewhere. You then still get the effect of 
estimating the dummy coefficient in multiple strata corresponding to an 
extended model where the effect of the dummy is different for block means than 
for residuals. However, at least you then know fairly well what is going on. 

So, something like this (removing block from the fixed effects because you also 
had is as a random effect):

> i5 <- rep(0,72); i5[5] <- 1
> summary(aov(yield ~ i5 + nitro*Variety + Error(Block/Variety),data))

Error: Block
  Df Sum Sq Mean Sq F value  Pr(>F)   
i5 1  14163   14163   33.08 0.00453 **
Residuals  4   1713 428   
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Error: Block:Variety
  Df Sum Sq Mean Sq F value Pr(>F)
i5 1 2626.0   0.039  0.847
Variety2   1809   904.7   1.365  0.304
Residuals  9   5964   662.7   

Error: Within
  Df Sum Sq Mean Sq F value   Pr(>F)
i5 1352 352   1.9710.167
nitro  3  197666589  36.885 4.49e-12 ***
nitro:Variety  6333  55   0.3100.928
Residuals 44   7860 179 
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

You will notice that in this analysis, you can modify the value for yield[5] at 
will, and still get the same output, except of course for the "i5" entries. 
Also, quite interestingly, this reproduces the analysis with the 5th obs 
removed, _provided_ that you put nitro before 

Re: [R] changing "," to "." in data.frame

2017-10-11 Thread Eric Berger
Along the lines of Petr's followup:

AXnew <- data.frame(lapply( AX, function(s) sub(",",".",s)))



On Wed, Oct 11, 2017 at 10:59 AM, PIKAL Petr  wrote:

> And as follow up,
>
> fff<-function(x) gsub(",", ".", x)
>
> BX <- apply(apply(AX, 2, fff), 2, as.numeric)
>
> this seems to be easier.
>
> Cheers
> Petr
>
>
>
>
> S pozdravem | Best Regards
> RNDr. Petr PIKAL
> Vedoucí Výzkumu a vývoje | Research Manager
> PRECHEZA a.s.
> nábř. Dr. Edvarda Beneše 1170/24 | 750 02 Přerov | Czech Republic
> Tel: +420 581 252 256 | GSM: +420 724 008 364
> petr.pi...@precheza.cz | www.precheza.cz
>
> > -Original Message-
> > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Troels
> Ring
> > Sent: Wednesday, October 11, 2017 9:46 AM
> > To: r-help@r-project.org
> > Subject: [R] changing "," to "." in data.frame
> >
> > Dear friends - I have a data.frame with "," instead of "." and found the
> > discussion
> >
> > http://r.789695.n4.nabble.com/How-to-replace-all-commas-
> with-semicolon-in-
> > a-string-tt4721187.html#a4721192
> >
> > so copying the code of Ulrik(I hope:-)) I tried
> >
> > (making some data)
> >
> > AX <-
> > data.frame(a=chartr(".",",",rnorm(5)),b=chartr(".",",",
> rnorm(5)),c=rnorm(5))
> >
> >
> > library(plyr)
> >
> > adply(AX, 2, function(x){
> > if(!is.numeric(x[[1]]){
> > gsub(",", ".", x[[1]])
> > }else{
> > x[[1]]
> > }
> > })
> >
> > and got the unwelcome error
> >
> > Error: unexpected '{' in:
> > "adply(AX, 2, function(x){
> > if(!is.numeric(x[[1]]){"
> >
> > Here is:
> >
> >  > sessionInfo()
> > R version 3.4.1 (2017-06-30)
> > Platform: x86_64-w64-mingw32/x64 (64-bit)
> > Running under: Windows 7 x64 (build 7601) Service Pack 1
> >
> > Matrix products: default
> >
> > locale:
> > [1] LC_COLLATE=Danish_Denmark.1252  LC_CTYPE=Danish_Denmark.1252
> > [3] LC_MONETARY=Danish_Denmark.1252 LC_NUMERIC=C
> > [5] LC_TIME=Danish_Denmark.1252
> >
> > attached base packages:
> > [1] stats graphics  grDevices utils datasets  methods base
> >
> > other attached packages:
> > [1] plyr_1.8.4  TinnRcom_1.0.20 formatR_1.5 svSocket_0.9-57
> >
> > loaded via a namespace (and not attached):
> > [1] compiler_3.4.1 tools_3.4.1svMisc_0.9-70  Rcpp_0.12.13 tcltk_3.4.1
> >
> > All best wishes
> >
> > Troels Ring, Aalborg, Denmark
> >
> > __
> > 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 

Re: [R] changing "," to "." in data.frame

2017-10-11 Thread Troels Ring

Thanks a  lot  -

BW
Troels


Den 11-10-2017 kl. 09:58 skrev Berend Hasselman:

On 11 Oct 2017, at 09:45, Troels Ring  wrote:

Dear friends - I have a data.frame with "," instead of "." and found the 
discussion

http://r.789695.n4.nabble.com/How-to-replace-all-commas-with-semicolon-in-a-string-tt4721187.html#a4721192

so copying the code of Ulrik(I hope:-)) I tried

(making some data)

AX <- 
data.frame(a=chartr(".",",",rnorm(5)),b=chartr(".",",",rnorm(5)),c=rnorm(5))

library(plyr)

adply(AX, 2, function(x){
if(!is.numeric(x[[1]]){
gsub(",", ".", x[[1]])
}else{
x[[1]]
}
})

and got the unwelcome error

Error: unexpected '{' in:
"adply(AX, 2, function(x){
if(!is.numeric(x[[1]]){"



Missing ) in if(!is.numeric(x[[1]]){

It should be

if(!is.numeric(x[[1]]) ){

Berend Hasselman


Here is:


sessionInfo()

R version 3.4.1 (2017-06-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=Danish_Denmark.1252  LC_CTYPE=Danish_Denmark.1252
[3] LC_MONETARY=Danish_Denmark.1252 LC_NUMERIC=C
[5] LC_TIME=Danish_Denmark.1252

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

other attached packages:
[1] plyr_1.8.4  TinnRcom_1.0.20 formatR_1.5 svSocket_0.9-57

loaded via a namespace (and not attached):
[1] compiler_3.4.1 tools_3.4.1svMisc_0.9-70  Rcpp_0.12.13 tcltk_3.4.1

All best wishes

Troels Ring, Aalborg, Denmark

__
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] changing "," to "." in data.frame

2017-10-11 Thread PIKAL Petr
And as follow up,

fff<-function(x) gsub(",", ".", x)

BX <- apply(apply(AX, 2, fff), 2, as.numeric)

this seems to be easier.

Cheers
Petr




S pozdravem | Best Regards
RNDr. Petr PIKAL
Vedoucí Výzkumu a vývoje | Research Manager
PRECHEZA a.s.
nábř. Dr. Edvarda Beneše 1170/24 | 750 02 Přerov | Czech Republic
Tel: +420 581 252 256 | GSM: +420 724 008 364
petr.pi...@precheza.cz | www.precheza.cz

> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Troels Ring
> Sent: Wednesday, October 11, 2017 9:46 AM
> To: r-help@r-project.org
> Subject: [R] changing "," to "." in data.frame
>
> Dear friends - I have a data.frame with "," instead of "." and found the
> discussion
>
> http://r.789695.n4.nabble.com/How-to-replace-all-commas-with-semicolon-in-
> a-string-tt4721187.html#a4721192
>
> so copying the code of Ulrik(I hope:-)) I tried
>
> (making some data)
>
> AX <-
> data.frame(a=chartr(".",",",rnorm(5)),b=chartr(".",",",rnorm(5)),c=rnorm(5))
>
>
> library(plyr)
>
> adply(AX, 2, function(x){
> if(!is.numeric(x[[1]]){
> gsub(",", ".", x[[1]])
> }else{
> x[[1]]
> }
> })
>
> and got the unwelcome error
>
> Error: unexpected '{' in:
> "adply(AX, 2, function(x){
> if(!is.numeric(x[[1]]){"
>
> Here is:
>
>  > sessionInfo()
> R version 3.4.1 (2017-06-30)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
> Running under: Windows 7 x64 (build 7601) Service Pack 1
>
> Matrix products: default
>
> locale:
> [1] LC_COLLATE=Danish_Denmark.1252  LC_CTYPE=Danish_Denmark.1252
> [3] LC_MONETARY=Danish_Denmark.1252 LC_NUMERIC=C
> [5] LC_TIME=Danish_Denmark.1252
>
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods base
>
> other attached packages:
> [1] plyr_1.8.4  TinnRcom_1.0.20 formatR_1.5 svSocket_0.9-57
>
> loaded via a namespace (and not attached):
> [1] compiler_3.4.1 tools_3.4.1svMisc_0.9-70  Rcpp_0.12.13 tcltk_3.4.1
>
> All best wishes
>
> Troels Ring, Aalborg, Denmark
>
> __
> 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 

Re: [R] changing "," to "." in data.frame

2017-10-11 Thread Berend Hasselman

> On 11 Oct 2017, at 09:45, Troels Ring  wrote:
> 
> Dear friends - I have a data.frame with "," instead of "." and found the 
> discussion
> 
> http://r.789695.n4.nabble.com/How-to-replace-all-commas-with-semicolon-in-a-string-tt4721187.html#a4721192
> 
> so copying the code of Ulrik(I hope:-)) I tried
> 
> (making some data)
> 
> AX <- 
> data.frame(a=chartr(".",",",rnorm(5)),b=chartr(".",",",rnorm(5)),c=rnorm(5)) 
> 
> library(plyr)
> 
> adply(AX, 2, function(x){
> if(!is.numeric(x[[1]]){
> gsub(",", ".", x[[1]])
> }else{
> x[[1]]
> }
> })
> 
> and got the unwelcome error
> 
> Error: unexpected '{' in:
> "adply(AX, 2, function(x){
> if(!is.numeric(x[[1]]){"
> 


Missing ) in if(!is.numeric(x[[1]]){

It should be 

if(!is.numeric(x[[1]]) ){

Berend Hasselman

> Here is:
> 
> > sessionInfo()
> R version 3.4.1 (2017-06-30)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
> Running under: Windows 7 x64 (build 7601) Service Pack 1
> 
> Matrix products: default
> 
> locale:
> [1] LC_COLLATE=Danish_Denmark.1252  LC_CTYPE=Danish_Denmark.1252
> [3] LC_MONETARY=Danish_Denmark.1252 LC_NUMERIC=C
> [5] LC_TIME=Danish_Denmark.1252
> 
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods base
> 
> other attached packages:
> [1] plyr_1.8.4  TinnRcom_1.0.20 formatR_1.5 svSocket_0.9-57
> 
> loaded via a namespace (and not attached):
> [1] compiler_3.4.1 tools_3.4.1svMisc_0.9-70  Rcpp_0.12.13 tcltk_3.4.1
> 
> All best wishes
> 
> Troels Ring, Aalborg, Denmark
> 
> __
> 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] changing "," to "." in data.frame

2017-10-11 Thread PIKAL Petr
Hi

missing ) after if statement.

adply(AX, 2, function(x){
if(!is.numeric(x[[1]])){
gsub(",", ".", x[[1]])
}else{
x[[1]]
}
})

However the data frame is transposed after the function which could be desired 
or not.

Cheers
Petr

> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Troels Ring
> Sent: Wednesday, October 11, 2017 9:46 AM
> To: r-help@r-project.org
> Subject: [R] changing "," to "." in data.frame
>
> Dear friends - I have a data.frame with "," instead of "." and found the
> discussion
>
> http://r.789695.n4.nabble.com/How-to-replace-all-commas-with-semicolon-in-
> a-string-tt4721187.html#a4721192
>
> so copying the code of Ulrik(I hope:-)) I tried
>
> (making some data)
>
> AX <-
> data.frame(a=chartr(".",",",rnorm(5)),b=chartr(".",",",rnorm(5)),c=rnorm(5))
>
>
> library(plyr)
>
> adply(AX, 2, function(x){
> if(!is.numeric(x[[1]]){
> gsub(",", ".", x[[1]])
> }else{
> x[[1]]
> }
> })
>
> and got the unwelcome error
>
> Error: unexpected '{' in:
> "adply(AX, 2, function(x){
> if(!is.numeric(x[[1]]){"
>
> Here is:
>
>  > sessionInfo()
> R version 3.4.1 (2017-06-30)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
> Running under: Windows 7 x64 (build 7601) Service Pack 1
>
> Matrix products: default
>
> locale:
> [1] LC_COLLATE=Danish_Denmark.1252  LC_CTYPE=Danish_Denmark.1252
> [3] LC_MONETARY=Danish_Denmark.1252 LC_NUMERIC=C
> [5] LC_TIME=Danish_Denmark.1252
>
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods base
>
> other attached packages:
> [1] plyr_1.8.4  TinnRcom_1.0.20 formatR_1.5 svSocket_0.9-57
>
> loaded via a namespace (and not attached):
> [1] compiler_3.4.1 tools_3.4.1svMisc_0.9-70  Rcpp_0.12.13 tcltk_3.4.1
>
> All best wishes
>
> Troels Ring, Aalborg, Denmark
>
> __
> 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 person represented by the 
recipient, or the existence of such 

[R] changing "," to "." in data.frame

2017-10-11 Thread Troels Ring
Dear friends - I have a data.frame with "," instead of "." and found the 
discussion


http://r.789695.n4.nabble.com/How-to-replace-all-commas-with-semicolon-in-a-string-tt4721187.html#a4721192

so copying the code of Ulrik(I hope:-)) I tried

(making some data)

AX <- 
data.frame(a=chartr(".",",",rnorm(5)),b=chartr(".",",",rnorm(5)),c=rnorm(5)) 



library(plyr)

adply(AX, 2, function(x){
if(!is.numeric(x[[1]]){
gsub(",", ".", x[[1]])
}else{
x[[1]]
}
})

and got the unwelcome error

Error: unexpected '{' in:
"adply(AX, 2, function(x){
if(!is.numeric(x[[1]]){"

Here is:

> sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=Danish_Denmark.1252  LC_CTYPE=Danish_Denmark.1252
[3] LC_MONETARY=Danish_Denmark.1252 LC_NUMERIC=C
[5] LC_TIME=Danish_Denmark.1252

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

other attached packages:
[1] plyr_1.8.4  TinnRcom_1.0.20 formatR_1.5 svSocket_0.9-57

loaded via a namespace (and not attached):
[1] compiler_3.4.1 tools_3.4.1svMisc_0.9-70  Rcpp_0.12.13 tcltk_3.4.1

All best wishes

Troels Ring, Aalborg, Denmark

__
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] "Time Series Plotting"

2017-10-11 Thread PIKAL Petr
Hi
keep your emails to R help, I do not offer private consultance and others could 
have different opinion how to solve your problem.
Did you even try my suggestion? If not, why not? If yes in what respect it does 
not comply with your expectations.
Cheers
Petr

From: niharika singhal [mailto:niharikasinghal1...@gmail.com]
Sent: Tuesday, October 10, 2017 2:34 PM
To: PIKAL Petr 
Subject: Re: [R] "Time Series Plotting"

Hello,

My Energy column looks like in the image in the attachment, and my sequence 
column correspond to state.
I wanted to look at the graph and see the state correspond to the energy column 
in the Times series

Thanks & Regards
Niharika


On Tue, Oct 10, 2017 at 2:28 PM, niharika singhal 
> wrote:
hello,

I just wanted the result in Time series thats why i am doing ts

On Tue, Oct 10, 2017 at 2:23 PM, PIKAL Petr 
> wrote:
Hi

I wonder why do you want to change it to ts. If I am not mistaken


plot(Data$Energy, col=Data$sequence)

or

plot(1:nrow(Data), Data$Energy, col=Data$sequence)

should do the trick.

Cheers
Petr

> -Original Message-
> From: R-help 
> [mailto:r-help-boun...@r-project.org] On 
> Behalf Of niharika
> singhal
> Sent: Tuesday, October 10, 2017 2:09 PM
> To: r-help@r-project.org
> Subject: [R] "Time Series Plotting"
>
> Hello,
>
>
> I need some help in plotting time series.
>
>
> I have dataframe Data with two column and thousands of row, I want wherever
> the sequence corresponding to Energy column is changed the color change
> should be reflected in Time Series plot, some rows of dataframe are below
>
>
>
> Energy  sequence
>
> 13536 3
>
> 14335 3
>
> 14638 3
>
> 25363 3
>
> 18511 2
>
> 18371 2
>
> 14555 3
>
>
>
> I am able to plot time series by:-
>
> Data.energy<- ts(Data$ Energy, frequency=1)
>
> plot(Data.energy)
>
>
>
> How should I add the color effect based on the sequence column value?
>
>
>
> Thanks & Regards
>
> Niharika Singhal
>
>   [[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