Re: [R] lubridate inserting unwelcome 9:21

2017-03-28 Thread Troels Ring
Thanks a lot - I got interested to make it work since just formatting  
in lubricate as a time  automatically puts the same complete date, which 
was OK for me - and also provided a utility for adding days - which 
apparently then needs tweaking -


Best wishes

Troels


Den 28-03-2017 kl. 20:38 skrev Jeff Newmiller:

Analyzing time data as POSIXct without dates is IMO unwise (likely to give you 
trouble). My approach is to always keep the date and time together or to use 
numeric hours-after-midnight. Others have invented packages like chron to deal 
with such data.


__
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] A question on modeling brain growth using GAM

2017-03-28 Thread David Winsemius

> On Mar 28, 2017, at 9:32 AM, Leon Lee  wrote:
> 
> Hi, R experts
> 
> I am new to R & GAM toolbox and would like to get inputs from you all on my
> models. The question I have is as follows:
> I have 30 subjects with each subject being scanned from one to three times
> in the first year of life. The brain volume from each scan was measured.
> The scan time was randomly distributed from birth to 1 year.
> Each subject has different gestational age ranging from 38 to 41 weeks
> Each subject has chronological age from birth to 1 year old
> Each subject has gender category.
> Now, I want to look at how predictors, such as subject's chronological age,
> gestational age and gender will explain the changes in brain volume. I also
> want to include interactions between gender and age, gestational and
> chronological age. Random effects are also included in the model to account
> for subject variability. My model looks like the follows:
> 
> gam=gam(brainVolume~ s(age) + ti(age, gestationalAge) + gestationalAge +
> sex + s(age, by=sex) +  s(subjIndexF, bs="re"), method="REML", data=mydata)
> 
> Are there any obvious mistakes in the model? Any suggestions will be
> greatly appreciated!

I'm not seeing mistakes in the syntax but I would question whether 30 subjects 
is sufficient to adequately support estimates in a a model of this complexity. 
I would also think that the 's(age)' and 'sex' terms would get aliased out in a 
model with "+ s(age, by=sex)". Most R regression functions handle removal of 
over-parametrization automatically.

You also have a variable number of measurements per subject. I am unable to 
comment on the effort to account for the implicit and variably measured 
correlation and auto-correlation of values within subjects using a "smooth" on 
subjIndexF, since that is not an approach I was familiar with.  But I am 
getting concerned whether you are also new to statistical modeling in addition 
to your use of R and GAM being "new to you"?

(Perhaps Simon or one of the mixed-effects experts can correct the gaps in my 
understanding of how to model repeated measures in the context of small numbers 
of subjects and irregular emasurements.)

Please read the Posting Guide and the pages of candidate mailing lists. Rhelp 
is not really the place to go when you need statistical advice. I'm not sure if 
this is really in the center of concerns that get discussed on the Mixed Models 
list, but to my eyes it would be a better fit there.

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

David Winsemius
Alameda, CA, USA

__
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] lubridate inserting unwelcome 9:21

2017-03-28 Thread Jeff Newmiller
Analyzing time data as POSIXct without dates is IMO unwise (likely to give you 
trouble). My approach is to always keep the date and time together or to use 
numeric hours-after-midnight. Others have invented packages like chron to deal 
with such data.
-- 
Sent from my phone. Please excuse my brevity.

On March 28, 2017 8:28:30 AM PDT, Troels Ring  wrote:
>Dear friends - I have a series of times on successive days and would 
>like to convert them into a successive common time for each person (ID)
>
>. Using lubridate and adding days(1) does as expected apart from 
>changing time zone to LMT from UTC and suddenly adding 9:21 (H:M) to
>all 
>times. Individual parts of the instructions seem OK. I'm sorry for the 
>clumsy demonstration - but the error comes through.
>
>R version 3.3.2 (2016-10-31) - Windows.
>
>All best wishes
>Troels
>
>library(lubridate)
>
>SSS <- structure(list(ID = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
>1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L,
>3L, 3L, 3L, 3L, 3L, 3L), Time = c(-1L, 0L, 1L, 2L, 3L, 4L, 5L,
>6L, 7L, 8L, 9L, 10L, 11L, -1L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
>8L, 9L, 10L, -1L, 0L, 1L, 2L, 3L, 4L, 5L), VT = structure(c(3L,
>5L, 11L, 11L, 8L, 10L, 8L, 10L, 8L, 7L, 11L, 5L, 5L, 12L, 5L,
>7L, 7L, 5L, 5L, 8L, 10L, 8L, 7L, 7L, 7L, 2L, 8L, 7L, 8L, 7L,
>10L, 8L), .Label = c("02:00", "03:00", "04:00", "05:00", "06:00",
>"09:00", "10:00", "11:00", "11:30", "12:00", "13:00", "14:00",
>"15:00", "17:00", "18:00", "21:30", "23:00"), class = "factor")),
>.Names 
>= c("ID",
>"Time", "VT"), row.names = c(NA, 32L), class = "data.frame")
>
>SSS$VT  <- parse_date_time(SSS$VT,"HM")
>str(SSS$VT)
>
>TT <- list()
>for(i in 1:3) {
>#i <- 1
>BS <- subset(SSS,ID==i)
>TT[[i]] <- c(BS$VT + (1:length(BS[,1])-1)*days(1))
>}
>BS$VT
>(1:length(BS[,1])-1)*days(1)
>
>#these appear as expected but
>
>TT
>
>#appears disturbed 9:21 inserted - LMT time zone - how comes?
>
>__
>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] Splitting on metacharacters

2017-03-28 Thread Nordlund, Dan (DSHS/RDA)
What you are seeing when printing depends on how you do it (and it can be 
confusing).  Try this, type the following lines exactly (or copy and paste)  
and carefully study the results.  In particular, compare the results of 
cat(s,'\n') with the results of strsplit(s, '"') .

s <- "{\"Q0\":\"37\",\"Q1\":\"f\"}"
s
cat(s,'\n')
'"'# single quote, double quote, single quote

strsplit(s, '"')


Hope this is helpful,

Dan

Daniel Nordlund, PhD
Research and Data Analysis Division
Services & Enterprise Support Administration
Washington State Department of Social and Health Services


> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Patzelt,
> Edward
> Sent: Tuesday, March 28, 2017 9:50 AM
> To: R-help@r-project.org
> Subject: [R] Splitting on metacharacters
> 
> Hi R-help,
> 
> I would like to:
> 
> Extract the "26" and "f" from the following string (i.e. age and gender).
> I've tried a bunch of strsplit, grep, etc. Please help!
> 
> *"{\"Q0\":\"37\",\"Q1\":\"f\"}"*
> 
> 
> Thanks,
> 
> Edward
> 
> --
> Edward H Patzelt | Clinical Science PhD Student
> Psychology | Harvard University
> *Computational Cognitive Neuroscience Laboratory
> *
> 
>   [[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] How to apply calculations in "formula" to "data frame"

2017-03-28 Thread Sören Vogel
`model.matrix` was what I was looking for.

Thanks,
Sören

> On 28.03.2017, at 16:57, peter dalgaard  wrote:
> 
> 
>> On 28 Mar 2017, at 16:14 , Sören Vogel  wrote:
>> 
>> Hello
>> 
>> Ho can I apply a formula to a data frame?
> 
> 
> That would depend on whether the formula has any special interpretation.
> 
> If if is just an elementary expression, then it would be like 
> 
> eval(For1[[3]], Data, environment(For1))
> 
> but you are using "." to represent... what exactly?
> 
> One possibility is model.matrix(For1, Data)
> 
> but I'm not at all sure that that is what you want.
> 
> -pd
> 
>> 
>> library("formula.tools")
>> Data <- data.frame("v1" = rnorm(31), "v2" = runif(31), "v3" = sample(1:7, 
>> 31, repl=T), "v4" = rlnorm(31))
>> For1 <- as.formula(v1 ~ .^3)
>> Lhs <- Data[, formula.tools::lhs.vars(formula)]
>> Rhs <- apply_formula_to_data_frame_and_return_result(data, formula) # ???
>> 
>> Thank you,
>> Sören
>> 
>> __
>> 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.
> 
> -- 
> Peter Dalgaard, Professor,
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Office: A 4.23
> Email: pd@cbs.dk  Priv: pda...@gmail.com
> 
> 
> 
> 
> 
> 
> 
> 
> 

__
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] Splitting on metacharacters

2017-03-28 Thread Boris Steipe
You haven't actually _defined_ what the expected range of variations of your 
string are, but if I speculate wildly, I can come up with the following two 
solutions that may get you started.

s <- '*"{\"Q0\":\"37\",\"Q1\":\"f\"}"*'
regmatches(s, gregexpr("([0-9]{2,}|[a-z]+)", s))[[1]]
strsplit(s, "\\\"")[[1]][c(5, 9)]


Obviously, there are many more possibilities.
B.


