Re: [R] Please help(urgent) - How to simulate transactional data for reliability/survival analysis

2017-07-04 Thread Mark Sharp
A small example data set that illustrates your question will be of great value 
to those trying to help. This appears to be a transformation that you are 
wanting to do (timestamp to units of time) so a data representing what you have 
(dput() is handy for this) and one representing what you want to have with any 
guidance regarding how to use the other columns in you data set (e.g., the 
event(0/1)).

Mark
R. Mark Sharp, Ph.D.
msh...@txbiomed.org





> On Jul 4, 2017, at 7:02 AM, Sunny Singha  
> wrote:
>
> Thanks Boris and Bret,
> I was successful in simulating granular/transactional data.
> Now I need some guidance to transform the same data in format acceptable
> for survival analysis i.e below format:
>
> pump_id | event_episode_no. | event(0/1) | start | stop | time_to_dropout
>
> The challenge I'm experience is to generate the 'start' and 'stop' in units
> of minutes/days from single column of 'Timestamp' which is
> the column from transactional/granular data based on condition tagged in
> separate column, 'event 0/1, (i.e event ).
>
> Please guide how to do such transformation in 'R'.
>
> Regards,
> Sandeep
>
>
>
> On Wed, Jun 28, 2017 at 2:51 PM, Boris Steipe 
> wrote:
>
>> In principle what you need to do is the following:
>>
>> - break down the time you wish to simulate into intervals.
>> - for each interval, and each failure mode, determine the probability of
>> an event.
>>   Determining the probability is the fun part, where you make your domain
>>   knowledge explicit and include all the factors into your model:
>> cumulative load,
>>   failure history, pressure, temperature, phase of the moon ...
>> - once you have a probability of failure, use the runif() function to
>> give you
>>   a uniformly distributed random number in [0, 1]. If the number is
>> smaller than
>>   your failure probability, accept the failure event, and record it.
>> - Repeat many times.
>>
>> Hope this helps.
>> B.
>>
>>
>>
>>
>>> On Jun 27, 2017, at 10:58 AM, sandeep Rana  wrote:
>>>
>>> Hi friends,
>>> I haven't done such a simulation before and any help would be greatly
>> appreciated. I need your guidance.
>>>
>>> I need to simulate end to end data for Reliability/survival analysis of
>> a Pump ,with correlation in place, that is at 'Transactional level' or at
>> the granularity of time-minutes, where each observation is a reading
>> captured via Pump's sensors each minute.
>>> Once transactional data is prepared I Then need to summarise above data
>> for reliability/ survival analysis.
>>>
>>> To begin with below is the transactional data format that i want prepare:
>>> Pump-id| Timestamp | temp | vibration | suction pressure| discharge
>> pressure | Flow
>>>
>>> Above transactional data has to be prepared with below failure modes
>>> Defects :
>>> (1)Cavitation – very high in frequency but low impact
>>> (2)Bearing Damage – very low in frequency but high impact
>>> (3)Worn Shaft – medium frequency but medium impact
>>>
>>> I have used survsim package but that's not what I need here.
>>> Please help and guide.
>>>
>>> Regards,
>>> Sandeep
>>>
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/
>> posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/
>> posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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 
addre

Re: [R] Please help(urgent) - How to simulate transactional data for reliability/survival analysis

2017-07-05 Thread Mark Sharp
I am trying to figure out the algorithm you are using to calculate 
event_episodes, event_status, and start_minutes.

Where does the 129600 come from?

Why is the start(minutes) 0 for the last row instead of 40?

Mark
R. Mark Sharp, Ph.D.
msh...@txbiomed.org





> On Jul 5, 2017, at 1:03 AM, Sunny Singha  
> wrote:
>
> Mark,
> Below is the sampled simulated granular data format for pumps for
> trial period of 3 months that I need to transform for survival
> analysis:
> 3 months = (60*24*90) minutes i.e 129600 minutes
>
> pump_id timingsevents   vibration temprature flow
> pump1 01-07-2017 00:00   03.44369.6   139.806
> pump1 01-07-2017 00:10   10.50145.27 140.028
> pump1 01-07-2017 00:20   02.03152.9   137.698
> pump1 01-07-2017 00:30   02.26760.12 139.054
> pump1 01-07-2017 00:40   12.26760.12 139.054
> pump1 01-07-2017 00:50   02.26760.12 139.054
> pump2 01-07-2017 00:00   03.44369.6   139.806
> pump2 01-07-2017 00:10   00.50145.27 140.028
> pump2 01-07-2017 00:20   02.03152.9   137.698
> pump2 01-07-2017 00:30   02.26760.12 139.054
> pump2 01-07-2017 00:40   12.26760.12 139.054
> pump2 01-07-2017 00:50   02.26760.12 139.054
>
> The above data set records observations and timings where 'pumps'
> experienced failure, tagged as '1' in column 'events'.
> In the above granular dataset the pump1 experiences 2 "event episodes."
>
> Below is the desired transformed format. the covariates in this data
> set will have the mean value:
> pump_id  event_episodes  event_status  start(minutes)
> stop(minutes)
> pump1  1 1
>  0   10
> pump1  2 1
> 10  40
> pump1  3 0
> 40  129600
> pump2  1 1
>  0   40
> pump2  2 0
>  0   129600
> .
> .
>
> The 'start' and 'stop' columns are evaluated from the 'timings'
> columns. I need help in performing such transformation in 'R'.
> Please guide and help.
>
> Regards,
> Sandeep
>
> On Wed, Jul 5, 2017 at 7:26 AM, Mark Sharp  wrote:
>> A small example data set that illustrates your question will be of great 
>> value to those trying to help. This appears to be a transformation that you 
>> are wanting to do (timestamp to units of time) so a data representing what 
>> you have (dput() is handy for this) and one representing what you want to 
>> have with any guidance regarding how to use the other columns in you data 
>> set (e.g., the event(0/1)).
>>
>> Mark
>> R. Mark Sharp, Ph.D.
>> msh...@txbiomed.org
>>
>>
>>
>>
>>
>>> On Jul 4, 2017, at 7:02 AM, Sunny Singha  
>>> wrote:
>>>
>>> Thanks Boris and Bret,
>>> I was successful in simulating granular/transactional data.
>>> Now I need some guidance to transform the same data in format acceptable
>>> for survival analysis i.e below format:
>>>
>>> pump_id | event_episode_no. | event(0/1) | start | stop | time_to_dropout
>>>
>>> The challenge I'm experience is to generate the 'start' and 'stop' in units
>>> of minutes/days from single column of 'Timestamp' which is
>>> the column from transactional/granular data based on condition tagged in
>>> separate column, 'event 0/1, (i.e event ).
>>>
>>> Please guide how to do such transformation in 'R'.
>>>
>>> Regards,
>>> Sandeep
>>>
>>>
>>>
>>> On Wed, Jun 28, 2017 at 2:51 PM, Boris Steipe 
>>> wrote:
>>>
>>>> In principle what you need to do is the following:
>>>>
>>>> - break down the time you wish to simulate into intervals.
>>>> - for each interval, and each failure mode, determine the probability of
>>>> an event.
>>>>  Determining the probability is the fun part, where you make your domain
>>>>  knowledge explicit and include all the factors into your mode

Re: [R] Loading Rcmdr

2017-07-24 Thread Mark Sharp
Jack,

I do not use Rcmdr, but I installed the binary package version 2.3-2. It came 
right up when I then ran the following at the prompt (console output is 
appended without edits):
> sessionInfo();library("Rcmdr");sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6

Matrix products: default
BLAS: 
/Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRblas.0.dylib
LAPACK: 
/Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

loaded via a namespace (and not attached):
[1] compiler_3.4.1
Loading required package: splines
Loading required package: RcmdrMisc
Loading required package: car
Loading required package: sandwich

Rcmdr Version 2.3-2

R version 3.4.1 (2017-06-30)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6

Matrix products: default
BLAS: 
/Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRblas.0.dylib
LAPACK: 
/Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] Rcmdr_2.3-2 RcmdrMisc_1.0-5 sandwich_2.3-4  car_2.1-5

loaded via a namespace (and not attached):
 [1] zoo_1.8-0   lattice_0.20-35 tcltk_3.4.1 
colorspace_1.3-2
 [5] htmltools_0.3.6 mgcv_1.8-17 base64enc_0.1-3 relimp_1.0-5
 [9] survival_2.41-3 rlang_0.1.1.9000e1071_1.6-8 nloptr_1.0.4
[13] foreign_0.8-69  RColorBrewer_1.1-2  readxl_1.0.0plyr_1.8.4
[17] stringr_1.2.0   MatrixModels_0.4-1  cellranger_1.1.0munsell_0.4.3
[21] gtable_0.2.0htmlwidgets_0.9 latticeExtra_0.6-28 knitr_1.16
[25] SparseM_1.77class_7.3-14quantreg_5.33   pbkrtest_0.4-7
[29] parallel_3.4.1  htmlTable_1.9   Rcpp_0.12.12acepack_1.4.1
[33] tcltk2_1.2-11   scales_0.4.1backports_1.1.0 checkmate_1.8.3
[37] Hmisc_4.0-3 abind_1.4-5 lme4_1.1-13 gridExtra_2.2.1
[41] ggplot2_2.2.1   digest_0.6.12   stringi_1.1.5   grid_3.4.1
[45] tools_3.4.1 magrittr_1.5lazyeval_0.2.0  tibble_1.3.3
[49] Formula_1.2-2   cluster_2.0.6   MASS_7.3-47 Matrix_1.2-10
[53] data.table_1.10.4   minqa_1.2.4 rpart_4.1-11nnet_7.3-12
[57] nlme_3.1-131compiler_3.4.1
> R. Mark Sharp, Ph.D.
msh...@txbiomed.org