> On Mar 28, 2017, at 12:50 PM, Patzelt, Edward  wrote:
> 
> Hi R-help,
> 
> I would like to:
> 
> Extract the "26" and "f" from the following string (i.e. age and gender).
> I've tried a bunch of strsplit, grep, etc. Please help!
> 
> *"{\"Q0\":\"37\",\"Q1\":\"f\"}"*
> 
> 
> Thanks,
> 
> Edward
> 
> -- 
> Edward H Patzelt | Clinical Science PhD Student
> Psychology | Harvard University
> *Computational Cognitive Neuroscience Laboratory
> *
> 
>   [[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] Splitting on metacharacters

2017-03-28 Thread Patzelt, Edward
Hi R-help,

I would like to:

Extract the "26" and "f" from the following string (i.e. age and gender).
I've tried a bunch of strsplit, grep, etc. Please help!

*"{\"Q0\":\"37\",\"Q1\":\"f\"}"*


Thanks,

Edward

-- 
Edward H Patzelt | Clinical Science PhD Student
Psychology | Harvard University
*Computational Cognitive Neuroscience Laboratory
*

[[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] A question on modeling brain growth using GAM

2017-03-28 Thread Leon Lee
Hi, R experts

I am new to R & GAM toolbox and would like to get inputs from you all on my
models. The question I have is as follows:
I have 30 subjects with each subject being scanned from one to three times
in the first year of life. The brain volume from each scan was measured.
The scan time was randomly distributed from birth to 1 year.
Each subject has different gestational age ranging from 38 to 41 weeks
Each subject has chronological age from birth to 1 year old
Each subject has gender category.
Now, I want to look at how predictors, such as subject's chronological age,
gestational age and gender will explain the changes in brain volume. I also
want to include interactions between gender and age, gestational and
chronological age. Random effects are also included in the model to account
for subject variability. My model looks like the follows:

gam=gam(brainVolume~ s(age) + ti(age, gestationalAge) + gestationalAge +
sex + s(age, by=sex) +  s(subjIndexF, bs="re"), method="REML", data=mydata)

Are there any obvious mistakes in the model? Any suggestions will be
greatly appreciated!

L

[[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] Looping Through DataFrames with Differing Lenghts

2017-03-28 Thread David L Carlson
You have multiple problems. You do not seem to understand read.csv() or 
as.Date() so you really need to read the manual pages:

?read.csv
?as.Date

> Data <- read.csv("Container.csv")
> str(Data)
'data.frame':   362 obs. of  1 variable:
 $ TransitDate.Transits: Factor w/ 362 levels "1-Apr-00\t25",..: 319 289 78 140 
110 229 18 259 199 169 ...

Notice you have a single factor that combines the TransitDate and Transits 
because the file you sent was NOT a .csv file, but a tab-delimited file:

> Data <- read.delim("Container.csv")
> str(Data)
'data.frame':   362 obs. of  2 variables:
 $ TransitDate: Factor w/ 362 levels "1-Apr-00","1-Apr-01",..: 319 289 78 140 
110 229 18 259 199 169 ...
 $ Transits   : int  4 4 5 4 3 6 4 3 4 5 ...

Now we get two variables, but the date is still a factor.

> Data <- read.delim("Container.csv", stringsAsFactors=FALSE)
> str(Data)
'data.frame':   362 obs. of  2 variables:
 $ TransitDate: chr  "1-Oct-85" "1-Nov-85" "1-Dec-85" "1-Jan-86" ...
 $ Transits   : int  4 4 5 4 3 6 4 3 4 5 ...

Now we get the date as characters, but as Ng Bo Lin pointed out, it is not in 
the format you indicated: "%Y-%m-%d", %Y means a year with the century (e.g. 
1985), but you have 2-digit years (85), %m means month as a decimal number 
(e.g. 10 for October), but you have a 3-digit abbreviation for the month. And 
the order is backwards. What you need is

> TDate <- as.Date(Data$TransitDate, "%e-%B-%y")
> head(TDate)
[1] "1985-10-01" "1985-11-01" "1985-12-01" "1986-01-01" "1986-02-01" 
"1986-03-01"

You probably should preserve the original date and not overwrite it so 
something like

> Data$Transit <- TDate
> str(Data)
'data.frame':   362 obs. of  3 variables:
 $ TransitDate: chr  "1-Oct-85" "1-Nov-85" "1-Dec-85" "1-Jan-86" ...
 $ Transits   : int  4 4 5 4 3 6 4 3 4 5 ...
 $ Transit: Date, format: "1985-10-01" "1985-11-01" ...

Would be preferable. 

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


From: Paul Bernal [mailto:paulberna...@gmail.com] 
Sent: Tuesday, March 28, 2017 9:41 AM
To: David L Carlson 
Cc: Ng Bo Lin ; r-help@r-project.org
Subject: Re: [R] Looping Through DataFrames with Differing Lenghts

Dear friend David,

Thank you for your valuable suggestion. So here is the file in .txt format.

Best of regards,

Paul

2017-03-28 9:35 GMT-05:00 David L Carlson :
We did not get the file on the list. You need to rename your file to 
"Container.txt" or the mailing list will strip it from your message. The 
read.csv() function returns a data frame so Data is already a data frame. The 
command DataFrame<-data.frame(Data) just makes a copy of Data.

Without the file, it is difficult to be certain, but your dates are probably 
stored as character strings and read.csv() will turn those to factors unless 
you tell it not to do that. Try

Data<-read.csv("Container.csv", stringsAsFactors=FALSE)
str(Data) # To see how the dates are stored

and see if things work better. If not, rename the file or use dput(Data) and 
copy the result into your email message. If the data is very long, use 
dput(head(Data, 15)).

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


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Paul Bernal
Sent: Tuesday, March 28, 2017 9:12 AM
To: Ng Bo Lin 
Cc: r-help@r-project.org
Subject: Re: [R] Looping Through DataFrames with Differing Lenghts

Dear friends Ng Bo Lin, Mark and Ulrik, thank you all for your kind and
valuable replies,

I am trying to reformat a date as follows:

Data<-read.csv("Container.csv")

DataFrame<-data.frame(Data)

DataFrame$TransitDate<-as.Date(DataFrame$TransitDate, "%Y-%m-%d")

#trying to put it in -MM-DD format

However, when I do this, I get a bunch of NAs for the dates.

I am providing a sample dataset as a reference.

Any help will be greatly appreciated,

Best regards,

Paul

2017-03-28 8:15 GMT-05:00 Ng Bo Lin :

> Hi Paul,
>
> Using the example provided by Ulrik, where
>
> > exdf1 <- data.frame(Date = c("1985-10-01", "1985-11-01", "1985-12-01”,
> "1986-01-01"), Transits = c(NA, NA, NA, NA))
> > exdf2 <- data.frame(Date = c("1985-10-01", "1986-01-01"), Transits =
> c(15,20)),
>
> You could also try the following function:
>
> for (i in 1:dim(exdf1)[1]){
>         if (!exdf1[i, 1] %in% exdf2[, 1]){
>                 exdf2 <- rbind(exdf2, exdf1[i,])
>         }
> }
>
> Basically, what the function does is that it runs through the number of
> rows in exdf1, and checks if the Date of the exdf1 row already exists in
> Date column of exdf2. If so, it skips it. Otherwise, it binds the row to
> df2.
>
> Hope this helps!
>
>
> Side note.: Computational efficiency wise, think Ulrik’s answer is
> probably better. Presentation wise, his is also much 

Re: [R-es] Alternativa a RStudio

2017-03-28 Thread rubenfcasal

Hola a todos,

La lista de mensajes es muy grande pero creo que no se comentaron 
algunos que uso/usé:


TinnR: (para Windows) Un editor de código que interacciona con la 
consola de R [https://sourceforge.net/projects/tinn-r]


Notepad++ con NppToR: (para Windows) similar al anterior 
[https://sourceforge.net/projects/npptor]


Eclipse con StatET: Entorno de programación para distintos lenguajes 
entre ellos R (ofrece también un depurador de código integrado del 
estilo del de RStudio; muy útil si se mezcla R con otros lenguajes...) 
[e.g. 
http://lukemiller.org/index.php/2010/04/eclipse-and-statet-a-nice-working-environment-for-r]


Un saludo, Rubén.

--
Ruben Fernandez Casal
Department of Mathematics
Faculty of Computer Science
Universidade da Coruña
Corporate email: ruben.fcasal  udc  es
--

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


Re: [R] Looping Through DataFrames with Differing Lenghts

2017-03-28 Thread Paul Bernal
Dear friend David,

Thank you for your valuable suggestion. So here is the file in .txt format.

Best of regards,

Paul

2017-03-28 9:35 GMT-05:00 David L Carlson :

> We did not get the file on the list. You need to rename your file to
> "Container.txt" or the mailing list will strip it from your message. The
> read.csv() function returns a data frame so Data is already a data frame.
> The command DataFrame<-data.frame(Data) just makes a copy of Data.
>
> Without the file, it is difficult to be certain, but your dates are
> probably stored as character strings and read.csv() will turn those to
> factors unless you tell it not to do that. Try
>
> Data<-read.csv("Container.csv", stringsAsFactors=FALSE)
> str(Data) # To see how the dates are stored
>
> and see if things work better. If not, rename the file or use dput(Data)
> and copy the result into your email message. If the data is very long, use
> dput(head(Data, 15)).
>
> -
> David L Carlson
> Department of Anthropology
> Texas A University
> College Station, TX 77840-4352
>
>
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Paul
> Bernal
> Sent: Tuesday, March 28, 2017 9:12 AM
> To: Ng Bo Lin 
> Cc: r-help@r-project.org
> Subject: Re: [R] Looping Through DataFrames with Differing Lenghts
>
> Dear friends Ng Bo Lin, Mark and Ulrik, thank you all for your kind and
> valuable replies,
>
> I am trying to reformat a date as follows:
>
> Data<-read.csv("Container.csv")
>
> DataFrame<-data.frame(Data)
>
> DataFrame$TransitDate<-as.Date(DataFrame$TransitDate, "%Y-%m-%d")
>
> #trying to put it in -MM-DD format
>
> However, when I do this, I get a bunch of NAs for the dates.
>
> I am providing a sample dataset as a reference.
>
> Any help will be greatly appreciated,
>
> Best regards,
>
> Paul
>
> 2017-03-28 8:15 GMT-05:00 Ng Bo Lin :
>
> > Hi Paul,
> >
> > Using the example provided by Ulrik, where
> >
> > > exdf1 <- data.frame(Date = c("1985-10-01", "1985-11-01", "1985-12-01”,
> > "1986-01-01"), Transits = c(NA, NA, NA, NA))
> > > exdf2 <- data.frame(Date = c("1985-10-01", "1986-01-01"), Transits =
> > c(15,20)),
> >
> > You could also try the following function:
> >
> > for (i in 1:dim(exdf1)[1]){
> > if (!exdf1[i, 1] %in% exdf2[, 1]){
> > exdf2 <- rbind(exdf2, exdf1[i,])
> > }
> > }
> >
> > Basically, what the function does is that it runs through the number of
> > rows in exdf1, and checks if the Date of the exdf1 row already exists in
> > Date column of exdf2. If so, it skips it. Otherwise, it binds the row to
> > df2.
> >
> > Hope this helps!
> >
> >
> > Side note.: Computational efficiency wise, think Ulrik’s answer is
> > probably better. Presentation wise, his is also much better.
> >
> > Regards,
> > Bo Lin
> >
> > > On 28 Mar 2017, at 5:22 PM, Ulrik Stervbo 
> > wrote:
> > >
> > > Hi Paul,
> > >
> > > does this do what you want?
> > >
> > > exdf1 <- data.frame(Date = c("1985-10-01", "1985-11-01", "1985-12-01",
> > > "1986-01-01"), Transits = c(NA, NA, NA, NA))
> > > exdf2 <- data.frame(Date = c("1985-10-01", "1986-01-01"), Transits =
> > c(15,
> > > 20))
> > >
> > > tmpdf <- subset(exdf1, !Date %in% exdf2$Date)
> > >
> > > rbind(exdf2, tmpdf)
> > >
> > > HTH,
> > > Ulrik
> > >
> > > On Tue, 28 Mar 2017 at 10:50 Paul Bernal 
> wrote:
> > >
> > > Dear friend Mark,
> > >
> > > Great suggestion! Thank you for replying.
> > >
> > > I have two dataframes, dataframe1 and dataframe2.
> > >
> > > dataframe1 has two columns, one with the dates in -MM-DD format and
> > the
> > > other colum with number of transits (all of which were set to NA
> values).
> > > dataframe1 starts in 1985-10-01 (october 1st 1985) and ends in
> 2017-03-01
> > > (march 1 2017).
> > >
> > > dataframe2 has the same  two columns, one with the dates in -MM-DD
> > > format, and the other column with number of transits. dataframe2 starts
> > > have the same start and end dates, however, dataframe2 has missing
> dates
> > > between the start and end dates, so it has fewer observations.
> > >
> > > dataframe1 has a total of 378 observations and dataframe2 has a  total
> of
> > > 362 observations.
> > >
> > > I would like to come up with a code that could do the following:
> > >
> > > Get the dates of dataframe1 that are missing in dataframe2 and add them
> > as
> > > records to dataframe 2 but with NA values.
> > >
> > >  > >
> > > Date  Transits  Date
> > > Transits
> > > 1985-10-01NA 1985-10-0115
> > > 1985-11-01NA 1986-01-01 20
> > > 1985-12-01NA 1986-02-01 5
> > > 1986-01-01NA
> > > 1986-02-01NA
> > > 2017-03-01NA
> > >
> > > I would like to fill in the missing dates in dataframe2, with 

Re: [R] Looping Through DataFrames with Differing Lenghts

2017-03-28 Thread Ng Bo Lin
Hi Paul,

Using the example provided by Ulrik, where

> exdf1 <- data.frame(Date = c("1985-10-01", "1985-11-01", "1985-12-01”, 
> "1986-01-01"), Transits = c(NA, NA, NA, NA))
> exdf2 <- data.frame(Date = c("1985-10-01", "1986-01-01"), Transits = 
> c(15,20)),

You could also try the following function:

for (i in 1:dim(exdf1)[1]){
if (!exdf1[i, 1] %in% exdf2[, 1]){
exdf2 <- rbind(exdf2, exdf1[i,])
}
}

Basically, what the function does is that it runs through the number of rows in 
exdf1, and checks if the Date of the exdf1 row already exists in Date column of 
exdf2. If so, it skips it. Otherwise, it binds the row to df2.

Hope this helps!


Side note.: Computational efficiency wise, think Ulrik’s answer is probably 
better. Presentation wise, his is also much better.

Regards,
Bo Lin

> On 28 Mar 2017, at 5:22 PM, Ulrik Stervbo  wrote:
> 
> Hi Paul,
> 
> does this do what you want?
> 
> exdf1 <- data.frame(Date = c("1985-10-01", "1985-11-01", "1985-12-01",
> "1986-01-01"), Transits = c(NA, NA, NA, NA))
> exdf2 <- data.frame(Date = c("1985-10-01", "1986-01-01"), Transits = c(15,
> 20))
> 
> tmpdf <- subset(exdf1, !Date %in% exdf2$Date)
> 
> rbind(exdf2, tmpdf)
> 
> HTH,
> Ulrik
> 
> On Tue, 28 Mar 2017 at 10:50 Paul Bernal  wrote:
> 
> Dear friend Mark,
> 
> Great suggestion! Thank you for replying.
> 
> I have two dataframes, dataframe1 and dataframe2.
> 
> dataframe1 has two columns, one with the dates in -MM-DD format and the
> other colum with number of transits (all of which were set to NA values).
> dataframe1 starts in 1985-10-01 (october 1st 1985) and ends in 2017-03-01
> (march 1 2017).
> 
> dataframe2 has the same  two columns, one with the dates in -MM-DD
> format, and the other column with number of transits. dataframe2 starts
> have the same start and end dates, however, dataframe2 has missing dates
> between the start and end dates, so it has fewer observations.
> 
> dataframe1 has a total of 378 observations and dataframe2 has a  total of
> 362 observations.
> 
> I would like to come up with a code that could do the following:
> 
> Get the dates of dataframe1 that are missing in dataframe2 and add them as
> records to dataframe 2 but with NA values.
> 
>  
> Date  Transits  Date
> Transits
> 1985-10-01NA 1985-10-0115
> 1985-11-01NA 1986-01-01 20
> 1985-12-01NA 1986-02-01 5
> 1986-01-01NA
> 1986-02-01NA
> 2017-03-01NA
> 
> I would like to fill in the missing dates in dataframe2, with NA as value
> for the missing transits, so that I  could end up with a dataframe3 looking
> as follows:
> 
>  DateTransits
> 1985-10-01  15
> 1985-11-01   NA
> 1985-12-01   NA
> 1986-01-01   20
> 1986-02-01   5
> 2017-03-01   NA
> 
> This is what I want to accomplish.
> 
> Thanks, beforehand for your help,
> 
> Best regards,
> 
> Paul
> 
> 
> 2017-03-27 15:15 GMT-05:00 Mark Sharp :
> 
>> Make some small dataframes of just a few rows that illustrate the problem
>> structure. Make a third that has the result you want. You will get an
>> answer very quickly. Without a self-contained reproducible problem,
> results
>> vary.
>> 
>> Mark
>> R. Mark Sharp, Ph.D.
>> msh...@txbiomed.org
>> 
>> 
>> 
>> 
>> 
>>> On Mar 27, 2017, at 3:09 PM, Paul Bernal  wrote:
>>> 
>>> Dear friends,
>>> 
>>> I have one dataframe which contains 378 observations, and another one,
>>> containing 362 observations.
>>> 
>>> Both dataframes have two columns, one date column and another one with
>> the
>>> number of transits.
>>> 
>>> I wanted to come up with a code so that I could fill in the dates that
>> are
>>> missing in one of the dataframes and replace the column of transits with
>>> the value NA.
>>> 
>>> I have tried several things but R obviously complains that the length of
>>> the dataframes are different.
>>> 
>>> How can I solve this?
>>> 
>>> Any guidance will be greatly appreciated,
>>> 
>>> Best regards,
>>> 
>>> Paul
>>> 
>>> [[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 

Re: [R] Antwort: Re: Way to Plot Multiple Variables and Change Color

2017-03-28 Thread Ulrik Stervbo
Hi Georg,

you were on the right path - it is all about scale_fill*

The 'problem' as you've discovered is that value is continuous, but
applying scale_fill_manual or others (except scale_fill_gradient) expects
discrete values.

The solution is simply to set the fill with that by using factor():

ggplot(
  d_result,
  aes(variable, y = n, fill = factor(value))) +
  geom_bar(stat = "identity") +
scale_fill_manual(values = RColorBrewer::brewer.pal(4, "Blues"))
or:
 ggplot(
  d_result,
  aes(variable, y = n, fill = factor(value))) +
  geom_bar(stat = "identity") +
  scale_fill_manual(values = c("red","blue", "green", "purple"))

When using colorBrewer (which I highly recommend), I use scale_*_brewer
rather than setting the colour manually:

ggplot(
  d_result,
  aes(variable, y = n, fill = factor(value))) +
  geom_bar(stat = "identity") +
  scale_fill_brewer(palette = "Blues ")

Best,
Ulrik


On Tue, 28 Mar 2017 at 18:21  wrote:

> Hi Richard,
>
> many thanks for your reply.
>
> Your solution is not exactly what I was looking for. I would like to know
> how I can change the colors of the stacked bars in my plot and not use the
> default values. How can this be done?
>
> Kind regards
>
> Georg
>
>
>
>
> Von:"Richard M. Heiberger" 
> An: g.maub...@weinwolf.de,
> Kopie:  r-help 
> Datum:  28.03.2017 17:40
> Betreff:Re: [R] Way to Plot Multiple Variables and Change Color
>
>
>
> I think you are looking for the likert function in the HH package.
> >From ?likert
>
>
> Diverging stacked barcharts for Likert, semantic differential, rating
> scale data, and population pyramids.
>
>
> This will get you started.  Much more fine control is available.  See
> the examples and demo.
>
> ## install.packages("HH") ## if not yet on your system.
>
> library(HH)
>
> AA <- dfr[,-9]
>
> labels <- sort(unique(as.vector(data.matrix(AA
> result.template <- integer(length(labels))
> names(result.template) <- labels
>
> BB <- apply(AA, 2, function(x, result=result.template) {
>   tx <- table(x)
>   result[names(tx)] <- tx
>   result
> }
> )
>
> BB
>
> likert(t(BB), ReferenceZero=0, horizontal=FALSE)
>
>
> On Tue, Mar 28, 2017 at 6:05 AM,   wrote:
> > Hi All,
> >
> > in my current project I have to plot a whole bunch of related variables
> > (item batteries, e.g. How do you rate ... a) Accelaration, b) Horse
> Power,
> > c) Color Palette, etc.) which are all rated on a scale from 1 .. 4.
> >
> > I need to present the results as stacked bar charts where the variables
> > are columns and the percentages of the scales values (1 .. 4) are the
> > chunks of the stacked bar for each variable. To do this I have
> transformed
> > my data from wide to long and calculated the percentage for each
> variable
> > and value. The code for this is as follows:
> >
> > -- cut --
> >
> > dfr <- structure(
> >   list(
> > v07_01 = c(3, 1, 1, 4, 3, 4, 4, 1, 3, 2, 2, 3,
> >4, 4, 4, 1, 1, 3, 3, 4),
> > v07_02 = c(1, 2, 1, 1, 2, 1, 4, 1, 1,
> >4, 4, 1, 4, 4, 1, 3, 2, 3, 3, 1),
> > v07_03 = c(3, 2, 2, 1, 4, 1,
> >2, 3, 3, 1, 4, 2, 3, 1, 4, 1, 4, 2, 2, 3),
> > v07_04 = c(3, 1, 1,
> >4, 2, 4, 4, 2, 2, 2, 4, 1, 2, 1, 3, 1, 2, 4, 1, 4),
> > v07_05 = c(1,
> >2, 2, 2, 4, 4, 1, 1, 4, 4, 2, 1, 2, 1, 4, 1, 2, 4, 1, 4),
> > v07_06 = c(1,
> >2, 1, 2, 1, 1, 3, 4, 3, 2, 2, 3, 3, 2, 4, 2, 3, 1, 4, 3),
> > v07_07 = c(3,
> >2, 3, 3, 1, 1, 3, 3, 4, 4, 1, 3, 1, 3, 2, 4, 1, 2, 3, 4),
> > v07_08 = c(3,
> >2, 1, 2, 2, 2, 3, 3, 4, 4, 1, 1, 1, 2, 3, 1, 4, 2, 2, 4),
> > cased_id = structure(
> >   1:20,
> >   .Label = c(
> > "1",
> > "2",
> > "3",
> > "4",
> > "5",
> > "6",
> > "7",
> > "8",
> > "9",
> > "10",
> > "11",
> > "12",
> > "13",
> > "14",
> > "15",
> > "16",
> > "17",
> > "18",
> > "19",
> > "20"
> >   ),
> >   class = "factor"
> > )
> >   ),
> >   .Names = c(
> > "v07_01",
> > "v07_02",
> > "v07_03",
> > "v07_04",
> > "v07_05",
> > "v07_06",
> > "v07_07",
> > "v07_08",
> > "cased_id"
> >   ),
> >   row.names = c(NA, -20L),
> >   class = c("tbl_df", "tbl",
> > "data.frame")
> > )
> >
> > mdf <- melt(df)
> > d_result <- mdf  %>%
> >   dplyr::group_by(variable) %>%
> >   count(value)
> >
> > ggplot(
> >   d_result,
> >   aes(variable, y = n, fill = value)) +
> >   geom_bar(stat = "identity") +
> >   coord_cartesian(ylim = c(0,100))
> >
> > -- cut --
> >
> > Is there an easier way of doing this, i. e. a way without need to
> > transform the data?
> >
> > How can I change the colors for the data points 1 .. 4?
> >
> > I tried
> >
> > -- cut --
> >
> >   d_result,
> >   aes(variable, y = n, 

[R] ANOVA for one subject

2017-03-28 Thread Uri Eduardo Ramírez Pasos
Dear everyone,

I have a 2x3  design (medication x stimulus type) but very few subjects (6)
and I would like to perform intra-subject stats using r's aov (I've already
run the group analysis). Is there a conceptual problem with this, as long
as I don't interpret the results as representative of the population with
the disease I'm studying? Could anyone point me to any discussion of this
practice, as to its merits for example?

Many thanks,
U. Pasos

[[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] Looping Through DataFrames with Differing Lenghts

2017-03-28 Thread Ng Bo Lin
Hi Paul,

The date format that you have supplied to R isn’t exactly right.

Instead of supplying the format “%Y-%m-%d”, it appears that the format of your 
data adheres to the “%e-%B-%y” format. In this case, %e refers to Day, and 
takes an integer between (0 - 31), %B refers to the 3 letter abbreviated 
version of the Month, and %y refers to the Year provided in a “2-integer” 
format.

Hope this helps!

Thank you.

Regards,
Bo Lin
> On 28 Mar 2017, at 10:12 PM, Paul Bernal  wrote:
> 
> Dear friends Ng Bo Lin, Mark and Ulrik, thank you all for your kind and 
> valuable replies,
> 
> I am trying to reformat a date as follows:
> 
> Data<-read.csv("Container.csv")
> 
> DataFrame<-data.frame(Data)
> 
> DataFrame$TransitDate<-as.Date(DataFrame$TransitDate, "%Y-%m-%d")
> 
> #trying to put it in -MM-DD format
> 
> However, when I do this, I get a bunch of NAs for the dates.
> 
> I am providing a sample dataset as a reference.
> 
> Any help will be greatly appreciated,
> 
> Best regards,
> 
> Paul
> 
> 2017-03-28 8:15 GMT-05:00 Ng Bo Lin  >:
> Hi Paul,
> 
> Using the example provided by Ulrik, where
> 
> > exdf1 <- data.frame(Date = c("1985-10-01", "1985-11-01", "1985-12-01”, 
> > "1986-01-01"), Transits = c(NA, NA, NA, NA))
> > exdf2 <- data.frame(Date = c("1985-10-01", "1986-01-01"), Transits = 
> > c(15,20)),
> 
> You could also try the following function:
> 
> for (i in 1:dim(exdf1)[1]){
> if (!exdf1[i, 1] %in% exdf2[, 1]){
> exdf2 <- rbind(exdf2, exdf1[i,])
> }
> }
> 
> Basically, what the function does is that it runs through the number of rows 
> in exdf1, and checks if the Date of the exdf1 row already exists in Date 
> column of exdf2. If so, it skips it. Otherwise, it binds the row to df2.
> 
> Hope this helps!
> 
> 
> Side note.: Computational efficiency wise, think Ulrik’s answer is probably 
> better. Presentation wise, his is also much better.
> 
> Regards,
> Bo Lin
> 
> > On 28 Mar 2017, at 5:22 PM, Ulrik Stervbo  > > wrote:
> >
> > Hi Paul,
> >
> > does this do what you want?
> >
> > exdf1 <- data.frame(Date = c("1985-10-01", "1985-11-01", "1985-12-01",
> > "1986-01-01"), Transits = c(NA, NA, NA, NA))
> > exdf2 <- data.frame(Date = c("1985-10-01", "1986-01-01"), Transits = c(15,
> > 20))
> >
> > tmpdf <- subset(exdf1, !Date %in% exdf2$Date)
> >
> > rbind(exdf2, tmpdf)
> >
> > HTH,
> > Ulrik
> >
> > On Tue, 28 Mar 2017 at 10:50 Paul Bernal  > > wrote:
> >
> > Dear friend Mark,
> >
> > Great suggestion! Thank you for replying.
> >
> > I have two dataframes, dataframe1 and dataframe2.
> >
> > dataframe1 has two columns, one with the dates in -MM-DD format and the
> > other colum with number of transits (all of which were set to NA values).
> > dataframe1 starts in 1985-10-01 (october 1st 1985) and ends in 2017-03-01
> > (march 1 2017).
> >
> > dataframe2 has the same  two columns, one with the dates in -MM-DD
> > format, and the other column with number of transits. dataframe2 starts
> > have the same start and end dates, however, dataframe2 has missing dates
> > between the start and end dates, so it has fewer observations.
> >
> > dataframe1 has a total of 378 observations and dataframe2 has a  total of
> > 362 observations.
> >
> > I would like to come up with a code that could do the following:
> >
> > Get the dates of dataframe1 that are missing in dataframe2 and add them as
> > records to dataframe 2 but with NA values.
> >
> >  >
> > Date  Transits  Date
> > Transits
> > 1985-10-01NA 1985-10-0115
> > 1985-11-01NA 1986-01-01 20
> > 1985-12-01NA 1986-02-01 5
> > 1986-01-01NA
> > 1986-02-01NA
> > 2017-03-01NA
> >
> > I would like to fill in the missing dates in dataframe2, with NA as value
> > for the missing transits, so that I  could end up with a dataframe3 looking
> > as follows:
> >
> >  > DateTransits
> > 1985-10-01  15
> > 1985-11-01   NA
> > 1985-12-01   NA
> > 1986-01-01   20
> > 1986-02-01   5
> > 2017-03-01   NA
> >
> > This is what I want to accomplish.
> >
> > Thanks, beforehand for your help,
> >
> > Best regards,
> >
> > Paul
> >
> >
> > 2017-03-27 15:15 GMT-05:00 Mark Sharp  > >:
> >
> >> Make some small dataframes of just a few rows that illustrate the problem
> >> structure. Make a third that has the result you want. You will get an
> >> answer very quickly. Without a self-contained reproducible problem,
> > results
> >> vary.
> >>
> >> Mark
> >> R. Mark Sharp, Ph.D.
> >> 

Re: [R] Way to Plot Multiple Variables and Change Color

2017-03-28 Thread Richard M. Heiberger
The colors can be specified with the standard lattice "col=" argument.

likert(t(BB), ReferenceZero=0, horizontal=FALSE,
   col=RColorBrewer::brewer.pal(4, "Blues"))

Most other customizations you might need are also possible.  Many examples
are in the examples section of ?likert and in the demo.

Rich


On Tue, Mar 28, 2017 at 8:56 AM,   wrote:
> Hi Richard,
>
> many thanks for your reply.
>
> Your solution is not exactly what I was looking for. I would like to know
> how I can change the colors of the stacked bars in my plot and not use the
> default values. How can this be done?
>
> Kind regards
>
> Georg
>
>
>
>
> Von:"Richard M. Heiberger" 
> An: g.maub...@weinwolf.de,
> Kopie:  r-help 
> Datum:  28.03.2017 17:40
> Betreff:Re: [R] Way to Plot Multiple Variables and Change Color
>
>
>
> I think you are looking for the likert function in the HH package.
> From ?likert
>
>
> Diverging stacked barcharts for Likert, semantic differential, rating
> scale data, and population pyramids.
>
>
> This will get you started.  Much more fine control is available.  See
> the examples and demo.
>
> ## install.packages("HH") ## if not yet on your system.
>
> library(HH)
>
> AA <- dfr[,-9]
>
> labels <- sort(unique(as.vector(data.matrix(AA
> result.template <- integer(length(labels))
> names(result.template) <- labels
>
> BB <- apply(AA, 2, function(x, result=result.template) {
>   tx <- table(x)
>   result[names(tx)] <- tx
>   result
> }
> )
>
> BB
>
> likert(t(BB), ReferenceZero=0, horizontal=FALSE)
>
>
> On Tue, Mar 28, 2017 at 6:05 AM,   wrote:
>> Hi All,
>>
>> in my current project I have to plot a whole bunch of related variables
>> (item batteries, e.g. How do you rate ... a) Accelaration, b) Horse
> Power,
>> c) Color Palette, etc.) which are all rated on a scale from 1 .. 4.
>>
>> I need to present the results as stacked bar charts where the variables
>> are columns and the percentages of the scales values (1 .. 4) are the
>> chunks of the stacked bar for each variable. To do this I have
> transformed
>> my data from wide to long and calculated the percentage for each
> variable
>> and value. The code for this is as follows:
>>
>> -- cut --
>>
>> dfr <- structure(
>>   list(
>> v07_01 = c(3, 1, 1, 4, 3, 4, 4, 1, 3, 2, 2, 3,
>>4, 4, 4, 1, 1, 3, 3, 4),
>> v07_02 = c(1, 2, 1, 1, 2, 1, 4, 1, 1,
>>4, 4, 1, 4, 4, 1, 3, 2, 3, 3, 1),
>> v07_03 = c(3, 2, 2, 1, 4, 1,
>>2, 3, 3, 1, 4, 2, 3, 1, 4, 1, 4, 2, 2, 3),
>> v07_04 = c(3, 1, 1,
>>4, 2, 4, 4, 2, 2, 2, 4, 1, 2, 1, 3, 1, 2, 4, 1, 4),
>> v07_05 = c(1,
>>2, 2, 2, 4, 4, 1, 1, 4, 4, 2, 1, 2, 1, 4, 1, 2, 4, 1, 4),
>> v07_06 = c(1,
>>2, 1, 2, 1, 1, 3, 4, 3, 2, 2, 3, 3, 2, 4, 2, 3, 1, 4, 3),
>> v07_07 = c(3,
>>2, 3, 3, 1, 1, 3, 3, 4, 4, 1, 3, 1, 3, 2, 4, 1, 2, 3, 4),
>> v07_08 = c(3,
>>2, 1, 2, 2, 2, 3, 3, 4, 4, 1, 1, 1, 2, 3, 1, 4, 2, 2, 4),
>> cased_id = structure(
>>   1:20,
>>   .Label = c(
>> "1",
>> "2",
>> "3",
>> "4",
>> "5",
>> "6",
>> "7",
>> "8",
>> "9",
>> "10",
>> "11",
>> "12",
>> "13",
>> "14",
>> "15",
>> "16",
>> "17",
>> "18",
>> "19",
>> "20"
>>   ),
>>   class = "factor"
>> )
>>   ),
>>   .Names = c(
>> "v07_01",
>> "v07_02",
>> "v07_03",
>> "v07_04",
>> "v07_05",
>> "v07_06",
>> "v07_07",
>> "v07_08",
>> "cased_id"
>>   ),
>>   row.names = c(NA, -20L),
>>   class = c("tbl_df", "tbl",
>> "data.frame")
>> )
>>
>> mdf <- melt(df)
>> d_result <- mdf  %>%
>>   dplyr::group_by(variable) %>%
>>   count(value)
>>
>> ggplot(
>>   d_result,
>>   aes(variable, y = n, fill = value)) +
>>   geom_bar(stat = "identity") +
>>   coord_cartesian(ylim = c(0,100))
>>
>> -- cut --
>>
>> Is there an easier way of doing this, i. e. a way without need to
>> transform the data?
>>
>> How can I change the colors for the data points 1 .. 4?
>>
>> I tried
>>
>> -- cut --
>>
>>   d_result,
>>   aes(variable, y = n, fill = value)) +
>>   geom_bar(stat = "identity") +
>>   coord_cartesian(ylim = c(0,100)) +
>>   scale_fill_manual(values = RColorBrewer::brewer.pal(4, "Blues"))
>>
>> -- cut -
>>
>> but this does not work cause I am mixing continuous and descrete values.
>>
>> How can I change the colors for the bars?
>>
>> Kind regards
>>
>> Georg
>>
>> __
>> 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] Antwort: Re: Way to Plot Multiple Variables and Change Color

2017-03-28 Thread G . Maubach
Hi Ulrik,

your answer is very valuable to me. If you do not know what I do, others 
don't either. So I should definitely adapt my code.

The result of your code and my code is the same. Thus, I use your code 
cause it is better readable.

My other question was how I can change the color palette for the stacked 
bars. Could you give me a hint where I need to look in ggplot2 
documentation?

Kind regards

Georg




Von:Ulrik Stervbo 
An: g.maub...@weinwolf.de, r-help@r-project.org, 
Datum:  28.03.2017 16:35
Betreff:Re: [R] Way to Plot Multiple Variables and Change Color



Hi Georg,

I am a little unsure of what you want to do, but maybe this:

mdf <- melt(dfr)
d_result <- mdf  %>%
  dplyr::group_by(variable, value) %>%
  summarise(n = n())

ggplot(
  d_result,
  aes(variable, y = n, fill = value)) +
  geom_bar(stat = "identity") 

HTH
Ulrik

On Tue, 28 Mar 2017 at 15:11  wrote:
Hi All,

in my current project I have to plot a whole bunch of related variables
(item batteries, e.g. How do you rate ... a) Accelaration, b) Horse Power,
c) Color Palette, etc.) which are all rated on a scale from 1 .. 4.

I need to present the results as stacked bar charts where the variables
are columns and the percentages of the scales values (1 .. 4) are the
chunks of the stacked bar for each variable. To do this I have transformed
my data from wide to long and calculated the percentage for each variable
and value. The code for this is as follows:

-- cut --

dfr <- structure(
  list(
v07_01 = c(3, 1, 1, 4, 3, 4, 4, 1, 3, 2, 2, 3,
   4, 4, 4, 1, 1, 3, 3, 4),
v07_02 = c(1, 2, 1, 1, 2, 1, 4, 1, 1,
   4, 4, 1, 4, 4, 1, 3, 2, 3, 3, 1),
v07_03 = c(3, 2, 2, 1, 4, 1,
   2, 3, 3, 1, 4, 2, 3, 1, 4, 1, 4, 2, 2, 3),
v07_04 = c(3, 1, 1,
   4, 2, 4, 4, 2, 2, 2, 4, 1, 2, 1, 3, 1, 2, 4, 1, 4),
v07_05 = c(1,
   2, 2, 2, 4, 4, 1, 1, 4, 4, 2, 1, 2, 1, 4, 1, 2, 4, 1, 4),
v07_06 = c(1,
   2, 1, 2, 1, 1, 3, 4, 3, 2, 2, 3, 3, 2, 4, 2, 3, 1, 4, 3),
v07_07 = c(3,
   2, 3, 3, 1, 1, 3, 3, 4, 4, 1, 3, 1, 3, 2, 4, 1, 2, 3, 4),
v07_08 = c(3,
   2, 1, 2, 2, 2, 3, 3, 4, 4, 1, 1, 1, 2, 3, 1, 4, 2, 2, 4),
cased_id = structure(
  1:20,
  .Label = c(
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"11",
"12",
"13",
"14",
"15",
"16",
"17",
"18",
"19",
"20"
  ),
  class = "factor"
)
  ),
  .Names = c(
"v07_01",
"v07_02",
"v07_03",
"v07_04",
"v07_05",
"v07_06",
"v07_07",
"v07_08",
"cased_id"
  ),
  row.names = c(NA, -20L),
  class = c("tbl_df", "tbl",
"data.frame")
)

mdf <- melt(df)
d_result <- mdf  %>%
  dplyr::group_by(variable) %>%
  count(value)

ggplot(
  d_result,
  aes(variable, y = n, fill = value)) +
  geom_bar(stat = "identity") +
  coord_cartesian(ylim = c(0,100))

-- cut --

Is there an easier way of doing this, i. e. a way without need to
transform the data?

How can I change the colors for the data points 1 .. 4?

I tried

-- cut --

  d_result,
  aes(variable, y = n, fill = value)) +
  geom_bar(stat = "identity") +
  coord_cartesian(ylim = c(0,100)) +
  scale_fill_manual(values = RColorBrewer::brewer.pal(4, "Blues"))

-- cut -

but this does not work cause I am mixing continuous and descrete values.

How can I change the colors for the bars?

Kind regards

Georg

__
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] Antwort: Re: Way to Plot Multiple Variables and Change Color

2017-03-28 Thread G . Maubach
Hi Richard,

many thanks for your reply.

Your solution is not exactly what I was looking for. I would like to know 
how I can change the colors of the stacked bars in my plot and not use the 
default values. How can this be done?

Kind regards

Georg




Von:"Richard M. Heiberger" 
An: g.maub...@weinwolf.de, 
Kopie:  r-help 
Datum:  28.03.2017 17:40
Betreff:Re: [R] Way to Plot Multiple Variables and Change Color



I think you are looking for the likert function in the HH package.
>From ?likert


Diverging stacked barcharts for Likert, semantic differential, rating
scale data, and population pyramids.


This will get you started.  Much more fine control is available.  See
the examples and demo.

## install.packages("HH") ## if not yet on your system.

library(HH)

AA <- dfr[,-9]

labels <- sort(unique(as.vector(data.matrix(AA
result.template <- integer(length(labels))
names(result.template) <- labels

BB <- apply(AA, 2, function(x, result=result.template) {
  tx <- table(x)
  result[names(tx)] <- tx
  result
}
)

BB

likert(t(BB), ReferenceZero=0, horizontal=FALSE)


On Tue, Mar 28, 2017 at 6:05 AM,   wrote:
> Hi All,
>
> in my current project I have to plot a whole bunch of related variables
> (item batteries, e.g. How do you rate ... a) Accelaration, b) Horse 
Power,
> c) Color Palette, etc.) which are all rated on a scale from 1 .. 4.
>
> I need to present the results as stacked bar charts where the variables
> are columns and the percentages of the scales values (1 .. 4) are the
> chunks of the stacked bar for each variable. To do this I have 
transformed
> my data from wide to long and calculated the percentage for each 
variable
> and value. The code for this is as follows:
>
> -- cut --
>
> dfr <- structure(
>   list(
> v07_01 = c(3, 1, 1, 4, 3, 4, 4, 1, 3, 2, 2, 3,
>4, 4, 4, 1, 1, 3, 3, 4),
> v07_02 = c(1, 2, 1, 1, 2, 1, 4, 1, 1,
>4, 4, 1, 4, 4, 1, 3, 2, 3, 3, 1),
> v07_03 = c(3, 2, 2, 1, 4, 1,
>2, 3, 3, 1, 4, 2, 3, 1, 4, 1, 4, 2, 2, 3),
> v07_04 = c(3, 1, 1,
>4, 2, 4, 4, 2, 2, 2, 4, 1, 2, 1, 3, 1, 2, 4, 1, 4),
> v07_05 = c(1,
>2, 2, 2, 4, 4, 1, 1, 4, 4, 2, 1, 2, 1, 4, 1, 2, 4, 1, 4),
> v07_06 = c(1,
>2, 1, 2, 1, 1, 3, 4, 3, 2, 2, 3, 3, 2, 4, 2, 3, 1, 4, 3),
> v07_07 = c(3,
>2, 3, 3, 1, 1, 3, 3, 4, 4, 1, 3, 1, 3, 2, 4, 1, 2, 3, 4),
> v07_08 = c(3,
>2, 1, 2, 2, 2, 3, 3, 4, 4, 1, 1, 1, 2, 3, 1, 4, 2, 2, 4),
> cased_id = structure(
>   1:20,
>   .Label = c(
> "1",
> "2",
> "3",
> "4",
> "5",
> "6",
> "7",
> "8",
> "9",
> "10",
> "11",
> "12",
> "13",
> "14",
> "15",
> "16",
> "17",
> "18",
> "19",
> "20"
>   ),
>   class = "factor"
> )
>   ),
>   .Names = c(
> "v07_01",
> "v07_02",
> "v07_03",
> "v07_04",
> "v07_05",
> "v07_06",
> "v07_07",
> "v07_08",
> "cased_id"
>   ),
>   row.names = c(NA, -20L),
>   class = c("tbl_df", "tbl",
> "data.frame")
> )
>
> mdf <- melt(df)
> d_result <- mdf  %>%
>   dplyr::group_by(variable) %>%
>   count(value)
>
> ggplot(
>   d_result,
>   aes(variable, y = n, fill = value)) +
>   geom_bar(stat = "identity") +
>   coord_cartesian(ylim = c(0,100))
>
> -- cut --
>
> Is there an easier way of doing this, i. e. a way without need to
> transform the data?
>
> How can I change the colors for the data points 1 .. 4?
>
> I tried
>
> -- cut --
>
>   d_result,
>   aes(variable, y = n, fill = value)) +
>   geom_bar(stat = "identity") +
>   coord_cartesian(ylim = c(0,100)) +
>   scale_fill_manual(values = RColorBrewer::brewer.pal(4, "Blues"))
>
> -- cut -
>
> but this does not work cause I am mixing continuous and descrete values.
>
> How can I change the colors for the bars?
>
> Kind regards
>
> Georg
>
> __
> 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] Way to Plot Multiple Variables and Change Color

2017-03-28 Thread Richard M. Heiberger
I think you are looking for the likert function in the HH package.
>From ?likert


Diverging stacked barcharts for Likert, semantic differential, rating
scale data, and population pyramids.


This will get you started.  Much more fine control is available.  See
the examples and demo.

## install.packages("HH") ## if not yet on your system.

library(HH)

AA <- dfr[,-9]

labels <- sort(unique(as.vector(data.matrix(AA
result.template <- integer(length(labels))
names(result.template) <- labels

BB <- apply(AA, 2, function(x, result=result.template) {
  tx <- table(x)
  result[names(tx)] <- tx
  result
}
)

BB

likert(t(BB), ReferenceZero=0, horizontal=FALSE)


On Tue, Mar 28, 2017 at 6:05 AM,   wrote:
> Hi All,
>
> in my current project I have to plot a whole bunch of related variables
> (item batteries, e.g. How do you rate ... a) Accelaration, b) Horse Power,
> c) Color Palette, etc.) which are all rated on a scale from 1 .. 4.
>
> I need to present the results as stacked bar charts where the variables
> are columns and the percentages of the scales values (1 .. 4) are the
> chunks of the stacked bar for each variable. To do this I have transformed
> my data from wide to long and calculated the percentage for each variable
> and value. The code for this is as follows:
>
> -- cut --
>
> dfr <- structure(
>   list(
> v07_01 = c(3, 1, 1, 4, 3, 4, 4, 1, 3, 2, 2, 3,
>4, 4, 4, 1, 1, 3, 3, 4),
> v07_02 = c(1, 2, 1, 1, 2, 1, 4, 1, 1,
>4, 4, 1, 4, 4, 1, 3, 2, 3, 3, 1),
> v07_03 = c(3, 2, 2, 1, 4, 1,
>2, 3, 3, 1, 4, 2, 3, 1, 4, 1, 4, 2, 2, 3),
> v07_04 = c(3, 1, 1,
>4, 2, 4, 4, 2, 2, 2, 4, 1, 2, 1, 3, 1, 2, 4, 1, 4),
> v07_05 = c(1,
>2, 2, 2, 4, 4, 1, 1, 4, 4, 2, 1, 2, 1, 4, 1, 2, 4, 1, 4),
> v07_06 = c(1,
>2, 1, 2, 1, 1, 3, 4, 3, 2, 2, 3, 3, 2, 4, 2, 3, 1, 4, 3),
> v07_07 = c(3,
>2, 3, 3, 1, 1, 3, 3, 4, 4, 1, 3, 1, 3, 2, 4, 1, 2, 3, 4),
> v07_08 = c(3,
>2, 1, 2, 2, 2, 3, 3, 4, 4, 1, 1, 1, 2, 3, 1, 4, 2, 2, 4),
> cased_id = structure(
>   1:20,
>   .Label = c(
> "1",
> "2",
> "3",
> "4",
> "5",
> "6",
> "7",
> "8",
> "9",
> "10",
> "11",
> "12",
> "13",
> "14",
> "15",
> "16",
> "17",
> "18",
> "19",
> "20"
>   ),
>   class = "factor"
> )
>   ),
>   .Names = c(
> "v07_01",
> "v07_02",
> "v07_03",
> "v07_04",
> "v07_05",
> "v07_06",
> "v07_07",
> "v07_08",
> "cased_id"
>   ),
>   row.names = c(NA, -20L),
>   class = c("tbl_df", "tbl",
> "data.frame")
> )
>
> mdf <- melt(df)
> d_result <- mdf  %>%
>   dplyr::group_by(variable) %>%
>   count(value)
>
> ggplot(
>   d_result,
>   aes(variable, y = n, fill = value)) +
>   geom_bar(stat = "identity") +
>   coord_cartesian(ylim = c(0,100))
>
> -- cut --
>
> Is there an easier way of doing this, i. e. a way without need to
> transform the data?
>
> How can I change the colors for the data points 1 .. 4?
>
> I tried
>
> -- cut --
>
>   d_result,
>   aes(variable, y = n, fill = value)) +
>   geom_bar(stat = "identity") +
>   coord_cartesian(ylim = c(0,100)) +
>   scale_fill_manual(values = RColorBrewer::brewer.pal(4, "Blues"))
>
> -- cut -
>
> but this does not work cause I am mixing continuous and descrete values.
>
> How can I change the colors for the bars?
>
> Kind regards
>
> Georg
>
> __
> 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] lubridate inserting unwelcome 9:21

2017-03-28 Thread Troels Ring
Dear friends - I have a series of times on successive days and would 
like to convert them into a successive common time for each person (ID) 
. Using lubridate and adding days(1) does as expected apart from 
changing time zone to LMT from UTC and suddenly adding 9:21 (H:M) to all 
times. Individual parts of the instructions seem OK. I'm sorry for the 
clumsy demonstration - but the error comes through.


R version 3.3.2 (2016-10-31) - Windows.

All best wishes
Troels

library(lubridate)

SSS <- structure(list(ID = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L,
3L, 3L, 3L, 3L, 3L, 3L), Time = c(-1L, 0L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, -1L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, -1L, 0L, 1L, 2L, 3L, 4L, 5L), VT = structure(c(3L,
5L, 11L, 11L, 8L, 10L, 8L, 10L, 8L, 7L, 11L, 5L, 5L, 12L, 5L,
7L, 7L, 5L, 5L, 8L, 10L, 8L, 7L, 7L, 7L, 2L, 8L, 7L, 8L, 7L,
10L, 8L), .Label = c("02:00", "03:00", "04:00", "05:00", "06:00",
"09:00", "10:00", "11:00", "11:30", "12:00", "13:00", "14:00",
"15:00", "17:00", "18:00", "21:30", "23:00"), class = "factor")), .Names 
= c("ID",

"Time", "VT"), row.names = c(NA, 32L), class = "data.frame")

SSS$VT  <- parse_date_time(SSS$VT,"HM")
str(SSS$VT)

TT <- list()
for(i in 1:3) {
#i <- 1
BS <- subset(SSS,ID==i)
TT[[i]] <- c(BS$VT + (1:length(BS[,1])-1)*days(1))
}
BS$VT
(1:length(BS[,1])-1)*days(1)

#these appear as expected but

TT

#appears disturbed 9:21 inserted - LMT time zone - how comes?

__
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] How to apply calculations in "formula" to "data frame"

2017-03-28 Thread peter dalgaard

> On 28 Mar 2017, at 16:14 , Sören Vogel  wrote:
> 
> Hello
> 
> Ho can I apply a formula to a data frame?


That would depend on whether the formula has any special interpretation.

If if is just an elementary expression, then it would be like 

eval(For1[[3]], Data, environment(For1))

but you are using "." to represent... what exactly?

One possibility is model.matrix(For1, Data)

but I'm not at all sure that that is what you want.

-pd

> 
> library("formula.tools")
> Data <- data.frame("v1" = rnorm(31), "v2" = runif(31), "v3" = sample(1:7, 31, 
> repl=T), "v4" = rlnorm(31))
> For1 <- as.formula(v1 ~ .^3)
> Lhs <- Data[, formula.tools::lhs.vars(formula)]
> Rhs <- apply_formula_to_data_frame_and_return_result(data, formula) # ???
> 
> Thank you,
> Sören
> 
> __
> 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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
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] Looping Through DataFrames with Differing Lenghts

2017-03-28 Thread David L Carlson
We did not get the file on the list. You need to rename your file to 
"Container.txt" or the mailing list will strip it from your message. The 
read.csv() function returns a data frame so Data is already a data frame. The 
command DataFrame<-data.frame(Data) just makes a copy of Data. 