> On Jul 24, 2017, at 6:17 PM, Jack Talley  wrote:
>
> With the lastest version of R 3.4.1 I have not been able to loard Rcmdr.
> Advice please.
>
> Thank you,
>
> Jack Talley, PhD
>
> [[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...{{dropped:10}}

__
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 concatenate in R

2017-08-02 Thread Mark Sharp
You will need to understand dataframes and how to add those together. Use the 
help system by typing ?rbind at the console prompt. There are numerous examples 
to be found with a simple web search.

Robert Kabacoff has a great book and website the provides examples and 
explanation at http://www.statmethods.net/management/merging.html

Look at the readxl package. You may want to start with 
http://readxl.tidyverse.org.

Mark
R. Mark Sharp, Ph.D.
msh...@txbiomed.org





> On Aug 2, 2017, at 6:06 AM, Swain, Subrat  wrote:
>
>
> Hi,
>
> I have 6 excel files, I want to concatenate all and create one excel files, 
> How to program that in R.(I need the code)
>
> Kind regards,
>
> SUBRAT SWAIN
>
> IMPORTANT NOTICE:
> The information in this email (and any attachments) is confidential. If you 
> are not the intended recipient, you must not use or disseminate the 
> information. If you have received this email in error, please immediately 
> notify me by "Reply" command and permanently delete the original and any 
> copies or printouts thereof. Although this email and any attachments are 
> believed to be free of any virus or other defect that might affect any 
> computer system into which it is received and opened, it is the 
> responsibility of the recipient to ensure that it is virus free and no 
> responsibility is accepted by American International Group, Inc. or its 
> subsidiaries or affiliates either jointly or severally, for any loss or 
> damage arising in any way from its use.
>
> [[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...{{dropped:10}}

__
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] Package nleqslv ERROR

2017-08-09 Thread Mark Sharp
Santi,


In the second line of your function you have the following:
f <- numeric(length(x))

This sets the length of this numeric vector (i.e., "f") to the length of the 
vector "x".
Later, inside the function you assign to values to 4 elements of the vector "f".
This assumes that "f" is at least 4 element in length.

However, you define "startx" to be a numeric vector of length 2 with
startx <- c(16350, 1.33)
which you then use as the argument to the function "fun" (bad name for a 
function, by the way, as it is not descriptive).

Thus, when "x" inside your function gets the value of "startx" it becomes a 
numeric vector of length 2, which is then used to set the length of the numeric 
vector "f". As soon as the function tries to assign a value to f[3], R 
correctly throws an informative error.

Mark
R. Mark Sharp, Ph.D.
msh...@txbiomed.org





> On Aug 9, 2017, at 3:56 PM, Santi Burone  wrote:
>
> Dear all,
> I am relatively new to R and have had some difficulty in understanding an 
> error i get when running a code to solve a system of non-linear equations, 
> with four equations and two variables.
>
> This is my code:
>
> ALPHA <- c(-0.0985168033402, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4)
> BETA <- c(-0.0985168033402, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4)
> GAMMA <- c(0.3940672148378, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4)
> MEA <- 3
> MIA <- 1
> MAA <- 5
> DEA <- 0.385
> fun <- function(x)  {
>  f <- numeric(length(x))
>  f[1] <-   1*x[1] - 
> MEA*((0.5*((MIA-MEA)^2))^(-BETA[1+j]))*((0.5*((MAA-MEA)^2))^(-ALPHA[1+i]))*((DEA)^(-GAMMA[1+k]*((12^0.5)^(-GAMMA[1+k])))/(((0.5)^(-BETA[1+j]-ALPHA[1+i]))*(((1-1*x[2])/(2))^(-BETA[1+j]))*(((-1+1*x[2])/(2))^(-ALPHA[1+i]))*(2*(1*x[2]-1)^(-GAMMA[1+k]^(1/(-1-BETA[1+j]-ALPHA[1+i]-1.5*GAMMA[1+k]))
>  f[2] <-   1*x[1] - 
> (((MAA*((0.5*((MIA+MAA)^(2)))^(-BETA[1+j]))*((DEA)^(-GAMMA[1+k])))*((12^0.5)^(-GAMMA[1+k])))/((1*x[2])*(2^(-BETA[1+j]-GAMMA[1+k]))*((1*x[2]-1)^(-GAMMA[1+k]))*1-1*x[2])^2)/2)^(-BETA[1+j]^(1/(1-2*BETA[1+j]-1.5*(GAMMA[1+k])))
>  f[3] <-   1*x[1] - 
> (((MIA*((0.5*((MIA+MAA)^(2)))^(-ALPHA[1+i]))*((DEA)^(-GAMMA[1+k])))*((12^0.5)^(-GAMMA[1+k])))/((2-1*x[2])*(2^(-ALPHA[1+i]-GAMMA[1+k]))*((1*x[2]-1)^(-GAMMA[1+k]))*-1+1*x[2])^2)/2)^(-ALPHA[1+i]^(1/(1-2*ALPHA[1+i]-1.5*(GAMMA[1+k])))
>  f[4] <- 1*x[2] > 1
>  f
>
> }
>
> Result <- matrix(0,nrow=9*9*9,ncol=6)
> startx<-c(16350, 1.33)
> indx <- 1
> for (i in 1:9) {
>  for (j in 1:9) {
>for (k in 1:9) {
>  f.startx <- fun(startx)
>  if(anyNA(f.startx)) {
>Result[indx,1:3] <- NA
>  } else {
>z <- nleqslv(startx,fun)
>Result[indx,1:3] <- c(z$termcd,z$x)
>  }
>  Result[indx,4:6] <- c(i,j,k)
>  indx <- indx+1
>}
>  }
> }
>
>
> The error i get when solving for specific values of ALPHA, BETA and GAMMA, 
> not using the loop is:
>
> Error in nleqslv(xstart, fun) : Length of fn result <> length of x!
>
> I had already solved this problem useing ALPHA, BETA and GAMMA as X[1], X[2] 
> and X[3] and being X[1] and X[2] of this system  given values, in that case 
> for the first values of alpha beta and gamma given here the solution was 
> (16350, 1.33).
> I dont understand what’s the error i get here, as i know the system as a 
> unique solution. "What’s the meaning of Length of fn result <> length of x!"?
>
> Thanks in advance!
> Santiago.
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

CONFIDENTIALITY NOTICE: This e-mail and any files and/or attachments 
transmitted, may contain privileged and confidential information and is 
intended solely for the exclusive use of the individual or entity to whom it is 
addressed. If you are not the intended recipient, you are hereby notified that 
any review, dissemination, distribution or copying of this e-mail and/or 
attachments is strictly prohibited. If you have received this e-mail in error, 
please immediately notify the sender stating that this transmission was 
misdirected; return the e-mail to sender; destroy all paper copies and delete 
all electronic copies from your system without disclosing its contents.
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Re: [R] Comparing 2 dale columns

2017-08-23 Thread Mark Sharp
Patrick,

## Run the following script an notice the different values of the dataframe 
"data" in each instance.

# I understand you have done something like the following:
data <- data.frame(COL1 = c("6/1/14", "7/1/14"),
   COL2 = c("5/1/15", "5/1/15"), stringsAsFactors = FALSE)
data$Date_Flag <- ifelse(data$COL2 > data$COL1, 0,1)
data
data$COL2 <- as.Date(as.character(data$COL2, format = "%y/%m/%d"))
data$COL1 <- as.Date(as.character(data$COL1, format = "%y/%m/%d"))
data$Date_Flag <- ifelse(data$COL2 > data$COL1, 0,1)
data

# What you may want instead is the following:
data <- data.frame(COL1 = c("6/1/14", "7/1/14"),
   COL2 = c("5/1/15", "5/1/15"), stringsAsFactors = FALSE)
data
## strptime() converts the character vector to POSIXct so you do not necessarily
## need the as.Date. However, they are not the same and you may need the Date
## class.
data$COL2 <- as.Date(strptime(data$COL2, format = "%m/%d/%y"))
data$COL1 <- as.Date(strptime(data$COL1, format = "%m/%d/%y"))
data
data$Date_Flag <- ifelse(data$COL2 > data$COL1, 0,1)
data


R. Mark Sharp, Ph.D.
msh...@txbiomed.org





> On Aug 23, 2017, at 9:53 AM, Patrick Casimir  wrote:
>
> data$Date_Flag <- ifelse(data$COL2 > data$COL1, 0,1)
>
>
> COL1   COL2
> 6/1/14 5/1/15
> 7/1/14 5/1/15
>
>
> data$COL2<- as.Date(as.character(data$COL2, format="%y/%m/%d"))
> data$COL1<- as.Date(as.character(data$COL1, format="%y/%m/%d"))
>

CONFIDENTIALITY NOTICE: This e-mail and any files and/or...{{dropped:10}}

__
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 connect Microsoft Sql server from R studio using freeTDS instead of RODBC package

2016-08-29 Thread Mark Sharp
Manu,

Read the first paragraph under section "1 ODBC Concepts" of 
https://cran.r-project.org/web/packages/RODBC/vignettes/RODBC.pdf. This 
describes the relationship among the various parts of the technical stack that 
allows connectivity to the database system via ODBC. One of the points made is 
that RODBC uses an ODBC driver (e.g., Actual Technologies, Easysoft and 
OpenLink).

I use the driver from Actual Technologies on Mac OS, but many others have used 
freeTDS. I had trouble with freeTDS years ago and decided my time was worth the 
minor cost of using the commercial product from Actual Technologies.

The driver you use is computer OS specific while RODBC is not.

It is also convenient to use an ODBC manager, which is typically a graphical 
application used to create and manage the configuration files used by the ODBC 
driver.

Mark

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

> On Aug 28, 2016, at 11:53 PM, Manohar Reddy  wrote:
>
> Hi,
>
>
>
>   Can anyone guide me how to connect the Microsoft Sql server 2012/14 from
> R studio using freeTDS package instead of RODBC ,I can able to connect the
> MS Sql server from R studio using RODBC.
>
>  Actually my requirement is I have developed webpage/report using Shiny
> package then I was deployed it on Shinyapps.io ,but after deploying I’m
> encountering error like “”ERROR: *first argument is not an open RODBC
> channel*” ,based on this error message I did searched in google and found
> that we need to use freeTDS drivers instead of RODBC but I found some
> articles regarding freeTDS but it’s not useful for me.
>
>
>
> I was eagerly waiting for solution from someone since last month, but not
> yet and this issue is not allowing me to further .Can anyone please help me
> out me(how to install freeTDS and how to configure it) on same.
>
>
>
> My environment details :
>
>
>
>Os : windows 8
>
>R version 3.3.1 (2016-06-21)
>
>
>
> Thanks in Advance .
>
> Manu.
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.







CONFIDENTIALITY NOTICE: This e-mail and any files and/or attachments 
transmitted, may contain privileged and confidential information and is 
intended solely for the exclusive use of the individual or entity to whom it is 
addressed. If you are not the intended recipient, you are hereby notified that 
any review, dissemination, distribution or copying of this e-mail and/or 
attachments is strictly prohibited. If you have received this e-mail in error, 
please immediately notify the sender stating that this transmission was 
misdirected; return the e-mail to sender; destroy all paper copies and delete 
all electronic copies from your system without disclosing its contents.
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Re: [R] How to connect Microsoft Sql server from R studio using freeTDS instead of RODBC package

2016-08-29 Thread Mark Sharp
Manu,

I believe you are mistaken regarding using freeTDS instead of RODBC. 
shinyapps.io apparently has freeTDS drivers already installed. I am guessing 
that either you have not configured your connections string 
(odbcDriverConnect("driver = FreeTDS; ...")) correctly or your database server 
has a firewall rule that is not allowing a connection from shinyapps.io.

However, please note, I have not used shinyapps.io and am making these guesses 
based on my experience with RODBC and the documentation I have read. You will 
want to find someone with shinyapps.io experience.

Mark

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

On Aug 29, 2016, at 12:26 PM, Manohar Reddy  wrote:
>
> Hi Mark,
>
>
>   Thank you so much for reply, using exiting ODBC drivers I will make a 
> connection  to sql server and it’s working fine in my local, but as per 
> shinyapps.io I need to use freeTDS drivers instead RODBC ,so that I may not 
> encounter the any issue .For me here challenging work is how to install 
> freeTDS on my machine and how to configure it?
>
>
>  Is there any drivers/way that can i  make a connection to sql server and 
> I shouldn’t encounter the issue after deploying application on shinyapps.io.
>
>
> Thanks,Manu.
>
>
> On Mon, Aug 29, 2016 at 9:35 PM, Mark Sharp  wrote:
> Manu,
>
> Read the first paragraph under section "1 ODBC Concepts" of 
> https://cran.r-project.org/web/packages/RODBC/vignettes/RODBC.pdf. This 
> describes the relationship among the various parts of the technical stack 
> that allows connectivity to the database system via ODBC. One of the points 
> made is that RODBC uses an ODBC driver (e.g., Actual Technologies, Easysoft 
> and OpenLink).
>
> I use the driver from Actual Technologies on Mac OS, but many others have 
> used freeTDS. I had trouble with freeTDS years ago and decided my time was 
> worth the minor cost of using the commercial product from Actual Technologies.
>
> The driver you use is computer OS specific while RODBC is not.
>
> It is also convenient to use an ODBC manager, which is typically a graphical 
> application used to create and manage the configuration files used by the 
> ODBC driver.
>
> Mark
>
> R. Mark Sharp, Ph.D.
> Director of Primate Records Database
> Southwest National Primate Research Center
> Texas Biomedical Research Institute
> P.O. Box 760549
> San Antonio, TX 78245-0549
> Telephone: (210)258-9476
> e-mail: msh...@txbiomed.org
>
> > On Aug 28, 2016, at 11:53 PM, Manohar Reddy  wrote:
> >
> > Hi,
> >
> >
> >
> >   Can anyone guide me how to connect the Microsoft Sql server 2012/14 from
> > R studio using freeTDS package instead of RODBC ,I can able to connect the
> > MS Sql server from R studio using RODBC.
> >
> >  Actually my requirement is I have developed webpage/report using Shiny
> > package then I was deployed it on Shinyapps.io ,but after deploying I’m
> > encountering error like “”ERROR: *first argument is not an open RODBC
> > channel*” ,based on this error message I did searched in google and found
> > that we need to use freeTDS drivers instead of RODBC but I found some
> > articles regarding freeTDS but it’s not useful for me.
> >
> >
> >
> > I was eagerly waiting for solution from someone since last month, but not
> > yet and this issue is not allowing me to further .Can anyone please help me
> > out me(how to install freeTDS and how to configure it) on same.
> >
> >
> >
> > My environment details :
> >
> >
> >
> >Os : windows 8
> >
> >R version 3.3.1 (2016-06-21)
> >
> >
> >
> > Thanks in Advance .
> >
> > Manu.
> >
> > [[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-ma

Re: [R] How to connect Microsoft Sql server from R studio using freeTDS instead of RODBC package

2016-08-30 Thread Mark Sharp
Manu,

As far as I can tell you have not taken the advice from Wim Jansen, who gave 
you guidance on how to specify the freetds driver in your connection function. 
I do not think you need the unixodbc. In my experience having too much is as 
bad as not having enough.


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

On Aug 30, 2016, at 07:05, Manohar Reddy 
mailto:manu.redd...@gmail.com>> wrote:

Hi Mark,

  Thanks,as per your suggestion and based on below link, I�m trying to connect 
my remote server but while connecting I have encountered attached error, can 
you please look in that and help out me.

  Link : https://groups.google.com/forum/#!topic/shinyapps-users/hs4bQHsk9JU

 Note :


1.   I tired without freeTDS versions also though nolock

2.   We have set it my remote sql server like by default it will allow all 
the connections.


Thnaks,Manu.

On Tue, Aug 30, 2016 at 12:53 AM, Mark Sharp 
mailto:msh...@txbiomed.org>> wrote:
Manu,

I believe you are mistaken regarding using freeTDS instead of RODBC. 
shinyapps.io<http://shinyapps.io> apparently has freeTDS drivers already 
installed. I am guessing that either you have not configured your connections 
string (odbcDriverConnect("driver = FreeTDS; ...")) correctly or your database 
server has a firewall rule that is not allowing a connection from 
shinyapps.io<http://shinyapps.io>.

However, please note, I have not used shinyapps.io<http://shinyapps.io> and am 
making these guesses based on my experience with RODBC and the documentation I 
have read. You will want to find someone with shinyapps.io<http://shinyapps.io> 
experience.

Mark

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

On Aug 29, 2016, at 12:26 PM, Manohar Reddy 
mailto:manu.redd...@gmail.com>> wrote:
>
> Hi Mark,
>
>
>   Thank you so much for reply, using exiting ODBC drivers I will make a 
> connection  to sql server and it�s working fine in my local, but as per 
> shinyapps.io<http://shinyapps.io> I need to use freeTDS drivers instead RODBC 
> ,so that I may not encounter the any issue .For me here challenging work is 
> how to install freeTDS on my machine and how to configure it?
>
>
>  Is there any drivers/way that can i  make a connection to sql server and 
> I shouldn�t encounter the issue after deploying application on 
> shinyapps.io<http://shinyapps.io>.
>
>
> Thanks,Manu.
>
>
> On Mon, Aug 29, 2016 at 9:35 PM, Mark Sharp 
> mailto:msh...@txbiomed.org>> wrote:
> Manu,
>
> Read the first paragraph under section "1 ODBC Concepts" of 
> https://cran.r-project.org/web/packages/RODBC/vignettes/RODBC.pdf. This 
> describes the relationship among the various parts of the technical stack 
> that allows connectivity to the database system via ODBC. One of the points 
> made is that RODBC uses an ODBC driver (e.g., Actual Technologies, Easysoft 
> and OpenLink).
>
> I use the driver from Actual Technologies on Mac OS, but many others have 
> used freeTDS. I had trouble with freeTDS years ago and decided my time was 
> worth the minor cost of using the commercial product from Actual Technologies.
>
> The driver you use is computer OS specific while RODBC is not.
>
> It is also convenient to use an ODBC manager, which is typically a graphical 
> application used to create and manage the configuration files used by the 
> ODBC driver.
>
> Mark
>
> R. Mark Sharp, Ph.D.
> Director of Primate Records Database
> Southwest National Primate Research Center
> Texas Biomedical Research Institute
> P.O. Box 760549
> San Antonio, TX 78245-0549
> Telephone: (210)258-9476
> e-mail: msh...@txbiomed.org<mailto:msh...@txbiomed.org>
>
> > On Aug 28, 2016, at 11:53 PM, Manohar Reddy 
> > mailto:manu.redd...@gmail.com>> wrote:
> >
> > Hi,
> >
> >
> >
> >   Can anyone guide me how to connect the Microsoft Sql server 2012/14 from
> > R studio using freeTDS package instead of RODBC ,I can able to connect the
> > MS Sql server from R studio using RODBC.
> >
> >  Actually my requirement is I have developed webpage/report using Shiny
> > package then I was deployed it on Shinyapps.io<http://shinyapps.io> ,but 
> > after deploying I�m
> > encountering error like ��ERROR: *first argument is not an open RODBC
> > channel*� ,based on this error message I di

Re: [R] 0 rows> (or 0-length row.names)

2016-08-30 Thread Mark Sharp
What do you get from
str(SFDC$case_age)

Mark

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







> On Aug 30, 2016, at 11:24 AM, Shivi Bhatia  wrote:
>
> I know this question has been asked zillion times but even after consulting
> Stack Overflow & other forum cant figure out the reason.
>
> I have one var in my data-set names case age. This variable is numeric as:
>
> class(SFDC$case_age)
>
> *numeric*
>
> however it throws this error:
>
> <0 rows> (or 0-length row.names)
> As checked this only happens either there is some space at the end of the
> variable name, or there are no values whereas this is a numeric variable
> with no missing values and has a total of 5400 observations.
>
> This var has a range from 0 to 240 in number of days for case variable
> hence i need to do a logarithm transformation & make it use in the model.
> Total unique obs are around 1500.
>
> Please advice.
>
> [[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...{{dropped:10}}

__
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] 0 rows> (or 0-length row.names)

2016-08-30 Thread Mark Sharp
Shivi,

Can you show the code that throws the error?
<0 rows> (or 0-length row.names)

Of course as always a reproducible sample would be great. Perhaps you can make 
a small subset of the data and use dput() to provide a defined object.

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

> On Aug 30, 2016, at 11:38 AM, Shivi Bhatia  wrote:
>
> Hi Mark,
>
> It gives me num [1:5083]. I have used head also to see first 10 obs:
>
> head(SFDC$case_age,10)
>  [1] 24.84  0.05 13.38  0.15 11.11  4.16  8.13  0.07  3.61  0.00
>
> Thanks.
>
> On Tue, Aug 30, 2016 at 10:05 PM, Mark Sharp  wrote:
> What do you get from
> str(SFDC$case_age)
>
> Mark
>
> R. Mark Sharp, Ph.D.
> Director of Primate Records Database
> Southwest National Primate Research Center
> Texas Biomedical Research Institute
> P.O. Box 760549
> San Antonio, TX 78245-0549
> Telephone: (210)258-9476
> e-mail: msh...@txbiomed.org
>
>
>
>
>
>
>
> > On Aug 30, 2016, at 11:24 AM, Shivi Bhatia  wrote:
> >
> > I know this question has been asked zillion times but even after consulting
> > Stack Overflow & other forum cant figure out the reason.
> >
> > I have one var in my data-set names case age. This variable is numeric as:
> >
> > class(SFDC$case_age)
> >
> > *numeric*
> >
> > however it throws this error:
> >
> > <0 rows> (or 0-length row.names)
> > As checked this only happens either there is some space at the end of the
> > variable name, or there are no values whereas this is a numeric variable
> > with no missing values and has a total of 5400 observations.
> >
> > This var has a range from 0 to 240 in number of days for case variable
> > hence i need to do a logarithm transformation & make it use in the model.
> > Total unique obs are around 1500.
> >
> > Please advice.
> >
> > [[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.
>




CONFIDENTIALITY NOTICE: This e-mail and any files and/or...{{dropped:10}}

__
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] 0 rows> (or 0-length row.names)

2016-08-30 Thread Mark Sharp
Shivi,

It is likely that William knows what you are trying to do because of his 
considerable experience, but I am not able to figure it out from what you have 
written. You have apparently sent the output from something like 
dput(SFDC[1:50, ]), but I still do not know what you did to get the error.

I successfully assigned the structure you sent to the name SFDC and nothing 
seems amiss.


Mark

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







> On Aug 30, 2016, at 12:32 PM, Shivi Bhatia  wrote:
>
> Hi William/ Mark,
>
> I am using WOE & IV (weight of evidence) reduce the number of independent
> vars.
> I have read this data as a csv file.
> reproducible example for your reference please:
>
> structure(list(date = structure(c(6L, 6L, 6L, 6L, 6L, 6L, 14L,
> 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
>
... truncated
> __
> 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...{{dropped:10}}

__
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] 0 rows> (or 0-length row.names)

2016-08-30 Thread Mark Sharp
Shivi,

What package(s) are you using. What functions are you using. How are you 
calling the functions. A reproducible sample has all of the actual code needed 
to create a representative error. There are multiple packages you could be 
using to look at weight of evidence and information value. For example, there 
is a WOE function in the Information package and a woe function in the woe 
package.

Mark
On Aug 30, 2016, at 2:15 PM, Shivi Bhatia 
mailto:shivipm...@gmail.com>> wrote:

Hi Mark,
What i understand, probably when i run the WOE & IV to check significant 
variables that is where i get this error. Thanks for your assistance Mark 
really appreciate i will look into some other measure on this.

On Wed, Aug 31, 2016 at 12:35 AM, Mark Sharp 
mailto:msh...@txbiomed.org>> wrote:
Shivi,

It is likely that William knows what you are trying to do because of his 
considerable experience, but I am not able to figure it out from what you have 
written. You have apparently sent the output from something like 
dput(SFDC[1:50, ]), but I still do not know what you did to get the error.

I successfully assigned the structure you sent to the name SFDC and nothing 
seems amiss.


Mark

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







> On Aug 30, 2016, at 12:32 PM, Shivi Bhatia 
> mailto:shivipm...@gmail.com>> wrote:
>
> Hi William/ Mark,
>
> I am using WOE & IV (weight of evidence) reduce the number of independent
> vars.
> I have read this data as a csv file.
> reproducible example for your reference please:
>
> structure(list(date = structure(c(6L, 6L, 6L, 6L, 6L, 6L, 14L,
> 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
>
... truncated
> __
> R-help@r-project.org<mailto: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<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...{{dropped:23}}

__
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] 0 rows> (or 0-length row.names)

2016-08-31 Thread Mark Sharp
Shivi,

Looking at the help from ?WOE, ?WOETable, and ?IV, your Y vector in all cases 
is to be categorical and it is numeric.

Mark


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


On Aug 31, 2016, at 5:37 AM, Shivi Bhatia  wrote:
>
> These are the packages i am using:
> library(woe)  #WEIGHT OF EVIDENCE
> library(InformationValue)  #INFORMATION VALUE
>
> The syntax used is :
> WOE(X=SFDC1$log_caseage, Y=SFDC1$survey)
> WOETable(X=SFDC1$case_age, Y=SFDC1$survey)
> IV(X=SFDC1$case_age, Y=SFDC1$survey)
>
> On Wed, Aug 31, 2016 at 12:54 AM, Mark Sharp  wrote:
> Shivi,
>
> What package(s) are you using. What functions are you using. How are you 
> calling the functions. A reproducible sample has all of the actual code 
> needed to create a representative error. There are multiple packages you 
> could be using to look at weight of evidence and information value. For 
> example, there is a WOE function in the Information package and a woe 
> function in the woe package.
>
> Mark
>
>> On Aug 30, 2016, at 2:15 PM, Shivi Bhatia  wrote:
>>
>> Hi Mark,
>> What i understand, probably when i run the WOE & IV to check significant 
>> variables that is where i get this error. Thanks for your assistance Mark 
>> really appreciate i will look into some other measure on this.
>>
>> On Wed, Aug 31, 2016 at 12:35 AM, Mark Sharp  wrote:
>> Shivi,
>>
>> It is likely that William knows what you are trying to do because of his 
>> considerable experience, but I am not able to figure it out from what you 
>> have written. You have apparently sent the output from something like 
>> dput(SFDC[1:50, ]), but I still do not know what you did to get the error.
>>
>> I successfully assigned the structure you sent to the name SFDC and nothing 
>> seems amiss.
>>
>>
>> Mark
>>
>> R. Mark Sharp, Ph.D.
>> Director of Primate Records Database
>> Southwest National Primate Research Center
>> Texas Biomedical Research Institute
>> P.O. Box 760549
>> San Antonio, TX 78245-0549
>> Telephone: (210)258-9476
>> e-mail: msh...@txbiomed.org
>>
>>
>>
>>
>>
>>
>>
>> > On Aug 30, 2016, at 12:32 PM, Shivi Bhatia  wrote:
>> >
>> > Hi William/ Mark,
>> >
>> > I am using WOE & IV (weight of evidence) reduce the number of independent
>> > vars.
>> > I have read this data as a csv file.
>> > reproducible example for your reference please:
>> >
>> > structure(list(date = structure(c(6L, 6L, 6L, 6L, 6L, 6L, 14L,
>> > 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
>> >
>> ... truncated
>> > __
>> > 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.
>
> 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.
>

CONFIDENTIALITY NOTICE: This e-mail and any files and/or...{{dropped:10}}

__
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] Help with a code in R

2016-09-05 Thread Mark Sharp
Erika,

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

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


Mark

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







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


CONFIDENTIALITY NOTICE: This e-mail and any files and/or attachments 
transmitted, may contain privileged and confidential information and is 
intended solely for the exclusive use of the individual or entity to whom it is 
addressed. If you are not the intended recipient, you are hereby notified that 
any review, dissemination, distribution or copying of this e-mail and/or 
attachments is strictly prohibited. If you have received this e-mail in error, 
please immediately notify the sender stating that this transmission was 
misdirected; return the e-mail to sender; destroy all paper copies and delete 
all electronic copies from your system without disclosing its contents.
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Re: [R] Help with a code in R

2016-09-07 Thread Mark Sharp
Erika,

The code you sent is missing some matching braces. For example, see this pair 
of lines:

forecast_nal <- rbind.data.frame(forecast_nal, fct)
}

I do not see a left brace anywhere before this right brace.



Without the content of the data structures datos, calendar and espejo from the 
three files, we will not be able to reproduce your code. Often you can use only 
a small subset of the data and reproduce a problem, but only you will be able 
to find out how much of the data are sufficient to reproduce the problem.

You could start by trying to produce the problem with a minimum amount of data. 
Try something along these lines:

datos <- read.csv("C:/Users/ErikaRocío/Documents/Curso
  R/FCST_YEAR_WEEK_PROD_NAC.csv")
b <- data.frame(datos)[1:10, ]

calendar <-
  read.csv("C:/Users/ErikaRocío/Documents/Curso R/cat_sem.csv")
forecast_date <- calendar[1:10, c(8, 9, 14, 10)]

espejo <-
  read.csv("C:/Users/ErikaRocío/Documents/Curso R/cat_prod.csv")[1:10, ]

Then use these short versions of the dataframes in the rest of your code and 
see if you get the same error. You will likely have to play with the number of 
rows in each dataframe to fine the smallest number that will work. When you 
discover the smallest dataframes that recreate the error, you can send us the 
output from dput() as shown below:


datos <- read.csv("C:/Users/ErikaRocío/Documents/Curso
  R/FCST_YEAR_WEEK_PROD_NAC.csv")
b <- data.frame(datos)
dput(b[1:10, ])

calendar <-
  read.csv("C:/Users/ErikaRocío/Documents/Curso R/cat_sem.csv")
forecast_date <- calendar[, c(8, 9, 14, 10)]
dput(forecast_date[1:10, ])

espejo <-
  read.csv("C:/Users/ErikaRocío/Documents/Curso R/cat_prod.csv")
dput(espejo[1:10, ])






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







> On Sep 7, 2016, at 9:45 AM, Erika Rocío Espinosa Balbuena 
>  wrote:
>
> Hi,
>
> Sorry, how can I review on line, but here is the complete code:
>
>
> ##Librerias
> library(stats)
> library(base)
> library(dplyr)
> library(timeDate)
> library(zoo)
> library(forecast)
> #library(parallel)
> library(foreach)
> library(iterators)
> #library(doParallel)
> #library(snow)
> #library(doSNOW)
> library(reshape2)
> library(pryr)
> #library(rpivotTable)
>
>
> #numCores <- detectCores()
> #cl <- makeCluster(numCores)
>
>
>
> ###NACIONAL###
> #setwd("C:/RealMetrics/02_Aplicaciones/RM_SCM_DRM/RTools/Erika_Test")
>
> #write.csv(out, file="C:/Users/ErikaRocío/Documents/Curso R/nuevos.csv")
> #rpivotTable(forecast_nal,rows="Familia","Submarca","prod_id",col="s",
> aggregatorName="sum",vals="Point.Forecast")
>
> ##Lectura de datos
> #datos<-read.csv("FCST_YEAR_WEEK_PROD_NAC.csv")
> datos<-read.csv("C:/Users/ErikaRocío/Documents/Curso
> R/FCST_YEAR_WEEK_PROD_NAC.csv")
> b<-data.frame(datos)
>
> calendar<-read.csv("C:/Users/ErikaRocío/Documents/Curso R/cat_sem.csv")
> forecast_date<-calendar[,c(8,9,14,10)]
>
> espejo<-read.csv("C:/Users/ErikaRocío/Documents/Curso R/cat_prod.csv")
>
> ##Subbases
> #Combinaciones
> comb<-b[,c(3,4,5)]
> comb<-comb %>% distinct
> g<-seq(1,nrow(comb),by=1)
> dates <- attr(fca$mean, "tsp")
> datecol <- seq(from=dates[1], to=dates[2], by=1/dates[3])
> fct<-cbind.data.frame(s,datecol,Point=fca$mean)
> forecast_nal<- rbind.data.frame(forecast_nal,fct)
> }
> else
> {
>
> fit <- tbats(y)
> fcb <- forecast(fit, h = 16)
> dates <- attr(fcb$mean, "tsp")
> datecol <- seq(from=dates[1], to=dates[2], by=1/dates[3])
> fct<-cbind.data.frame(s,datecol,Point=fcb$mean)
>forecast_nal<- rbind.data.frame(forecast_nal,fct)
> }
> }
> }
>
>
> 2016-09-07 9:00 GMT-05:00 PIKAL Petr :
>
>> Hi
>>
>>
>>
>> see in line
>>
>>
>>
>> *From:* Erika Rocío Espinosa Balbuena [mailto:erika...@gmail.com]
>> *Sent:* Tuesday, September 6, 2016 10:52 PM
>> *To:* PIKAL Petr 
>> *Cc:* r-help@r-project.org
>> *Subject:* Re: [R] Help with a code in R
>>
>>
>>
>> Hi Erika
>>
>>
>>
>> Yes the objetcs have the same structure, and forecast_nal is the variable
>> where I a trying to keep all the results of the forecast but I get the
>> error that it
>>
>>
>>
>> How did you check? Can you prove it?
>>
>&

Re: [R] Drill down reports in R

2016-09-13 Thread Mark Sharp
Manu,

With pure R, you can simply write a link in the parent document to a child 
document you have created. Alternative, and likely better, solutions could be 
based on AJAX, but I do not think you are going to do that all within R.

Mark
> On Sep 13, 2016, at 11:11 AM, Manohar Reddy  wrote:
>
> Hi Jhon,
>
>
>
> Thanks for responding my email ,actually my requirement is I have Orders
> and related tables and now I need to generate a report something looks like
> below whenever user click on “+” that report will be expanded .I know it is
> possible in SSRS (SQl Server Reporting Services) but now my requirement is
> I need to generate that kind of report in R.
>
>
>
> If we look at screen shot (or PFA) almost 100244 order exists  8 times
> ,now I want to generate the report whenever user clicks on order 100244 and
> it needs to be expand and need to display the cost of all the products and
> what are the products they were purchased on this orderID .
>
>
>
> Note: in backend I did using Group by (sql) but I don’t know how to present
> in this report.
>
>
>
>
>
> Hi Marc,
>
>
>
>   Thanks,Currently I’m creating reports  using shinyapps only ,I have
> checked out throghly with shinyapps but I didn’t find any solution,is there
> any alternative way that I can use to genarate the drill down report.
>
>
>
> Manu.
>
> On Tue, Sep 13, 2016 at 8:33 PM, Marc Schwartz  wrote:
>
>> Hi,
>>
>> Generally "drilldown" reports require a dynamic GUI that supports widgets
>> that generate the data queries behind the scenes in response to user
>> input/clicks and then updated the display dynamically with the additional
>> data/content.
>>
>> This would be more typical of business oriented reporting/OLAP tools like
>> Cognos, Business Objects, Crystal Reports, etc.
>>
>> The first thing that came to mind is RStudio's Shiny, which I do not use,
>> but their gallery seems to have some possibilities:
>>
>>  http://shiny.rstudio.com/gallery/
>>
>> Regards,
>>
>> Marc Schwartz
>>
>>
>>> On Sep 13, 2016, at 9:48 AM, John Kane  wrote:
>>>
>>> It is not really clear what you want but have a look at ?subset perhaps.
>>>
>>> John Kane
>>> Kingston ON Canada
>>>
>>>
 -Original Message-
 From: manu.redd...@gmail.com
 Sent: Tue, 13 Sep 2016 16:16:05 +0530
 To: r-help@r-project.org
 Subject: [R] Drill down reports in R

 Hi,



 How to generate “Drill down reports ”  (like please refer below url) in
 R
 using any package ? I did lot of research in google but I didn’t found
 suitable link .

 Can anyone help how to do that in R ?



 url :  http://bhushan.extreme-advice.com/drilldown-report-in-ssrs/



 Thanks in Advance !

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

CONFIDENTIALITY NOTICE: This e-mail and any files and/or attachments 
transmitted, may contain privileged and confidential information and is 
intended solely for the exclusive use of the individual or entity to whom it is 
addressed. If you are not the intended recipient, you are hereby notified that 
any review, dissemination, distribution or copying of this e-mail and/or 
attachments is strictly prohibited. If you have received this e-mail in error, 
please immediately notify the sender stating that this transmission was 
misdirected; return the e-mail to sender; destroy all paper copies and delete 
all electronic copies from your system without disclosing its contents.
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Re: [R] Closed list?

2016-09-29 Thread Mark Sharp
Its not closed. Have you read the posting guide?

Mark

R. Mark Sharp, Ph.D.
msh...@txbiomed.org<mailto:msh...@txbiomed.org>





On Sep 29, 2016, at 1:38 PM, Joysn71 
mailto:joys...@gmail.com>> wrote:

Hello,

a few weeks ago i subscribed to this list and afterwards i send a question. I 
got a reply that my post needs moderator approval. It never happened.
Then i wrote to the list owners address. No reply.

How can i proceed?

Thanks in advance,
Joysn

__
R-help@r-project.org<mailto: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...{{dropped:13}}

__
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] Help with making Loop

2015-05-02 Thread Mark Sharp
Fazal,

I am not sure what you want, but I have guessed. I have tried to provide a 
straight forward simplistic solution.

If you examine the intermediate results, I think what is being done will be 
clear.

Mark

Michael Dewey’s suggestion to look at merge is excellent. You may also need to 
look at the other functions used below. All are commonly used.

# Code follows
set.seed(1) # ensures you get the same results
id <- paste0("id_", 1:10) # I did not want to copy down your Ids so I made them 
up.
small_dataframe <- data.frame(unique_sample_id = id, 
  g_1 = character(length(id)), 
  g_2 = character(length(id)))
# Making up some genotypes for g_1_table and g_2_table
g_1_table <- 
  data.frame(unique_sample_id = sample(id, length(id), replace = FALSE),
 cond = sample(c("M", "N/M"), length(id), replace = TRUE, 
prob = c(0.5, 0.5)))
g_2_table <- 
  data.frame(unique_sample_id = sample(id, length(id), replace = FALSE),
 cond = sample(c("M", "N/M"), length(id), replace = TRUE, 
prob = c(0.5, 0.5)))

new_dataframe <- merge(small_dataframe, g_1_table, by = "unique_sample_id")
names(new_dataframe) <- 
  c("unique_sample_id", "g_1", "g_2", "g_1_cond")
new_dataframe <- merge(new_dataframe, g_2_table, by = "unique_sample_id")
names(new_dataframe) <- 
  c("unique_sample_id", "g_1", "g_2", "g_1_cond", 
"g_2_cond")
new_dataframe$g_1_emoticon <- ifelse(new_dataframe$g_1_cond == "M",
":-)", "No")
new_dataframe$g_2_emoticon <- ifelse(new_dataframe$g_2_cond == "M",
":-)", "No")
new_dataframe

# End of code
# Output of last line of code.
   unique_sample_id g_1 g_2 g_1_cond g_2_cond g_1_emoticon g_2_emoticon
1  id_1M  N/M  :-)   No
2 id_10  N/M  N/M   No   No
3  id_2MM  :-)  :-)
4  id_3  N/MM   No  :-)
5  id_4  N/M  N/M   No   No
6  id_5M  N/M  :-)   No
7  id_6M  N/M  :-)   No
8  id_7  N/MM   No  :-)
9  id_8  N/MM   No  :-)
10 id_9MM  :-)  :-)


> On May 1, 2015, at 3:05 PM, Hadi Fazal  wrote:
> 
> Hi everyone, 
> I am a real beginner to R and have probably a very naive issue. I've a small 
> data frame with three columns: Unique Sample ID, Gene 1 and Gene 2 (the 
> columns on Gene1 and Gene2 are empty). I have two separate tables for the 
> genes which contain the Unique Subject ID in one column and information on 
> whether the gene is mutated or not in that particular subject (M, N/M) in 
> another column called (Condition). I want to make a loop which can read the 
> Unique Subject ID from my data frame, then look up for the same ID in the two 
> tables and depending on whether the gene is mutated (M)/not mutated (N/M), 
> inserts Yes like emoticon / No (N) in the appropriate gene column 
> (Gene1/Gene2) for each Subject ID.
> If anyone can help, I would really appreciate
> Thanks in advance
> 
> Fazal,
> __
> 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] best way to handle database connections from within a package

2015-05-29 Thread Mark Sharp
I would simply separate the database connect and disconnect functions from the 
query functions. 

Mark
R. Mark Sharp, Ph.D.
msh...@txbiomed.org





> On May 28, 2015, at 12:18 PM, Luca Cerone  wrote:
> 
> Dear all,
> I am writing a package that is a collection of queries to be run
> against a postgresql database,
> so that the users do not have to worry about the structure of the database.
> 
> In my package I import dbDriver, dbUnloadDriver, dbConnect,
> dbDisconnect from the package DBI
> and dbGetQuery from the package RPostgreSQL.
> 
> All the function in a function in my package have the same structure:
> 
> getFancyData <- function( from, to) {
>on.exit( dbDisconnect(con), add=TRUE)
>on.exit( dbUnloadDriver(drv), add=TRUE)
>drv <- dbDriver("PostgreSQL")
>con <- dbConnect(drv,
> user=pkguser,
> host=pkghost,
> password=pkgpassword,
> port = pkgport)
> 
>query <- sprintf("select * from fancyTable where dt between '%s'
> and '%s'", from, to)
>res <- dbGetQuery(con,query)
>return(res)
> }
> 
> The various access details are read from an encrypted profile that the
> user has to
> create when she installs the package.
> 
> Such functions work perfectly fine, but I have to replicate a lot of
> times loading and unloading the driver and connecting and
> disconnecting from the database.
> 
> I am wondering if there is a better way to do this job, like loading
> the driver and opening the connection only once when the package is
> loaded. However I have to make sure that
> if R crashes or the code where the function is called contains an
> error then the connection
> with the database is closed. How would you implement this?
> 
> 
> Also how would you write a functional that would at least allow me to
> avoid replicating
> the boilerplate code to load and unload the drivers?
> 
> I am thinking something on the lines of:
> 
> querybuild <- function(query, )
>on.exit( dbDisconnect(con), add=TRUE)
>on.exit( dbUnloadDriver(drv), add=TRUE)
>query <- sprintf(query, ... )
>res <- dbSendQuery(query)
>return(res)
> }
> 
> and then define
> 
> getFancyData <- function(from, to) querybuild("select * from
> fancyTable where dt between '%s' and '%s'", from, to)
> 
> Do you see a better way?
> 
> Thanks a lot in advance for your help and advice on this!
> 
> Cheers,
> Luca
> 
> __
> 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] source code for dbeta

2015-06-07 Thread Mark Sharp
Varun,

If you type dbeta at the command line you get the R source, which in this case 
tells you that the code is calling a compiled source. This is indicated by the 
line 

See the following. 
> dbeta
function (x, shape1, shape2, ncp = 0, log = FALSE) 
{
if (missing(ncp)) 
.Call(C_dbeta, x, shape1, shape2, log)
else .Call(C_dnbeta, x, shape1, shape2, ncp, log)
}



Compiled code in a package

If you want to view compiled code in a package, you will need to 
download/unpack the package source. The installed binaries are not sufficient. 
A package's source code is available from the same CRAN (or CRAN compatible) 
repository that the package was originally installed from. The 
download.packages() function can get the package source for you.

Extracted from 
http://stackoverflow.com/questions/19226816/how-can-i-view-the-source-code-for-a-function

Mark


R. Mark Sharp, Ph.D.
msh...@txbiomed.org


> On Jun 7, 2015, at 4:31 AM, Varun Sinha  wrote:
> 
> Hi,
> 
> I am trying to find the source code for dbeta function.
> 
> I tried edit(dbeta) and this is what I got:
>> edit(dbeta)
> function (x, shape1, shape2, ncp = 0, log = FALSE)
> {
>if (missing(ncp))
>.Call(C_dbeta, x, shape1, shape2, log)
>else .Call(C_dnbeta, x, shape1, shape2, ncp, log)
> }
> 
> 
> It looks like it is calling calling C_dbeta, but I'm not sure. If it does,
> how do I find it's source code?
> 
> Thank you!
> Varun
> 
>   [[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] source code for dbeta

2015-06-07 Thread Mark Sharp
Varun,

I apologize. I hit send before completing.

Look at the source document in the link I provided. dbeta is part of the stats 
package, which is part of the core R system and I do not think it is available 
as a standalone package. The linked document provides instructions for finding 
base R compiled code.

Mark

R. Mark Sharp, Ph.D.
msh...@txbiomed.org
> On Jun 7, 2015, at 5:11 PM, Mark Sharp  wrote:
> 
> Varun,
> 
> If you type dbeta at the command line you get the R source, which in this 
> case tells you that the code is calling a compiled source. This is indicated 
> by the line 
> 
> See the following. 
>> dbeta
> function (x, shape1, shape2, ncp = 0, log = FALSE) 
> {
>if (missing(ncp)) 
>.Call(C_dbeta, x, shape1, shape2, log)
>else .Call(C_dnbeta, x, shape1, shape2, ncp, log)
> }
> 
> 
> 
> Compiled code in a package
> 
> If you want to view compiled code in a package, you will need to 
> download/unpack the package source. The installed binaries are not 
> sufficient. A package's source code is available from the same CRAN (or CRAN 
> compatible) repository that the package was originally installed from. The 
> download.packages() function can get the package source for you.
> 
> Extracted from 
> http://stackoverflow.com/questions/19226816/how-can-i-view-the-source-code-for-a-function
> 
> Mark
> 
> 
> R. Mark Sharp, Ph.D.
> msh...@txbiomed.org
> 
> 
>> On Jun 7, 2015, at 4:31 AM, Varun Sinha  wrote:
>> 
>> Hi,
>> 
>> I am trying to find the source code for dbeta function.
>> 
>> I tried edit(dbeta) and this is what I got:
>>> edit(dbeta)
>> function (x, shape1, shape2, ncp = 0, log = FALSE)
>> {
>>   if (missing(ncp))
>>   .Call(C_dbeta, x, shape1, shape2, log)
>>   else .Call(C_dnbeta, x, shape1, shape2, ncp, log)
>> }
>> 
>> 
>> It looks like it is calling calling C_dbeta, but I'm not sure. If it does,
>> how do I find it's source code?
>> 
>> Thank you!
>> Varun
>> 
>>  [[alternative HTML version deleted]]
>> 
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] problems editing R console

2015-06-07 Thread Mark Sharp
Rosa,

See save() and load() functions for background. However, I suspect you will 
want to do something as described in the article in this link 
http://www.fromthebottomoftheheap.net/2012/04/01/saving-and-loading-r-objects/


Mark



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



> On Jun 7, 2015, at 5:58 PM, Rosa Oliveira  wrote:
> 
> Dear Mark,
> 
> 
> I’ll try to explain better.
> 
> Imagine I write:
> 
> library(foreign)
> library(nlme)
> 
> set.seed(1000)
> n.sample<-1 #sample size
> M <- 5
> DP_x <- 2
> x <- rnorm(n.sample,M,DP_x)
> p <- pnorm(-3+x)  
> y <- rbinom(n.sample,1,p)
> dp_erro <- 0.01
> erro <- rnorm(n.sample,0,dp_erro)
> x.erro <- x+erro
> 
> but with a function, with 2000 simulations. 
> I save my “output” and I get X.erro in a .txt file. (text edit file).
> 
> I do another setting with DP_x=3 and save, and so on.
> 
> For some reason I realize I’ve done my simulation the wrong way and I have to 
> apply a correction, for example:
> 
> x.erro = 1.4X+erro, i.e. in the truth I could use my first X and erro values 
> in each setting, but as it is in a .txt file I can’t use them any more. Is 
> there a way to save the results in a  format that I can use the values? Just 
> apply my corrections and don’t have to do the 2000 simulations for each 
> setting again?
> 
> My problem is that the function I use takes 3 days running, and just 500 
> simulations :(
> 
> Best,
> RO
> 
> 
> Atenciosamente,
> Rosa Oliveira
> 
> -- 
> 
>  
> 
> Rosa Celeste dos Santos Oliveira, 
> 
> E-mail: rosit...@gmail.com
> Tlm: +351 939355143 
> Linkedin: https://pt.linkedin.com/in/rosacsoliveira
> 
> "Many admire, few know"
> Hippocrates
> 
>> On 07 Jun 2015, at 23:03, Mark Sharp  wrote:
>> 
>> I cannot understand your request as stated. Can you provide a small example?
>> 
>> Mark
>> 
>> R. Mark Sharp, Ph.D.
>> msh...@txbiomed.org
>> 
>>> On Jun 7, 2015, at 2:49 PM, Rosa Oliveira  wrote:
>>> 
>>> Dear all,
>>> 
>>> I’m doing simulations on R, and as my code is being changed and improved I 
>>> need to, sometimes, work in finished simulations, i.e, 
>>> 
>>> After my simulation is  over I need to settle another setting.
>>> The problem is that I need to get back to the previous result.
>>> 
>>> When I save the result it saves as txt, so I can’t edit that result any 
>>> more.
>>> 
>>> Imagine I save a setting and save the mean, nonetheless, in another setting 
>>> the mean as problems, so I have to ask the median.
>>> 
>>> As I have to have the same statistics to all settings, nowadays I have to 
>>> run my first setting again.
>>> 
>>> My advisor told me that I could save another way so I can “edit” my first 
>>> result. Is it possible?
>>> 
>>> I tried to save as "save my workplace", … but after I don’t know what to do 
>>> with it.
>>> 
>>> Can you please help me?
>>> I know is a naive question, but I have to go through this every 3 days 
>>> (time each simulation takes long). And my work is being delayed :(
>>> 
>>> 
>>> Best,
>>> RO
>>> 
>>> 
>>> 
>>> Atenciosamente,
>>> Rosa Oliveira
>>> 
>>> -- 
>>> 
>>> 
>>> 
>>> Rosa Celeste dos Santos Oliveira, 
>>> 
>>> E-mail: rosit...@gmail.com
>>> Tlm: +351 939355143 
>>> Linkedin: https://pt.linkedin.com/in/rosacsoliveira
>>> 
>>> "Many admire, few know"
>>> Hippocrates
>>> 
>>> __
>>> 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] Blank spaces are replaced by period in read.csv, I want to replace blacks with an underline

2015-06-08 Thread Mark Sharp
John,

I like using stringr or stringi for this type of thing. stringi is written in C 
and faster so I now typically use it. You can also use base functions. The main 
trick is the handy names() function.

> example <- data.frame("Col 1 A" = 1:3, "Col 1 B" = letters[1:3])
> example
  Col.1.A Col.1.B
1   1   a
2   2   b
3   3   c
> library(stringi)
> names(example) <- stri_replace_all_fixed(names(example), ".", "_")
> example
  Col_1_A Col_1_B
1   1   a
2   2   b
3   3   c

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







> On Jun 8, 2015, at 9:15 AM, John Sorkin  wrote:
> 
> I am reading a csv file. The column headers have spaces in them. The spaces 
> are replaced by a period. I want to replace the space by another character 
> (e.g. the underline) rather than the period. Can someone tell me how to 
> accomplish this?Thank you,
> John
> 
> John David Sorkin M.D., Ph.D.
> Professor of Medicine
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology and 
> Geriatric Medicine
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing) 
> 
> 
> Confidentiality Statement:
> This email message, including any attachments, is for ...{{dropped:12}}

__
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] create a dummy variables for companies with complete history.

2015-06-24 Thread Mark Sharp
Giacomo,

Please include some representative data. It is not clear why your offset of 4 
(z$cod[i - 4]) is going to be an accurate surrogate for complete data.

Since I do not have your data set or its true structure I am having to guess.
# make 5 copies of 200 companies
companies <- paste0(rep(LETTERS[1:4], 5, each = 50), rep(1:50, 5))
companies <- companies[order(companies)]
years <- rep(1:5, 200)
z <- data.frame(cod = companies, year = years,
revenue = round(rnorm(1000, mean = 10, sd = 1)))
# trim this down to the 728 rows you have by pulling out records at random
set.seed(1) # so that you can repeat these results
z <- z[sample.int(1000, 728), ]
z <- z[order(z$cod, z$year), ]

#No matter how you order these data, your offset approach will not tell you 
which companies have full records.
> head(z, 10)
   cod year revenue
1   A11  112192
2   A12  105840
4   A14  112357
5   A15   91772
7  A102  102601
8  A103  105183
11 A111  101269
12 A112  100719
14 A114   86138
15 A115  105044

#You can do something like the following.

counts <- table(z$cod)
complete <- names(counts[as.integer(counts) == 5])
# It is probably better to keep the dummy variable inside the dataframe.
z$complete <- ifelse(z$cod %in% complete, TRUE, FALSE)

> head(z, 20)
   cod year revenue complete
1   A11  112192FALSE
2   A12  105840FALSE
4   A14  112357FALSE
5   A15   91772FALSE
7  A102  102601FALSE
8  A103  105183FALSE
11 A111  101269FALSE
12 A112  100719FALSE
14 A114   86138FALSE
15 A115  105044FALSE
20 A125   95872FALSE
21 A131   78513 TRUE
22 A132   90502 TRUE
23 A133  108683 TRUE
24 A134  110711 TRUE
25 A135   87842 TRUE
28 A143   99939FALSE
30 A145  111289FALSE
31 A151  100930FALSE
32 A152   93765FALSE
> 
Do not use HTML. Use plain text. The character string "//" is not a comment 
indicator in R. Do not use attach(). It does not do anything in your example, 
but it is poor practice. Always write out TRUE and FALSE
R. Mark Sharp, Ph.D.
msh...@txbiomed.org





> On Jun 24, 2015, at 1:26 PM, giacomo begnis  wrote:
> 
> Hi, I have a dataset  (728 obs) containing three variables code of a company, 
> year and revenue. Some companies have a complete history of 5 years, others 
> have not a complete history (for instance observations for three or four 
> years).I would like to determine the companies with a complete history using 
> a dummy variables.I have written the following program but there is somehting 
> wrong because the dummy variable that I have create is always equal to 
> zero.Can somebody help me?Thanks, gm
> 
> z<-read.table(file="c:/Rp/cddat.txt", sep="", header=T)
> attach(z)
> n<-length(z$cod)  // number of obs dataset
> 
> d1<-numeric(n)   // dummy variable
> 
> for (i in 5:n)  {
>if (z$cod[i]==z$cod[i-4]) // cod is the code of a company  
>{ d1[i]<=1} else { d1[i]<=0}  // d1=1 for a company with 
> complete history, d1=0 if the history is not complete  }d1
> When I run the program d1 is always equal to zero. Why?
> Once I have create the dummy variable with subset I obtains the code of the 
> companies with a complete history and finally with a merge  I determine a 
> panel of companies with a complete history.But how to determine correctly 
> d1?My best regards, gm
> 
> 
> 
>   [[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] question

2015-07-03 Thread Mark Sharp
Lida,

I expect that there is a better way to solve your problem than the process you 
propose.

However, something like this may do what you want.

###
## met <- read.csv("your_met_file”)
## Since I do not have your file a made a small 5*1 character vector.
met <- c("glycine_imp",
"Nacetylglycine_imp",
"sarcosine_imp",
"dimethylglycine_imp",
"betaine_imp")

for (i in seq_along(met)) {
  my_formula <- paste0(met[i], "~egfr_v1_ckdepi+pc1+pc2+pc3+V1AGE01+GENDER")
  prep <- Scores(Z=metalofGT, formula = my_formula)
  save(prep, file = paste0("prep", i))
}
###

Mark


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

> On Jul 2, 2015, at 11:48 AM, Lida Zeighami  wrote:
> 
> Thank you so much for replying me!
> for better understanding my problem, I explain my problem more:
> 
> I have a 682*1 matrix called "met" , the first 5 rows similar below:
> 
>> rownames(met)[1:5]
> 
> [1]  "glycine_imp"
> [2]  "Nacetylglycine_imp"
> [3]  "sarcosine_imp"
> [4]  "dimethylglycine_imp"
> [5]  "betaine_imp"
> 
> and I have a function in R that each time use one of the row names of "met"
> matrix and create a new object file and I should save the objects!
> 
> my function is  "
> Scores(Z=metalofGT,formula="met[i]~egfr_v1_ckdepi+pc1+pc2+pc3+V1AGE01+GENDER")
> " that each time just I should change the met[i] and replace by row names
> "met" one by one and for each of them I should rename the function and
> after that I should save each object!
> for example for first row of "met" I have
> 
>>  prep1<- 
>> Scores(Z=metalofGT,formula="glycine_imp~egfr_v1_ckdepi+pc1+pc2+pc3+V1AGE01+GENDER")
> #creat the object file for first row and called prep1###
> 
>>  save(prep1, file="prep1.RData", compress="bzip2")  ##save the
> object file as "prep1.RData"#
> 
> I should do this process for 682 row names of "met" matrix and at the end I
> should have"prep1.RData"  ,   "prep2.RData"   , "prep3.RData"
> 
> so, would you please help me how to do it?
> 
> Many Thanks,
> Ati
> 
> On Wed, Jul 1, 2015 at 1:07 PM, Lida Zeighami  wrote:
> 
>> I have 682 variables in a data frame , and a function that  I should feed
>> 682 variables in this function one by one and each time save the file as a
>> special name!
>> for emaple:
>> my data frame file includes 682 names :
>> 1  aaa
>> 2  bbb
>> 3  dfdsfg
>> 4 fghh
>> .
>> 
>> 682 fgfhg
>> and a function like prep(Z, aaa, .) and each time I should change the
>> variable name in this function and read the variable from the data frame
>> and each time I should save the file as a special name such as:
>> 
>> prep1<- prep(z, aaa,...)
>> prep2<- prep(z, bbb,...)
>> prep3<- prep(z, dfdsfg,..)
>> Prep4<- prep(z, fghh,...)
>> 
>> How can I use loop function in R to that?
>> 
>> Thanks
>> 
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.







__
R-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] question

2015-07-06 Thread Mark Sharp
Lida,

Please send the code that you ran. It is almost certain that you have a vector 
being formed that is the wrong length. There should be only one vector that you 
use to increment through the loop and that is the character vector formed when 
you read in your_met_file to form the met character vector.

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







> On Jul 6, 2015, at 9:05 AM, Lida Zeighami  wrote:
> 
> Hi Mark,
> 
> Thank you so much for your help.
> 
> I run your code and it works great for 5*1 character vector but if I run it 
> for 682*1 character vector it has some error like this:
> 
> Error in model.frame.default(formula = formula, ...) : 
>   variable lengths differ (found for 'egfr_v1_ckdepi')
> 
> Would you please let me know what's the reason is?
> 
> Many Thanks,
> Lida
> 
> On Fri, Jul 3, 2015 at 11:38 PM, Mark Sharp  wrote:
> Lida,
> 
> I expect that there is a better way to solve your problem than the process 
> you propose.
> 
> However, something like this may do what you want.
> 
> ###
> ## met <- read.csv("your_met_file”)
> ## Since I do not have your file a made a small 5*1 character vector.
> met <- c("glycine_imp",
> "Nacetylglycine_imp",
> "sarcosine_imp",
> "dimethylglycine_imp",
> "betaine_imp")
> 
> for (i in seq_along(met)) {
>   my_formula <- paste0(met[i], "~egfr_v1_ckdepi+pc1+pc2+pc3+V1AGE01+GENDER")
>   prep <- Scores(Z=metalofGT, formula = my_formula)
>   save(prep, file = paste0("prep", i))
> }
> ###
> 
> Mark
> 
> 
> R. Mark Sharp, Ph.D.
> Director of Primate Records Database
> Southwest National Primate Research Center
> Texas Biomedical Research Institute
> P.O. Box 760549
> San Antonio, TX 78245-0549
> Telephone: (210)258-9476
> e-mail: msh...@txbiomed.org
> 
> > On Jul 2, 2015, at 11:48 AM, Lida Zeighami  wrote:
> >
> > Thank you so much for replying me!
> > for better understanding my problem, I explain my problem more:
> >
> > I have a 682*1 matrix called "met" , the first 5 rows similar below:
> >
> >> rownames(met)[1:5]
> >
> > [1]  "glycine_imp"
> > [2]  "Nacetylglycine_imp"
> > [3]  "sarcosine_imp"
> > [4]  "dimethylglycine_imp"
> > [5]  "betaine_imp"
> >
> > and I have a function in R that each time use one of the row names of "met"
> > matrix and create a new object file and I should save the objects!
> >
> > my function is  "
> > Scores(Z=metalofGT,formula="met[i]~egfr_v1_ckdepi+pc1+pc2+pc3+V1AGE01+GENDER")
> > " that each time just I should change the met[i] and replace by row names
> > "met" one by one and for each of them I should rename the function and
> > after that I should save each object!
> > for example for first row of "met" I have
> >
> >>  prep1<- 
> >> Scores(Z=metalofGT,formula="glycine_imp~egfr_v1_ckdepi+pc1+pc2+pc3+V1AGE01+GENDER")
> > #creat the object file for first row and called prep1###
> >
> >>  save(prep1, file="prep1.RData", compress="bzip2")  ##save the
> > object file as "prep1.RData"#
> >
> > I should do this process for 682 row names of "met" matrix and at the end I
> > should have"prep1.RData"  ,   "prep2.RData"   , "prep3.RData"
> >
> > so, would you please help me how to do it?
> >
> > Many Thanks,
> > Ati
> >
> > On Wed, Jul 1, 2015 at 1:07 PM, Lida Zeighami  wrote:
> >
> >> I have 682 variables in a data frame , and a function that  I should feed
> >> 682 variables in this function one by one and each time save the file as a
> >> special name!
> >> for emaple:
> >> my data frame file includes 682 names :
> >> 1  aaa
> >> 2  bbb
> >> 3  dfdsfg
> >> 4 fghh
> >> .
> >>
> >> 682 fgfhg
> >> and a function like prep(Z, aaa, .) and each time I should change the
> >> variable name in this function and read the variable from the data frame
> >> and each time I should save the file as a special name such as:
> >>
> >> prep1<- prep(z, aaa,...)
> >> prep2<- prep(z, bbb,...)
> >> prep3<- prep(z, dfdsfg,..)
> >> Prep4<- prep(z, fghh,...)
> >>
> >> How can I use loop function in R to that?
> >>
> >> Thanks
> >>
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> 
> 
> 
> 
> 
> 
> 
> 

__
R-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] write.table with append=T after using cat on same file

2015-07-27 Thread Mark Sharp
I do not get an error with R-3.2.1 on Mac OS. You may have done something prior 
to this code so that perhaps F is not FALSE or T is not TRUE.

R. Mark Sharp, Ph.D.
msh...@txbiomed.org





> On Jul 27, 2015, at 3:32 PM, Waichler, Scott R  
> wrote:
> 
> Hi, 
> 
> For years I've been writing text to the beginning of files with cat(append=F) 
> , then following that text with data written by write.table(append=T).  It is 
> now giving me an error message.  I'm using R-3.1.2.  What gives?
> 
> df <- data.frame(x = 1, y = 1:10, z = 10:1)
> cat(file="junk.txt", sep="", "# An introductory note.\n")
> write.table(df, file="junk.txt", sep=",", append=T, quote=F, row.names=F, 
> col.names=F)
> 
> Error in file(file, ifelse(append, "a", "w")) : invalid 'open' argument
> 
> Thanks,
> Scott Waichler
> Pacific Northwest National Laboratory
> Richland, WA  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.

__
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] Reading Json data

2015-07-27 Thread Mark Sharp
Mayukh,

I think you are missing an argument to paste() and a right parenthesis 
character.

Try 
json_data <- fromJSON(paste(readLines(json_file), collapse = " "))

Mark
R. Mark Sharp, Ph.D.
msh...@txbiomed.org





> On Jul 27, 2015, at 3:41 PM, Mayukh Dass  wrote:
> 
> Hello,
> 
> I am trying to read a set of json files containing tweets using the
> following code:
> 
> json_data <- fromJSON(paste(readLines(json_file))
> 
> Unfortunately, it only reads the first record on the file. For example, in
> the file below, it only reads the first record starting with "id":"tag:
> search.twitter.com,2005:3318539389". What is the best way to retrieve these
> records? I have 20 such json files with varying number of tweets in it.
> Thank you in advance.
> 
> Best,
> Mayukh
> 
> {"id":"tag:search.twitter.com
> ,2005:3318539389","objectType":"activity","actor":{"objectType":"person","id":"id:
> twitter.com:2859421","link":"http://www.twitter.com/meetjenn","displayName":"Jenn","postedTime":"2007-01-29T17:06:00.000Z","image":"06-19-07_2010.jpg","summary":"I
> say 'like' a lot. I fall down a lot. I walk into everything. Love Pgh Pens,
> NE Pats, Fundraising, Dogs & History. Craft Beer & Running
> Novice.","links":[{"href":"http://meetjenn.tumblr.com","rel":"me"}],"friendsCount":0,"followersCount":0,"listedCount":0,"statusesCount":0,"twitterTimeZone":"Eastern
> Time (US &
> Canada)","verified":false,"utcOffset":"0","preferredUsername":"meetjenn","languages":["en"],"location":{"objectType":"place","displayName":"Pgh/Philajersey"},"favoritesCount":0},"verb":"post","postedTime":"2009-08-15T00:00:12.000Z","generator":{"displayName":"tweetdeck","link":"
> http://twitter.com
> "},"provider":{"objectType":"service","displayName":"Twitter","link":"
> http://www.twitter.com"},"link":";
> http://twitter.com/meetjenn/statuses/3318539389","body":"Cool story about
> the man who created the @Starbucks logo. Additional link at the bottom on
> how it came to be:  http://bit.ly/16bOJk
> ","object":{"objectType":"note","id":"object:search.twitter.com,2005:3318539389","summary":"Cool
> story about the man who created the @Starbucks logo. Additional link at the
> bottom on how it came to be:  http://bit.ly/16bOJk","link":";
> http://twitter.com/meetjenn/statuses/3318539389
> ","postedTime":"2009-08-15T00:00:12.000Z"},"twitter_entities":{"urls":[{"expanded_url":null,"indices":[111,131],"url":"
> http://bit.ly/16bOJk
> "}],"hashtags":[],"user_mentions":[{"id":null,"name":null,"indices":[41,51],"screen_name":"@Starbucks","id_str":null}]},"retweetCount":0,"gnip":{"matching_rules":[{"value":"Starbucks","tag":null}]}}
> {"id":"tag:search.twitter.com
> ,2005:3318543260","objectType":"activity","actor":{"objectType":"person","id":"id:
> twitter.com:61595468","link":"http://www.twitter.com/FastestFood","displayName":"FastFood
> Bob","postedTime":"2009-01-30T20:51:10.000Z","image":"","summary":"Just A
> little food for
> thought","links":[{"href":"http://www.TeamSantilli.com","rel":"me"}],"friendsCount":0,"followersCount":0,"listedCount":0,"statusesCount":0,"twitterTimeZone":"Pacific
> Time (US &
> Canada)","verified":false,"utcOffset":"0","preferredUsername":"FastestFood","languages":["en"],"location":{"objectType":"place","displayName":"eating
> some
> thoughts"},"favoritesCount":0},"verb":"post","postedTime":"2009-08-15T00:00:23.000Z","generator":{"displayName":"oauth:17","link":"
> http://twitter.com
> "},"provider":{"objectType":"service","displayName":"Twitter","link":"
> http://www.twitter.com"},"link":";
> http://twitter.com/FastestFood/statuses/3318543260","body":"Oregon Biz
> Report » How Starbucks saved millions. Oregon closures ...
> http://u.mavrev.com/02bdj","object":{"objectType":"note","id":"object:
> search.twitter.com,2005:3318543260","summary":"Oregon Biz Report » How
> Starbucks saved millions. Oregon closures ... http://u.mavrev.com/02bdj
> ","link":"http://twitter.com/FastestFood/statuses/3318543260
> ","postedTime":"2009-08-15T00:00:23.000Z"},"twitter_entities":{"urls":[{"expanded_url":null,"indices":[70,95],"url":"
> http://u.mavrev.com/02bdj
> "}],"hashtags":[],"user_mentions":[]},"retweetCount":0,"gnip":{"matching_rules":[{"value":"Starbucks","tag":null}]}}
> {"info":{"message":"Replay Request
> Completed","sent":"2015-02-18T00:05:15+00:00","activity_count":2}}
> 
>   [[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] R command to open a file "browser" on Windows and Mac?

2015-08-03 Thread Mark Sharp
Set your path with setwd(“my_path”) and then use file.choose().

You could have gotten this information sooner with a simple online search.

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







> On Aug 3, 2015, at 10:19 AM, Jonathan Greenberg  wrote:
> 
> Folks:
> 
> Is there an easy function to open a finder window (on mac) or windows
> explorer window (on windows) given an input folder?  A lot of times I want
> to be able to see via a file browser my working directory.  Is there a good
> R hack to do this?
> 
> --j
> 
>   [[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] Reading Json data

2015-08-10 Thread Mark Sharp
Mayukh,

I apologize for taking so long to get back to your problem. I expect you may 
have found the solution. If so I would be interested. I have developed a hack 
to solve the problem, but I expect if someone knew how to handle JSON objects 
or even text parsing better they could develop a more elegant solution. 

As I understand the problem, your text file has more than one JSON object in 
text form. There are three. The first two are very similar and the last is a 
trailer indication what was done, when it was done and the number of JSON 
objects sent. The problem is that fromJSON() only pulls off the first of the 
JSON objects. 

I have defined three helper functions to separate the JSON objects, read them 
in, and store them in a list.

library(RJSONIO)
library(stringi, quietly = TRUE)
#library(jsonlite) # also works

#' Returns dataframe with ordered locations of the matching braces.
#'
#' There is almost certainly a better function to do this. 
#' @param txt character vector of length one having 0 or more matching braces.
#' @import stringi
#' @examples 
#' library(rmsutilityr)
#' match_braces("{123{456{78}9}10}")
#' @export
match_braces <- function(txt) {
  txt <- txt[1] # just in the case of having more than one element
  left <- stri_locate_all_regex(txt, "\\{")[[1]][ , 1]
  right <- stri_locate_all_regex(txt, "\\}")[[1]][ , 2]
  len <- length(left)
  braces <- data.frame(left = rep(0, len), right = rep(0, len))
  for (i in seq_along(right)) {
for (j in rev(seq_along(left))) {
  if (left[j] < right[i] & left[j] != 0) {
braces$left[i] <- left[j]
braces$right[i] <- right[i]
left[j] <- 0
break
  }
}
  }
  braces[order(braces$left), ]
}

#' Returns a list containing two objects in the text of a character vector 
#' of length one: (1) object = the first json object found and (2) remainder = 
#' the remaining text.
#' 
#'  Properly formed messages are assumed. Error checking is non-existent.
#' @param json_txt character vector of length one having one or more JSON
#' objects in character form.
#' @import stringi
#' @export
get_first_json_message <- function(json_txt) {
  len <- stri_length(json_txt)
  braces <- match_braces(json_txt)
  if (braces$right[1] + 1 > len) {
remainder <- ""
  } else {
remainder <- stri_trim_both(stri_sub(json_txt, braces$right[1] + 1))
  }
  list(object = stri_sub(json_txt, braces$left[1], to = braces$right[1]),
   remainder = remainder)
}
#' Returns list of lists made by call to fromJSON()

#' @param json_txt character vector of length 1 having one or more
#' JSON objects in text form.
#' @import stringi
#' @export
get_json_list <- function (json_txt) {
  t_json_txt <- json_txt
  i <- 0
  json_list <- list()
  repeat{
i <- i + 1
message_remainder <- get_first_json_message(t_json_txt)
json_list[i] <- list(fromJSON(message_remainder$object))
if (message_remainder$remainder == "")
  break
    t_json_txt <- message_remainder$remainder
  }
  json_list
}

json_file <- "../data/json_file.txt"
json_txt <- stri_trim_both(stri_c(readLines(json_file), collapse = " "))
json_list <- get_json_list(json_txt)
length(json_list)


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







> On Jul 27, 2015, at 5:16 PM, Mark Sharp  wrote:
> 
> Mayukh,
> 
> I think you are missing an argument to paste() and a right parenthesis 
> character.
> 
> Try 
> json_data <- fromJSON(paste(readLines(json_file), collapse = " "))
> 
> Mark
> R. Mark Sharp, Ph.D.
> msh...@txbiomed.org
> 
> 
> 
> 
> 
>> On Jul 27, 2015, at 3:41 PM, Mayukh Dass  wrote:
>> 
>> Hello,
>> 
>> I am trying to read a set of json files containing tweets using the
>> following code:
>> 
>> json_data <- fromJSON(paste(readLines(json_file))
>> 
>> Unfortunately, it only reads the first record on the file. For example, in
>> the file below, it only reads the first record starting with "id":"tag:
>> search.twitter.com,2005:3318539389". What is the best way to retrieve these
>> records? I have 20 such json files with varying number of tweets in it.
>> Thank you in advance.
>> 
>> Best,
>> Mayukh
>> 
>> {"id":"tag:search.twitter.com
>> ,2005:3318539389","objectType":"activity","actor":{"objectType":"person","id":"id:

Re: [R] New to R

2014-12-15 Thread Mark Sharp
I would recommend finding some tutorials on line in areas that you enjoy, read 
http://r-bloggers.com every day, find introductory texts in the statistical 
areas of interest, and study some texts on R programming. I really enjoyed The 
Art of R Programming: A Tour of Statistical Software Design by Norman Matloff. 
For a bit more depth I like Hadley Wickham's Advanced R book 
(http://adv-r.had.co.nz).

Mark Sharp

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

> On Dec 15, 2014, at 5:12 AM, Lalitha Kristipati 
>  wrote:
>
> Hi
>
> I'm learning R language from  past  one month .As R is used highly for data 
> analysis ,mining and modeling ,I want to know few real time examples in R in 
> order to make my learning  fun filled and practical .Any quick suggestions  
> are appreciated .
>
>
>
> Regards,
> Lalitha Kristipati
> Associate Software Engineer
>
>
>
>
> 
> Disclaimer:  This message and the information contained herein is proprietary 
> and confidential and subject to the Tech Mahindra policy statement, you may 
> review the policy at http://www.techmahindra.com/Disclaimer.html externally 
> http://tim.techmahindra.com/tim/disclaimer.html internally within 
> TechMahindra.
> 
>
>
>   [[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.



NOTICE:  This E-Mail (including attachments) is confidential and may be legally 
privileged.  It is covered by the Electronic Communications Privacy Act, 18 
U.S.C.2510-2521.  If you are not the intended recipient, you are hereby 
notified that any retention, dissemination, distribution or copying of this 
communication is strictly prohibited.  Please reply to the sender that you have 
received this message in error, then delete it.

__
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] Help with looping

2015-02-17 Thread Mark Sharp
Alexandra,

According to the documentation (?readLines), readLines returns a character 
vector with one line from the file being read in each element of the vector. 
You can put the character vector from each file (as represented by a year 
designation in your example) in a separate list element. You want to count the 
elements in the list starting at 1 not 2000. The integers from years[i] get 
converted to strings in sprintf in the code below.

years <- 2000:2003
Data <- list(length(years))

for (i in seq_along(years)){
#script for downloading each year
Data[i] = readLines(sprintf('file/%s',years[i]))
}
# Data[1] will have the character vector made up of the lines in 'file/2000'.

Mark

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







> On Feb 17, 2015, at 12:15 PM, Alexandra Catena  wrote:
>
> Hi,
>
> I need help with a for loop and printing data.  I want to loop through a
> few years and print the data from each year stacked on top of each other.
> For example,
>
> for (i in 2000:2003){
> #script for downloading each year
> Data = readLines(sprintf('file/%4i,i))
> }
>
> It only prints out the data from the last year.  Also, I tried
>
> Data[i] =  readLines(sprintf('file/%4i,i))
>
> but it says:
>
> "number of items to replace is not a multiple of replacement length"
>
> How do I get it to not replace each year of data? I have R version 2.15.1
>
> Thanks,
> Alexandra
>
>   [[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.


NOTICE:  This E-Mail (including attachments) is confidential and may be legally 
privileged.  It is covered by the Electronic Communications Privacy Act, 18 
U.S.C.2510-2521.  If you are not the intended recipient, you are hereby 
notified that any retention, dissemination, distribution or copying of this 
communication is strictly prohibited.  Please reply to the sender that you have 
received this message in error, then delete it.

__
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] Help with looping

2015-02-17 Thread Mark Sharp
Alexandra,

According to the documentation (?readLines), readLines returns a character 
vector with one line from the file being read in each element of the vector. 
You can put the character vector from each file (as represented by a year 
designation in your example) in a separate list element. You want to count the 
elements in the list starting at 1 not 2000. The integers from years[i] get 
converted to strings in sprintf in the code below.

years <- 2000:2003
Data <- list(length(years))

for (i in seq_along(years)){
   #script for downloading each year
   Data[i] = readLines(sprintf('file/%s',years[i]))
}
# Data[1] will have the character vector made up of the lines in 'file/2000'.

Mark

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







> On Feb 17, 2015, at 12:15 PM, Alexandra Catena  wrote:
>
> Hi,
>
> I need help with a for loop and printing data.  I want to loop through a
> few years and print the data from each year stacked on top of each other.
> For example,
>
> for (i in 2000:2003){
> #script for downloading each year
> Data = readLines(sprintf('file/%4i,i))
> }
>
> It only prints out the data from the last year.  Also, I tried
>
> Data[i] =  readLines(sprintf('file/%4i,i))
>
> but it says:
>
> "number of items to replace is not a multiple of replacement length"
>
> How do I get it to not replace each year of data? I have R version 2.15.1
>
> Thanks,
> Alexandra
>
>   [[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. Mark Sharp, Ph.D.
Director of Primate Records Database
Southwest National Primate Research Center
Texas Biomedical Research Institute
P.O. Box 760549
San Antonio, TX 78245-0549
Telephone: (210)258-9476
e-mail: msh...@txbiomed.org








NOTICE:  This E-Mail (including attachments) is confidential and may be legally 
privileged.  It is covered by the Electronic Communications Privacy Act, 18 
U.S.C.2510-2521.  If you are not the intended recipient, you are hereby 
notified that any retention, dissemination, distribution or copying of this 
communication is strictly prohibited.  Please reply to the sender that you have 
received this message in error, then delete it.

__
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] Best Mac for R

2015-02-25 Thread Mark Sharp
For what I do, which does not require a lot of parallel work, the high end iMac 
was faster and much less expensive than the Mac Pro.

Mark
R. Mark Sharp, Ph.D.
msh...@txbiomed.org





> On Feb 25, 2015, at 1:50 PM, Dan Murphy  wrote:
>
> I am possibly in the market for a new laptop. Predominantly a Windows
> user, I owned a macbook pro 10 years ago and am considering going that
> route again. Does the standard advice still hold: Get the most
> powerful processor (i7), most ram (16GB), and largest internal storage
> (512GB), if affordable?
> thanks,
> dan
>
> __
> 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.


NOTICE:  This E-Mail (including attachments) is confidential and may be legally 
privileged.  It is covered by the Electronic Communications Privacy Act, 18 
U.S.C.2510-2521.  If you are not the intended recipient, you are hereby 
notified that any retention, dissemination, distribution or copying of this 
communication is strictly prohibited.  Please reply to the sender that you have 
received this message in error, then delete it.

__
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] Extract year from date

2015-03-08 Thread Mark Sharp
Make the question reproducible (I used dput after getting the data into a 
dataframe). 
You need to provide a date of origin for the as.Date function.
Try lubridate package.

library(lubridate)
wells <- structure(list(ID = structure(c(3L, 3L, 2L, 1L, 3L, 2L, 3L, 1L, 
 1L, 2L, 3L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L), .Label = 
c("BC-0002", 
 "BC-0003", "BC-0004"), class = "factor"), Date = c(41163L, 41255L, 
 41345L, 41351L, 41355L, 41438L, 41438L, 41443L, 41521L, 41522L, 
 41522L, 41627L, 41627L, 41634L, 41703L, 41703L, 41710L, 41795L, 
 41795L, 41801L, 41905L, 41905L, 41906L), DepthtoWater_bgs = c(260.6, 
 261.65, 166.58, 317.85, 262.15, 167.55, 265.45, 317.25, 321.25, 
 168.65, 266.15, 168.95, 265.25, 312.31, 169.25, 265.05, 313.01, 
 168.85, 266.95, 330.41, 169.75, 267.75, 321.01), test = 3:25, 
 test2 = 1:23), .Names = c("ID", "Date", "DepthtoWater_bgs", 
 "test", "test2"), class = "data.frame", row.names = c("1", "2", 
 "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", 
 "15", "16", "17", "18", "19", "20", "21", "22", "23"))

wells$year <- year(as.Date(wells$Date, origin = '1900-1-1'))
head(wells$year)

Mark

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



> On Mar 8, 2015, at 12:50 AM, Steve Archambault  wrote:
> 
> Hi all,
> 
> I am trying in vain to create a new object "Year" in my data frame from
> existing Date data. I have tried many different approaches, but can't seem
> to get it to work. Here is an example of some code I tried.
> 
> date1<- as.Date(wells$Date,"%m/%d/%Y")
> wells$year<-as.numeric(format(date1, "%Y"))
> 
> I am starting with data that looks like this.
> 
>ID  Date DepthtoWater_bgs test test2
> 1  BC-0004 41163   260.603 1
> 2  BC-0004 41255   261.654 2
> 3  BC-0003 41345   166.585 3
> 4  BC-0002 41351   317.856 4
> 5  BC-0004 41355   262.157 5
> 6  BC-0003 41438   167.558 6
> 7  BC-0004 41438   265.459 7
> 8  BC-0002 41443   317.25   10 8
> 9  BC-0002 41521   321.25   11 9
> 10 BC-0003 41522   168.65   1210
> 11 BC-0004 41522   266.15   1311
> 12 BC-0003 41627   168.95   1412
> 13 BC-0004 41627   265.25   1513
> 14 BC-0002 41634   312.31   1614
> 15 BC-0003 41703   169.25   1715
> 16 BC-0004 41703   265.05   1816
> 17 BC-0002 41710   313.01   1917
> 18 BC-0003 41795   168.85   2018
> 19 BC-0004 41795   266.95   2119
> 20 BC-0002 41801   330.41   2220
> 21 BC-0003 41905   169.75   2321
> 22 BC-0004 41905   267.75   2422
> 23 BC-0002 41906   321.01   2523
> 
> Any help would be greatly appreciated!
> 
> -Steve
> Sent from my iPhone
> 
> __
> 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] ANY ONE HERE PLZ Urgent

2014-08-28 Thread Mark Sharp
If you use the lubridate package, this is very easy.
See the help file for month() within lubridate for more examples.

library(lubridate)
x <- now()
month(x)
month(x, label = TRUE)
month(x, label = TRUE, abbr = FALSE)
as.character(month(x, label = TRUE, abbr = FALSE))

When you run the above your get the following.

> library(lubridate)
> x <- now()
> month(x)
[1] 8
> month(x, label = TRUE)
[1] Aug
Levels: Jan < Feb < Mar < Apr < May < Jun < Jul < Aug < Sep < Oct < Nov < Dec
> month(x, label = TRUE, abbr = FALSE)
[1] August
12 Levels: January < February < March < April < May < June < July < ... < 
December
> as.character(month(x, label = TRUE, abbr = FALSE))
[1] "August"

Mark

On Aug 28, 2014, at 5:33 AM, arun  wrote:

> Try:
>
> format(as.Date("05/07/2014", "%m/%d/%Y"), "%m")
> #[1] "05"
>
> #or
> strptime("05/07/2014", "%m/%d/%Y")$mon+1
> #[1] 5
>
>
>
> A.K.
>
>
> How to extract a Month from Date object?
>
> almost 13 peoples visited my Question with out replying in New to R , i have 
> task yaar
>
>
>
> don't mind plz could you HELP ME
>
> How to extract a Month from Date object?
>
> as.month("05/07/2014", format = "%m")
>
> tried wityh this
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


NOTICE:  This E-Mail (including attachments) is confidential and may be legally 
privileged.  It is covered by the Electronic Communications Privacy Act, 18 
U.S.C.2510-2521.  If you are not the intended recipient, you are hereby 
notified that any retention, dissemination, distribution or copying of this 
communication is strictly prohibited.  Please reply to the sender that you have 
received this message in error, then delete it.

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


Re: [R] R-tool - OS compatibility help

2014-08-29 Thread Mark Sharp
See
http://cran.r-project.org/
On Aug 28, 2014, at 11:41 PM, Ravi Kumar Rupakula wrote:

> Dear Support,
>
> Please let us know Windows 2008R2 OS compatibility for "R" tool is available 
> or not?
> If available, please let us know the details.
> --
> RaviKumar Rupakula | HP: +65-98537306 | Email: 
> r...@websynergies.biz | Web Synergies (S) Pte 
> Ltd
>
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


NOTICE:  This E-Mail (including attachments) is confidential and may be legally 
privileged.  It is covered by the Electronic Communications Privacy Act, 18 
U.S.C.2510-2521.  If you are not the intended recipient, you are hereby 
notified that any retention, dissemination, distribution or copying of this 
communication is strictly prohibited.  Please reply to the sender that you have 
received this message in error, then delete it.

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


Re: [R] Getting the most recent dates in a new column from dates in four columns using the dplyr package (mutate verb)

2014-11-10 Thread Mark Sharp
Pradip,

mutate() works on the entire column as a vector so that you find the maximum of 
the entire data set.

I am almost certain there is some nice way to handle this, but the sapply() 
function is a standard approach.

max() does not want a dataframe thus the use of unlist().

Using your definition of data1:

data3 <- data1
data3$oidflag <- as.Date(sapply(seq_along(data3$id), function(row) {
  if (all(is.na(unlist(data1[row, -1] {
max_d <- NA
  } else {
max_d <- max(unlist(data1[row, -1]), na.rm = TRUE)
  }
  max_d}),
  origin = "1970-01-01")

data3
  idmrjdatecocdateinhdatehaldateoidflag
1  1 2004-11-04 2008-07-18 2005-07-07 2007-11-07 2008-07-18
2  2   
3  3 2009-10-242011-10-132011-10-13
4  4 2007-10-10  2007-10-10
5  5 2006-09-01 2005-08-10   2006-09-01
6  6 2007-09-04 2011-10-05   2011-10-05
7  7 2005-10-25   2011-11-04 2011-11-04



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





NOTICE:  This E-Mail (including attachments) is confidential and may be legally 
privileged.  It is covered by the Electronic Communications Privacy Act, 18 
U.S.C.2510-2521.  If you are not the intended recipient, you are hereby 
notified that any retention, dissemination, distribution or copying of this 
communication is strictly prohibited.  Please reply to the sender that you have 
received this message in error, then delete it.

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


Re: [R] range () does not remove NA's with complete.cases() for dates (dplyr/mutate)

2014-11-10 Thread Mark Sharp
Pradip,

For some reason mutate is not setting the is.NA value for the new column. Note 
the output below using your data structures.

> ## It looks at first as if the second element of both columns are NA.
> data2$mrjdate[2]
[1] NA
> data2$oiddate[2]
[1] NA
> ## for convenience
> mrj <- data2$mrjdate[2]
> oid <- data2$oiddate[2]
> mode(mrj)
[1] "numeric"
> mode(oid)
[1] "numeric"
> str(mrj)
 Date[1:1], format: NA
> str(oid)
 Date[1:1], format: NA
> class(mrj)
[1] "Date"
> class(oid)
[1] "Date"
> ## But note:
> identical(mrj, oid)
[1] FALSE
> all.equal(mrj, oid)
[1] "'is.NA' value mismatch: 0 in current 1 in target"
## functioning code
data2$mrjdate[2]
data2$oiddate[2]
mrj <- data2$mrjdate[2]
oid <- data2$oiddate[2]
mode(mrj)
mode(oid)
str(mrj)
str(oid)
class(mrj)
class(oid)
# But note:
identical(mrj, oid)
all.equal(mrj, oid)

## This ugly solution does not have the problem.
> data3 <- data1
> data3$oiddate <- as.Date(sapply(seq_along(data3$id), function(row) {
+   if (all(is.na(unlist(data1[row, -1] {
+ max_d <- NA
+   } else {
+ max_d <- max(unlist(data1[row, -1]), na.rm = TRUE)
+   }
+   max_d}),
+   origin = "1970-01-01")
>
> range(data3$mrjdate[complete.cases(data3$mrjdate)])
[1] "2004-11-04" "2009-10-24"
> range(data3$cocdate[complete.cases(data3$cocdate)])
[1] "2005-08-10" "2011-10-05"
> range(data3$inhdate[complete.cases(data3$inhdate)])
[1] "2005-07-07" "2011-10-13"
> range(data3$haldate[complete.cases(data3$haldate)])
[1] "2007-11-07" "2011-11-04"
> range(data3$oiddate[complete.cases(data3$oiddate)])
[1] "2006-09-01" "2011-11-04"
>
Working code below.

data3 <- data1
data3$oiddate <- as.Date(sapply(seq_along(data3$id), function(row) {
  if (all(is.na(unlist(data1[row, -1] {
max_d <- NA
  } else {
max_d <- max(unlist(data1[row, -1]), na.rm = TRUE)
  }
  max_d}),
  origin = "1970-01-01")

range(data3$mrjdate[complete.cases(data3$mrjdate)])
range(data3$cocdate[complete.cases(data3$cocdate)])
range(data3$inhdate[complete.cases(data3$inhdate)])
range(data3$haldate[complete.cases(data3$haldate)])
range(data3$oiddate[complete.cases(data3$oiddate)])


On Nov 10, 2014, at 10:10 AM, Muhuri, Pradip (SAMHSA/CBHSQ) wrote:

> Hello,
>
> The range() with complete.cases() removes NA's for the date variables that 
> are read from a data frame.  However, the issue is that the same function 
> does not remove NA's for the other date variable that is created using the 
> dplyr/mutate().  The console and the reproducible example are given below. 
> Any advice how to resolve this issue would be appreciated.
>
> Thanks,
>
> Pradip Muhuri
>
>
> #  cut and pasted from the R console 
>
> idmrjdatecocdateinhdatehaldateoiddate
> 1  1 2004-11-04 2008-07-18 2005-07-07 2007-11-07 2008-07-18
> 2  2   
> 3  3 2009-10-242011-10-132011-10-13
> 4  4 2007-10-10  2007-10-10
> 5  5 2006-09-01 2005-08-10   2006-09-01
> 6  6 2007-09-04 2011-10-05   2011-10-05
> 7  7 2005-10-25   2011-11-04 2011-11-04
>>
>> # range of dates
>>
>> range(data2$mrjdate[complete.cases(data2$mrjdate)])
> [1] "2004-11-04" "2009-10-24"
>> range(data2$cocdate[complete.cases(data2$cocdate)])
> [1] "2005-08-10" "2011-10-05"
>> range(data2$inhdate[complete.cases(data2$inhdate)])
> [1] "2005-07-07" "2011-10-13"
>> range(data2$haldate[complete.cases(data2$haldate)])
> [1] "2007-11-07" "2011-11-04"
>> range(data2$oiddate[complete.cases(data2$oiddate)])
> [1] NA   "2011-11-04"
>
>
>   reproducible code #
>
> library(dplyr)
> library(lubridate)
> library(zoo)
> # data object - description of the
>
> temp <- "id  mrjdate cocdate inhdate haldate
> 1 2004-11-04 2008-07-18 2005-07-07 2007-11-07
> 2 NA NA NA NA
> 3 2009-10-24 NA 2011-10-13 NA
> 4 2007-10-10 NA NA NA
> 5 2006-09-01 2005-08-10 NA NA
> 6 2007-09-04 2011-10-05 NA NA
> 7 2005-10-25 NA NA 2011-11-04"
>
> # read the data object
>
> data1 <- read.table(textConnection(temp),
>colClasses=c("character", "Date", "Date", "Date", "Date"),
>header=TRUE, as.is=TRUE
>)
>
>
> # create a new column
>
> data2 <- data1 %>%
> rowwise() %>%
>  mutate(oiddate=as.Date(max(mrjdate,cocdate, inhdate, haldate,
>   na.rm=TRUE), 
> origin='1970-01-01'))
>
> # print records
>
> print (data2)
>
> # range of dates
>
> range(data2$mrjdate[complete.cases(data2$mrjdate)])
> range(data2$cocdate[complete.cases(data2$cocdate)])
> range(data2$inhdate[complete.cases(data2$inhdate)])
> range(data2$haldate[complete.cases(data2$haldate)])
> range(data2$oiddate[complete.cases(data2$oiddate)])
>
>
>
>
>
> Pradip K. Muhuri, PhD
> SAMHSA/CBHSQ
> 1 Choke 

Re: [R] Error: (list) object cannot be coerced to type double; on running the following code in R ver 3.1.2

2014-11-11 Thread Mark Sharp
Aditya,

Please use plan text. HTML is not handled correctly.

Within your last statement it appears you are trying to find the sum of a 
logical vector - is.na(). This is what is causing the error.

My guess is that you want to count the number of elements in the second column 
that are not NA values. You probably want the following for your last line. 
(See ?sum).

nummk <- length(vbm[ !is.na(vbm[ , 2], 2])
## or
nummk <- nrow(vbm[!is.na(vbm[ , 2], ])

## The is.na(vbm[ ,2]) returns a logical vector (for example c(FALSE, TRUE, 
TRUE))

Mark

R. Mark Sharp, Ph.D.
Director Primate Records Database
Southwest National Primate Research Center
Director of Scientific Computing
Texas Biomedical Research Institute
P.O. Box 760549
San Antonio, TX 78245-0549
Office telephone: (210)258-9476 (is forwarded to mobile telephone; message are 
captured into e-mail.)
Mobile telephone: (210) 218-2868




On Nov 11, 2014, at 3:05 AM, Aditya Singh wrote:

setwd("C:/Documents and 
Settings/Administrator/Desktop/Coursera/specdata/specdata")temp=list.files(pattern="*.csv")myfiles=lapply(temp,read.delim)summk=0nummk=0for
 (i in 1:10) {  vb=data.frame(myfiles[i])  vbm=as.double(vb)  
summk=sum(vbm[,2])  nummk=length(vbm[,2]) - sum(is.na(vbm[,2]))}
Aditya

[[alternative HTML version deleted]]

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



NOTICE: This E-Mail (including attachments) is confidential and may be legally 
privileged. It is covered by the Electronic Communications Privacy Act, 18 
U.S.C.2510-2521. If you are not the intended recipient, you are hereby notified 
that any retention, dissemination, distribution or copying of this 
communication is strictly prohibited. Please reply to the sender that you have 
received this message in error, then delete it.

[[alternative HTML version deleted]]

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


Re: [R] C project within R function

2014-11-21 Thread Mark Sharp
Diogo,

For a gentle introduction to package creation see Hadley Wickham's book in 
progress on the subject at http://r-pkgs.had.co.nz. This site is particularly 
accessible if you use RStudio, but is not dependent on its use.

I use very simple packages that are not designed to be used by others to 
organize my work because it is the easiest way to structure projects that use 
many functions. As Duncan has stated, it is the only reasonable way to use C, 
FORTRAN, or C++ subroutines and functions.

Mark
> On Nov 21, 2014, at 6:52 PM, Duncan Murdoch  wrote:
>
> On 21/11/2014, 3:02 PM, Diogo André Alagador wrote:
>> Hi all,
>>
>>
>>
>> I need some assistance regarding the use of C project (set of programming
>> files)  as R functions in Windows OS.
>>
>> By now I really would like to avoid package-building.
>>
>> What are the steps to undergo or where can I check to perform that
>> successfully?
>>
>
> Sorry, but your constraint (no package building) is irrational.  By
> *far* the easiest way to do this is to write a package.
>
> Duncan Murdoch
>
>>
>>
>> Thanks in advance,
>>
>> My best regards,
>>
>> Diogo Alagador
>>
>> <http://www.cibioue.uevora.pt/9-uncategorised/185-dr-diogo-alagador>
>> http://www.cibioue.uevora.pt/9-uncategorised/185-dr-diogo-alagador
>>
>> CIBIO/UE - Research Center in Biodiversity and Genetic Resources, University
>> of �vora, Portugal
>>
>>
>>
>>
>>  [[alternative HTML version deleted]]
>>
>>
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

R. Mark Sharp, Ph.D.
msh...@txbiomed.org






NOTICE:  This E-Mail (including attachments) is confidential and may be legally 
privileged.  It is covered by the Electronic Communications Privacy Act, 18 
U.S.C.2510-2521.  If you are not the intended recipient, you are hereby 
notified that any retention, dissemination, distribution or copying of this 
communication is strictly prohibited.  Please reply to the sender that you have 
received this message in error, then delete it.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Presentation tables in R (knitr)

2014-11-25 Thread Mark Sharp
Tom,

If you are wanting PDF as your output, are you wanting to use LaTeX or Markdown 
with knitr. LaTeX will give you more options. You have not shown an attempt to 
use either for your table construction. Can you define what you mean by pretty? 
Is it the underscores in the column names that are the problem?

Mark
> On Nov 25, 2014, at 2:12 PM, Tom Wright  wrote:
>
> Hi,
> This problem has me stumped so I thought I'd ask the experts. I'm trying
> to create a pretty summary table of some data (which patients have had
> what tests at what times). Ideally I'd like to knitr this into a pretty
> PDF for presentation.
> If anyone has pointers I'll be grateful.
>
> require(tables)
> require(reshape2)
>
> data<-data.frame('ID'=paste0('pat',c(rep(1,8),rep(2,8))),
> 'Time'=c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4),
> 'Eye'=rep(c('OS','OS','OD','OD'),4),
> 'Measure'=rep(c('Height','Weight'),8))
>
> tabular(Measure~factor(ID)*factor(Time)*factor(Eye),data)
> #All levels of Time are repeated for all IDs, I'd prefer to just show
> the relevant times.
>
> tabular(Measure~factor(ID)*Time*factor(Eye),data)
> #Time is getting collapsed by ID
>
> data$value=1
> dcast(data,Measure~ID+Time+Eye)
> #close but not very pretty
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


NOTICE:  This E-Mail (including attachments) is confidential and may be legally 
privileged.  It is covered by the Electronic Communications Privacy Act, 18 
U.S.C.2510-2521.  If you are not the intended recipient, you are hereby 
notified that any retention, dissemination, distribution or copying of this 
communication is strictly prohibited.  Please reply to the sender that you have 
received this message in error, then delete it.

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


Re: [R] Rodbc retrieve data

2015-08-19 Thread Mark Sharp
Diaz,

paste() and paste0() will work here. paste0() defaults to "" between character 
vector elements and paste() defaults to " " (single blank character) between 
character vector elements. See ?paste.

I do not recall, but you may have to escape the "&" symbol, but that is another 
topic.

Try this.

title (main = paste0("Mapa de los dblinks del entorno: ", dbName),sub="Luis 
Diaz -
Emergencies & improvments")

Mark
P.S. Spelling correction - "improvements"

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







> On Aug 19, 2015, at 7:11 AM, Diaz Garcia, Luis Carlos  
> wrote:
> 
> Hi every one
> first I would like to introduce myself, as I'm new here.
> I'm Luis from Barcelona, I'm Oracle dba and I need to create some nice
> graphs.
> So, I was looking for a solution and I saw R...
> 
> I think it's a good tool to make the task I need.
> 
> So here is the task: I need to get all the dblink from one database and draw
> the result of the query.
> The dblink will have the origin database name, the destination, the name of
> the link the type too.
> So I look into the R doc and I saw the way to get the data from my database:
> 
> library("RODBC")
> con <- odbcConnect("DPL03", uid="myuser", pwd="mypass",believeNRows=FALSE )
> dbName <- sqlQuery(con, "SELECT instance_name from v$instance",errors=FALSE)
> 
> Now I have dbName with one value, the name of my instance, but I don't know
> how to insert this data into this:
> 
> plot.new()
> title (main ="Map of the dbLinks of the database",sub="Luis Diaz -
> Emergencies & improvments")
> 
> 
> As you see, I create a screen to plot where I'll draw shapes and lines but
> the first issue is to insert here the name of my instance, but I can't.
> I try to concatenate like this:
> 
> title (main ="Mapa de los dblinks del entorno: " + dbName ,sub="Luis Diaz -
> Emergencies & improvments")
> 
> 
> But I have an error, and if I use print(dbName) the value is printed but
> outside of the plot.new() screen.
> Some one can help ?
> Thanks in advance !
> 
> Cheers
> 
> __
> 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] SSD vs RAM upgrade

2015-09-14 Thread Mark Sharp
John,

Unless you are doing something very unusual (such as using a database to keep 
intermediate results) SSD hardware will have no affect on R being memory bound. 
According to the behavior you described, you need RAM. 

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




> On Sep 14, 2015, at 10:44 AM, Kulas, John T.  wrote:
> 
> I have several lab computers that frequently lag/crash with R apparently due 
> to low RAM (they're all 8 GB)
> 
> I put in a request to up the RAM to 32 GB on a few, but my tech support is 
> suggesting an SSD harddrive upgrade instead of the increased RAM.
> 
> Any suggestions on the better approach (SSD harddrive vs increased RAM to 
> help R chug along)?
> 
> Thanks much - John
> 
>   [[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] Plotting Numeric Values with Non-Numeric Values

2015-09-14 Thread Mark Sharp
Try
?boxplot

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







> On Sep 14, 2015, at 1:49 PM, mtilley3  wrote:
> 
> I have looked for quite a long time and can't quite find the answer for what
> I'm looking for. I want to graph bmi vs gender, with male/female on the
> x-axis and the bmi numerical value on the y-axis. Can anyone explain how to
> do this? Thanks!
> 
> 
> 
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Plotting-Numeric-Values-with-Non-Numeric-Values-tp4712253.html
> Sent from the R help mailing list archive at Nabble.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.

__
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] Extract from data.frame

2015-09-21 Thread Mark Sharp
Nico, 

I expect there are many better ways to do this, but this does work:
max_row <- (1:nrow(df))[which.max(df$Amount)]
mean(df$Amount[max_row + c(-1, 0, 1)])

> max_row <- (1:nrow(df))[which.max(df$Amount)]
> mean(df$Amount[max_row + c(-1, 0, 1)])
[1] 151.6667

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




> On Sep 21, 2015, at 9:52 AM, Nico Gutierrez  wrote:
> 
> Hi All,
> 
> I need to do the following operation from data.frame:
> 
> df <- data.frame(Year = c("2001", "2002", "2003", "2004", "2005", "2006",
> "2007"), Amount = c(150, 120, 175, 160, 120, 105, 135))
> df[which.max(df$Amount),]  #to extract row with max Amount.
> 
> Now I need to do 3 years average around the max Amount value (ie:
> mean(120,175,160))
> 
> Thanks!
> N
> 
>   [[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] Error in eval(expr, envir, enclos) : could not find function

2015-09-22 Thread Mark Sharp
Please provide a context for your question. See the posting guide referenced 
below for instructions on providing commented, minimal, self-contained, 
reproducible code. If you can show how to produce the error, someone can almost 
certainly show you how to avoid it.

Mark
R. Mark Sharp, Ph.D.
msh...@txbiomed.org





> On Sep 22, 2015, at 2:07 PM, Alaa Sindi  wrote:
> 
> hi all
> 
> I am getting this error "Error in eval(expr, envir, enclos) : could not find 
> function “
> 
> do you have an idea what might cause this problem. 
> 
> thanks
> __
> 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] Works on Mac, but not Windows: Using tempdir() to determine image location works with .tex file

2015-11-01 Thread Mark Sharp
Did you look at file.path()?


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







> On Oct 31, 2015, at 3:28 PM, Green Stone  wrote:
> 
> I am writing an R package that generates a .pdf file for users that outputs
> summarizations of data. I have a .Rnw script in the package (here, my MWE
> of it is called test.Rnw). The user can do:
> 
> knit2pdf("test.Rnw", clean=T)
> 
> This makes the process easy for them, because it automatically creates the
> .pdf file from the .tex file, and it erases unnecessary files for them
> (.aux and .log, for example). It also stores any images into a temporary
> directory (using tempdir()), which will then be erased routinely by the
> system after they have been incorporated into the .tex and .pdf file. This
> means they do not have to erase image files either.
> 
> Below is my test.Rnw MWE:
> 
> \documentclass[nohyper]{tufte-handout}
> \usepackage{tabularx}
> \usepackage{longtable}
> 
> \setcaptionfont{% changes caption font characteristics
>  \normalfont\footnotesize
>  \color{black}% <-- set color here}
> 
> \begin{document}
> <>=
> library(knitr)
> library(xtable)
> library(ggplot2)# Specify directory for figure output in a temporary directory
> temppath <- tempdir()
> opts_chunk$set(fig.path = temppath)@
> 
>  < out.width="0.95\\linewidth", fig.cap = "The diamond dataset has
> varibles depth and price.",fig.lp="mar:">>=
>  print(qplot(depth,price,data=diamonds))@
> 
>  <>=
>  myDF <- data.frame(a = rnorm(1:10), b = letters[1:10])
> print(xtable(myDF, caption= 'This data frame shows ten random
> variables from the distribution and a corresponding letter',
> label='tab:dataFrame'), floating = FALSE, tabular.environment =
> "longtable", include.rownames=FALSE)@
> 
>  Figure \ref{mar:diamondData} shows the diamonds data set, with the
> variables price and depth.Table \ref{tab:dataFrame} shows letters a through j
> corresponding to a random variable from a normal distribution.
> 
> \end{document}
> 
> I should note that, in reality, there is another .Rnw file in my package
> that calls the test.Rnw file via:
> 
> knit2pdf("/inst/Rnw/test.Rnw","/path/test.tex",clean=T)
> 
> In any case, I am trying to get this package ready to be submitted to CRAN
> and have run across two problems:
> 
> 1) The more perplexing question first: The MWE code above seems to work on
> Mac Systems, but does not seem to work on Windows Systems! On Windows, the
> .pdf file that is generated does not contain the images. After
> troubleshooting, I think I have figured out the problem, but still cannot
> find a solution.
> 
> Basically, on Windows, it seems that the tempdir() command will create a
> pathway with double back-slashes, such as \this\is\myPath. Then, in the
> .tex file, the pathway to the temporary directory (that contains the
> images) are single back-slashes, such as \this\is\myPath. However, these
> should be single forward-slashes, such as /this/is/myPath.
> 
> Indeed, if I manually the change the backslashes to forward slashes in the
> .tex file in Windows, then I can successfully convert it to .pdf file that
> successfully contains the images.
> 
> I am unsure how to solve this in my syntax, however. If I simply do
> something like:
> 
> # Specify directory for figure output in a temporary directory
> temppath <- tempdir()
> gsub("", "/", temppath)
> 
> Then the images cannot be stored into the pathway on the Windows in the
> first place, even if the .tex file will contain the correct single forward
> slashes needed.
> 
> 2) I am wondering if it would acceptable for me to, in my other .Rnw file,
> add a second line to call:
> 
> knit2pdf("/inst/Rnw/test.Rnw","/path/test.tex",clean=T)
> system(sprintf("%s", paste0("rm -r ", "/path/myFile.tex")))
> 
> So that the .tex file can also be automatically erased. I am trying to
> confirm that such syntax would be acceptable by CRAN standards, as it does
> involve erasing a file from the user's computer (which could seem like
> dangerous/malware), although it points specifically at the .tex file it
> just generated, and so it should not be deleting anything important for
> them.
> 
> *Note: I am by default erasing all intermediary files so the user only
> deals with the .pdf file. However, I am still allowing users the option to
> go against this default, and

Re: [R] Ordering Filenames stored in list or vector

2015-12-04 Thread Mark Sharp
Mario,

I am certain there are more elegant solutions. This is an effort to make the 
process clear by dividing out each transformation used into separate lines.

## Start of code
library(stringi) # This is written in C and C++ (ICU library), is fast, and is 
well documented.
filenames <- c("Q_Read_prist#1...@1.xls", "Q_Read_prist#1...@10.xls", 
   "Q_Read_prist#1...@11.xls", "Q_Read_prist#1...@12.xls", 
   "Q_Read_prist#1...@13.xls", "Q_Read_prist#1...@14.xls", 
   "Q_Read_prist#1...@15.xls", "Q_Read_prist#1...@16.xls", 
   "Q_Read_prist#1...@17.xls", "Q_Read_prist#1...@18.xls", 
   "Q_Read_prist#1...@19.xls", "Q_Read_prist#1...@2.xls", 
   "Q_Read_prist#1...@3.xls", "Q_Read_prist#1...@4.xls", 
   "Q_Read_prist#1...@5.xls", "Q_Read_prist#1...@6.xls", 
   "Q_Read_prist#1...@7.xls", "Q_Read_prist#1...@8.xls", 
   "Q_Read_prist#1...@9.xls")
indx_list <- stri_split_regex(filenames, pattern = "[@.]")
indx <- sapply(indx_list, function(x) {x[[2]]})
filenames_df <- data.frame(file_name = filenames, indx = indx, 
        stringsAsFactors = FALSE)
filenames_ordered <- filenames_df[order(as.numeric(filenames_df$indx)), 
"file_name"]
filenames_ordered
## end of code
Mark


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







> On Dec 4, 2015, at 4:51 AM, BARLAS Marios 247554  wrote:
> 
> Hello everyone,
> 
> I am an R rookie and I'm learning as I program.
> 
> I am working on a script to process a large amount of data: I read a pattern 
> of filenames in the folder I want and import their data
> 
> filenames = list.files(path, pattern="*Q_Read_prist*")
> 
> myfiles = lapply(filenames, function(x) read.xlsx2(file=x, sheetName="Data", 
> header=TRUE, FILENAMEVAR=x))
> 
> The problem is that R recognizes the files in a 'non human' order.
> 
> Q_Read_prist#1...@1.xls   Q_Read_prist#1...@1.xls
> Q_Read_prist#1...@10.xls Q_Read_prist#1...@10.xls
> Q_Read_prist#1...@11.xls Q_Read_prist#1...@11.xls
> Q_Read_prist#1...@12.xls Q_Read_prist#1...@12.xls
> Q_Read_prist#1...@13.xls Q_Read_prist#1...@13.xls
> Q_Read_prist#1...@14.xls Q_Read_prist#1...@14.xls
> Q_Read_prist#1...@15.xls Q_Read_prist#1...@15.xls
> Q_Read_prist#1...@16.xls Q_Read_prist#1...@16.xls
> Q_Read_prist#1...@17.xls Q_Read_prist#1...@17.xls
> Q_Read_prist#1...@18.xls Q_Read_prist#1...@18.xls
> Q_Read_prist#1...@19.xls Q_Read_prist#1...@19.xls
> Q_Read_prist#1...@2.xls   Q_Read_prist#1...@2.xls
> Q_Read_prist#1...@3.xls   Q_Read_prist#1...@3.xls
> Q_Read_prist#1...@4.xls   Q_Read_prist#1...@4.xls
> Q_Read_prist#1...@5.xls   Q_Read_prist#1...@5.xls
> Q_Read_prist#1...@6.xls   Q_Read_prist#1...@6.xls
> Q_Read_prist#1...@7.xls   Q_Read_prist#1...@7.xls
> Q_Read_prist#1...@8.xls   Q_Read_prist#1...@8.xls
> Q_Read_prist#1...@9.xls   Q_Read_prist#1...@9.xls
> 
> I tried to order them using order or sort but it doesn' seem to work. I have 
> had the same issue in matlab but there I have a function to re-define the 
> order in a "correct" way.
> 
> Anyone knows of a smart way to sort these guys from 1 to 19 ascending or 
> descending?
> 
> Thanks in advance,
> Mario
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Dput Help in R

2015-12-31 Thread Mark Sharp
Shivi,

It looks like you have copied and pasted with errors. When you use dput() on a 
dataframe, it will output a list (see example that follows). I think you have 
cut off the beginning of the output and have manually added the assignment 
“ab<-“. Also it is clear that the read.csv is interpreting your numbers as 
character strings. Note the quotation marks.

> sample_df <- data.frame(nums = 1:10, rand_num = runif(10))
> dput(sample_df)
structure(list(nums = 1:10, rand_num = c(0.346553232055157, 0.996620914200321, 
0.412795166717842, 0.250930240144953, 0.809035068377852, 0.782051374204457, 
0.0857722735963762, 0.938713687239215, 0.819887164747342, 0.870529293781146
)), .Names = c("nums", "rand_num"), row.names = c(NA, -10L), class = 
"data.frame”)


> On Dec 31, 2015, at 1:26 AM, SHIVI BHATIA  wrote:
> 
> Hi Duncan,
> Please find the dput from the data.
> 
> ab<-read.csv("collection_last.csv",header=TRUE)
> y<-ab[1:10,]
> 
> 
> ab<- "2,458", "2,461", "2,462", "2,463", "2,464", "2,465", "2,468",
> "2,469", "2,470", "2,473", "2,474", "2,475", "2,476", "2,477",
> "2,478", "2,479", "2,480", "2,483", "2,484,267", "2,485",
> "2,486", "2,487", "2,490", "2,491", "2,491,176", "2,492",
> "2,494", "2,495,976", "2,496", "2,497", "2,498", "2,499",
> "2,500", "2,500,001", "2,501", "2,502", "2,503", "2,504",
> "2,506", "2,507", "2,508", "2,509", "2,510", "2,511", "2,512",
> "2,513", "2,514", "2,515", "2,516", "2,517", "2,519", "2,520",
> "2,521", "2,523", "2,523,257", "2,524", "2,525", "2,526",
> "2,527", "2,528", "2,529", "2,530", "2,531", "2,535", "2,536",
> "2,538", "2,539", "2,540", "2,542", "2,543", "2,544", "2,545",
> "2,546", "2,547", "2,549", "2,550", "2,551", "2,553", "2,554",
> "2,556", "2,557", "2,558", "2,559", "2,560", "2,561", "2,563",
> "2,564", "2,565", "2,566", "2,567", "2,570", "2,572", "2,574",
> "2,576", "2,577", "2,578", "2,579", "2,580", "2,582", "2,583",
> "2,584", "2,585", "2,588", "2,589", "2,590", "2,591", "2,592",
> "2,593", "2,594", "2,596", "2,599", "2,600", "2,601", "2,602",
> "2,604", "2,605", "2,606", "2,607", "2,609", "2,611", "2,612",
> "2,613", "2,614", "2,615", "2,616", "2,617", "2,618", "2,619",
> "2,620", "2,621", "2,622", "2,624", "2,626", "2,627", "2,628",
> "2,628,385", "2,629", "2,630", "2,633", "2,634", "2,636",
> "2,637", "2,638", "2,640", "2,642", "2,644", "2,647", "2,648",
> "2,649", "2,650", "2,651", "2,654", "2,655", "2,656", "2,658",
> "2,660", "2,661", "2,663", "2,665", "2,666", "2,667", "2,668",
> "2,670", "2,671", "2,672", "2,673", "2,674", "2,676", "2,677",
> "2,678", "2,679", "2,679,505", "2,680", "2,682", "2,684",
> "2,687", "2,688", "2,689", "2,690", "2,692", "2,694", "2,695",
> "2,696", "2,697", "2,699", "2,700", "2,702", "2,703", "2,705",
> "2,706", "2,707", "2,708", "2,709", "2,710", "2,711", "2,712",
> "2,713", "2,714", "2,715", "2,716", "2,717", "2,718", "2,720",
> "2,721", "2,722", "2,723", "2,727", "2,728", "2,730", "2,732",
> "2,733", "2,736", "2,737", "2,738", "2,739", "2,742", "2,744",
> "2,747", "2,748", "2,749", "2,750", "2,752", "2,753", "2,754",
> "2,758", "2,759", "2,760", "2,761", "2,765,189", "2,766",
> "2,767", "2,770", "2,772", "2,773", "2,774", "2,776", "2,778",
> "2,780", "2,783", "2,784", "2,785", "2,786", "2,787", "2,789",
> "2,790", "2,792", "2,793", "2,794", "2,795", "2,797", "2,798",
> "2,799", "2,800", "2,803", "2,804", "2,806", "2,808", "2,808,003",
> "2,809", "2,810", "2,812", "2,813", "2,814", "2,816", "2,818",
> "2,820", "2,824", "2,825", "2,826", "2,832", "2,835", "2,839,850",
> "2,840", "2,841", "2,842", "2,844", "2,845", "2,846", "2,847",
> "2,848", "2,850", "2,851", "2,852", "2,853", "2,855", "2,856",
> "2,857", "2,858", "2,859", "2,861", "2,864", "2,865", "2,866",
> "2,867", "2,869", "2,870", "2,873", "2,874", "2,875", "2,876",
> "2,877", "2,878", "2,879", "2,880", "2,883", "2,884", "2,885",
> "2,886", "2,890", "2,891", "2,892", "2,893", "2,894", "2,895",
> "2,896", "2,897", "2,898", "2,899", "2,902", "2,903", "2,904",
> "2,905", "2,907", "2,908", "2,908,956", "2,910", "2,911",
> "2,912", "2,913", "2,916", "2,917", "2,922", "2,923", "2,924",
> "2,925", "2,926", "2,929", "2,930", "2,931", "2,932", "2,933",
> "2,934", "2,936", "2,937", "2,939", "2,941", "2,943", "2,944",
> "2,946", "2,947", "2,948", "2,950", "2,951", "2,953", "2,954",
> "2,955", "2,957", "2,959", "2,960", "2,961", "2,965", "2,967",
> "2,968", "2,970", "2,971", "2,973", "2,975", "2,976", "2,979",
> "2,981", "2,982", "2,983", "2,987", "2,988", "2,989", "2,990",
> "2,991", "2,992", "2,993", "2,994", "2,996", "2,997", "2,998",
> "2,999", "20", "20,000", "20,001", "20,003", "20,004", "20,028",
> "20,035", "20,054", "20,066", "20,071", "20,077", "20,079",
> "20,088", "20,101", "20,104", "20,116", "20,120", "20,126",
> "20,151", "20,153", "20,157", "20,174", "20,176", "20,190",
> "20,191", "20,196", "20,199", "20,213", "20,214", "20,217",
> "20,225", "20,257", "20,262", "20,263", "20,288", "20,294",
> "20,307", "20,320", "20,325", "20,349", "20,356", "20,375",
> "20,385

Re: [R] Splitting strings in data files R

2016-01-20 Thread Mark Sharp
Looks like homework.


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







> On Jan 20, 2016, at 2:53 PM, R. Help  wrote:
>
>
>
>
> Please I need help processing  files with strings in R. All the files have 
> two patterns (thus,examine separately):
> Pattern 1 (see file1 below): Delete Lines 1,2 & 4 in file1. Line 3 contains 
> the column names. Then find anything as.character and delete. Please do not 
> delete any values (e.g. delete T in 0.21T). Also find -999.99M,-999.99 and 
> replace with with NA.
>
> File1 output format should be: Year Month Day_1 Day_2 ... Day_31  ## so all 
> months should 31 days. Months with <31 days should have NA where appropraite 
> (e.g. Feb 30=NA, 31=NA)
>
> Pattern 2 (see file2 below): Delete Line 1 in file2.Then find anything 
> as.character and delete. Please do not delete any values (e.g. delete T in 
> 0.21T). Also find -999.99M,-999.99 and replace with withNA. File2 has no 
> column names. Please do not include any.
> File2 output format: Year Month Day_1 Day_2 ... Day_31 but no column names
>
> Here is a simple reproducible example for both files/cases:
>
>
> file1=list(df1,df1)df1=list(structure(list(X7011982.DONNACONAQC..station.joined..Homogenized.daily.maximum.temperature..Deg.Celcius...Updated.to.December.2014
>  
> =structure(c(20L,19L,21L,1L,2L,3L,4L,5L,6L,7L,8L,9L,10L,11L,12L,13L,14L,15L,16L,17L,18L),.Label
>  =c(" 1918  7 
> -.9M-.9M-.9M-.9M-.9M-.9M-.9M-.9M-.9M-.9M-.9M-.9M-.9M-.9M-.9M-.9M
>   23.6a  25.9a  25.8a  24.9a  24.9a  29.6a  27.4a  24.5a  28.5a  28.5a  30.1a 
>  25.3a  28.5a  19.6a  24.1a"," 1918  8   23.7a  18.6a  17.6a  19.0a  23.7a  
> 24.7a  18.6a  22.6a  20.1a  21.4a  22.6a  24.9a  24.1a  23.2a  22.0a  17.6a  
> 19.0a  19.0a  23.7a  24.1a  24.9a  27.9a  26.2a  22.6a  24.0a  25.4a  21.4a  
> 24.4a  19.0a  22.6a  23.7a"," 1918  9   22.0a  22.0a  24.0a  19.0a  14.4a  
> 11.2a  17.1a  18.1a  19.0a  12.0a  13.5a   9.6a  11.2a  10.7a  18.1a  18.1a  
> 16.3a  14.4a  14.3a  15.9a  10.1a   9.8a  11.3a  11.4a  13.6a  14.4a   9.3a   
> 9.6a   9.2a   8.4a-99!
 99!
> .9M"," 1918 109.3a   9.5a  11.3a  10.2a   9.9a-.9M   4.6a-.9M   
> 9.8a  13.6a  17.0a  15.2a  15.1a  15.9a   8.1a   9.3a   8.8a   6.0a   8.7a   
> 9.8a   9.8a  10.7a  11.3a   9.5a  10.7a-.9M  10.7a  16.9a  17.1a  10.7a  
> 12.7a"," 1918 118.8a-.9M   4.0a   3.4a   4.0a   6.6a   4.0a   7.3a   
> 8.1a   7.3a   2.5a   3.4a   7.7a   6.1a   2.2a   4.0a   4.6a   2.5a   2.2a   
> 1.6a   2.2a   3.0a  -3.4a   2.5a   1.6a  -3.4a   2.1a   0.0a   2.6a   
> 0.6a-.9M"," 1918 12  -10.1a  -8.3a  -6.3a  -5.5a  -5.1a  -7.2a-.9M  
> -3.4a  -2.2a  -5.5a  -6.0a  -3.4a   0.6a   3.0a   4.7a   0.6a  -5.0a  -6.4a  
> -5.9a  -2.2a   1.2a   4.0a   5.3a-.9M  -2.2a  -5.5a  -7.5a  -9.6a  -7.3a  
> -6.6a-.9M"," 1919  12.5a   0.0a  -7.3a  -6.7a  -6.6a  -9.2a  -5.9a  
> -0.7a  -2.9a  -13.2a  -8.0a  -17.1a  -7.4a  -4.0a  -5.5a   0.6a  -7.1a  -5.5a 
>  -2.2a  -7.6a  -7.0a  -3.4a  -2.2a  -6.7a  -8.0a  -2.9a  -1.5a  -5.9a  -5.5a  
> -5.8a  -3.4a"," 1919  2 -.9M   0.0a  -4.0a  -3.4a  -1.5a  -2.1a  -!
 3!
> .4a  -7.2a  -2.8a  -5.5a  -6.7a  -5.1a  -2.1a  -2.1a   1.2a  -2.1a  -5
> .9a  -2.8a  -4.5a  -4.5a  -3.4a   2.1a   0.0a   0.0a   1.2a  -2.1a  -8.3a  
> -6.6a-.9M-.9M-.9M"," 1919  3 -.9M   0.0a   1.6a   1.7a  -5.1a 
>  -6.7a  -5.1a  -3.4a  -2.0a   1.2a   3.4a   1.2a  -8.3a  -7.9a  -3.4a  -2.0a  
>  1.2a   3.4a   6.6a   1.2a   6.6a   1.2a   6.6a   6.6a   3.4a  10.7a   6.6a   
> 6.6a   0.6a   0.6a  -6.8a"," 1919  4   -5.9a  -3.4a   2.1a   3.4a   3.0a   
> 3.0a   8.1a   8.1a   6.0a   2.1a   6.6a   8.5a   6.0a   1.7a   4.7a   2.4a   
> 2.1a   8.5a   1.2a   1.7a   9.6a   8.6a  12.8a   9.5a  -2.8a   9.8a   4.7a  
> 10.7a   6.6a  11.2a-.9M"," 1919  5   16.4a   8.5a   9.4a   6.0a  10.7a   
> 9.8a   8.5a  13.6a  14.4a-.9M  16.4a  19.0a  23.2a  16.9a  17.0a  19.6a  
> 11.3a   9.4a  12.1a  17.2a  15.2a  17.0a  15.2a  17.5a  10.2a  22.6a  14.5a  
> 22.0a  24.9a  23.8a  19.0a"," 1919  6   17.7a  25.4a  31.2a  25.3a  26.8a  
> 22.0a  15.8a  19.0a  12.7a  19.6a  19.0a  24.5a  25.1a  27.4a  26.8a  19.0a  
> 20.8a  26.8a  27.9a  25.8a  20.1a  17.7a  19.0a  32.4a  30.7a  22.6!
 a !
>  19.0a  13.6a  17.5a  24.1a-.9M"," 1919  7   23.7a  24.4a  27.9a  29.6a  
> 23.7a  21.3a  23.7a  20.1a  23.7a  21.3a  17.0a  17.8a  23.7a  27.4a  18.2a  
> 23.2a  24.5a  26.2a  25.8a

Re: [R] Subset and sumerize

2016-10-14 Thread Mark Sharp
Ashta,

## I may have misunderstood your question and if so I apologize.

## I had to remove the extra line after "45" before
## the ",sep=" to use your code.
## You could have used dput(dat) to send a more reliable (robust) version.
dat <- structure(list(ID = c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L),
x1 = structure(c(1L, 5L, 5L, 5L, 2L, 5L, 3L, 4L, 5L, 5L), .Label = c("a",
"d", "g", "h", "x"), class = "factor"), x2 = structure(c(1L,
6L, 1L, 4L, 6L, 6L, 5L, 2L, 6L, 3L), .Label = c("b", "e",
"g", "k", "t", "z"), class = "factor"), y = c(15L, 21L, 16L,
25L, 31L, 28L, 41L, 32L, 38L, 45L)), .Names = c("ID", "x1",
"x2", "y"), class = "data.frame", row.names = c(NA, -10L))

# In your proposed solution "newdat" is never defined yet you are using it as 
if it were.

## It is my understanding that your goal is to define newdat as a
## subset of dat where x1 == "x" and x2 == "z".
## This can be done with one line.

newdat <- dat[dat$x1 == "x" & dat$x2 == "z", ]
newdat

> On Oct 14, 2016, at 1:26 PM, Ashta  wrote:
>
> Hi all,
>
> I am trying to summarize  big data set  by   selecting a row
> conditionally. and tried  to do it in a loop
>
> Here is  the sample of my data and my attempt
>
> dat<-read.table(text=" ID,x1,x2,y
> 1,a,b,15
> 1,x,z,21
> 1,x,b,16
> 1,x,k,25
> 2,d,z,31
> 2,x,z,28
> 2,g,t,41
> 3,h,e,32
> 3,x,z,38
> 3,x,g,45
> ",sep=",",header=TRUE)
>
> For  each unique ID,  I want to select  a data when x1= "x" and x2="z"
> Here is the selected data (newdat)
> ID,x1,x2,y
> 1,x,z,21
> 2,x,z,28
> 3,x,z,38
>
> Then I want summarize  Y values and out put as follows
> Summerize
> summary(newdat[i])
> ##
> ID   Min. 1st Qu.  MedianMean 3rd Qu.Max.
> 1
> 2
> 3
> .
> .
> .
> 28
> 
>
> Here is my attempt but did not work,
>
> trt=c(1:28)
> for(i  in 1:length (trt))
> {
>  day[i]= newdat[which(newdat$ID== trt[i] &  newdat$x1 =="x" &
> newdat$x2 =="z"),]
> NR[i]=dim(day[i])[1]
> print(paste("Number of Records  :", NR[i]))
> sm[i]=summary(day[i])
> }
>
> Thank you in advance
>
> __
> 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...{{dropped:10}}

__
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] need help in customising function in stat_summary function ggplot2

2016-10-20 Thread Mark Sharp
Indhira,

You have to assign cnt and new value in the loop if you want it to update in 
the loop. However, to count the number of values of x > median(x), there are 
multiple options. You are using a loop where none is needed in R, which has 
many implicit vector functions that run with relational operators and 
assignments.

x <- rnorm(10)
cnt <- sum(ifelse(x > median(x), 1, 0))

Because TRUE evaluates to 1 and FALSE evaluates to 0, you can also use
cnt <- sum(x > median(x))

I cannot help you with the ggplot question directly since you have not provided 
a definition of the object st_chg_51.

Mark

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







> On Oct 20, 2016, at 3:25 AM, Indhira, Anusha 
>  wrote:
>
> Hi,
>
> I would like to print percentage of points in a group which are greater than 
> median value in boxplot. I have tried below code but it always prints zero in 
> the graph. Can you let me know, how to modify code to get desired result?
>
>
> perc.greaterthan.median <- function(x){
>  cnt = 0
>  for(i in 1:length(x)){
>   ifelse(x[i] > median(x),cnt+1,cnt)
>  }
>  return(c(y = median(x)*1.7, label = round((cnt/length(x))*100,2)))
> }
>
> ggplot(st_chg_51, aes(x=factor(st_dv), P3))+ #label=rownames(st_chg_51))) +
>  geom_boxplot(fill = "grey80", colour = "#3366FF") +
>  stat_summary(fun.data = perc.greaterthan.median, geom = "text", fun.y = 
> median) +
>  theme_bw()+theme(axis.text = element_text(angle = 90, hjust = 1))
>
> Why does cnt in the function doesn't get incremented in the loop?
>
> Thanks,
> Anusha
>
> This e-mail (including attachments) contains contents owned by Rolls-Royce 
> plc and its subsidiaries, affiliated companies or customers and covered by 
> the laws of England and Wales, Brazil, US, or Canada (federal, state or 
> provincial). The information is intended to be confidential and may be 
> legally privileged. If you are not the intended recipient, you are hereby 
> notified that any retention, dissemination, distribution, interception or 
> copying of this communication is strictly prohibited and may subject you to 
> further legal action. Reply to the sender if you received this email by 
> accident, and then delete the email and any attachments.
>
> [[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...{{dropped:10}}

__
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] function which returns number of occurrences of a pattern in string

2016-10-20 Thread Mark Sharp
Jan,

Within the stringr package you can find the function str_count().

Mark


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







> On Oct 20, 2016, at 4:47 PM, Jan Kacaba  wrote:
>
> Hello dear R-help
>
> I tried to find function which returns number of occurrences of a pattern
> in string. The closest match I've found is str_locate_all in stringr
> package. I can use str_locate_all but write my function but I don't want
> reinvent wheel.
>
> JK
>
> [[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...{{dropped:10}}

__
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] using nested ifelse when i want to process values from more than 3 columns of data frame

2016-10-24 Thread Mark Sharp
Indira,

I think you are wanting to define a new column (target) with "all_true", 
"all_false", or "other" based on columns H1, H2, H3, and H8 all being equal to 
1, all being equal to 0, and other wise respectively. If so, then you do not 
need apply() or ifelse().

I believe this does what you were trying to do. I am not persuaded you are 
doing what you need to do.

kdata$target <- rep("other", nrow(kdata))
kdata$target[kdata$H1 == 0 &
 kdata$H2 == 0 &
 kdata$H3 == 0 &
 kdata$H8 == 0] <- "all_false"
kdata$target[kdata$H1 == 1 &
 kdata$H2 == 1 &
     kdata$H3 == 1 &
 kdata$H8 == 1] <- "all_true"

Mark

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








> On Oct 24, 2016, at 7:06 AM, Indhira, Anusha 
>  wrote:
>
> Got past the syntax error,now I got  new error below
>
> Error in match.fun(FUN) : c("'ifelse((kmeans.data$HBV51OpenDmd & 
> kmeans.data$HBV52OpenDmd & ' is not a function, character or symbol", "' 
> kmeans.data$HBV53OpenDmd & kmeans.data$HBV8OpenDmd) == 1, ' is not a 
> function, character or symbol", "' \"all-true\", 
> (ifelse((kmeans.data$HBV51OpenDmd == 0 & kmeans.data$HBV52OpenDmd == ' is not 
> a function, character or symbol", "' 0 & kmeans.data$HBV53OpenDmd == 0 & 
> kmeans.data$HBV8OpenDmd == ' is not a function, character or symbol", "' 0), 
> \"all-false\", \"other\")))' is not a function, character or symbol" )
>
>
> From: Indhira, Anusha
> Sent: 24 October 2016 12:56
> To: 'r-help@r-project.org'
> Subject: using nested ifelse when i want to process values from more than 3 
> columns of data frame
>
>
> Hi,
>
> I would like to process each row of data frame having 8 columns of which I am 
> interested in 4 columns for my analysis.I tried using apply function but I 
> get syntax error,although I checked for missing syntaxes ,couldn't figure out 
> the mistake.Can you also suggest me more efficient way to perform same action.
>
> # creating target column from result
> kdata$target <- apply(kdata,1,ifelse((kdata$H1 & kdata$H2 & kdata$H3 &
> kdata$H8) == 
> 1,"all-true",(ifelse(kdata$H1== 0 &
>   
>  kdata$H2 == 0 &
>   
>  kdata$H3 == 0 &
>   
>  kdata$H8 == 0) ,
>   
> "all-false","other")))
> Thanks.
> Alily
> This e-mail (including attachments) contains contents owned by Rolls-Royce 
> plc and its subsidiaries, affiliated companies or customers and covered by 
> the laws of England and Wales, Brazil, US, or Canada (federal, state or 
> provincial). The information is intended to be confidential and may be 
> legally privileged. If you are not the intended recipient, you are hereby 
> notified that any retention, dissemination, distribution, interception or 
> copying of this communication is strictly prohibited and may subject you to 
> further legal action. Reply to the sender if you received this email by 
> accident, and then delete the email and any attachments.
>
> [[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...{{dropped:10}}

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


Re: [R] About converting files in R

2016-10-25 Thread Mark Sharp
Lily,

Bob's suggestion is the best. You can also look at readBin(). Enter ?readBin at 
the R prompt.

Mark
R. Mark Sharp, Ph.D.
msh...@txbiomed.org





> On Oct 25, 2016, at 4:40 PM, Bob Rudis  wrote:
>
> I'm afraid we'll need more information that that since the answer from
> many folks on the list to such a generic question is going to be a
> generic "yes".
>
> What's the source of the binary files? If you know the type, there may
> even be an R package for it already.
>
> On Tue, Oct 25, 2016 at 5:28 PM, lily li  wrote:
>> Hi R users,
>>
>> Do any of you have any experience about converting binary files to ascii or
>> txt files in R? Thanks a lot for your help.
>>
>>[[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.

CONFIDENTIALITY NOTICE: This e-mail and any files and/or...{{dropped:10}}

__
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] lsa-cosine subscript out of bounds error

2016-10-28 Thread Mark Sharp
Anusha,

You have written to r-help multiple times and are still using HTML and failing 
to provide a reproducible example of your problem. Please read and comply with 
the posting guide.

Mark
R. Mark Sharp, Ph.D.
msh...@txbiomed.org





> On Oct 28, 2016, at 7:07 AM, Indhira, Anusha 
>  wrote:
>
> Hi,
>
> I have created a document term matrix from corpus.I would like to apply 
> Cosine similarity to find similar documents,when I apply cosine(w.mt) I get " 
> Error in x[,i] : Subscript out of bounds"
> Can anyone let me know how to overcome this error?
>
> Thanks,
> alily
> This e-mail (including attachments) contains contents owned by Rolls-Royce 
> plc and its subsidiaries, affiliated companies or customers and covered by 
> the laws of England and Wales, Brazil, US, or Canada (federal, state or 
> provincial). The information is intended to be confidential and may be 
> legally privileged. If you are not the intended recipient, you are hereby 
> notified that any retention, dissemination, distribution, interception or 
> copying of this communication is strictly prohibited and may subject you to 
> further legal action. Reply to the sender if you received this email by 
> accident, and then delete the email and any attachments.
>
> [[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...{{dropped:10}}

__
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] Alternative to "apply" in R 3.2.2

2016-11-11 Thread Mark Sharp
Olu,

I think you may have misread what na.rm is supposed to do. I think you are 
getting the correct value. If you want the vectors that contain NA values to be 
evaluated to NA then you will need to set na.rm to FALSE (which is the default 
for prod()).

prod(c(7, 2, NA), na.rm = TRUE)
[1] 14
prod(c(7, 2, NA), na.rm = FALSE)
[1] NA

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









> On Nov 11, 2016, at 2:45 PM, Olu Ola via R-help  wrote:
>
> Hello,I have a dataset that is similar to the one as follows:
>
>> Df.1 <- data.frame(A = c(5,4,7,6,8,4),B = 
>> (c(1,5,2,4,9,1)),C=(c(2,3,NA,5,NA,9)))
>> Df.1
>  A B  C
> 1 5 1  2
> 2 4 5  3
> 3 7 2 NA
> 4 6 4  5
> 5 8 9 NA
> 6 4 1  9
>> Df.1$D = apply(Df.1, 1, prod, na.rm=T)
>> Df.1$D[1]  10  60  14 120  72  36
>> Df.1
>  A B  C   D
> 1 5 1  2  10
> 2 4 5  3  60
> 3 7 2 NA  14
> 4 6 4  5 120
> 5 8 9 NA  72
> 6 4 1  9  36I intend to obtain a column D that takes into account na.rm=T but 
> 'apply' does not work in R 3.2.2
>
> A way forward will be greatly appreciated.
>
> [[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...{{dropped:10}}

__
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] Merging two columns of unequal length

2016-12-12 Thread Mark Sharp
I did not look at the code, but note the following.

By definition,
1. You cannot highlight code in plan text, which is the format accepted by 
r-help.
2. You cannot have columns of different lengths in a dataframe.


R. Mark Sharp, Ph.D.
msh...@txbiomed.org





> On Dec 12, 2016, at 5:41 PM, Bailey Hewitt  wrote:
>
> Dear R Help,
>
>
> I am trying to put together two columns of unequal length in a data frame. 
> Unfortunately, so far I have been unsuccessful in the functions I have tried 
> (such as cbind). The code I am currently using is : (I have highlighted the 
> code that is not working)
>
>
> y<- mydata[,2:75]
>
> year <- mydata$Year
>
> res <- data.frame()
>
> for (i in 1:74){
>
>  y.val <- y[,i]
>
>  lake.lm= lm(y.val ~ year)
>
>  lake.res=residuals(lake.lm)
>
>  new.res <- data.frame(lake.res=lake.res)
>
>  colnames(new.res) <- colnames(y)[i]
>
> #cbind doesn't work because of the unequal lengths of my data columns
>
>  res <- cbind(res, new.res)
>
>  print(res)
>
> }
>
>
> mydata is a csv file with "Year" from 1950 on as my first column and then 
> each proceeding column has a lake name and a day of year (single number) in 
> each row.
>
>
> Please let me know if there is any more information I can provide as I am new 
> to emailing in this list. Thank you for your time!
>
>
> Bailey Hewitt
>
> [[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...{{dropped:10}}

__
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] Urgent help

2016-12-27 Thread Mark Sharp
Please note that your message should be plain text and any attachments must be 
text and have a .txt extension. Your attached code was apparently removed 
because it did not have an extension of .txt.

It is best to include your code within the body of the message.

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









> On Dec 26, 2016, at 11:09 PM, amit rathee  
> wrote:
>
> I am trying to perform hierarchical clustering and evaluating it using 
> "ClusterCrit" Package, specially interested in precision and recall 
> for multi class problem, my code is attached.my problem is that in each 
> iteration even if my data is different in extCriteria() (used to evaluate 
> clustering based on various external criteria's) function but it is 
> giving same result every time.kindly helpthe program relies on data from 
> ClassCouplingData.txt file and it is read first as .csv file containing 32 by 
> 32 data and it contains only numeric data & not stringA Great thanks in 
> advance..AMIT 
> RATHEE __
> 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...{{dropped:10}}

__
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] Coverting HTML data into CSV

2017-01-20 Thread Mark Sharp
An example of your data will be very helpful. Saying that you have contents of 
an HTML file is not sufficiently descriptive. Note that the instructions 
recommend commented, minimal, self-contained, reproducible code. In leu of the 
HTML data file and code used to read it, you can use dput() with its argument 
being the object containing the HTML data.

Mark
R. Mark Sharp, Ph.D.
msh...@txbiomed.org





> On Jan 19, 2017, at 4:11 PM, El Polidan  wrote:
>
> Good evening,
>
>
> I need to convert and HTML data file into a CSV file.
>
>
> I managed to read the html files in R. Any pointers on how to convert  into a 
> readable data frame or csv?
>
>
> Thank you.
>
>
> Sent from Outlook<http://aka.ms/weboutlook>
>
> [[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...{{dropped:10}}

__
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] Save a generated .txt (or .csv) file on the desktop

2017-01-30 Thread Mark Sharp
You can define the "file" argument in your call to write.csv()

## This will write out a file named "test_file.csv" to your working directory
write.csv(tableau,file = "test_file.csv", row.names=FALSE)


R. Mark Sharp, Ph.D.
msh...@txbiomed.org





> On Jan 30, 2017, at 2:26 PM, varin sacha  wrote:
>
> Dear R-Experts,
>
> I have generated a data.frame. Now I would like to get it (the generated 
> data.frame) saved on my desktop (desktop of my computer) in a .csv or .txt 
> file. How can I proceed ?
>
> Many thanks.
>
> Here is the reproducible example :
>
>
>
> # Génération aléatoire des colonnes
> Individu<-1:50
> Genre<-sample(c("H","F"),50,replace=T)
> Age<-sample(18:45,50,replace=T)
> Pratique<-sample(c("PI","I","TI"),50,replace=T)
> Statut<-sample(c("C","M","D"),50, replace=T)
>
> # Génération du Data.frame "tableau" contenant les colonnes précédentes
> tableau <- data.frame(Individu,Genre,Age,Pratique,Statut)
>
> # Exportation du data.frame dans un fichier csv
> write.csv(tableau,row.names=FALSE)
>
>
>
> # Sauvegarder...save(tableau, file = "saveddf.txt")
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

CONFIDENTIALITY NOTICE: This e-mail and any files and/or attachments 
transmitted, may contain privileged and confidential information and is 
intended solely for the exclusive use of the individual or entity to whom it is 
addressed. If you are not the intended recipient, you are hereby notified that 
any review, dissemination, distribution or copying of this e-mail and/or 
attachments is strictly prohibited. If you have received this e-mail in error, 
please immediately notify the sender stating that this transmission was 
misdirected; return the e-mail to sender; destroy all paper copies and delete 
all electronic copies from your system without disclosing its contents.
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

[R] Failure to understand namespaces in XML::getNodeSet

2017-01-31 Thread Mark Sharp
I am trying to read a series of XML files that use a namespace and I have 
failed, thus far, to discover the proper syntax. I have a reproducible example 
below. I have two XML character strings defined: one without a namespace and 
one with. I show that I can successfully extract the node using the XML string 
without the namespace and fail when using the XML string with the namespace.

Mark
PS I am having the same problem with the xml2 package and am hoping 
understanding one with help with the other.

##
library(XML)
## The first XML text (no_ns_xml) does not have a namespace defined
no_ns_xml <- c("", "",
   "MFIA 9-Plex (CharlesRiver)",
   "")
l_no_ns_xml <-xmlTreeParse(no_ns_xml, asText = TRUE, getDTD = FALSE,
   useInternalNodes = TRUE)
## The node is found
getNodeSet(l_no_ns_xml, "/WorkSet//Description")

## The second XML text (with_ns_xml) has a namespace defined
with_ns_xml <- c("",
 "http://labkey.org/etl/xml\";>",
 "MFIA 9-Plex (CharlesRiver)",
 "")

l_with_ns_xml <-xmlTreeParse(with_ns_xml, asText = TRUE, getDTD = FALSE,
   useInternalNodes = TRUE)
## The node is not found
getNodeSet(l_with_ns_xml, "/WorkSet//Description")
## I attempt to provide the namespace, but fail.
ns <-  "http://labkey.org/etl/xml";
names(ns)[1] <- "xmlns"
getNodeSet(l_with_ns_xml, "/WorkSet//Description", namespaces = ns)

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









CONFIDENTIALITY NOTICE: This e-mail and any files and/or...{{dropped:10}}

__
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] Failure to understand namespaces in XML::getNodeSet

2017-01-31 Thread Mark Sharp
Hadley,

Thank you. I am able to get the xml_ns_strip() function to work with my file 
directly so I will likely be able to reach my immediate goal.

However, I still have had no success with understanding the namespace problem. 
I am not able to use read_xml() using the object I generated for the 
reproducible example, which is simply a character vector of length 4 having the 
contents of the XML file as produce by readLines(). I then used dput() to 
define the structure. The resulting structure apparently is not to the liking 
of read_xml(). I have reproduced the necessary code here for your convenience. 
There error is below.

##
library(xml2)
library(stringr)
with_ns_xml <- c("",
 "http://labkey.org/etl/xml\";>",
 "MFIA 9-Plex (CharlesRiver)",
 "")
## without str_c() collapse it complain of a vector of length > 1 also.
read_xml(str_c(with_ns_xml, collapse = TRUE))
Error in doc_parse_raw(x, encoding = encoding, base_url = base_url, as_html = 
as_html,  :
  Start tag expected, '<' not found [4]

## produces the following error message.
Error in doc_parse_raw(x, encoding = encoding, base_url = base_url, as_html = 
as_html,  :
  Start tag expected, '<' not found [4]

I have similar issues with xml2::xml_find_all
xml_find_all(str_c(with_ns_xml, collapse = TRUE), "/WorkSet//Description")

## Produces the following error message.
Error in UseMethod("xml_find_all") :
  no applicable method for 'xml_find_all' applied to an object of class 
"character"



R. Mark Sharp, Ph.D.
msh...@txbiomed.org





> On Jan 31, 2017, at 4:27 PM, Hadley Wickham  wrote:
>
> See the last example in ?xml2::xml_find_all or use xml2::xml2::xml_ns_strip()
>
> Hadley
>
> On Tue, Jan 31, 2017 at 9:43 AM, Mark Sharp  wrote:
>> I am trying to read a series of XML files that use a namespace and I have 
>> failed, thus far, to discover the proper syntax. I have a reproducible 
>> example below. I have two XML character strings defined: one without a 
>> namespace and one with. I show that I can successfully extract the node 
>> using the XML string without the namespace and fail when using the XML 
>> string with the namespace.
>>
>> Mark
>> PS I am having the same problem with the xml2 package and am hoping 
>> understanding one with help with the other.
>>
>> ##
>> library(XML)
>> ## The first XML text (no_ns_xml) does not have a namespace defined
>> no_ns_xml <- c("", "",
>>   "MFIA 9-Plex (CharlesRiver)",
>>   "")
>> l_no_ns_xml <-xmlTreeParse(no_ns_xml, asText = TRUE, getDTD = FALSE,
>>   useInternalNodes = TRUE)
>> ## The node is found
>> getNodeSet(l_no_ns_xml, "/WorkSet//Description")
>>
>> ## The second XML text (with_ns_xml) has a namespace defined
>> with_ns_xml <- c("",
>> "http://labkey.org/etl/xml\";>",
>> "MFIA 9-Plex (CharlesRiver)",
>> "")
>>
>> l_with_ns_xml <-xmlTreeParse(with_ns_xml, asText = TRUE, getDTD = FALSE,
>>   useInternalNodes = TRUE)
>> ## The node is not found
>> getNodeSet(l_with_ns_xml, "/WorkSet//Description")
>> ## I attempt to provide the namespace, but fail.
>> ns <-  "http://labkey.org/etl/xml";
>> names(ns)[1] <- "xmlns"
>> getNodeSet(l_with_ns_xml, "/WorkSet//Description", namespaces = ns)
>>
>> R. Mark Sharp, Ph.D.
>> Director of Data Science Core
>> Southwest National Primate Research Center
>> Texas Biomedical Research Institute
>> P.O. Box 760549
>> San Antonio, TX 78245-0549
>> Telephone: (210)258-9476
>> e-mail: msh...@txbiomed.org
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> CONFIDENTIALITY NOTICE: This e-mail and any files and/or...{{dropped:10}}
>>
>> __
>> 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.
>
>
>
> --
> http://hadley.nz

CONFIDENTIALITY NOTICE: This e-mail and any files and/or...{{dropped:10}}

__
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] Failure to understand namespaces in XML::getNodeSet

2017-01-31 Thread Mark Sharp
Hadley,

It’s sometimes amazing the mistakes I can make. No, it did not do what I 
wanted, which was
read_xml(str_c(with_ns_xml, collapse = “")

Reproducible example follows:
library(stringr)
library(xml2)
## Given the correct argument value for collapse, the next two lines work
no_ns <- read_xml(str_c(no_ns_xml, collapse = ""))
with_ns <- read_xml(str_c(with_ns_xml, collapse = ""))
## The next line finds the node in the XML without a namespace
xml_find_all(no_ns, "//WorkSet//Description")
## With a namespace designated in the XML
## Neither of the next two work, though I thought the second should
xml_find_all(with_ns, "//WorkSet//Description")
xml_find_all(with_ns, "/WorkSet//Description", ns = xml_ns(with_ns))
## Using xml_ns_strip() works as predicted
xml_find_all(xml_ns_strip(with_ns), "//WorkSet//Description")
## I was surprised to find the incorrect namespace value did not matter
xml_find_all(no_ns, "//WorkSet//Description", ns = xml_ns(with_ns))
## This also seems to ignore the namespace argument value
xml_find_all(xml_ns_strip(with_ns), "/WorkSet//Description", ns = 
xml_ns(with_ns))


Full output follows:
> ## Given the correct argument value for collapse, the next two lines work
> no_ns <- read_xml(str_c(no_ns_xml, collapse = ""))
> with_ns <- read_xml(str_c(with_ns_xml, collapse = ""))
> ## The next line finds the node in the XML without a namespace
> xml_find_all(no_ns, "//WorkSet//Description")
{xml_nodeset (1)}
[1] MFIA 9-Plex (CharlesRiver)
> ## With a namespace designated in the XML
> ## Neither of the next two work, though I thought the second should
> xml_find_all(with_ns, "//WorkSet//Description")
{xml_nodeset (0)}
> xml_find_all(with_ns, "/WorkSet//Description", ns = xml_ns(with_ns))
{xml_nodeset (0)}
> ## Using xml_ns_strip() works as predicted
> xml_find_all(xml_ns_strip(with_ns), "//WorkSet//Description")
{xml_nodeset (1)}
[1] MFIA 9-Plex (CharlesRiver)
> ## I was surprised to find the incorrect namespace value did not matter
> xml_find_all(no_ns, "//WorkSet//Description", ns = xml_ns(with_ns))
{xml_nodeset (1)}
[1] MFIA 9-Plex (CharlesRiver)
> ## This also seems to ignore the namespace argument value
> xml_find_all(xml_ns_strip(with_ns), "/WorkSet//Description", ns = 
> xml_ns(with_ns))
{xml_nodeset (1)}
[1] MFIA 9-Plex (CharlesRiver)
R. Mark Sharp, Ph.D.
msh...@txbiomed.org





> On Jan 31, 2017, at 5:52 PM, Hadley Wickham  wrote:
>
> I think you want
>
> x <- read_xml('
>  http://labkey.org/etl/xml";>
>  MFIA 9-Plex (CharlesRiver)
> ')
>
> The collapse argument do what you think it does.
>
> Hadley
>
> On Tue, Jan 31, 2017 at 5:36 PM, Mark Sharp  wrote:
>> Hadley,
>>
>> Thank you. I am able to get the xml_ns_strip() function to work with my file 
>> directly so I will likely be able to reach my immediate goal.
>>
>> However, I still have had no success with understanding the namespace 
>> problem. I am not able to use read_xml() using the object I generated for 
>> the reproducible example, which is simply a character vector of length 4 
>> having the contents of the XML file as produce by readLines(). I then used 
>> dput() to define the structure. The resulting structure apparently is not to 
>> the liking of read_xml(). I have reproduced the necessary code here for your 
>> convenience. There error is below.
>>
>> ##
>> library(xml2)
>> library(stringr)
>> with_ns_xml <- c("",
>> "http://labkey.org/etl/xml\";>",
>> "MFIA 9-Plex (CharlesRiver)",
>> "")
>> ## without str_c() collapse it complain of a vector of length > 1 also.
>> read_xml(str_c(with_ns_xml, collapse = TRUE))
>> Error in doc_parse_raw(x, encoding = encoding, base_url = base_url, as_html 
>> = as_html,  :
>>  Start tag expected, '<' not found [4]
>>
>> ## produces the following error message.
>> Error in doc_parse_raw(x, encoding = encoding, base_url = base_url, as_html 
>> = as_html,  :
>>  Start tag expected, '<' not found [4]
>>
>> I have similar issues with xml2::xml_find_all
>> xml_find_all(str_c(with_ns_xml, collapse = TRUE), "/WorkSet//Description")
>>
>> ## Produces the following error message.
>> Error in UseMethod("xml_find_all") :
>>  no applicable method for 'xml_find_all' applied to an object of class 
>> "character"
>>
>>
>>
>> R. Mark Sharp, Ph.D.
>> msh...@txbiomed.org
>>
>>
>>

Re: [R] Correlations Table of Items when compute Cronbach's Alpha

2017-02-21 Thread Mark Sharp
Have you looked at the help page?
?alpha::alpha

See the section labeled Value.

Look at
output <- alpha(data, keys = c(1, 1, 1, -1))
output$r
output$r.cor
output$r.drop


R. Mark Sharp, Ph.D.
msh...@txbiomed.org





> On Feb 21, 2017, at 9:43 AM, Steven Stoline  wrote:
>
> Dear All:
>
>
> I am using *alpha(data, **check.keys=TRUE)  or  alpha(data, keys = c(1, 1,
> 1, -1))*  to compute the Cronbach's Alpha. I am using  *check.keys=TRUE*
> or *keys = c(1, 1, 1, -1) *to automatically reverse items.
>
>
> *My question is: *how can I get the correlation tables (matrix) of the
> reversed items as part of the R output.
>
>
>
> *Here is an example of the data set:*
>
>
> X1 X2 X3 X4
>  2  5   4   4
>  1  1   1   6
>  1  2   1   6
>  2  3   2   4
>  1  2   1   6
>  1  3   1   6
>  2  2   2   5
>  2  1   1   6
>  2  2   4   5
>  5  5   2   1
>  1  3   1   6
>  1  1   1   6
>  1  1   1   6
>  2  2   2   5
>  2  2   2   2
>  1  6   1   6
>  1  2   1   6
>  2  2   3   5
>  2  5   4   5
>  2  1   2   6
>  2  2   1   5
>  2  2   2   6
>  1  1   1   6
>  1  1   1   6
>  1  1   1   5
>  1  2   2   5
>  2  2   2   5
>  1  2   2   5
>  1  4   2   5
>  2  2   2   2
>  2  2   4   5
>  2  1   2   5
>  2  2   2   5
>  2  2   2   5
>  2  2   2   5
>  2  2   2   5
>  5  2   2   5
>  2  2   1   5
>  2  5   6   2
>  2  4   2   5
>  2  2   2   4
>  2  3   5   1
>  3  3   3   6
>  2  2   2   4
>  2  2   2   5
>  2  2   2   5
>  1  1   1   6
>  1  1   1   5
>  6  1   1   6
>  1  1   1   6
>  2  6   4   3
>  1  1   1   6
>  1  1   1   6
>  4  5   5   5
>  5  2   2   5
>  2  2   2   5
>  1  2   1   6
>  1  5   1   6
>  1  4   2   5
>  2  1   1   5
>  4  2   1   5
>  2  2   2   5
>  1  1   1   6
>  6  1   1   4
>  1  2   1   6
>  1  1   1   5
>  1  1   1   6
>  1  4   1   3
>  1  1   1   6
>  5  2   2   5
>  2  2   2   5
>  1  1   1   6
>  1  1   1   5
>  4  4   2   4
>  3  2   2   5
>  1  2   1   6
>  1  2   1   6
>  2  1   1   5
>  2  6   1   6
>  4  3   1   5
>  1  1   1   5
>  1  1   1   6
>  4  5   4   5
>  1  1   1   2
>  1  1   1   6
>  1  1   1   6
>  4  4   3   4
>  2  2   2   4
>  1  2   2   4
>  1  1   1   6
>  2  3   2   5
>  2  6  NA   5
>  2  2   2   5
>  1  2   3   4
>  2  1   2   5
>  1  2   2   6
>  1  1   2   6
>  1  2   2   5
>  2  2   2   5
>  1  5   5   2
>  1  2   1   5
>  1  5   2   4
>  2  4   1   6
>  6  1   1   2
>  2  2   2   5
>  1  1   1   6
>  1  1   1   2
>  2  2   2   4
>  1  1   1   6
>  4  2   2   5
>  2  3   1   5
>  2  1   2   5
>  2  2   1   5
>  1  2   2   5
>  1  2   1   5
>  6  2   2   4
>  2  2   5   2
>  2  5   3   5
>  1  4   4   4
>  1  1   1   6
>
>
> thank you
> steve
>
> 
> Steven M. Stoline
> sstol...@gmail.com
>
> [[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...{{dropped:10}}

__
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] Reversing table()

2017-03-17 Thread Mark Sharp
Kevin,

The short answer is no.

The function table() takes in the vectors provided as arguments, counts the 
number of occurrences of each category by adding the integer 1L to a bin (one 
for each category or factor level), and at the end it returns the counts in 
each bin. Since it does not return the vectors, those values that went into the 
function do not survive the trip.

Mark
R. Mark Sharp, Ph.D.
msh...@txbiomed.org





> On Mar 17, 2017, at 7:23 AM, Kevin E. Thorpe  wrote:
>
> I am wondering if there is a way to undo the results of table().
>
> For example if you had a table that looked like the result of table(x, y) or
> table(x, y, z) is there a simple/elegant way to reverse the process to get the
> "original" x, y and z vectors?
>
> Thanks,
>
> Kevin
>
> --
> Kevin E. Thorpe
> Head of Biostatistics,  Applied Health Research Centre (AHRC)
> Li Ka Shing Knowledge Institute of St. Michael's Hospital
> Assistant Professor, Dalla Lana School of Public Health
> University of Toronto
> email: kevin.tho...@utoronto.ca  Tel: 416.864.5776  Fax: 416.864.3016
>
> __
> 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...{{dropped:10}}

__
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-27 Thread 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...{{dropped:10}}

__
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] Replace two nested loop with an apply kind of function

2013-08-24 Thread Mark Sharp

On Aug 23, 2013, at 3:33 PM, gi...@metu.edu.tr wrote:



Dear R users,

I am confused with the usage of apply kind of functions instead of nested
loops. Let me illustrate my problem, I have an array,named C, with
dimesions c(nr,nr,nt*n). I want to fill in a Tmat array according to the
rule as given below:

Tmat<-array(diag(nt*nr), c(nt*nr,nt*nr,n))

for( i in 1:n)  {
for( t in 2:nt) {
Tmat[(2*t-1):(2*t),(2*t-3):(2*t-2),i]<-C[,,(i*t)]
}
}

Instead of using two for loops, I want to use any apply kind of function,
but I couldn't figure it out. At this point, any help will be appreciated.
Thank you very much for your interest.


gul

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


[[alternative HTML version deleted]]

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


Re: [R] Replace two nested loop with an apply kind of function

2013-08-24 Thread Mark Sharp
The only reason to use one of the apply family of functions is because the 
idiom makes your code more clear. I do not see how that would be the case here. 
The apply functions are not typically any faster. If you really need speed the 
Rcpp package is very easy to use.

Mark
On Aug 23, 2013, at 3:33 PM, gi...@metu.edu.tr wrote:

> 
> 
> Dear R users,
> 
> I am confused with the usage of apply kind of functions instead of nested
> loops. Let me illustrate my problem, I have an array,named C, with
> dimesions c(nr,nr,nt*n). I want to fill in a Tmat array according to the
> rule as given below:
> 
> Tmat<-array(diag(nt*nr), c(nt*nr,nt*nr,n))
> 
> for( i in 1:n)  {
> for( t in 2:nt) {
> Tmat[(2*t-1):(2*t),(2*t-3):(2*t-2),i]<-C[,,(i*t)]
> }
> }
> 
> Instead of using two for loops, I want to use any apply kind of function,
> but I couldn't figure it out. At this point, any help will be appreciated.
> Thank you very much for your interest.
> 
> 
> gul
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Working with date

2012-12-29 Thread Mark Sharp
Ron,

I hope this will be helpful.

require(lubridate, quietly = TRUE)
require(stringr, quietly = TRUE)
test_date_str1 <- "6/3/2012"
test_date_1 <- mdy(test_date_str1, quiet = TRUE)
test_date_1
test_date_str2 <- "2-3-2011"
my_date_strings <- c(test_date_str1, test_date_str2)
my_dates <- mdy(my_date_strings, quiet = TRUE)
make_date <- function(.date, sep = "/") {
  str_c(month(.date), sep, day(.date), sep, year(.date))
}
make_date(test_date_1)
make_date(my_dates)


A slightly more complex function allows you to take more advantage of the 
lubridate package.

require(lubridate, quietly = TRUE)
require(stringr, quietly = TRUE)
test_date_str1 <- "6/3/2012"
test_date_1 <- mdy(test_date_str1, quiet = TRUE)
test_date_1
test_date_str2 <- "2-3-2011"
my_date_strings <- c(test_date_str1, test_date_str2)
my_dates <- mdy(my_date_strings, quiet = TRUE)
make_date <- function(.date, sep = "/", label = FALSE, abbr = TRUE) {
  str_c(month(.date, label, abbr), sep, day(.date), sep, year(.date))
}
make_date(test_date_1)
make_date(my_dates)
make_date(my_dates, sep = "-", label = TRUE)
make_date(my_dates, sep = " ", label = TRUE, abbr = FALSE)


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

On Dec 26, 2012, at 8:38 PM, Jim Holtman 
mailto:jholt...@gmail.com>> wrote:

what happens with   25/12/2012?

Sent from my iPad

On Dec 26, 2012, at 20:22, arun 
mailto:smartpink...@yahoo.com>> wrote:

Hi,
gsub("^\\d(.*/)\\d(.*/.*)","\\1\\2",format(asd,"%d/%m/%Y"))
#[1] "3/1/2012"
A.K.




- Original Message -
From: Ron Michael mailto:ron_michae...@yahoo.com>>
To: jim holtman mailto:jholt...@gmail.com>>
Cc: "r-help@r-project.org<mailto:r-help@r-project.org>" 
mailto:r-help@r-project.org>>
Sent: Wednesday, December 26, 2012 2:25 PM
Subject: Re: [R] Working with date

Thanks Jim for your reply.

However I want "3/1/2012" not "03/01/2012"

Any idea ?

Thanks


- Original Message -
From: jim holtman mailto:jholt...@gmail.com>>
To: Ron Michael mailto:ron_michae...@yahoo.com>>
Cc: "r-help@r-project.org<mailto:r-help@r-project.org>" 
mailto:r-help@r-project.org>>
Sent: Thursday, 27 December 2012 1:01 AM
Subject: Re: [R] Working with date

forgot you were asking for mdy format

# interchange day and month
format(asd, format = '%d/%m/%Y')
[1] "03/01/2012"



On Wed, Dec 26, 2012 at 2:14 PM, jim holtman 
mailto:jholt...@gmail.com>> wrote:
try this:

asd <- as.Date("2012-01-03")
asd
[1] "2012-01-03"
format(asd, format = '%m/%d/%Y')
[1] "01/03/2012"




On Wed, Dec 26, 2012 at 1:31 PM, Ron Michael 
mailto:ron_michae...@yahoo.com>> wrote:
asd <- as.Date("2012-01-03")



--
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.



--
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.


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


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

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


[[alternative HTML version deleted]]

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


Re: [R] Pattern match

2013-03-20 Thread Mark Sharp
I like the stringr package. Its functions allow vectors for the patterns. 

>From the examples of str_detect()
> fruit <- c("apple", "banana", "pear", "pinapple")
> str_detect(fruit, "a")
[1] TRUE TRUE TRUE TRUE
> str_detect(fruit, "^a")
[1]  TRUE FALSE FALSE FALSE
> str_detect(fruit, "a$")
[1] FALSE  TRUE FALSE FALSE
> str_detect(fruit, "b")
[1] FALSE  TRUE FALSE FALSE
> str_detect(fruit, "[aeiou]")
[1] TRUE TRUE TRUE TRUE
> 
> # Also vectorised over pattern
> str_detect("aecfg", letters)
 [1]  TRUE FALSE  TRUE FALSE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE 
FALSE FALSE FALSE FALSE FALSE
[18] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE

R. Mark Sharp
msh...@txbiomed.org




On Mar 20, 2013, at 11:28 AM, Christofer Bogaso wrote:

> Hello again, in the help page of grep() function, it is written that
> 
> pattern:
> 
> character string containing a regular expression (or character string
> for fixed = TRUE) to be matched in the given character vector. Coerced
> by as.character to a character string if possible. If a character
> vector of length 2 or more is supplied, the first element is used with
> a warning. Missing values are allowed except for regexpr and gregexpr.
> 
> But I have a vetcor of length '(> 1)' for the pattern match, and I
> need to have approximate match.
> 
> Is there any function similar to grep() to handle that?
> 
> Thanks for your help.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] (no subject)

2013-04-05 Thread Mark Sharp
Ana,

I cannot help you with how to include weights in your analysis. However, you 
can use formals(poLCA) or ?poLCA to see that weights is not one of the 
acceptable arguments. R ignores arguments not used by the called function 
because functions within the called function may use them.

You can probably have (weights = "no weights here") in your function call and 
get the same result.

Mark
R. Mark Sharp
msh...@txbiomed.org<mailto:msh...@txbiomed.org>




On Apr 3, 2013, at 3:48 AM, Ana Lucía Cárdenas Martínez wrote:

Hello,

I want to perform a latent class analysis using poLCA package. My formula
is:

substances <- cbind(subs1, subs2, subs3, subs4, subs5, subs6) ~
gender+age+education+income+occupation+urban+dbehavior+incarceration+treatment+depression+alcriteria

I want to include sample weights in the model, I have read that poLCA does
not take into account weights, but when I introduce them, it seems that the
model is running correctly. This is the command I am using:

lca2 <- poLCA(substances, ena, nclass=2, graphs=TRUE, maxiter=2000,
(weights=p_adicc))

my question is, if the results are really taking into account the weights ?
if not, how can I introduce weights into my analysis?

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


[[alternative HTML version deleted]]

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


[R] forming function arguments from strings

2011-01-01 Thread Mark Sharp
I am wanting to change arguments to a function dynamically. For example, in 
making a call to qplot, I want to dynamically define all of the arguments so 
that I can create the plot dependent on user input. I have played with eval() a 
bit, but have had no success.

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


Re: [R] Calendar in R-program

2011-01-04 Thread Mark Sharp
Look at the lubridate package from Hadley Wickham for great basic routines for 
handling date objects.

Mark
R. Mark Sharp, Ph.D.
msh...@sfbr.org<mailto:msh...@sfbr.org>




On Jan 4, 2011, at 8:02 AM, LOON88 wrote:


Hey.
I have to do calendar in program R. I was looking for examples on this forum
but havent found it. Can someone help me in this thing ? I would be really
appreciate for that. Calendar should be the same as we have in Windows but I
really dont know how to begin it. Hope u can show me the best way to do it.
Cheers
--
View this message in context: 
http://r.789695.n4.nabble.com/Calendar-in-R-program-tp3173566p3173566.html
Sent from the R help mailing list archive at Nabble.com<http://Nabble.com>.

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


[[alternative HTML version deleted]]

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


Re: [R] question about creating data frame

2012-06-14 Thread Mark Sharp
Below are two equivalent solutions.

study_df <- data.frame(course = c(rep('Mathematics', 80 + 15),
  rep('Physics', 32 + 24),
  rep('Biology', 18 + 29)),
   A = c(rep(1, 80), rep(0, 15),
 rep(1, 32), rep(0, 24),
 rep(1, 18), rep(0, 29)))

and
my_courses <- c(rep('Mathematics', 80 + 15),
rep('Physics', 32 + 24),
rep('Biology', 18 + 29))
my_A <- c(rep(1, 80), rep(0, 15), rep(1, 32), rep(0, 24),
  rep(1, 18), rep(0, 29))

study_df <- data.frame(course = my_courses, A = my_A)




R. Mark Sharp
msh...@txbiomed.org<mailto:msh...@txbiomed.org>




On May 15, 2012, at 2:09 PM, T Bal wrote:

Hello,



My data is "study.txt":



"A" "Not A"
"Mathematics" 80 15
"Physics" 32 24
"Biology" 18 29





I want to transform this data into with column names 'course' and 'A':



  course   A

1   Mathematics  1

2   Mathematics  1

..  .. ..

   80  Mathematics  1

   81  Mathematics  0

   ...    ...

   95  Mathematics  0

   96  Physics  1

...   ...

  127 Physics  1
  128 Physics  0

  ...  ...

  151  Physics 0



   etc.



How should I do it? So this data frame will consist from 198 rows.



Thank you very much.



kind regards,

T. Bal

[[alternative HTML version deleted]]

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


[[alternative HTML version deleted]]

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


Re: [R] save to Rdata file and to txt

2012-06-14 Thread Mark Sharp
Though not exactly what you asked for, I find the output of dput() to be useful
dput(moransl, file = "moransl.txt")

results in 
list("Moran.I.First", structure(list(observed = 0.06988288, expected = 
-0.03225806, 
sd = 0.02513276, p.value = 4.822722e-05), .Names = c("observed", 
"expected", "sd", "p.value")))

R. Mark Sharp
msh...@txbiomed.org




On May 15, 2012, at 12:35 PM, David L Carlson wrote:

> capture.output(moransI, file="moransI.txt")
> 
> 
> --
> David L Carlson
> Associate Professor of Anthropology
> Texas A&M University
> College Station, TX 77843-4352
> 
> 
>> -Original Message-
>> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
>> project.org] On Behalf Of Alaios
>> Sent: Tuesday, May 15, 2012 12:10 PM
>> To: R help
>> Subject: [R] save to Rdata file and to txt
>> 
>> Dear all,
>> I am using the
>> 
>> 
>> save(moransI,file=saveString) to save a variable called moransI to a
>> file.
>> This works well but unfortunately I have to open R every time I want to
>> look to the contents.
>> 
>> Would it be also possible to have a second line that saves the contents
>> of the moransI variable in a normal txt file?
>> The ideal is inside the txt file to get what you see in R's console
>> when you print the moransI variable.
>> So something like that
>> 
>> moransI
>> [[1]]
>> [1] "Moran.I.First"
>> 
>> [[2]]
>> [[2]]$observed
>> [1] 0.06988288
>> 
>> [[2]]$expected
>> [1] -0.03225806
>> 
>> [[2]]$sd
>> [1] 0.02513276
>> 
>> [[2]]$p.value
>> [1] 4.822722e-05
>> 
>> 
>> 
>> Cheers
>> Alex
>> 
>>  [[alternative HTML version deleted]]
>> 
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-
>> guide.html
>> and provide commented, minimal, self-contained, reproducible code.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Timezone problem with 3.4.2

2017-11-30 Thread R. Mark Sharp
Dennis,

Brian Ripley pointed out shortly after 3.4.2 was released that the timezone was 
not being set correctly because of last minute changes to MacOS. You will have 
to install 3.4.3. I am waiting for the native installer, which will likely be 
out within a few days.

Mark
R. Mark Sharp, Ph.D.
Data Scientist and Biomedical Statistical Consultant
7526 Meadow Green St.
San Antonio, TX 78251
mobile: 210-218-2868
rmsh...@me.com










> On Nov 30, 2017, at 8:47 PM, Dennis Fisher  wrote:
> 
> Mark
> 
> Thanks for pointing this out.  I did a default installation of R.  Does this 
> mean that I need to reinstall from the command line?
> 
> Dennis
> 
> Dennis Fisher MD
> P < (The "P Less Than" Company)
> Phone / Fax: 1-866-PLessThan (1-866-753-7784)
> www.PLessThan.com <http://www.plessthan.com/>
> 
> 
> 
> 
>> On Nov 30, 2017, at 6:42 PM, R. Mark Sharp  wrote:
>> 
>> From Peter Dalgaard announcement earlier today.
>> 
>> 
>> CHANGES IN R 3.4.3:
>> 
>> INSTALLATION on a UNIX-ALIKE:
>> 
>>  * A workaround has been added for the changes in location of
>>time-zone files in macOS 10.13 'High Sierra' and again in
>>10.13.1, so the default time zone is deduced correctly from the
>>system setting when R is configured with --with-internal-tzcode
>>(the default on macOS).
>> 
>> R. Mark Sharp, Ph.D.
>> Data Scientist and Biomedical Statistical Consultant
>> 7526 Meadow Green St.
>> San Antonio, TX 78251
>> mobile: 210-218-2868
>> rmsh...@me.com
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>>> On Nov 30, 2017, at 8:37 PM, Dennis Fisher  wrote:
>>> 
>>> Colleagues
>>> 
>>> I just installed 3.4.2 on a Mac running High Sierra.
>>> 
>>> I encountered the following:
>>> 
>>> R version 3.4.2 (2017-09-28) -- "Short Summer"
>>> Copyright (C) 2017 The R Foundation for Statistical Computing
>>> Platform: x86_64-apple-darwin15.6.0 (64-bit)
>>> 
>>> R is free software and comes with ABSOLUTELY NO WARRANTY.
>>> You are welcome to redistribute it under certain conditions.
>>> Type 'license()' or 'licence()' for distribution details.
>>> 
>>> Natural language support but running in an English locale
>>> 
>>> R is a collaborative project with many contributors.
>>> Type 'contributors()' for more information and
>>> 'citation()' on how to cite R or R packages in publications.
>>> 
>>> Type 'demo()' for some demos, 'help()' for on-line help, or
>>> 'help.start()' for an HTML browser interface to help.
>>> Type 'q()' to quit R.
>>> 
>>>> Sys.Date()
>>> [1] "2017-12-01"
>>> Warning message:
>>> In as.POSIXlt.POSIXct(Sys.time()) :
>>> unknown timezone 'zone/tz/2017c.1.0/zoneinfo/America/Los_Angeles'
>>> 
>>> There is nothing odd about the date/time settings on the computer.
>>> 
>>> I then tried:
>>>> Sys.timezone()
>>> [1] NA
>>> 
>>> Previously, there was not a problem with timezones.
>>> 
>>> Can I override this?
>>> 
>>> Any thoughts?
>>> 
>>> Dennis
>>> 
>>> Dennis Fisher MD
>>> P < (The "P Less Than" Company)
>>> Phone / Fax: 1-866-PLessThan (1-866-753-7784)
>>> www.PLessThan.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.
>>> 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

Re: [R] Timezone problem with 3.4.2

2017-11-30 Thread R. Mark Sharp
>From Peter Dalgaard announcement earlier today.


CHANGES IN R 3.4.3:

 INSTALLATION on a UNIX-ALIKE:

   * A workaround has been added for the changes in location of
 time-zone files in macOS 10.13 'High Sierra' and again in
 10.13.1, so the default time zone is deduced correctly from the
 system setting when R is configured with --with-internal-tzcode
 (the default on macOS).

R. Mark Sharp, Ph.D.
Data Scientist and Biomedical Statistical Consultant
7526 Meadow Green St.
San Antonio, TX 78251
mobile: 210-218-2868
rmsh...@me.com










> On Nov 30, 2017, at 8:37 PM, Dennis Fisher  wrote:
> 
> Colleagues
> 
> I just installed 3.4.2 on a Mac running High Sierra.
> 
> I encountered the following:
> 
> R version 3.4.2 (2017-09-28) -- "Short Summer"
> Copyright (C) 2017 The R Foundation for Statistical Computing
> Platform: x86_64-apple-darwin15.6.0 (64-bit)
> 
> R is free software and comes with ABSOLUTELY NO WARRANTY.
> You are welcome to redistribute it under certain conditions.
> Type 'license()' or 'licence()' for distribution details.
> 
>  Natural language support but running in an English locale
> 
> R is a collaborative project with many contributors.
> Type 'contributors()' for more information and
> 'citation()' on how to cite R or R packages in publications.
> 
> Type 'demo()' for some demos, 'help()' for on-line help, or
> 'help.start()' for an HTML browser interface to help.
> Type 'q()' to quit R.
> 
>> Sys.Date()
> [1] "2017-12-01"
> Warning message:
> In as.POSIXlt.POSIXct(Sys.time()) :
>  unknown timezone 'zone/tz/2017c.1.0/zoneinfo/America/Los_Angeles'
> 
> There is nothing odd about the date/time settings on the computer.
> 
> I then tried:
>> Sys.timezone()
> [1] NA
> 
> Previously, there was not a problem with timezones.
> 
> Can I override this?
> 
> Any thoughts?
> 
> Dennis
> 
> Dennis Fisher MD
> P < (The "P Less Than" Company)
> Phone / Fax: 1-866-PLessThan (1-866-753-7784)
> www.PLessThan.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.
> CONFIDENTIALITY NOTICE: This e-mail and any files and/or attachments 
> transmitted, may contain privileged and confidential information and is 
> intended solely for the exclusive use of the individual or entity to whom it 
> is addressed. If you are not the intended recipient, you are hereby notified 
> that any review, dissemination, distribution or copying of this e-mail and/or 
> attachments is strictly prohibited. If you have received this e-mail in 
> error, please immediately notify the sender stating that this transmission 
> was misdirected; return the e-mail to sender; destroy all paper copies and 
> delete all electronic copies from your system without disclosing its contents.

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


Re: [R] require help

2017-12-27 Thread R. Mark Sharp
Yadav,

We need some information that is missing in order to help you.


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

Mark
R. Mark Sharp, Ph.D.
Data Scientist and Biomedical Statistical Consultant
7526 Meadow Green St.
San Antonio, TX 78251
mobile: 210-218-2868
rmsh...@me.com










> On Dec 27, 2017, at 2:05 PM, yadav neog  wrote:
> 
> Respected sir,
> hoping that you are well.sir, i am trying to run Tado-Yamamoto causality
> test with my data. I have three variables. but in running wal.test in R, I
> have faced problems (especially in 'terms' arguments). my results have
> shown as...
> 
> Error in L %*% V : non-conformable arguments
> 
> -- kindly help me in solving this issue. I have also attached my codes
> and data to this email.
> 
> 
> Yadawananda Neog
> Research Scholar
> Department of Economics
> Banaras Hindu University
> Mob. 9838545073
> 
> 2 Attachments
> 
> 
> 
> -- 
> Yadawananda Neog
> Research Scholar
> Department of Economics
> Banaras Hindu University
> Mob. 9838545073
> __
> 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] Creating list or numeric vectors out of selected columns of row oriented data

2009-01-27 Thread R. Mark Sharp
I am just assuming this can be done, but I have not gotten close to  
making it happen. I have a data file with about 1 million rows with  
1470 unique subjects. Each row represents a small set of observations  
made on a specific date for a single subject. I would like to  
transform the data so that I have an R object with a single entry for  
each subject and start date and vectors for the observation dates and  
the observations. The data are something like the following where for  
each subject the subject_id does not change and the start_date does  
not change, but the obeservation_date and the three different  
observations change between rows. (There is one row for each day for  
each subject over a three year period although some entered the study  
late):
'subject_id', 'start_date','observation_date','weight_obs',  
'activity_obs','calories_obs'
1,'1/1/2005','1/1/2005',3.26,'a',93
1,'1/1/2005','1/2/2005',3.22,'o',85
1,'1/1/2005','1/3/2005',3.28,'o',91
...
1,'1/1/2005','12/31/2008',4.38,'h',102
2,'2/13/2005','2/13/2005',3.02,'l',80
2,'2/13/2005','2/14/2005',3.08,'j',85
...

Any guidance is appreciated.

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




[[alternative HTML version deleted]]

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


Re: [R] Making objects global in a package

2018-07-13 Thread R. Mark Sharp via R-help
I would usually use a function for this. It may not be more R like, but it is 
more readable to me. If you want, to keep the columns in a file, you could have 
the function initialize itself on the first call. 

Mark
R. Mark Sharp, Ph.D.
Data Scientist and Biomedical Statistical Consultant
7526 Meadow Green St.
San Antonio, TX 78251
mobile: 210-218-2868
rmsh...@me.com











> On Jul 13, 2018, at 7:51 PM, Michael Hannon  
> wrote:
> 
> Greetings.  I'm putting together a small package in which I use
> `dplyr::read_csv()` to read CSV files from several different sources.  I do
> this in several different files, but with various kinds of subsequent
> processing, depending on the file.
> 
> I find it useful to specify column types, as the apparent data type of a given
> column sometimes changes unexpectedly deep into the file.  I.e., a field that
> consistently looks like an integer, suddenly becomes a fraction:
> 
>1, 1, ..., 1, 1/2, 1, ...
> 
> Hence, the column type has to be treated as a character, rather than as an
> integer (with the possibility of later conversion to double, if necessary).
> (This is just an example.)
> 
> Therefore I use the `col_types` argument in all of the calls to `read_csv()`.
> 
> These calls are spread over several files, but I want the keep all of the
> column types in a single place, yet have them available in each of the several
> files.  This is just for the sake of maintainability.
> 
> At the moment I do this by putting the column-type definitions into a single,
> file:
> 
>000_define_data_attributes.R
> 
> that:
> 
>(1) is named so that it's parsed first by `devtools::build()`
>(2) sets up an environment and stuffs the column types into it:
> 
>data_env <- new.env(parent=emptyenv())
>data_env$col_types_alpha <- list(
>Date = col_date(),
>var1 = col_double(),
>...
>)
> 
> There are a few other things that go into the file as well.
> 
> Then I pick off the appropriate stuff from the environment in the other files:
> 
>foo_alpha <- read_csv("alpha.csv", col_types = data_env$col_types_alpha)
> 
> This seems to work, but it doesn't "feel" right to me.  (If this were Python,
> people would accuse me of being "non-pythonic").
> 
> Hence, I'm seeking suggestions for the best practice for this kind of thing.
> 
> BTW, I note that both the sources of data ("alpha", etc.) and the column types
> are more or less guaranteed to be static for the foreseeable future.  Hence,
> there really isn't much danger in just replicating the column-type definitions
> in each of the various files, which would obviate the need for the "000..."
> file.  In other words, this is mostly a style thing.
> 
> Thanks for any advice you can provide.
> 
> -- Mike
> 
> __
> 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] help

2018-08-10 Thread R. Mark Sharp via R-help
Marco,

The error message indicates that nlon*nlat is 420 and that 1378620/420 has a 
remainder. For the matrix to form, all rows have to be complete. 

I am guessing you have at least one value incorrect among nlon, nlat, t or the 
length of fulldatav.

Mark
R. Mark Sharp, Ph.D.
Data Scientist and Biomedical Statistical Consultant
7526 Meadow Green St.
San Antonio, TX 78251
mobile: 210-218-2868
rmsh...@me.com











> On Aug 10, 2018, at 10:00 AM, Marco Antonio Pérez  
> wrote:
> 
> I am trying to write a function to make a matrix of precipitation with
> this secuencie;
>  PRIMER PERIODO
> cordex1 <-
> nc_open("pr_CAM-44i_ICHEC-EC-EARTH_rcp45_r12i1p1_SMHI-RCA4_v1_mon_200601-201012.nc")
> fullmon1<-ncvar_get(cordex1,"pr")
> lat<-ncvar_get(cordex1,"lat", start=c(35.5),count=c(20))
> lon <-ncvar_get(cordex1,"lon", start=c(125),count=c(21.5))
> t <- ncvar_get(cordex1,"time")
> nlon <- dim(lon)
> nlat <- dim(lat)
> nt <- dim(t)
> fulldatav <- as.vector(fullmon1)
> fulldata <- matrix(fulldatav, nrow=nlon*nlat, ncol=nt)
> lonlat <- expand.grid(lon,lat)
> df_cordex1<- data.frame(lonlat,fulldata)
> 
> but with the expresion  fulldata <- matrix(fulldatav, nrow=nlon*nlat,
> ncol=nt) this error appears
> Warning message:
> In matrix(fulldatav, nrow = nlon * nlat, ncol = nt) :
>  data length [1378620] is not a sub-multiple or multiple of the number of
> rows [420]
> 
> Somebody help me!!!
> 
>   [[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] Writing .nc files

2018-08-28 Thread R. Mark Sharp via R-help
Marco,

Always post to the r-help list to have a better chance of finding someone that 
can help.

There is a very nice tutorial that you should have found. See 
http://geog.uoregon.edu/bartlein/courses/geog490/week04-netCDF.html#create-and-write-a-netcdf-file

Mark
R. Mark Sharp, Ph.D.
Data Scientist and Biomedical Statistical Consultant
7526 Meadow Green St.
San Antonio, TX 78251
mobile: 210-218-2868
rmsh...@me.com











> On Aug 28, 2018, at 8:26 AM, R. Mark Sharp  wrote:
> 
> Marco,
> 
> You will need to ask the list. I have never worked with .nc files.
> 
> Most are wanting to go the other direction .nc to .csv or dataframe. Google 
> search with “.nc file in r”.
> 
> R. Mark Sharp, Ph.D.
> Data Scientist and Biomedical Statistical Consultant
> 7526 Meadow Green St.
> San Antonio, TX 78251
> mobile: 210-218-2868
> rmsh...@me.com
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
>> On Aug 27, 2018, at 10:12 AM, Marco Antonio Pérez  
>> wrote:
>> 
>> Hello Mark:
>> 
>> I appreciate your sopport in this subject. But now, I need your help again, 
>> please. 
>> I wondering if you know how to transform a .csv file to .nc file_
>> 
>> Thanks a lot!!
>> 
>> 2018-08-10 17:08 GMT-03:00 R. Mark Sharp :
>> Marco,
>> 
>> The error message indicates that nlon*nlat is 420 and that 1378620/420 has a 
>> remainder. For the matrix to form, all rows have to be complete. 
>> 
>> I am guessing you have at least one value incorrect among nlon, nlat, t or 
>> the length of fulldatav.
>> 
>> Mark
>> R. Mark Sharp, Ph.D.
>> Data Scientist and Biomedical Statistical Consultant
>> 7526 Meadow Green St.
>> San Antonio, TX 78251
>> mobile: 210-218-2868
>> rmsh...@me.com
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>>> On Aug 10, 2018, at 10:00 AM, Marco Antonio Pérez  
>>> wrote:
>>> 
>>> I am trying to write a function to make a matrix of precipitation with
>>> this secuencie;
>>>  PRIMER PERIODO
>>> cordex1 <-
>>> nc_open("pr_CAM-44i_ICHEC-EC-EARTH_rcp45_r12i1p1_SMHI-RCA4_v1_mon_200601-201012.nc")
>>> fullmon1<-ncvar_get(cordex1,"pr")
>>> lat<-ncvar_get(cordex1,"lat", start=c(35.5),count=c(20))
>>> lon <-ncvar_get(cordex1,"lon", start=c(125),count=c(21.5))
>>> t <- ncvar_get(cordex1,"time")
>>> nlon <- dim(lon)
>>> nlat <- dim(lat)
>>> nt <- dim(t)
>>> fulldatav <- as.vector(fullmon1)
>>> fulldata <- matrix(fulldatav, nrow=nlon*nlat, ncol=nt)
>>> lonlat <- expand.grid(lon,lat)
>>> df_cordex1<- data.frame(lonlat,fulldata)
>>> 
>>> but with the expresion  fulldata <- matrix(fulldatav, nrow=nlon*nlat,
>>> ncol=nt) this error appears
>>> Warning message:
>>> In matrix(fulldatav, nrow = nlon * nlat, ncol = nt) :
>>> data length [1378620] is not a sub-multiple or multiple of the number of
>>> rows [420]
>>> 
>>> Somebody help me!!!
>>> 
>>>  [[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] wanting to count instances of values in each cell of a series of simulated symmetric matrices of the same size

2021-06-01 Thread R. Mark Sharp via R-help
I want to capture the entire distribution of values for each cell in a sequence 
of symmetric matrices of the same size. The diagonal values are all 0.5 so I 
need only the values above or below the diagonal. 

A small example with three of the structures I am wanting to count follows:
   F  G  H  I J
F 0.6250 0.3750 0.2500 0.1875 0.125
G 0.3750 0.6250 0.2500 0.1875 0.125
H 0.2500 0.2500 0.5000 0.1875 0.125
I 0.1875 0.1875 0.1875 0.5000 0.250
J 0.1250 0.1250 0.1250 0.2500 0.500

   F  G  H  I J
F 0.5625 0.3125 0.1875 0.1250 0.125
G 0.3125 0.5625 0.1875 0.1250 0.125
H 0.1875 0.1875 0.5000 0.1875 0.125
I 0.1250 0.1250 0.1875 0.5000 0.250
J 0.1250 0.1250 0.1250 0.2500 0.500

F   G  H   I  J
F 0.5 0.25000 0.1250 0.09375 0.0625
G 0.25000 0.5 0.1250 0.09375 0.0625
H 0.12500 0.12500 0.5000 0.18750 0.1250
I 0.09375 0.09375 0.1875 0.5 0.2500
J 0.06250 0.06250 0.1250 0.25000 0.5000


To be more specific, I have coded up a solution for a single cell with the 
sequence of values (one from each matrix) in a vector. 

I used match() below and it works with a matrix but I do not know how to do 
what is in the if statements with matrices. Since the number of values and the 
values will be different among the various cells a simple array structure does 
not seem appropriate and I am assuming I will need to use a list but I would 
like to do as much as I can with matrices for speed and clarity.

#' Counts the number of occurrences of each kinship value seen for a pair of
#' individuals.
#'
#' @examples
#' \donttest{
#' set.seed(20210529)
#' kSamples <- sample(c(0, 0.0675, 0.125, 0.25, 0.5, 0.75), 1, replace = 
TRUE,
#'prob = c(0.005, 0.3, 0.15, 0.075, 0.0375, 0.01875))
#' kVC <- list(kinshipValues = numeric(0),
#' kinshipCounts = numeric(0))
#' for (kSample in kSamples) {
#'   kVC <- countKinshipValues(kSample, kVC$kinshipValues, kVC$kinshipCounts)
#' }
#' kVC
#' ## $kinshipValues
#' ## [1] 0.2500 0.1250 0.0675 0.7500 0.5000 0.
#' ##
#' ## $kinshipCounts
#' ## [1]  301 2592 5096 1322  592   97
#' }
#'
#' @param kValue numeric value being counted (kinship value in
#' \emph{nprcgenekeepr})
#' @param kinshipValues vector of unique values of \code{kValue} seen
#' thus far.
#' @param kinshipCounts vector of the counts of the unique values of
#' \code{kValue} seen thus far.
#' @export
countKinshipValues <- function(kValue, kinshipValues = numeric(0),
  kinshipCounts = numeric(0)) {
  kinshipValue <- match(kValue, kinshipValues, nomatch = -1L)
  if (kinshipValue == -1L) {
kinshipValues <- c(kinshipValues, kValue)
kinshipCounts[length(kinshipCounts) + 1] <- 1
  } else {
    kinshipCounts[kinshipValue] <- kinshipCounts[kinshipValue] + 1
  }
  list(kinshipValues = kinshipValues,
   kinshipCounts = kinshipCounts)
}

Mark


R. Mark Sharp, Ph.D.
Data Scientist and Biomedical Statistical Consultant
7526 Meadow Green St.
San Antonio, TX 78251
mobile: 210-218-2868
rmsh...@me.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] wanting to count instances of values in each cell of a series of simulated symmetric matrices of the same size

2021-06-01 Thread R. Mark Sharp via R-help
Bert, 

You are obviously correct about the diagonals. I was not thinking carefully. 
Typically they are expected to be at or near 0.5 in an outbred population but 
can theoretically go to 1.0 in completely inbred populations. This was subset 
from a madeup pedigree and I reused parents, hence the inbreeding.

Space is a concern since I will need to simulate more matrices for the same 
precision as the matrices (breeding populations) increase in size. However, I 
will certainly look into your suggestion. I am doing this on the side so it may 
take a few days.

Thank you for your kind attention. I will provide more definitive feedback 
later.

Mark
R. Mark Sharp, Ph.D.
Data Scientist and Biomedical Statistical Consultant
7526 Meadow Green St.
San Antonio, TX 78251
mobile: 210-218-2868
rmsh...@me.com











> On Jun 1, 2021, at 10:44 PM, Bert Gunter  wrote:
> 
> Come again?! The diagonal values in your example are not all .5.
> 
> If space is not an issue, a straightforward approach is to collect all the 
> matrices into a 3d array and use indexing.
> Here is a simple reprex (as you did not provide one in a convenient form, e.g 
> via dput())
> 
> x <- matrix(1:9, nr = 3); y <- x+10
> diag(x) <- diag(y) <- 0
> print(x) ; print(y)
> ## Now you need to populate a 3 x 3 x 2 array with these matrices
> ## How you do this depends on your naming conventions
> ## You might use a loop, or ls() and assign(),
> ##  or collect your matrices into a list and use do.call() or ...
> ## You will *not*want to do this if you have lots of matrices:
> list_of_mats <- list(x,y) 
> arr <- array(do.call(c,list_of_mats), dim = c(3,3,length(list_of_mats)))
> arr
> arr[2,3,] ## all the values in the [2,3] cell of the matrices; do whatever 
> you want with them.
> 
> Cheers,
> Bert
> 
> 
> 
> Bert Gunter
> 
> "The trouble with having an open mind is that people keep coming along and 
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
> 
> 
> On Tue, Jun 1, 2021 at 7:00 PM R. Mark Sharp via R-help  <mailto:r-help@r-project.org>> wrote:
> I want to capture the entire distribution of values for each cell in a 
> sequence of symmetric matrices of the same size. The diagonal values are all 
> 0.5 so I need only the values above or below the diagonal. 
> 
> A small example with three of the structures I am wanting to count follows:
>F  G  H  I J
> F 0.6250 0.3750 0.2500 0.1875 0.125
> G 0.3750 0.6250 0.2500 0.1875 0.125
> H 0.2500 0.2500 0.5000 0.1875 0.125
> I 0.1875 0.1875 0.1875 0.5000 0.250
> J 0.1250 0.1250 0.1250 0.2500 0.500
> 
>F  G  H  I J
> F 0.5625 0.3125 0.1875 0.1250 0.125
> G 0.3125 0.5625 0.1875 0.1250 0.125
> H 0.1875 0.1875 0.5000 0.1875 0.125
> I 0.1250 0.1250 0.1875 0.5000 0.250
> J 0.1250 0.1250 0.1250 0.2500 0.500
> 
> F   G  H   I  J
> F 0.5 0.25000 0.1250 0.09375 0.0625
> G 0.25000 0.5 0.1250 0.09375 0.0625
> H 0.12500 0.12500 0.5000 0.18750 0.1250
> I 0.09375 0.09375 0.1875 0.5 0.2500
> J 0.06250 0.06250 0.1250 0.25000 0.5000
> 
> 
> To be more specific, I have coded up a solution for a single cell with the 
> sequence of values (one from each matrix) in a vector. 
> 
> I used match() below and it works with a matrix but I do not know how to do 
> what is in the if statements with matrices. Since the number of values and 
> the values will be different among the various cells a simple array structure 
> does not seem appropriate and I am assuming I will need to use a list but I 
> would like to do as much as I can with matrices for speed and clarity.
> 
> #' Counts the number of occurrences of each kinship value seen for a pair of
> #' individuals.
> #'
> #' @examples
> #' \donttest{
> #' set.seed(20210529)
> #' kSamples <- sample(c(0, 0.0675, 0.125, 0.25, 0.5, 0.75), 1, replace = 
> TRUE,
> #'prob = c(0.005, 0.3, 0.15, 0.075, 0.0375, 0.01875))
> #' kVC <- list(kinshipValues = numeric(0),
> #' kinshipCounts = numeric(0))
> #' for (kSample in kSamples) {
> #'   kVC <- countKinshipValues(kSample, kVC$kinshipValues, kVC$kinshipCounts)
> #' }
> #' kVC
> #' ## $kinshipValues
> #' ## [1] 0.2500 0.1250 0.0675 0.7500 0.5000 0.
> #' ##
> #' ## $kinshipCounts
> #' ## [1]  301 2592 5096 1322  592   97
> #' }
> #'
> #' @param kValue numeric value being counted (kinship value in
> #' \emph{nprcgenekeepr})
> #' @param kinshipValues vector of unique values of \code{kValue} seen
> #' thus far.
&

Re: [R] Sweave

2022-06-26 Thread R. Mark Sharp via R-help
Naresh,

First of all thanks for using reporoducible methods.

I now use knitr instead of Sweave and the switch was fairly trivial. What you 
are wanting to do has been supported for a few years within RStudio. I found 
https://support.rstudio.com/hc/en-us/articles/200552336-Getting-Help-with-R 
<https://support.rstudio.com/hc/en-us/articles/200552336-Getting-Help-with-R> 
provided the following guidance with regard to get help with RStudio.

The RStudio Community <http://community.rstudio.com/> is our discussion board 
for asking questions about R, Shiny, and package development.

Mark

R. Mark Sharp, Ph.D.
Data Scientist and Biomedical Statistical Consultant
7526 Meadow Green St.
San Antonio, TX 78251
mobile: 210-218-2868
rmsh...@me.com











> On Jun 26, 2022, at 9:28 AM, Naresh Gurbuxani  
> wrote:
> 
> I want to use Sweave, but incorporate some features from emacs org mode.  
> 
> When I first started writing reproducible documents, I used Sweave to combine 
> LaTeX and R.  Four years ago, I started using org mode in emacs, which has a 
> few additional features:
> 
> 1.  In org mode, it is possible to see R-generated figures and tables in the 
> running text.  In R Studio, I have to go to the plots window to look at the 
> figures and R console to look at tables.  When reviewing the document, it 
> interrupts the flow.  
> 
> 2.  In org mode document, it is possible to set a global variable so that, at 
> the time of compilation, embedded code is not rerun.  org mode simply uses 
> the results from the most recently run code and embeds them in the document.  
> This makes the compilation much faster.  In Sweave, it is possible to achieve 
> this for individual code blocks by setting eval=FALSE.  But in a long 
> document with many code blocks, this method is time consuming.  
> 
> My new workplace does not support emacs.  I have gone back to using Sweave, 
> but miss above features.  Is it possible to have these features in R Studio?
> 
> Thanks,
> Naresh
> __
> 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] Increasing number of observations worsen the regression model

2019-05-26 Thread R. Mark Sharp via R-help
Raffa, 

I ran this on a MacOS machine and got what you expected. I added a call to 
sessionInfo() for your information.

> rm(list=ls())
> N = 3
> xvar <- runif(N, -10, 10)
> e <- rnorm(N, mean=0, sd=1)
> yvar <- 1 + 2*xvar + e
> plot(xvar,yvar)
> lmMod <- lm(yvar~xvar)
> print(summary(lmMod))

Call:
lm(formula = yvar ~ xvar)

Residuals:
Min  1Q  Median  3Q Max 
-4.2407 -0.6738 -0.0031  0.6822  4.0619 

Coefficients:
 Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.0059022  0.0057370   175.3   <2e-16 ***
xvar2.0005811  0.0009918  2017.2   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.9937 on 29998 degrees of freedom
Multiple R-squared:  0.9927,Adjusted R-squared:  0.9927 
F-statistic: 4.069e+06 on 1 and 29998 DF,  p-value: < 2.2e-16

> domain <- seq(min(xvar), max(xvar))# define a vector of x values to feed 
> into model
> lines(domain, predict(lmMod, newdata = data.frame(xvar=domain)))# add 
> regression line, using `predict` to generate y-values
> sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.4

Matrix products: default
BLAS:   
/Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRblas.0.dylib
LAPACK: 
/Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

loaded via a namespace (and not attached):
[1] compiler_3.6.0




R. Mark Sharp, Ph.D.
Data Scientist and Biomedical Statistical Consultant
7526 Meadow Green St.
San Antonio, TX 78251
mobile: 210-218-2868
rmsh...@me.com











> On May 25, 2019, at 7:38 AM, Raffa  wrote:
> 
> I have the following code:
> 
> ```
> 
> rm(list=ls())
> N = 3
> xvar <- runif(N, -10, 10)
> e <- rnorm(N, mean=0, sd=1)
> yvar <- 1 + 2*xvar + e
> plot(xvar,yvar)
> lmMod <- lm(yvar~xvar)
> print(summary(lmMod))
> domain <- seq(min(xvar), max(xvar))# define a vector of x values to 
> feed into model
> lines(domain, predict(lmMod, newdata = data.frame(xvar=domain)))# 
> add regression line, using `predict` to generate y-values
> 
> ```
> 
> I expected the coefficients to be something similar to [1,2]. Instead R 
> keeps throwing at me random numbers that are not statistically 
> significant and don't fit the model, and I have 20k observations. For 
> example
> 
> ```
> 
> Call:
> lm(formula = yvar ~ xvar)
> 
> Residuals:
> Min  1Q  Median  3Q Max
> -21.384  -8.908   1.016  10.972  23.663
> 
> Coefficients:
>  Estimate Std. Error t value Pr(>|t|)
> (Intercept) 0.0007145  0.0670316   0.0110.991
> xvar0.0168271  0.0116420   1.4450.148
> 
> Residual standard error: 11.61 on 29998 degrees of freedom
> Multiple R-squared:  7.038e-05,Adjusted R-squared: 3.705e-05
> F-statistic: 2.112 on 1 and 29998 DF,  p-value: 0.1462
> 
> ```
> 
> 
> The strange thing is that the code works perfectly for N=200 or N=2000. 
> It's only for larger N that this thing happen U(for example, N=2). I 
> have tried to ask for example in CrossValidated 
> <https://stats.stackexchange.com/questions/410050/increasing-number-of-observations-worsen-the-regression-model>
>  
> but the code works for them. Any help?
> 
> I am runnign R 3.6.0 on Kubuntu 19.04
> 
> Best regards
> 
> Raffaele
> 
> 
>   [[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] File names for mac newby

2020-01-21 Thread R. Mark Sharp via R-help
Open the terminal application in the Utilities folder. Select the file you want 
to use in R in a Finder window and drag it to the terminal applications command 
line prompt and then release the file. The absolute path of the file will be 
entered in the command line of the terminal’s window. Though this absolute path 
will work, relative paths are often preferred. 


Mark

R. Mark Sharp, Ph.D.
rmsh...@me.com

> On Jan 21, 2020, at 2:02 PM, Kevin Thorpe  wrote:
> 
> You would also need to drop the c: as that is a DOS/Windows thing.
> 
> -- 
> Kevin E. Thorpe
> Head of Biostatistics,  Applied Health Research Centre (AHRC)
> Li Ka Shing Knowledge Institute of St. Michael's
> Assistant Professor, Dalla Lana School of Public Health
> University of Toronto
> email: kevin.tho...@utoronto.ca  Tel: 416.864.5776  Fax: 416.864.3016
> 
> 
> On 2020-01-21, 1:26 PM, "R-help on behalf of James Spottiswoode" 
>  wrote:
> 
>OSX is based on BSD UNIX so paths use the forward slash as separator, e.g.
> 
>temps <- 
> read.table("c:/Users/DFP/Documents/ah/house/HouseTemps.txt",header=T,row.names=1)
> 
>Best James
> 
>> On Jan 21, 2020, at 9:20 AM, David  wrote:
>> 
>> I moved to a mac a few months ago after years in windows, and I'm still 
>> learning basics.  I'm wanting to create a data frame based on a text file 
>> called HouseTemps.txt.  That's a file within one called house which is 
>> within one called ah.  That may further be in one called  Documents.  I 
>> tried various lines like:
>> 
>> temps <- 
>> read.table("c:\\Users\\DFP\\Documents\\ah\\house\\HouseTemps.txt",header=T,row.names=1)
>> 
>> based on my windows DOS experience, but nothing I try works.  So my question 
>> is, what do complete file names look like in a mac?
>> 
>> I tried Apple support, but they couldn't help me with R.
>> 
>> __
>> 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-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.