Without the file, it is difficult to be certain, but your dates are probably 
stored as character strings and read.csv() will turn those to factors unless 
you tell it not to do that. Try

Data<-read.csv("Container.csv", stringsAsFactors=FALSE)
str(Data) # To see how the dates are stored

and see if things work better. If not, rename the file or use dput(Data) and 
copy the result into your email message. If the data is very long, use 
dput(head(Data, 15)).

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


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Paul Bernal
Sent: Tuesday, March 28, 2017 9:12 AM
To: Ng Bo Lin 
Cc: r-help@r-project.org
Subject: Re: [R] Looping Through DataFrames with Differing Lenghts

Dear friends Ng Bo Lin, Mark and Ulrik, thank you all for your kind and
valuable replies,

I am trying to reformat a date as follows:

Data<-read.csv("Container.csv")

DataFrame<-data.frame(Data)

DataFrame$TransitDate<-as.Date(DataFrame$TransitDate, "%Y-%m-%d")

#trying to put it in -MM-DD format

However, when I do this, I get a bunch of NAs for the dates.

I am providing a sample dataset as a reference.

Any help will be greatly appreciated,

Best regards,

Paul

2017-03-28 8:15 GMT-05:00 Ng Bo Lin :

> Hi Paul,
>
> Using the example provided by Ulrik, where
>
> > exdf1 <- data.frame(Date = c("1985-10-01", "1985-11-01", "1985-12-01”,
> "1986-01-01"), Transits = c(NA, NA, NA, NA))
> > exdf2 <- data.frame(Date = c("1985-10-01", "1986-01-01"), Transits =
> c(15,20)),
>
> You could also try the following function:
>
> for (i in 1:dim(exdf1)[1]){
> if (!exdf1[i, 1] %in% exdf2[, 1]){
> exdf2 <- rbind(exdf2, exdf1[i,])
> }
> }
>
> Basically, what the function does is that it runs through the number of
> rows in exdf1, and checks if the Date of the exdf1 row already exists in
> Date column of exdf2. If so, it skips it. Otherwise, it binds the row to
> df2.
>
> Hope this helps!
>
>
> Side note.: Computational efficiency wise, think Ulrik’s answer is
> probably better. Presentation wise, his is also much better.
>
> Regards,
> Bo Lin
>
> > On 28 Mar 2017, at 5:22 PM, Ulrik Stervbo 
> wrote:
> >
> > Hi Paul,
> >
> > does this do what you want?
> >
> > exdf1 <- data.frame(Date = c("1985-10-01", "1985-11-01", "1985-12-01",
> > "1986-01-01"), Transits = c(NA, NA, NA, NA))
> > exdf2 <- data.frame(Date = c("1985-10-01", "1986-01-01"), Transits =
> c(15,
> > 20))
> >
> > tmpdf <- subset(exdf1, !Date %in% exdf2$Date)
> >
> > rbind(exdf2, tmpdf)
> >
> > HTH,
> > Ulrik
> >
> > On Tue, 28 Mar 2017 at 10:50 Paul Bernal  wrote:
> >
> > Dear friend Mark,
> >
> > Great suggestion! Thank you for replying.
> >
> > I have two dataframes, dataframe1 and dataframe2.
> >
> > dataframe1 has two columns, one with the dates in -MM-DD format and
> the
> > other colum with number of transits (all of which were set to NA values).
> > dataframe1 starts in 1985-10-01 (october 1st 1985) and ends in 2017-03-01
> > (march 1 2017).
> >
> > dataframe2 has the same  two columns, one with the dates in -MM-DD
> > format, and the other column with number of transits. dataframe2 starts
> > have the same start and end dates, however, dataframe2 has missing dates
> > between the start and end dates, so it has fewer observations.
> >
> > dataframe1 has a total of 378 observations and dataframe2 has a  total of
> > 362 observations.
> >
> > I would like to come up with a code that could do the following:
> >
> > Get the dates of dataframe1 that are missing in dataframe2 and add them
> as
> > records to dataframe 2 but with NA values.
> >
> >  >
> > Date  Transits  Date
> > Transits
> > 1985-10-01NA 1985-10-0115
> > 1985-11-01NA 1986-01-01 20
> > 1985-12-01NA 1986-02-01 5
> > 1986-01-01NA
> > 1986-02-01NA
> > 2017-03-01NA
> >
> > I would like to fill in the missing dates in dataframe2, with NA as value
> > for the missing transits, so that I  could end up with a dataframe3
> looking
> > as follows:
> >
> >  > DateTransits
> > 1985-10-01  15
> > 1985-11-01   NA
> > 1985-12-01   NA
> > 1986-01-01   20
> > 1986-02-01   5
> > 2017-03-01   NA
> >
> > This is what I want to accomplish.
> >
> > 

Re: [R] Way to Plot Multiple Variables and Change Color

2017-03-28 Thread Ulrik Stervbo
Hi Georg,

I am a little unsure of what you want to do, but maybe this:

mdf <- melt(dfr)
d_result <- mdf  %>%
  dplyr::group_by(variable, value) %>%
  summarise(n = n())

ggplot(
  d_result,
  aes(variable, y = n, fill = value)) +
  geom_bar(stat = "identity")

HTH
Ulrik

On Tue, 28 Mar 2017 at 15:11  wrote:

> Hi All,
>
> in my current project I have to plot a whole bunch of related variables
> (item batteries, e.g. How do you rate ... a) Accelaration, b) Horse Power,
> c) Color Palette, etc.) which are all rated on a scale from 1 .. 4.
>
> I need to present the results as stacked bar charts where the variables
> are columns and the percentages of the scales values (1 .. 4) are the
> chunks of the stacked bar for each variable. To do this I have transformed
> my data from wide to long and calculated the percentage for each variable
> and value. The code for this is as follows:
>
> -- cut --
>
> dfr <- structure(
>   list(
> v07_01 = c(3, 1, 1, 4, 3, 4, 4, 1, 3, 2, 2, 3,
>4, 4, 4, 1, 1, 3, 3, 4),
> v07_02 = c(1, 2, 1, 1, 2, 1, 4, 1, 1,
>4, 4, 1, 4, 4, 1, 3, 2, 3, 3, 1),
> v07_03 = c(3, 2, 2, 1, 4, 1,
>2, 3, 3, 1, 4, 2, 3, 1, 4, 1, 4, 2, 2, 3),
> v07_04 = c(3, 1, 1,
>4, 2, 4, 4, 2, 2, 2, 4, 1, 2, 1, 3, 1, 2, 4, 1, 4),
> v07_05 = c(1,
>2, 2, 2, 4, 4, 1, 1, 4, 4, 2, 1, 2, 1, 4, 1, 2, 4, 1, 4),
> v07_06 = c(1,
>2, 1, 2, 1, 1, 3, 4, 3, 2, 2, 3, 3, 2, 4, 2, 3, 1, 4, 3),
> v07_07 = c(3,
>2, 3, 3, 1, 1, 3, 3, 4, 4, 1, 3, 1, 3, 2, 4, 1, 2, 3, 4),
> v07_08 = c(3,
>2, 1, 2, 2, 2, 3, 3, 4, 4, 1, 1, 1, 2, 3, 1, 4, 2, 2, 4),
> cased_id = structure(
>   1:20,
>   .Label = c(
> "1",
> "2",
> "3",
> "4",
> "5",
> "6",
> "7",
> "8",
> "9",
> "10",
> "11",
> "12",
> "13",
> "14",
> "15",
> "16",
> "17",
> "18",
> "19",
> "20"
>   ),
>   class = "factor"
> )
>   ),
>   .Names = c(
> "v07_01",
> "v07_02",
> "v07_03",
> "v07_04",
> "v07_05",
> "v07_06",
> "v07_07",
> "v07_08",
> "cased_id"
>   ),
>   row.names = c(NA, -20L),
>   class = c("tbl_df", "tbl",
> "data.frame")
> )
>
> mdf <- melt(df)
> d_result <- mdf  %>%
>   dplyr::group_by(variable) %>%
>   count(value)
>
> ggplot(
>   d_result,
>   aes(variable, y = n, fill = value)) +
>   geom_bar(stat = "identity") +
>   coord_cartesian(ylim = c(0,100))
>
> -- cut --
>
> Is there an easier way of doing this, i. e. a way without need to
> transform the data?
>
> How can I change the colors for the data points 1 .. 4?
>
> I tried
>
> -- cut --
>
>   d_result,
>   aes(variable, y = n, fill = value)) +
>   geom_bar(stat = "identity") +
>   coord_cartesian(ylim = c(0,100)) +
>   scale_fill_manual(values = RColorBrewer::brewer.pal(4, "Blues"))
>
> -- cut -
>
> but this does not work cause I am mixing continuous and descrete values.
>
> How can I change the colors for the bars?
>
> Kind regards
>
> Georg
>
> __
> 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] Looping Through DataFrames with Differing Lenghts

2017-03-28 Thread Paul Bernal
Dear Bo Lin,

I tried doing
Containerdata$TransitDate<-as.Date(Containerdata$TransitDate, "%e-%B-%y")
but I keep getting NAs.

I also tried a solution that I saw in stackoverflow doing:

> lct<-Sys.getlocale("LC_TIME"); Sys.setlocale("LC_TIME", "C")
[1] "C"
>
> Sys.setlocale("LC_TIME", lct)
[1] "English_United States.1252"

but didn´t work.

Any other suggestion?

Thank you for your valuable help,

Regards,

Paul

2017-03-28 9:19 GMT-05:00 Ng Bo Lin :

> Hi Paul,
>
> The date format that you have supplied to R isn’t exactly right.
>
> Instead of supplying the format “%Y-%m-%d”, it appears that the format of
> your data adheres to the “%e-%B-%y” format. In this case, %e refers to Day,
> and takes an integer between (0 - 31), %B refers to the 3 letter
> abbreviated version of the Month, and %y refers to the Year provided in a
> “2-integer” format.
>
> Hope this helps!
>
> Thank you.
>
> Regards,
> Bo Lin
>
> On 28 Mar 2017, at 10:12 PM, Paul Bernal  wrote:
>
> Dear friends Ng Bo Lin, Mark and Ulrik, thank you all for your kind and
> valuable replies,
>
> I am trying to reformat a date as follows:
>
> Data<-read.csv("Container.csv")
>
> DataFrame<-data.frame(Data)
>
> DataFrame$TransitDate<-as.Date(DataFrame$TransitDate, "%Y-%m-%d")
>
> #trying to put it in -MM-DD format
>
> However, when I do this, I get a bunch of NAs for the dates.
>
> I am providing a sample dataset as a reference.
>
> Any help will be greatly appreciated,
>
> Best regards,
>
> Paul
>
> 2017-03-28 8:15 GMT-05:00 Ng Bo Lin :
>
>> Hi Paul,
>>
>> Using the example provided by Ulrik, where
>>
>> > exdf1 <- data.frame(Date = c("1985-10-01", "1985-11-01", "1985-12-01”,
>> "1986-01-01"), Transits = c(NA, NA, NA, NA))
>> > exdf2 <- data.frame(Date = c("1985-10-01", "1986-01-01"), Transits =
>> c(15,20)),
>>
>> You could also try the following function:
>>
>> for (i in 1:dim(exdf1)[1]){
>> if (!exdf1[i, 1] %in% exdf2[, 1]){
>> exdf2 <- rbind(exdf2, exdf1[i,])
>> }
>> }
>>
>> Basically, what the function does is that it runs through the number of
>> rows in exdf1, and checks if the Date of the exdf1 row already exists in
>> Date column of exdf2. If so, it skips it. Otherwise, it binds the row to
>> df2.
>>
>> Hope this helps!
>>
>>
>> Side note.: Computational efficiency wise, think Ulrik’s answer is
>> probably better. Presentation wise, his is also much better.
>>
>> Regards,
>> Bo Lin
>>
>> > On 28 Mar 2017, at 5:22 PM, Ulrik Stervbo 
>> wrote:
>> >
>> > Hi Paul,
>> >
>> > does this do what you want?
>> >
>> > exdf1 <- data.frame(Date = c("1985-10-01", "1985-11-01", "1985-12-01",
>> > "1986-01-01"), Transits = c(NA, NA, NA, NA))
>> > exdf2 <- data.frame(Date = c("1985-10-01", "1986-01-01"), Transits =
>> c(15,
>> > 20))
>> >
>> > tmpdf <- subset(exdf1, !Date %in% exdf2$Date)
>> >
>> > rbind(exdf2, tmpdf)
>> >
>> > HTH,
>> > Ulrik
>> >
>> > On Tue, 28 Mar 2017 at 10:50 Paul Bernal 
>> wrote:
>> >
>> > Dear friend Mark,
>> >
>> > Great suggestion! Thank you for replying.
>> >
>> > I have two dataframes, dataframe1 and dataframe2.
>> >
>> > dataframe1 has two columns, one with the dates in -MM-DD format and
>> the
>> > other colum with number of transits (all of which were set to NA
>> values).
>> > dataframe1 starts in 1985-10-01 (october 1st 1985) and ends in
>> 2017-03-01
>> > (march 1 2017).
>> >
>> > dataframe2 has the same  two columns, one with the dates in -MM-DD
>> > format, and the other column with number of transits. dataframe2 starts
>> > have the same start and end dates, however, dataframe2 has missing dates
>> > between the start and end dates, so it has fewer observations.
>> >
>> > dataframe1 has a total of 378 observations and dataframe2 has a  total
>> of
>> > 362 observations.
>> >
>> > I would like to come up with a code that could do the following:
>> >
>> > Get the dates of dataframe1 that are missing in dataframe2 and add them
>> as
>> > records to dataframe 2 but with NA values.
>> >
>> > > >
>> > Date  Transits  Date
>> > Transits
>> > 1985-10-01NA 1985-10-0115
>> > 1985-11-01NA 1986-01-01 20
>> > 1985-12-01NA 1986-02-01 5
>> > 1986-01-01NA
>> > 1986-02-01NA
>> > 2017-03-01NA
>> >
>> > I would like to fill in the missing dates in dataframe2, with NA as
>> value
>> > for the missing transits, so that I  could end up with a dataframe3
>> looking
>> > as follows:
>> >
>> > > > DateTransits
>> > 1985-10-01  15
>> > 1985-11-01   NA
>> > 1985-12-01   NA
>> > 1986-01-01   20
>> > 1986-02-01   5
>> > 2017-03-01   NA
>> >
>> > This is what I want to 

Re: [R] Looping Through DataFrames with Differing Lenghts

2017-03-28 Thread Paul Bernal
Dear friends Ng Bo Lin, Mark and Ulrik, thank you all for your kind and
valuable replies,

I am trying to reformat a date as follows:

Data<-read.csv("Container.csv")

DataFrame<-data.frame(Data)

DataFrame$TransitDate<-as.Date(DataFrame$TransitDate, "%Y-%m-%d")

#trying to put it in -MM-DD format

However, when I do this, I get a bunch of NAs for the dates.

I am providing a sample dataset as a reference.

Any help will be greatly appreciated,

Best regards,

Paul

2017-03-28 8:15 GMT-05:00 Ng Bo Lin :

> Hi Paul,
>
> Using the example provided by Ulrik, where
>
> > exdf1 <- data.frame(Date = c("1985-10-01", "1985-11-01", "1985-12-01”,
> "1986-01-01"), Transits = c(NA, NA, NA, NA))
> > exdf2 <- data.frame(Date = c("1985-10-01", "1986-01-01"), Transits =
> c(15,20)),
>
> You could also try the following function:
>
> for (i in 1:dim(exdf1)[1]){
> if (!exdf1[i, 1] %in% exdf2[, 1]){
> exdf2 <- rbind(exdf2, exdf1[i,])
> }
> }
>
> Basically, what the function does is that it runs through the number of
> rows in exdf1, and checks if the Date of the exdf1 row already exists in
> Date column of exdf2. If so, it skips it. Otherwise, it binds the row to
> df2.
>
> Hope this helps!
>
>
> Side note.: Computational efficiency wise, think Ulrik’s answer is
> probably better. Presentation wise, his is also much better.
>
> Regards,
> Bo Lin
>
> > On 28 Mar 2017, at 5:22 PM, Ulrik Stervbo 
> wrote:
> >
> > Hi Paul,
> >
> > does this do what you want?
> >
> > exdf1 <- data.frame(Date = c("1985-10-01", "1985-11-01", "1985-12-01",
> > "1986-01-01"), Transits = c(NA, NA, NA, NA))
> > exdf2 <- data.frame(Date = c("1985-10-01", "1986-01-01"), Transits =
> c(15,
> > 20))
> >
> > tmpdf <- subset(exdf1, !Date %in% exdf2$Date)
> >
> > rbind(exdf2, tmpdf)
> >
> > HTH,
> > Ulrik
> >
> > On Tue, 28 Mar 2017 at 10:50 Paul Bernal  wrote:
> >
> > Dear friend Mark,
> >
> > Great suggestion! Thank you for replying.
> >
> > I have two dataframes, dataframe1 and dataframe2.
> >
> > dataframe1 has two columns, one with the dates in -MM-DD format and
> the
> > other colum with number of transits (all of which were set to NA values).
> > dataframe1 starts in 1985-10-01 (october 1st 1985) and ends in 2017-03-01
> > (march 1 2017).
> >
> > dataframe2 has the same  two columns, one with the dates in -MM-DD
> > format, and the other column with number of transits. dataframe2 starts
> > have the same start and end dates, however, dataframe2 has missing dates
> > between the start and end dates, so it has fewer observations.
> >
> > dataframe1 has a total of 378 observations and dataframe2 has a  total of
> > 362 observations.
> >
> > I would like to come up with a code that could do the following:
> >
> > Get the dates of dataframe1 that are missing in dataframe2 and add them
> as
> > records to dataframe 2 but with NA values.
> >
> >  >
> > Date  Transits  Date
> > Transits
> > 1985-10-01NA 1985-10-0115
> > 1985-11-01NA 1986-01-01 20
> > 1985-12-01NA 1986-02-01 5
> > 1986-01-01NA
> > 1986-02-01NA
> > 2017-03-01NA
> >
> > I would like to fill in the missing dates in dataframe2, with NA as value
> > for the missing transits, so that I  could end up with a dataframe3
> looking
> > as follows:
> >
> >  > DateTransits
> > 1985-10-01  15
> > 1985-11-01   NA
> > 1985-12-01   NA
> > 1986-01-01   20
> > 1986-02-01   5
> > 2017-03-01   NA
> >
> > This is what I want to accomplish.
> >
> > Thanks, beforehand for your help,
> >
> > Best regards,
> >
> > Paul
> >
> >
> > 2017-03-27 15:15 GMT-05:00 Mark Sharp :
> >
> >> Make some small dataframes of just a few rows that illustrate the
> problem
> >> structure. Make a third that has the result you want. You will get an
> >> answer very quickly. Without a self-contained reproducible problem,
> > results
> >> vary.
> >>
> >> Mark
> >> R. Mark Sharp, Ph.D.
> >> msh...@txbiomed.org
> >>
> >>
> >>
> >>
> >>
> >>> On Mar 27, 2017, at 3:09 PM, Paul Bernal 
> wrote:
> >>>
> >>> Dear friends,
> >>>
> >>> I have one dataframe which contains 378 observations, and another one,
> >>> containing 362 observations.
> >>>
> >>> Both dataframes have two columns, one date column and another one with
> >> the
> >>> number of transits.
> >>>
> >>> I wanted to come up with a code so that I could fill in the dates that
> >> are
> >>> missing in one of the dataframes and replace the column of transits
> with
> >>> the value NA.
> >>>
> >>> I have tried several things but R obviously complains that the length
> of
> >>> the dataframes are different.
> >>>
> >>> 

[R] How to apply calculations in "formula" to "data frame"

2017-03-28 Thread Sören Vogel
Hello

Ho can I apply a formula to a data frame?

library("formula.tools")
Data <- data.frame("v1" = rnorm(31), "v2" = runif(31), "v3" = sample(1:7, 31, 
repl=T), "v4" = rlnorm(31))
For1 <- as.formula(v1 ~ .^3)
Lhs <- Data[, formula.tools::lhs.vars(formula)]
Rhs <- apply_formula_to_data_frame_and_return_result(data, formula) # ???

Thank you,
Sören

__
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] How to load fonts in text3d?

2017-03-28 Thread olsen
Following these pointers given by Duncan Murdoch is the key to success,
at least on my system.

Many thanks!
olsen



On 28/03/17 13:49, Duncan Murdoch wrote:
> On 28/03/2017 6:39 AM, olsen wrote:
>> I think I found the fly in the ointment, running the same text3d() lines
>> with 'useFreeType=TRUE' returns:
>> "FreeType not supported in this build"
> 
> You need to install FreeType and FTGL.  I think this is how to do it on
> Trusty.  Don't know if it will work on your Ubuntu version.
> 
> sudo apt-get install libfreetype6-dev
> sudo apt-get install libftgl-dev
> 
> and then reinstall rgl from within R using
> 
> install.packages("rgl", type="source")
> 
> Duncan Murdoch
> 
>>
>>
>> On 28/03/17 11:05, olsen wrote:
>>> thanks, the fonts seem to be on:
 rglFonts()
>>> $serif
>>> [1] "/usr/lib/R/site-library/rgl/fonts/FreeSerif.ttf"
>>> [2] "/usr/lib/R/site-library/rgl/fonts/FreeSerif.ttf"
>>> [3] "/usr/lib/R/site-library/rgl/fonts/FreeSerif.ttf"
>>> [4] "/usr/lib/R/site-library/rgl/fonts/FreeSerif.ttf"
>>>
>>> $sans
>>> [1] "/usr/lib/R/site-library/rgl/fonts/FreeSans.ttf"
>>> [2] "/usr/lib/R/site-library/rgl/fonts/FreeSans.ttf"
>>> [3] "/usr/lib/R/site-library/rgl/fonts/FreeSans.ttf"
>>> [4] "/usr/lib/R/site-library/rgl/fonts/FreeSans.ttf"
>>>
>>> $mono
>>> [1] "/usr/lib/R/site-library/rgl/fonts/FreeMono.ttf"
>>> [2] "/usr/lib/R/site-library/rgl/fonts/FreeMono.ttf"
>>> [3] "/usr/lib/R/site-library/rgl/fonts/FreeMono.ttf"
>>> [4] "/usr/lib/R/site-library/rgl/fonts/FreeMono.ttf"
>>>
>>> $symbol
>>> [1] "/usr/lib/R/site-library/rgl/fonts/FreeSerif.ttf"
>>> [2] "/usr/lib/R/site-library/rgl/fonts/FreeSerif.ttf"
>>> [3] "/usr/lib/R/site-library/rgl/fonts/FreeSerif.ttf"
>>> [4] "/usr/lib/R/site-library/rgl/fonts/FreeSerif.ttf"
>>>
>>> On 27/03/17 20:21, Duncan Murdoch wrote:
 On 27/03/2017 1:09 PM, olsen wrote:
> I'm trying to run the example given in ?text3d as follows:
>
> library(rgl)
> open3d()
> famnum <- rep(1:4, 8)
> family <- c("serif", "sans", "mono", "symbol")[famnum]
> font <- rep(rep(1:4, each = 4), 2)
> cex <- rep(1:2, each = 16)
> text3d(font, cex, famnum, text = paste(family, font), adj = 0.5,
>color = "blue", family = family, font = font, cex = cex)
>
> This results in a couple of warning messages of the following kind:
>
> In rgl.texts(x = c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L,  ... :
>   font family "serif" not found, using "bitmap"
>
> I would like to use another font instead of bitmap but it seems to
> switchback to bitmap whatever argument I give as family e.g. 'family =
> "FreeSans"'.
> Wonder if this is a bug or I'm doing something wrong.
>
> This is on
> R version 3.3.2 (2016-10-31)
> Platform: x86_64-pc-linux-gnu (64-bit)
> Running under: Debian GNU/Linux 9 (stretch)
> with the following rgl version loaded:
> [1] rgl_0.96.0

 What do you see if you run rglFonts()?  It should list the fonts you
 have installed.  On MacOS, I see

> rglFonts()
 $serif
 [1]
 "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"


 [2]
 "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"


 [3]
 "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"


 [4]
 "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"



 $sans
 [1]
 "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSans.ttf"


 [2]
 "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSans.ttf"


 [3]
 "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSans.ttf"


 [4]
 "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSans.ttf"



 $mono
 [1]
 "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeMono.ttf"


 [2]
 "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeMono.ttf"


 [3]
 "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeMono.ttf"


 [4]
 "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeMono.ttf"



 $symbol
 [1]
 "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"


 [2]
 "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"


 [3]
 "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"


 [4]
 "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"



 If you don't have Freetype installed on your system, you won't be able

Re: [R] finding out if a method exists

2017-03-28 Thread Duncan Murdoch

On 28/03/2017 8:53 AM, Therneau, Terry M., Ph.D. wrote:

I'm thinking of adding a new "cmatrix" function/method to the survival package 
but before
I do I'd like to find out if any other packages already use this function name. 
  The
obvious method is to look at the NAMESPACE file for each package in CRAN and 
read the
export list.

This is the kind of task for which someone, somewhere will have written 
routines.  I just
don't know who or where.

Any hints?



Google is pretty good at finding documentation.  Since CRAN won't let 
you publish a package that exports a function without documenting it, 
that's probably good enough (though it will lead to a few false 
positives, e.g. multcomp::simtest has an argument named cmatrix).


I don't see a cmatrix function in a Google search.

I happen to have a copy of all CRAN packages on my system, and searching 
the NAMESPACE files finds no cmatrix, but it does find ibd::Cmatrix.  So 
I think you're safe.


Duncan Murdoch

__
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] Way to Plot Multiple Variables and Change Color

2017-03-28 Thread G . Maubach
Hi All,

in my current project I have to plot a whole bunch of related variables 
(item batteries, e.g. How do you rate ... a) Accelaration, b) Horse Power, 
c) Color Palette, etc.) which are all rated on a scale from 1 .. 4.

I need to present the results as stacked bar charts where the variables 
are columns and the percentages of the scales values (1 .. 4) are the 
chunks of the stacked bar for each variable. To do this I have transformed 
my data from wide to long and calculated the percentage for each variable 
and value. The code for this is as follows:

-- cut --

dfr <- structure(
  list(
v07_01 = c(3, 1, 1, 4, 3, 4, 4, 1, 3, 2, 2, 3,
   4, 4, 4, 1, 1, 3, 3, 4),
v07_02 = c(1, 2, 1, 1, 2, 1, 4, 1, 1,
   4, 4, 1, 4, 4, 1, 3, 2, 3, 3, 1),
v07_03 = c(3, 2, 2, 1, 4, 1,
   2, 3, 3, 1, 4, 2, 3, 1, 4, 1, 4, 2, 2, 3),
v07_04 = c(3, 1, 1,
   4, 2, 4, 4, 2, 2, 2, 4, 1, 2, 1, 3, 1, 2, 4, 1, 4),
v07_05 = c(1,
   2, 2, 2, 4, 4, 1, 1, 4, 4, 2, 1, 2, 1, 4, 1, 2, 4, 1, 4),
v07_06 = c(1,
   2, 1, 2, 1, 1, 3, 4, 3, 2, 2, 3, 3, 2, 4, 2, 3, 1, 4, 3),
v07_07 = c(3,
   2, 3, 3, 1, 1, 3, 3, 4, 4, 1, 3, 1, 3, 2, 4, 1, 2, 3, 4),
v07_08 = c(3,
   2, 1, 2, 2, 2, 3, 3, 4, 4, 1, 1, 1, 2, 3, 1, 4, 2, 2, 4),
cased_id = structure(
  1:20,
  .Label = c(
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"11",
"12",
"13",
"14",
"15",
"16",
"17",
"18",
"19",
"20"
  ),
  class = "factor"
)
  ),
  .Names = c(
"v07_01",
"v07_02",
"v07_03",
"v07_04",
"v07_05",
"v07_06",
"v07_07",
"v07_08",
"cased_id"
  ),
  row.names = c(NA, -20L),
  class = c("tbl_df", "tbl",
"data.frame")
)

mdf <- melt(df)
d_result <- mdf  %>%
  dplyr::group_by(variable) %>%
  count(value)

ggplot(
  d_result,
  aes(variable, y = n, fill = value)) +
  geom_bar(stat = "identity") +
  coord_cartesian(ylim = c(0,100))

-- cut --

Is there an easier way of doing this, i. e. a way without need to 
transform the data?

How can I change the colors for the data points 1 .. 4?

I tried

-- cut --

  d_result,
  aes(variable, y = n, fill = value)) +
  geom_bar(stat = "identity") +
  coord_cartesian(ylim = c(0,100)) +
  scale_fill_manual(values = RColorBrewer::brewer.pal(4, "Blues"))

-- cut -

but this does not work cause I am mixing continuous and descrete values.

How can I change the colors for the bars?

Kind regards

Georg

__
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] finding out if a method exists

2017-03-28 Thread Therneau, Terry M., Ph.D.
I'm thinking of adding a new "cmatrix" function/method to the survival package but before 
I do I'd like to find out if any other packages already use this function name.   The 
obvious method is to look at the NAMESPACE file for each package in CRAN and read the 
export list.


This is the kind of task for which someone, somewhere will have written routines.  I just 
don't know who or where.


Any hints?

Terry T.

__
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] How to load fonts in text3d?

2017-03-28 Thread Duncan Murdoch

On 28/03/2017 6:39 AM, olsen wrote:

I think I found the fly in the ointment, running the same text3d() lines
with 'useFreeType=TRUE' returns:
"FreeType not supported in this build"


You need to install FreeType and FTGL.  I think this is how to do it on 
Trusty.  Don't know if it will work on your Ubuntu version.


sudo apt-get install libfreetype6-dev
sudo apt-get install libftgl-dev

and then reinstall rgl from within R using

install.packages("rgl", type="source")

Duncan Murdoch




On 28/03/17 11:05, olsen wrote:

thanks, the fonts seem to be on:

rglFonts()

$serif
[1] "/usr/lib/R/site-library/rgl/fonts/FreeSerif.ttf"
[2] "/usr/lib/R/site-library/rgl/fonts/FreeSerif.ttf"
[3] "/usr/lib/R/site-library/rgl/fonts/FreeSerif.ttf"
[4] "/usr/lib/R/site-library/rgl/fonts/FreeSerif.ttf"

$sans
[1] "/usr/lib/R/site-library/rgl/fonts/FreeSans.ttf"
[2] "/usr/lib/R/site-library/rgl/fonts/FreeSans.ttf"
[3] "/usr/lib/R/site-library/rgl/fonts/FreeSans.ttf"
[4] "/usr/lib/R/site-library/rgl/fonts/FreeSans.ttf"

$mono
[1] "/usr/lib/R/site-library/rgl/fonts/FreeMono.ttf"
[2] "/usr/lib/R/site-library/rgl/fonts/FreeMono.ttf"
[3] "/usr/lib/R/site-library/rgl/fonts/FreeMono.ttf"
[4] "/usr/lib/R/site-library/rgl/fonts/FreeMono.ttf"

$symbol
[1] "/usr/lib/R/site-library/rgl/fonts/FreeSerif.ttf"
[2] "/usr/lib/R/site-library/rgl/fonts/FreeSerif.ttf"
[3] "/usr/lib/R/site-library/rgl/fonts/FreeSerif.ttf"
[4] "/usr/lib/R/site-library/rgl/fonts/FreeSerif.ttf"

On 27/03/17 20:21, Duncan Murdoch wrote:

On 27/03/2017 1:09 PM, olsen wrote:

I'm trying to run the example given in ?text3d as follows:

library(rgl)
open3d()
famnum <- rep(1:4, 8)
family <- c("serif", "sans", "mono", "symbol")[famnum]
font <- rep(rep(1:4, each = 4), 2)
cex <- rep(1:2, each = 16)
text3d(font, cex, famnum, text = paste(family, font), adj = 0.5,
   color = "blue", family = family, font = font, cex = cex)

This results in a couple of warning messages of the following kind:

In rgl.texts(x = c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L,  ... :
  font family "serif" not found, using "bitmap"

I would like to use another font instead of bitmap but it seems to
switchback to bitmap whatever argument I give as family e.g. 'family =
"FreeSans"'.
Wonder if this is a bug or I'm doing something wrong.

This is on
R version 3.3.2 (2016-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 9 (stretch)
with the following rgl version loaded:
[1] rgl_0.96.0


What do you see if you run rglFonts()?  It should list the fonts you
have installed.  On MacOS, I see


rglFonts()

$serif
[1]
"/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"

[2]
"/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"

[3]
"/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"

[4]
"/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"


$sans
[1]
"/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSans.ttf"

[2]
"/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSans.ttf"

[3]
"/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSans.ttf"

[4]
"/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSans.ttf"


$mono
[1]
"/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeMono.ttf"

[2]
"/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeMono.ttf"

[3]
"/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeMono.ttf"

[4]
"/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeMono.ttf"


$symbol
[1]
"/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"

[2]
"/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"

[3]
"/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"

[4]
"/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"


If you don't have Freetype installed on your system, you won't be able
to use any of those.

Duncan Murdoch





__
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] Looping Through DataFrames with Differing Lenghts

2017-03-28 Thread Ulrik Stervbo
Hi Paul,

does this do what you want?

exdf1 <- data.frame(Date = c("1985-10-01", "1985-11-01", "1985-12-01",
"1986-01-01"), Transits = c(NA, NA, NA, NA))
exdf2 <- data.frame(Date = c("1985-10-01", "1986-01-01"), Transits = c(15,
20))

tmpdf <- subset(exdf1, !Date %in% exdf2$Date)

rbind(exdf2, tmpdf)

HTH,
Ulrik

On Tue, 28 Mar 2017 at 10:50 Paul Bernal  wrote:

Dear friend Mark,

Great suggestion! Thank you for replying.

I have two dataframes, dataframe1 and dataframe2.

dataframe1 has two columns, one with the dates in -MM-DD format and the
other colum with number of transits (all of which were set to NA values).
dataframe1 starts in 1985-10-01 (october 1st 1985) and ends in 2017-03-01
(march 1 2017).

dataframe2 has the same  two columns, one with the dates in -MM-DD
format, and the other column with number of transits. dataframe2 starts
have the same start and end dates, however, dataframe2 has missing dates
between the start and end dates, so it has fewer observations.

dataframe1 has a total of 378 observations and dataframe2 has a  total of
362 observations.

I would like to come up with a code that could do the following:

Get the dates of dataframe1 that are missing in dataframe2 and add them as
records to dataframe 2 but with NA values.

:

> Make some small dataframes of just a few rows that illustrate the problem
> structure. Make a third that has the result you want. You will get an
> answer very quickly. Without a self-contained reproducible problem,
results
> vary.
>
> Mark
> R. Mark Sharp, Ph.D.
> msh...@txbiomed.org
>
>
>
>
>
> > On Mar 27, 2017, at 3:09 PM, Paul Bernal  wrote:
> >
> > Dear friends,
> >
> > I have one dataframe which contains 378 observations, and another one,
> > containing 362 observations.
> >
> > Both dataframes have two columns, one date column and another one with
> the
> > number of transits.
> >
> > I wanted to come up with a code so that I could fill in the dates that
> are
> > missing in one of the dataframes and replace the column of transits with
> > the value NA.
> >
> > I have tried several things but R obviously complains that the length of
> > the dataframes are different.
> >
> > How can I solve this?
> >
> > Any guidance will be greatly appreciated,
> >
> > Best regards,
> >
> > Paul
> >
> > [[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.
>

[[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] How to load fonts in text3d?

2017-03-28 Thread olsen
I think I found the fly in the ointment, running the same text3d() lines
with 'useFreeType=TRUE' returns:
"FreeType not supported in this build"


On 28/03/17 11:05, olsen wrote:
> thanks, the fonts seem to be on:
>> rglFonts()
> $serif
> [1] "/usr/lib/R/site-library/rgl/fonts/FreeSerif.ttf"
> [2] "/usr/lib/R/site-library/rgl/fonts/FreeSerif.ttf"
> [3] "/usr/lib/R/site-library/rgl/fonts/FreeSerif.ttf"
> [4] "/usr/lib/R/site-library/rgl/fonts/FreeSerif.ttf"
> 
> $sans
> [1] "/usr/lib/R/site-library/rgl/fonts/FreeSans.ttf"
> [2] "/usr/lib/R/site-library/rgl/fonts/FreeSans.ttf"
> [3] "/usr/lib/R/site-library/rgl/fonts/FreeSans.ttf"
> [4] "/usr/lib/R/site-library/rgl/fonts/FreeSans.ttf"
> 
> $mono
> [1] "/usr/lib/R/site-library/rgl/fonts/FreeMono.ttf"
> [2] "/usr/lib/R/site-library/rgl/fonts/FreeMono.ttf"
> [3] "/usr/lib/R/site-library/rgl/fonts/FreeMono.ttf"
> [4] "/usr/lib/R/site-library/rgl/fonts/FreeMono.ttf"
> 
> $symbol
> [1] "/usr/lib/R/site-library/rgl/fonts/FreeSerif.ttf"
> [2] "/usr/lib/R/site-library/rgl/fonts/FreeSerif.ttf"
> [3] "/usr/lib/R/site-library/rgl/fonts/FreeSerif.ttf"
> [4] "/usr/lib/R/site-library/rgl/fonts/FreeSerif.ttf"
> 
> On 27/03/17 20:21, Duncan Murdoch wrote:
>> On 27/03/2017 1:09 PM, olsen wrote:
>>> I'm trying to run the example given in ?text3d as follows:
>>>
>>> library(rgl)
>>> open3d()
>>> famnum <- rep(1:4, 8)
>>> family <- c("serif", "sans", "mono", "symbol")[famnum]
>>> font <- rep(rep(1:4, each = 4), 2)
>>> cex <- rep(1:2, each = 16)
>>> text3d(font, cex, famnum, text = paste(family, font), adj = 0.5,
>>>color = "blue", family = family, font = font, cex = cex)
>>>
>>> This results in a couple of warning messages of the following kind:
>>>
>>> In rgl.texts(x = c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L,  ... :
>>>   font family "serif" not found, using "bitmap"
>>>
>>> I would like to use another font instead of bitmap but it seems to
>>> switchback to bitmap whatever argument I give as family e.g. 'family =
>>> "FreeSans"'.
>>> Wonder if this is a bug or I'm doing something wrong.
>>>
>>> This is on
>>> R version 3.3.2 (2016-10-31)
>>> Platform: x86_64-pc-linux-gnu (64-bit)
>>> Running under: Debian GNU/Linux 9 (stretch)
>>> with the following rgl version loaded:
>>> [1] rgl_0.96.0
>>
>> What do you see if you run rglFonts()?  It should list the fonts you
>> have installed.  On MacOS, I see
>>
>>> rglFonts()
>> $serif
>> [1]
>> "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"
>>
>> [2]
>> "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"
>>
>> [3]
>> "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"
>>
>> [4]
>> "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"
>>
>>
>> $sans
>> [1]
>> "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSans.ttf"
>>
>> [2]
>> "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSans.ttf"
>>
>> [3]
>> "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSans.ttf"
>>
>> [4]
>> "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSans.ttf"
>>
>>
>> $mono
>> [1]
>> "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeMono.ttf"
>>
>> [2]
>> "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeMono.ttf"
>>
>> [3]
>> "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeMono.ttf"
>>
>> [4]
>> "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeMono.ttf"
>>
>>
>> $symbol
>> [1]
>> "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"
>>
>> [2]
>> "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"
>>
>> [3]
>> "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"
>>
>> [4]
>> "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"
>>
>>
>> If you don't have Freetype installed on your system, you won't be able
>> to use any of those.
>>
>> Duncan Murdoch
>>
>

__
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] How to load fonts in text3d?

2017-03-28 Thread olsen
thanks, the fonts seem to be on:
> rglFonts()
$serif
[1] "/usr/lib/R/site-library/rgl/fonts/FreeSerif.ttf"
[2] "/usr/lib/R/site-library/rgl/fonts/FreeSerif.ttf"
[3] "/usr/lib/R/site-library/rgl/fonts/FreeSerif.ttf"
[4] "/usr/lib/R/site-library/rgl/fonts/FreeSerif.ttf"

$sans
[1] "/usr/lib/R/site-library/rgl/fonts/FreeSans.ttf"
[2] "/usr/lib/R/site-library/rgl/fonts/FreeSans.ttf"
[3] "/usr/lib/R/site-library/rgl/fonts/FreeSans.ttf"
[4] "/usr/lib/R/site-library/rgl/fonts/FreeSans.ttf"

$mono
[1] "/usr/lib/R/site-library/rgl/fonts/FreeMono.ttf"
[2] "/usr/lib/R/site-library/rgl/fonts/FreeMono.ttf"
[3] "/usr/lib/R/site-library/rgl/fonts/FreeMono.ttf"
[4] "/usr/lib/R/site-library/rgl/fonts/FreeMono.ttf"

$symbol
[1] "/usr/lib/R/site-library/rgl/fonts/FreeSerif.ttf"
[2] "/usr/lib/R/site-library/rgl/fonts/FreeSerif.ttf"
[3] "/usr/lib/R/site-library/rgl/fonts/FreeSerif.ttf"
[4] "/usr/lib/R/site-library/rgl/fonts/FreeSerif.ttf"

On 27/03/17 20:21, Duncan Murdoch wrote:
> On 27/03/2017 1:09 PM, olsen wrote:
>> I'm trying to run the example given in ?text3d as follows:
>>
>> library(rgl)
>> open3d()
>> famnum <- rep(1:4, 8)
>> family <- c("serif", "sans", "mono", "symbol")[famnum]
>> font <- rep(rep(1:4, each = 4), 2)
>> cex <- rep(1:2, each = 16)
>> text3d(font, cex, famnum, text = paste(family, font), adj = 0.5,
>>color = "blue", family = family, font = font, cex = cex)
>>
>> This results in a couple of warning messages of the following kind:
>>
>> In rgl.texts(x = c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L,  ... :
>>   font family "serif" not found, using "bitmap"
>>
>> I would like to use another font instead of bitmap but it seems to
>> switchback to bitmap whatever argument I give as family e.g. 'family =
>> "FreeSans"'.
>> Wonder if this is a bug or I'm doing something wrong.
>>
>> This is on
>> R version 3.3.2 (2016-10-31)
>> Platform: x86_64-pc-linux-gnu (64-bit)
>> Running under: Debian GNU/Linux 9 (stretch)
>> with the following rgl version loaded:
>> [1] rgl_0.96.0
> 
> What do you see if you run rglFonts()?  It should list the fonts you
> have installed.  On MacOS, I see
> 
>> rglFonts()
> $serif
> [1]
> "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"
> 
> [2]
> "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"
> 
> [3]
> "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"
> 
> [4]
> "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"
> 
> 
> $sans
> [1]
> "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSans.ttf"
> 
> [2]
> "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSans.ttf"
> 
> [3]
> "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSans.ttf"
> 
> [4]
> "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSans.ttf"
> 
> 
> $mono
> [1]
> "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeMono.ttf"
> 
> [2]
> "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeMono.ttf"
> 
> [3]
> "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeMono.ttf"
> 
> [4]
> "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeMono.ttf"
> 
> 
> $symbol
> [1]
> "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"
> 
> [2]
> "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"
> 
> [3]
> "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"
> 
> [4]
> "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"
> 
> 
> If you don't have Freetype installed on your system, you won't be able
> to use any of those.
> 
> Duncan Murdoch
> 

-- 
Our solar system is the cream of the crop
http://hasa-labs.org

__
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] My installed R cannot run the X11 server

2017-03-28 Thread peter dalgaard
Did you follow XQuartz's advice of logging out and back in after the install?

-pd

> On 27 Mar 2017, at 22:44 , WILLIAM J HAYNES  wrote:
> 
> HI,
> 
> I installed R on a Mac Book Pro running 10.10.5 and for some reason my 
> X11.app is in a place that the R installation cannot find.  How can I set the 
> environmental variables so the X11 server will run. I also have Xquartx.app 
> but R does not seem to find that either.
> 
> Best Regards,
> William “John" Haynes
> 
> 
> 
> 
> 
>   [[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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
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] R glm function ignores some predictor variables

2017-03-28 Thread peter dalgaard

> On 27 Mar 2017, at 17:23 , Gabrielle Perron  
> wrote:
> 
> Hi,
> 
> 
> This is my first time using this mailing list. I have looked at the posting 
> guide, but please do let me know if I should be doing something differently.


Avoid sending in HTML. It's not really bad here except for excessive 
inter-paragraph spacing, but the autoconversion to plain text can make posts 
almost unreadable.

---
It looks like some of your predictors are equal to linear combinations of other 
predictors. E.g., if you have dummies for mutually exclusive groups, they will 
sum to a vector of ones, which is already in the model for the intercept term, 
so one must be removed. (R has a better interface to this sort of thing, using 
factor variables, but that is another story.) With many predictors, this can 
happen in less obvious ways as well.

For plain multiple regression, I think most would use lm() and not glm(). It 
shouldn't make much of a difference, but some details may differ.

-pd

> Here is my question, I apologize in advance for not being able to provide 
> example data, I am using very large tables, and what I am trying to do works 
> fine with simpler examples, so providing example data cannot help. It has 
> always worked for me until now. So I am just trying to get your ideas on what 
> might be the issue. But if there is any way I could provide more information, 
> do let me know.
> 
> 
> So, I have a vector corresponding to a response variable and a table of 
> predictor variables. The response vector is numeric, the predictor variables 
> (columns of the table) are in the binary format (0s and 1s).
> 
> 
> I am running the glm function (multivariate linear regression) using the 
> response vector and the table of predictors:
> 
> 
>fit <- glm(response ~ as.matrix(predictors), na.action=na.exclude)
> 
>coeff <- as.vector(coef(summary(fit))[,4])[-1]
> 
> 
> When I have been doing that in the past, I would extract the vector of 
> regression coefficient to use it for further analysis.
> 
> 
> The problem is that now the regression returns a vector of coefficients which 
> is missing some values. Essentially some predictor variables are not 
> attributed a coefficient at all by glm. But there are no error messages.
> 
> 
> The summary of the model looks normal, but some predictor variables are 
> missing like I mentioned. Most other predictors have assigned data 
> (coefficient, pvalue, etc.).
> 
> About 30 predictors are missing from the model, over 200.
> 
> 
> I have tried using different response variables (vectors), but I am getting 
> the same issue, although the missing predictors vary depending on the 
> response vector...
> 
> 
> Any ideas on what might be going on? I think this can happen if some 
> variables have 0 variance, but I have checked that. There are also no NA 
> values and no missing values in the tables.
> 
> 
> What could cause glm to ignore/remove some predictor variables?
> 
> 
> Any suggestion is welcome!
> 
> 
> Thank you,
> 
> 
> Gabrielle
> 
> 
> 
> 
> 
> 
> 
>   [[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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
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] R glm function ignores some predictor variables

2017-03-28 Thread Jim Lemon
Hi Gabrielle,
With that number of binary predictors it would be no surprise if some
were linear combinations of others.

Jim


On Tue, Mar 28, 2017 at 2:23 AM, Gabrielle Perron
 wrote:
> Hi,
>
>
> This is my first time using this mailing list. I have looked at the posting 
> guide, but please do let me know if I should be doing something differently.
>
>
> Here is my question, I apologize in advance for not being able to provide 
> example data, I am using very large tables, and what I am trying to do works 
> fine with simpler examples, so providing example data cannot help. It has 
> always worked for me until now. So I am just trying to get your ideas on what 
> might be the issue. But if there is any way I could provide more information, 
> do let me know.
>
>
> So, I have a vector corresponding to a response variable and a table of 
> predictor variables. The response vector is numeric, the predictor variables 
> (columns of the table) are in the binary format (0s and 1s).
>
>
> I am running the glm function (multivariate linear regression) using the 
> response vector and the table of predictors:
>
>
> fit <- glm(response ~ as.matrix(predictors), na.action=na.exclude)
>
> coeff <- as.vector(coef(summary(fit))[,4])[-1]
>
>
> When I have been doing that in the past, I would extract the vector of 
> regression coefficient to use it for further analysis.
>
>
> The problem is that now the regression returns a vector of coefficients which 
> is missing some values. Essentially some predictor variables are not 
> attributed a coefficient at all by glm. But there are no error messages.
>
>
> The summary of the model looks normal, but some predictor variables are 
> missing like I mentioned. Most other predictors have assigned data 
> (coefficient, pvalue, etc.).
>
> About 30 predictors are missing from the model, over 200.
>
>
> I have tried using different response variables (vectors), but I am getting 
> the same issue, although the missing predictors vary depending on the 
> response vector...
>
>
> Any ideas on what might be going on? I think this can happen if some 
> variables have 0 variance, but I have checked that. There are also no NA 
> values and no missing values in the tables.
>
>
> What could cause glm to ignore/remove some predictor variables?
>
>
> Any suggestion is welcome!
>
>
> Thank you,
>
>
> Gabrielle
>
>
>
>
>
>
>
> [[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] plot empty when drawing from custom function

2017-03-28 Thread Bert Gunter
FAQ 7.16

Bert



On Mar 28, 2017 1:20 AM, "Luigi Marongiu"  wrote:

Dear all,
I have set a function to draw some data using lattice; the drawing
works when I use lattice on its own, but if I put it into my custom
function, the final plot is empty, yet the terminal reports RStudioGD
1
as normal.
What am I missing?
regards,
Luigi

>>>
cluster <- c(rep("A", 90), rep("B", 100))
sample <- c(
  rep(c("cow-01", "cow-02", "cow-03", "cow-04", "cow-05", "cow-06",
"cow-07", "cow-08", "cow-09", "cow-10", "cow-11",
"cow-12", "cow-13", "cow-14", "cow-15", "cow-16", "cow-17",
"blank"), 5),
  rep(c("cow-26", "cow-35", "cow-36", "cow-37", "cow-38", "cow-39",
"cow-40", "cow-41", "cow-42", "cow-43", "cow-44", "cow-45",
"cow-46", "cow-47", "cow-48", "cow-49", "cow-50", "cow-51",
"cow-59", "blank"), 5)
)
type <- c(
  rep(c("negative", "negative", "negative", "negative", "negative",
"negative", "negative", "negative", "positive", "positive",
"positive", "positive", "positive", "positive", "positive",
"positive", "positive", "blank"), 5),
  rep(c("negative", "positive", "negative", "negative", "negative",
"negative", "negative", "negative", "positive", "positive",
"positive", "positive", "positive", "positive", "positive",
"positive", "positive", "positive", "positive", "blank"), 5)
)
target <- c(
c(rep("a", 18), rep("b", 18), rep("c", 18), rep("d", 18), rep("e", 18)),
c(rep("a", 20), rep("b", 20), rep("c", 20), rep("d", 20), rep("e", 20))
)
average <- c(88.5, 49, 41, 33, 35, 45, 95, 30, 41, 64, 22, 29, 59, 71,
128, 39, 42, 47, 86, 100,
 69, 44, 53, 66, 66, 71, 161, 69, 22.5, 30, 67, 99, 129,
94, 49, 33, 28, 31, 26, 23,
 30, 41, 35, 23, 38, 43, 15, 21, 45, 51.5, 34, 26, 43,
32.5, 59, 58.5, 61, 62.5, 58,
 59.5, 60.5, 60, 64, 110, 55, 66, 197, 83.5, 155, 76, 125,
90, 73, 84, 95.5, 62, 82, 138,
 103.5, 57, 138, 149.5, 57, 54, 245.5, 191, 131, 96, 176,
45, 76, 33, 37, 51, 44, 50, 54,
 66, 49, 90, 66.5, 42.5, 67, 56, 54, 50, 45, 99, 50, 51.5,
212, 40, 68, 121, 80, 57,
 81.5, 128, 77, 119.5, 126, 184, 101, 103, 88, 100, 140,
186, 297, 32, 184, 36, 45, 45, 44,
 86, 65, 61, 76, 62, 136, 84, 80, 56, 109, 116, 54, 59,
79, 34, 74.5, 54, 49, 55, 56,
 59, 56, 56, 57, 67, 65, 63, 52, 58, 59, 56, 54, 66, 92,
87, 59, 33, 58, 51, 54,
 52, 47, 45, 42, 52, 57, 79, 42, 45.5, 47, 47, 36, 50, 53, 49 )
stdev <- c(17.85, 6.31, 3.42, 1.04, 0.51, 6.04, 38.43, 2.78, 5.55,
26.72, 1.83, 9.92, 4.59, 19, 7.96,
   7.5, 1.06, 9.66, 75.94, 36.79, 50.45, 9.79, 1.55,
11.42, 64.12, 0.79, 15.14, 16.15, 8.12, 4.04, 92.57, 35.35,
   42.28, 52.96, 7.06, 4.97, 1.15, 4.77, 6.59, 7.27, 0.75,
4.25, 9, 0.1, 1.14, 4.17, 6.73, 3.81, 3.27,
   97.44, 9.74, 0.45, 8.14, 5.91, 13.1, 98.22, 8.92,
72.62, 70.26, 59.46, 29.89, 56.35, 91.25, 49.94, 20.65, 62.04,
   95.13, 35.89, 99.64, 29.44, 33.12, 45.91, 96.69, 9.05,
38.56, 3.09, 0.6, 8.69, 16.95, 74.03, 84.05, 39.87, 15.52,
   27.92, 35.72, 80.26, 71.93, 66.73, 87.8, 5.43, 98.3,
7.41, 9.86, 63.64, 0.36, 5.84, 1.58, 20.1, 4.21, 82.12,
   19.29, 9.02, 22.12, 54.08, 74.95, 3.24, 9.67, 67.98,
9.92, 40.69, 6.24, 8.76, 74.25, 46.34, 25.69, 90.63, 83.71,
   73.53, 57.88, 15.84, 82.07, 67.45, 47.39, 98.77, 75.1,
64.9, 3.71, 87.44, 61.06, 4.77, 57.54, 7.68, 4.54, 6.15,
   3.32, 60.39, 33.78, 66.22, 18.67, 76.53, 63.54, 47.06,
38.47, 88.15, 18.25, 4.26, 67.19, 88.87, 29.65, 7.33, 68.18,
   28.03, 6.91, 77.82, 22.23, 73.23, 95.21, 27.11, 37.01,
34.88, 28.15, 11.27, 15.67, 96.08, 89.52, 28.6, 8.22, 23.55,
   59.2, 36.38, 41.38, 0.4, 56.82, 32.35, 20.6, 18.13,
8.15, 1.08, 9.85, 1.07, 37.75, 97.6, 7.16, 8.51, 4.42,
   0.15, 1.28, 7.42, 71.15, 9.39)
ll <- c(70.65, 42.69, 37.58, 31.96, 34.49, 38.96, 56.57, 27.22, 35.45,
37.28, 20.17, 19.08, 54.41, 52, 120.04, 31.5, 40.94, 37.34,
10.06, 63.21, 18.55, 34.21, 51.45, 54.58, 1.88, 70.21, 145.86,
52.85, 14.38, 25.96, -25.57, 63.65, 86.72, 41.04, 41.94, 28.03,
26.85, 26.23, 19.41, 15.73, 29.25, 36.75, 26, 22.9, 36.86,
38.83, 8.27, 17.19, 41.73, -45.94, 24.26, 25.55, 34.86, 26.59, 45.9,
-39.72, 52.08, -10.12, -12.26, 0.0391, 30.61,
3.65, -27.25, 60.06, 34.35, 3.96, 101.87, 47.61, 55.36, 46.56, 91.88,
44.09,
-23.69, 74.95, 56.94, 58.91, 81.4, 129.31, 86.55, -17.03,
53.95, 109.63, 41.48, 26.08, 209.78, 110.74, 59.07, 29.27, 88.2,
39.57,
-22.3, 25.59, 27.14, -12.64, 43.64, 44.16, 52.42, 45.9, 44.79,
7.88, 47.21, 33.48, 44.88, 1.92, -20.95, 46.76, 35.33, 31.02,
40.08, 10.81, 205.76, 31.24, -6.25, 74.66, 54.31, -33.63,
-2.20, 54.47, 19.12, 103.66, 43.93, 116.55, 53.61, 4.23,
12.9, 35.1, 136.29, 98.56, 235.94, 27.23, 126.46, 28.32,
40.46, 38.85, 40.68, 25.61, 31.22, -5.22, 57.33, -14.53, 72.46, 36.94,
41.53, -32.15, 90.75, 

Re: [R] plot empty when drawing from custom function

2017-03-28 Thread Gerrit Eichner

Hi, Luigi,

you are probably missing a call to print() around the call to
the latticeExtra plotting function useOuterStrips() you use
inside your function printer().

 Hth  --  Gerrit

-
Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/eichner
-

Am 28.03.2017 um 10:19 schrieb Luigi Marongiu:

Dear all,
I have set a function to draw some data using lattice; the drawing
works when I use lattice on its own, but if I put it into my custom
function, the final plot is empty, yet the terminal reports RStudioGD
1
as normal.
What am I missing?
regards,
Luigi




cluster <- c(rep("A", 90), rep("B", 100))
sample <- c(
  rep(c("cow-01", "cow-02", "cow-03", "cow-04", "cow-05", "cow-06",
"cow-07", "cow-08", "cow-09", "cow-10", "cow-11",
"cow-12", "cow-13", "cow-14", "cow-15", "cow-16", "cow-17",
"blank"), 5),
  rep(c("cow-26", "cow-35", "cow-36", "cow-37", "cow-38", "cow-39",
"cow-40", "cow-41", "cow-42", "cow-43", "cow-44", "cow-45",
"cow-46", "cow-47", "cow-48", "cow-49", "cow-50", "cow-51",
"cow-59", "blank"), 5)
)
type <- c(
  rep(c("negative", "negative", "negative", "negative", "negative",
"negative", "negative", "negative", "positive", "positive",
"positive", "positive", "positive", "positive", "positive",
"positive", "positive", "blank"), 5),
  rep(c("negative", "positive", "negative", "negative", "negative",
"negative", "negative", "negative", "positive", "positive",
"positive", "positive", "positive", "positive", "positive",
"positive", "positive", "positive", "positive", "blank"), 5)
)
target <- c(
c(rep("a", 18), rep("b", 18), rep("c", 18), rep("d", 18), rep("e", 18)),
c(rep("a", 20), rep("b", 20), rep("c", 20), rep("d", 20), rep("e", 20))
)
average <- c(88.5, 49, 41, 33, 35, 45, 95, 30, 41, 64, 22, 29, 59, 71,
128, 39, 42, 47, 86, 100,
 69, 44, 53, 66, 66, 71, 161, 69, 22.5, 30, 67, 99, 129,
94, 49, 33, 28, 31, 26, 23,
 30, 41, 35, 23, 38, 43, 15, 21, 45, 51.5, 34, 26, 43,
32.5, 59, 58.5, 61, 62.5, 58,
 59.5, 60.5, 60, 64, 110, 55, 66, 197, 83.5, 155, 76, 125,
90, 73, 84, 95.5, 62, 82, 138,
 103.5, 57, 138, 149.5, 57, 54, 245.5, 191, 131, 96, 176,
45, 76, 33, 37, 51, 44, 50, 54,
 66, 49, 90, 66.5, 42.5, 67, 56, 54, 50, 45, 99, 50, 51.5,
212, 40, 68, 121, 80, 57,
 81.5, 128, 77, 119.5, 126, 184, 101, 103, 88, 100, 140,
186, 297, 32, 184, 36, 45, 45, 44,
 86, 65, 61, 76, 62, 136, 84, 80, 56, 109, 116, 54, 59,
79, 34, 74.5, 54, 49, 55, 56,
 59, 56, 56, 57, 67, 65, 63, 52, 58, 59, 56, 54, 66, 92,
87, 59, 33, 58, 51, 54,
 52, 47, 45, 42, 52, 57, 79, 42, 45.5, 47, 47, 36, 50, 53, 49 )
stdev <- c(17.85, 6.31, 3.42, 1.04, 0.51, 6.04, 38.43, 2.78, 5.55,
26.72, 1.83, 9.92, 4.59, 19, 7.96,
   7.5, 1.06, 9.66, 75.94, 36.79, 50.45, 9.79, 1.55,
11.42, 64.12, 0.79, 15.14, 16.15, 8.12, 4.04, 92.57, 35.35,
   42.28, 52.96, 7.06, 4.97, 1.15, 4.77, 6.59, 7.27, 0.75,
4.25, 9, 0.1, 1.14, 4.17, 6.73, 3.81, 3.27,
   97.44, 9.74, 0.45, 8.14, 5.91, 13.1, 98.22, 8.92,
72.62, 70.26, 59.46, 29.89, 56.35, 91.25, 49.94, 20.65, 62.04,
   95.13, 35.89, 99.64, 29.44, 33.12, 45.91, 96.69, 9.05,
38.56, 3.09, 0.6, 8.69, 16.95, 74.03, 84.05, 39.87, 15.52,
   27.92, 35.72, 80.26, 71.93, 66.73, 87.8, 5.43, 98.3,
7.41, 9.86, 63.64, 0.36, 5.84, 1.58, 20.1, 4.21, 82.12,
   19.29, 9.02, 22.12, 54.08, 74.95, 3.24, 9.67, 67.98,
9.92, 40.69, 6.24, 8.76, 74.25, 46.34, 25.69, 90.63, 83.71,
   73.53, 57.88, 15.84, 82.07, 67.45, 47.39, 98.77, 75.1,
64.9, 3.71, 87.44, 61.06, 4.77, 57.54, 7.68, 4.54, 6.15,
   3.32, 60.39, 33.78, 66.22, 18.67, 76.53, 63.54, 47.06,
38.47, 88.15, 18.25, 4.26, 67.19, 88.87, 29.65, 7.33, 68.18,
   28.03, 6.91, 77.82, 22.23, 73.23, 95.21, 27.11, 37.01,
34.88, 28.15, 11.27, 15.67, 96.08, 89.52, 28.6, 8.22, 23.55,
   59.2, 36.38, 41.38, 0.4, 56.82, 32.35, 20.6, 18.13,
8.15, 1.08, 9.85, 1.07, 37.75, 97.6, 7.16, 8.51, 4.42,
   0.15, 1.28, 7.42, 71.15, 9.39)
ll <- c(70.65, 42.69, 37.58, 31.96, 34.49, 38.96, 56.57, 27.22, 35.45,
37.28, 20.17, 19.08, 54.41, 52, 120.04, 31.5, 40.94, 37.34,
10.06, 63.21, 18.55, 34.21, 51.45, 54.58, 1.88, 70.21, 145.86,
52.85, 14.38, 25.96, -25.57, 63.65, 86.72, 41.04, 41.94, 28.03,
26.85, 26.23, 19.41, 15.73, 29.25, 36.75, 26, 22.9, 36.86,
38.83, 8.27, 17.19, 41.73, -45.94, 24.26, 25.55, 34.86, 26.59, 45.9,
-39.72, 52.08, -10.12, -12.26, 0.0391, 30.61,
3.65, -27.25, 60.06, 34.35, 3.96, 101.87, 47.61, 55.36, 46.56, 91.88,
44.09,

Re: [R] Arguments imply differing number of rows: 1, 0

2017-03-28 Thread Gerrit Eichner

Hi, John,

see inline.

Am 27.03.2017 um 20:47 schrieb John Murtagh:

Hi All,

I am trying to generate a cdf plot by using ggplot and have looked at some
examples online. However when I try to replicate it I get the following
error:

"arguments imply differing number of rows: 1, 0"

I made a search and it seems from what I gather the nrows!=ncol and that
doesn't work for a data.frame. I am confused a bit as my MCtab dataframe is
similar.

If someone can explain what is going wrong or what i am
misunderstanding/doing wrong would be great? Code is below to replicate.
Thanks

library (triangle)
library(ggplot2)

n = 1000
W1 = rtriangle(n,330,400)
W2 = rtriangle(n,300,420)
SO = rtriangle(n,0.2,0.3)

MCtab <- data.frame(W1,W2,SO)

set.seed(1)
for (n in 1:n) {
  N0 <- (W1 + W2 + SO )}

set.seed(1)
for (n in 1:n) {
  N1 <- ((0.99*W1 + 0.99*W2 + 0.99*SO ))}

set.seed(1)
for (n in 1:n) {
  N2 <- ((0.98*W1 + 0.98*W2 + 0.98*SO))}

ggdata <- data.frame(N0,N1,N2)


ggdata <- ddply(ggdata, .(N0,N1,N2), transform, ecd=ecdf)


I'm not familiar with ggplot, but I do not think that splitting your
ggdata by your numerical variables N1, N2 and N3 makes any sense ...

PS: I also think that your loops to create N1, N2 and N3 are pretty
nonsensical.



cdf <- ggplot(ggdata, aes(x=value)) +
stat_ecdf(aes(colour="blue","red","green"))
cdf

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



--

 Hth  --  Gerrit

-
Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/eichner

__
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] Managing axis labels

2017-03-28 Thread Ivan Calandra

Hi Jamil,

You first need to specify 'xaxt' and 'yaxt' in your plot() call, and 
then you can set the size of the labels with cex.axis:


plot(x, y, xlab=expression(vartheta), ylab="Concentration", xaxt="n", 
yaxt="n")axis(1, cex.axis=3) axis(2, cex.axis=2)


HTH,
Ivan

--
Ivan Calandra, PhD
MONREPOS Archaeological Research Centre and
Museum for Human Behavioural Evolution
Schloss Monrepos
56567 Neuwied, Germany
+49 (0) 2631 9772-243
https://www.researchgate.net/profile/Ivan_Calandra

On 27/03/2017 20:26, Naser Jamil wrote:

Dear R-users,
I would like to ask probably a silly thing. For some reason, I need x-axis
and y-axis labels to be of different size. Here is a little example where I
want "ϑ" to appear bigger than "Concentration". I have tried in the
following way, but it is not working.

​
x<-seq(1,10,1)
y<-seq(2,20,2)
plot(x, y, xlab=expression(vartheta), ylab="Concentration", cex.axis=1.5)

axis(1, cex.lab=3.0)
axis(2, cex.lab=2.0)

Any suggestion will be much appreciated.

Kind Regards,
Jamil.

[[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] My installed R cannot run the X11 server

2017-03-28 Thread WILLIAM J HAYNES
HI,

I installed R on a Mac Book Pro running 10.10.5 and for some reason my X11.app 
is in a place that the R installation cannot find.  How can I set the 
environmental variables so the X11 server will run. I also have Xquartx.app but 
R does not seem to find that either.

Best Regards,
William “John" Haynes





[[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] Looping Through DataFrames with Differing Lenghts

2017-03-28 Thread Paul Bernal
Dear friend Mark,

Great suggestion! Thank you for replying.

I have two dataframes, dataframe1 and dataframe2.

dataframe1 has two columns, one with the dates in -MM-DD format and the
other colum with number of transits (all of which were set to NA values).
dataframe1 starts in 1985-10-01 (october 1st 1985) and ends in 2017-03-01
(march 1 2017).

dataframe2 has the same  two columns, one with the dates in -MM-DD
format, and the other column with number of transits. dataframe2 starts
have the same start and end dates, however, dataframe2 has missing dates
between the start and end dates, so it has fewer observations.

dataframe1 has a total of 378 observations and dataframe2 has a  total of
362 observations.

I would like to come up with a code that could do the following:

Get the dates of dataframe1 that are missing in dataframe2 and add them as
records to dataframe 2 but with NA values.

:

> Make some small dataframes of just a few rows that illustrate the problem
> structure. Make a third that has the result you want. You will get an
> answer very quickly. Without a self-contained reproducible problem, results
> vary.
>
> Mark
> R. Mark Sharp, Ph.D.
> msh...@txbiomed.org
>
>
>
>
>
> > On Mar 27, 2017, at 3:09 PM, Paul Bernal  wrote:
> >
> > Dear friends,
> >
> > I have one dataframe which contains 378 observations, and another one,
> > containing 362 observations.
> >
> > Both dataframes have two columns, one date column and another one with
> the
> > number of transits.
> >
> > I wanted to come up with a code so that I could fill in the dates that
> are
> > missing in one of the dataframes and replace the column of transits with
> > the value NA.
> >
> > I have tried several things but R obviously complains that the length of
> > the dataframes are different.
> >
> > How can I solve this?
> >
> > Any guidance will be greatly appreciated,
> >
> > Best regards,
> >
> > Paul
> >
> > [[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.
>

[[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] Arguments imply differing number of rows: 1, 0

2017-03-28 Thread John Murtagh
Hi All,

I am trying to generate a cdf plot by using ggplot and have looked at some
examples online. However when I try to replicate it I get the following
error:

"arguments imply differing number of rows: 1, 0"

I made a search and it seems from what I gather the nrows!=ncol and that
doesn't work for a data.frame. I am confused a bit as my MCtab dataframe is
similar.

If someone can explain what is going wrong or what i am
misunderstanding/doing wrong would be great? Code is below to replicate.
Thanks

library (triangle)
library(ggplot2)

n = 1000
W1 = rtriangle(n,330,400)
W2 = rtriangle(n,300,420)
SO = rtriangle(n,0.2,0.3)

MCtab <- data.frame(W1,W2,SO)

set.seed(1)
for (n in 1:n) {
  N0 <- (W1 + W2 + SO )}

set.seed(1)
for (n in 1:n) {
  N1 <- ((0.99*W1 + 0.99*W2 + 0.99*SO ))}

set.seed(1)
for (n in 1:n) {
  N2 <- ((0.98*W1 + 0.98*W2 + 0.98*SO))}

ggdata <- data.frame(N0,N1,N2)


ggdata <- ddply(ggdata, .(N0,N1,N2), transform, ecd=ecdf)


cdf <- ggplot(ggdata, aes(x=value)) +
stat_ecdf(aes(colour="blue","red","green"))
cdf

[[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] ! in expression(!abc) that produces !(abc).

2017-03-28 Thread Jinsong Zhao

Hi there,

I happened to find the expression(!abc) produces !(abc) when I used 
plotmath in a text annotation. Here is the mini-example.


> plot(1, type = "n")
> text(1,1, expression(!abc))

I don't find "!" in plotmath document.

By the way, how to reduce the space between two adjacent strings, 
something opposite to "~~". I mean, to get a space that is narrower than 
"~" but wider than "*".


Best,
Jinsong

__
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] R glm function ignores some predictor variables

2017-03-28 Thread Gabrielle Perron
Hi,


This is my first time using this mailing list. I have looked at the posting 
guide, but please do let me know if I should be doing something differently.


Here is my question, I apologize in advance for not being able to provide 
example data, I am using very large tables, and what I am trying to do works 
fine with simpler examples, so providing example data cannot help. It has 
always worked for me until now. So I am just trying to get your ideas on what 
might be the issue. But if there is any way I could provide more information, 
do let me know.


So, I have a vector corresponding to a response variable and a table of 
predictor variables. The response vector is numeric, the predictor variables 
(columns of the table) are in the binary format (0s and 1s).


I am running the glm function (multivariate linear regression) using the 
response vector and the table of predictors:


fit <- glm(response ~ as.matrix(predictors), na.action=na.exclude)

coeff <- as.vector(coef(summary(fit))[,4])[-1]


When I have been doing that in the past, I would extract the vector of 
regression coefficient to use it for further analysis.


The problem is that now the regression returns a vector of coefficients which 
is missing some values. Essentially some predictor variables are not attributed 
a coefficient at all by glm. But there are no error messages.


The summary of the model looks normal, but some predictor variables are missing 
like I mentioned. Most other predictors have assigned data (coefficient, 
pvalue, etc.).

About 30 predictors are missing from the model, over 200.


I have tried using different response variables (vectors), but I am getting the 
same issue, although the missing predictors vary depending on the response 
vector...


Any ideas on what might be going on? I think this can happen if some variables 
have 0 variance, but I have checked that. There are also no NA values and no 
missing values in the tables.


What could cause glm to ignore/remove some predictor variables?


Any suggestion is welcome!


Thank you,


Gabrielle







[[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] Managing axis labels

2017-03-28 Thread Naser Jamil
Dear R-users,
I would like to ask probably a silly thing. For some reason, I need x-axis
and y-axis labels to be of different size. Here is a little example where I
want "ϑ" to appear bigger than "Concentration". I have tried in the
following way, but it is not working.

​
x<-seq(1,10,1)
y<-seq(2,20,2)
plot(x, y, xlab=expression(vartheta), ylab="Concentration", cex.axis=1.5)

axis(1, cex.lab=3.0)
axis(2, cex.lab=2.0)

Any suggestion will be much appreciated.

Kind Regards,
Jamil.

[[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] plot empty when drawing from custom function

2017-03-28 Thread Luigi Marongiu
Dear all,
I have set a function to draw some data using lattice; the drawing
works when I use lattice on its own, but if I put it into my custom
function, the final plot is empty, yet the terminal reports RStudioGD
1
as normal.
What am I missing?
regards,
Luigi

>>>
cluster <- c(rep("A", 90), rep("B", 100))
sample <- c(
  rep(c("cow-01", "cow-02", "cow-03", "cow-04", "cow-05", "cow-06",
"cow-07", "cow-08", "cow-09", "cow-10", "cow-11",
"cow-12", "cow-13", "cow-14", "cow-15", "cow-16", "cow-17",
"blank"), 5),
  rep(c("cow-26", "cow-35", "cow-36", "cow-37", "cow-38", "cow-39",
"cow-40", "cow-41", "cow-42", "cow-43", "cow-44", "cow-45",
"cow-46", "cow-47", "cow-48", "cow-49", "cow-50", "cow-51",
"cow-59", "blank"), 5)
)
type <- c(
  rep(c("negative", "negative", "negative", "negative", "negative",
"negative", "negative", "negative", "positive", "positive",
"positive", "positive", "positive", "positive", "positive",
"positive", "positive", "blank"), 5),
  rep(c("negative", "positive", "negative", "negative", "negative",
"negative", "negative", "negative", "positive", "positive",
"positive", "positive", "positive", "positive", "positive",
"positive", "positive", "positive", "positive", "blank"), 5)
)
target <- c(
c(rep("a", 18), rep("b", 18), rep("c", 18), rep("d", 18), rep("e", 18)),
c(rep("a", 20), rep("b", 20), rep("c", 20), rep("d", 20), rep("e", 20))
)
average <- c(88.5, 49, 41, 33, 35, 45, 95, 30, 41, 64, 22, 29, 59, 71,
128, 39, 42, 47, 86, 100,
 69, 44, 53, 66, 66, 71, 161, 69, 22.5, 30, 67, 99, 129,
94, 49, 33, 28, 31, 26, 23,
 30, 41, 35, 23, 38, 43, 15, 21, 45, 51.5, 34, 26, 43,
32.5, 59, 58.5, 61, 62.5, 58,
 59.5, 60.5, 60, 64, 110, 55, 66, 197, 83.5, 155, 76, 125,
90, 73, 84, 95.5, 62, 82, 138,
 103.5, 57, 138, 149.5, 57, 54, 245.5, 191, 131, 96, 176,
45, 76, 33, 37, 51, 44, 50, 54,
 66, 49, 90, 66.5, 42.5, 67, 56, 54, 50, 45, 99, 50, 51.5,
212, 40, 68, 121, 80, 57,
 81.5, 128, 77, 119.5, 126, 184, 101, 103, 88, 100, 140,
186, 297, 32, 184, 36, 45, 45, 44,
 86, 65, 61, 76, 62, 136, 84, 80, 56, 109, 116, 54, 59,
79, 34, 74.5, 54, 49, 55, 56,
 59, 56, 56, 57, 67, 65, 63, 52, 58, 59, 56, 54, 66, 92,
87, 59, 33, 58, 51, 54,
 52, 47, 45, 42, 52, 57, 79, 42, 45.5, 47, 47, 36, 50, 53, 49 )
stdev <- c(17.85, 6.31, 3.42, 1.04, 0.51, 6.04, 38.43, 2.78, 5.55,
26.72, 1.83, 9.92, 4.59, 19, 7.96,
   7.5, 1.06, 9.66, 75.94, 36.79, 50.45, 9.79, 1.55,
11.42, 64.12, 0.79, 15.14, 16.15, 8.12, 4.04, 92.57, 35.35,
   42.28, 52.96, 7.06, 4.97, 1.15, 4.77, 6.59, 7.27, 0.75,
4.25, 9, 0.1, 1.14, 4.17, 6.73, 3.81, 3.27,
   97.44, 9.74, 0.45, 8.14, 5.91, 13.1, 98.22, 8.92,
72.62, 70.26, 59.46, 29.89, 56.35, 91.25, 49.94, 20.65, 62.04,
   95.13, 35.89, 99.64, 29.44, 33.12, 45.91, 96.69, 9.05,
38.56, 3.09, 0.6, 8.69, 16.95, 74.03, 84.05, 39.87, 15.52,
   27.92, 35.72, 80.26, 71.93, 66.73, 87.8, 5.43, 98.3,
7.41, 9.86, 63.64, 0.36, 5.84, 1.58, 20.1, 4.21, 82.12,
   19.29, 9.02, 22.12, 54.08, 74.95, 3.24, 9.67, 67.98,
9.92, 40.69, 6.24, 8.76, 74.25, 46.34, 25.69, 90.63, 83.71,
   73.53, 57.88, 15.84, 82.07, 67.45, 47.39, 98.77, 75.1,
64.9, 3.71, 87.44, 61.06, 4.77, 57.54, 7.68, 4.54, 6.15,
   3.32, 60.39, 33.78, 66.22, 18.67, 76.53, 63.54, 47.06,
38.47, 88.15, 18.25, 4.26, 67.19, 88.87, 29.65, 7.33, 68.18,
   28.03, 6.91, 77.82, 22.23, 73.23, 95.21, 27.11, 37.01,
34.88, 28.15, 11.27, 15.67, 96.08, 89.52, 28.6, 8.22, 23.55,
   59.2, 36.38, 41.38, 0.4, 56.82, 32.35, 20.6, 18.13,
8.15, 1.08, 9.85, 1.07, 37.75, 97.6, 7.16, 8.51, 4.42,
   0.15, 1.28, 7.42, 71.15, 9.39)
ll <- c(70.65, 42.69, 37.58, 31.96, 34.49, 38.96, 56.57, 27.22, 35.45,
37.28, 20.17, 19.08, 54.41, 52, 120.04, 31.5, 40.94, 37.34,
10.06, 63.21, 18.55, 34.21, 51.45, 54.58, 1.88, 70.21, 145.86,
52.85, 14.38, 25.96, -25.57, 63.65, 86.72, 41.04, 41.94, 28.03,
26.85, 26.23, 19.41, 15.73, 29.25, 36.75, 26, 22.9, 36.86,
38.83, 8.27, 17.19, 41.73, -45.94, 24.26, 25.55, 34.86, 26.59, 45.9,
-39.72, 52.08, -10.12, -12.26, 0.0391, 30.61,
3.65, -27.25, 60.06, 34.35, 3.96, 101.87, 47.61, 55.36, 46.56, 91.88,
44.09,
-23.69, 74.95, 56.94, 58.91, 81.4, 129.31, 86.55, -17.03,
53.95, 109.63, 41.48, 26.08, 209.78, 110.74, 59.07, 29.27, 88.2,
39.57,
-22.3, 25.59, 27.14, -12.64, 43.64, 44.16, 52.42, 45.9, 44.79,
7.88, 47.21, 33.48, 44.88, 1.92, -20.95, 46.76, 35.33, 31.02,
40.08, 10.81, 205.76, 31.24, -6.25, 74.66, 54.31, -33.63,
-2.20, 54.47, 19.12, 103.66, 43.93, 116.55, 53.61, 4.23,
12.9, 35.1, 136.29, 98.56, 235.94, 27.23, 126.46, 28.32,
40.46, 38.85, 40.68, 25.61, 31.22, -5.22, 57.33, -14.53, 72.46, 36.94,
41.53, -32.15, 90.75, 111.74, -13.19, -29.87, 49.35, 26.67,
6.31, 25.97, 42.09, -22.82, 33.77, -14.23, 

[R] Remove dependency of Image's physical location while sending email.

2017-03-28 Thread Archit Soni
Hello All,

I am using below code to send alerts from R. However, while testing the
emails to other users The image which is used as inline in email
configuration is not showing up as it is referencing to my temp folder.

Any ideas to resolve this ? I need to have embedded image irrespective of
the fact if the image gets deleted etc.

My Code:

(require(mailR))
y <- TriggerEmailR #my variable to trigger the script
#ImgSaveLocation - Local temp folder where image is saved.
bdy <- paste(" Hello,   Avg. DIP has gone above 30
days   Check the analysis:
 Note: This is a system generated email, please do not reply to
this email.")
send.mail(from = "a...@abc.com",
  to = c("Recipient 1 <>" ),
  subject = "Alert",
  body = bdy,
  html = TRUE,
  inline = TRUE,
  smtp = list(host.name = "<<>>"),
  authenticate = FALSE,
  send = TRUE)

-- 
​Thanks in advance,
Archit

[[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] How to source a local R file to a remote session.

2017-03-28 Thread Jeff Newmiller
Use the "parallel" package? 
-- 
Sent from my phone. Please excuse my brevity.

On March 27, 2017 10:28:54 PM PDT, Jeremie Juste  wrote:
>
>Hello,
>
>I don't know exactly where to turn to.
>I'm using Emacs speak statistics and I can execute a codes on my local
>computer to a remote session seemlessly.
>
>But I've always wondered how to source a file on local computer to the
>remote session? Till now I have copied the files to the remote host and
>source from there but it complicates the version control process.
>
>
>Any suggestions on this?
>
>
>
>Best regards,
>
>Jeremie
>
>__
>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.