[R] Identifying columns with specific character

2018-04-18 Thread Farnoosh Sheikhi via R-help
Hello,
I have a data frame with 400 columns and wanted to filter character columns 
with "$" in it.For example: >  x <- c("$5", "$89", "$10", "$34")  >  y <- 
c(1:4)>  My.Data <- data.frame (x,y)> My.Data    x y1  $5 12 $89 23 $10 34 $34 4
I want to detect the columns with $ and remove the $ from the selected 
columns.I have tried apply(My.Data, 2, function (x) any(grepl("$", x))) but 
it's not really working.Or:  apply(My.Data, 2, function(x){x<-gsub("\\$", "", 
x)}) works but it turns all the columns to a factor.
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] Fw: passing different sample sizes

2017-09-25 Thread Farnoosh Sheikhi via R-help




Hi, 
I have the below function which returns confidence intervals. I wanted to pass 
different sample sizes through the function, but for some reason it's not 
working. n   <- seq(from=40, to=300, by=2o)

I was also wondering how I can return a plot for different sample sizes. 
plot(m~d, main="n(i)") 
Any help or suggestion is appreciated.


f<-function(n){  m = runif(n,50,200)  d =  
rnorm(n,0,1)   ci.u<-mean(d)+1.96*sd(d)  ci.l<-mean(d)-1.96*sd(d)  
ci.w<-ci.u-ci.l    se=sd(d)/sqrt(n)  w.ci.uu<-ci.u+(qt(.975, df=n-1))*1.71*se  
w.ci.ul<-ci.u-(qt(.975, df=n-1))*1.71*se  w.ci.upper<-w.ci.uu- w.ci.ul
w.ci.lu<-ci.l+(qt(.975, df=n-1))*1.71*se  w.ci.ll<-ci.l-(qt(.975, 
df=n-1))*1.71*se  w.ci.lower<-w.ci.lu- w.ci.ll    res<-as.data.frame(cbind(n, 
ci.u, ci.l, ci.w, w.ci.upper, w.ci.lower))  return(res)} Best,Nooshi





[[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] Different date formats in one column

2017-06-29 Thread Farnoosh Sheikhi via R-help
Thanks Jeff. This is a nice way of solving this problem. What about the cases 
with 0015-02-21?Many thanks. Best,Farnoosh

 

On Wednesday, June 28, 2017 10:49 PM, Jeff Newmiller 
<jdnew...@dcn.davis.ca.us> wrote:
 

 I doubt your actual file looks like the mess that made it to my email 
software (below) because you posted HTML-format email. Read the Posting 
Guide, and in particular figure out how to send plain text email.

You might try the "anytime" contributed package, though I suspect it too 
will choke on your mess. Otherwise, that will pretty much leave only a 
brute-force series of regular expression tests to recognize which date 
format patterns you have, and even that may not be able to get them all 
right unless you know something that limits the range of possible formats.

Below is an example of how this can be done. There are many tutorials on 
the internet that describe regular expressions... they are not unique to 
R.

#-
dta <- read.table( text=
"DtStr
020917
2/22/17
May-2-2015
May-12-15
", header=TRUE, as.is=TRUE )

dta$Dt <- as.Date( NA )

idx <- grepl( 
"^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-[0-9]+-[0-9]{4}$", 
dta$DtStr, perl=TRUE, ignore.case = TRUE )
dta$Dt[ idx ] <- as.Date( dta$DtStr[ idx ], format="%B-%d-%Y" )

idx <- grepl( 
"^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-[0-9]+-[0-9]{2}$", 
dta$DtStr, perl=TRUE, ignore.case = TRUE )
dta$Dt[ idx ] <- as.Date( dta$DtStr[ idx ], format="%B-%d-%y" )

idx <- grepl( "^(0[1-9]|1[0-2])[0-9]{2}[0-9]{2}$", dta$DtStr, perl=TRUE )
dta$Dt[ idx ] <- as.Date( dta$DtStr[ idx ], format="%m%d%y" )

idx <- grepl( "^([1-9]|1[0-2])/[0-9]{1,2}/[0-9]{2}$", dta$DtStr, perl=TRUE 
)
dta$Dt[ idx ] <- as.Date( dta$DtStr[ idx ], format="%m/%d/%y" )


On Wed, 28 Jun 2017, Farnoosh Sheikhi via R-help wrote:

> Hi, 
> I have a data set with various date formats in one column and not sure how to 
> unify it.Here is a few formats:
> 02091702/22/170221201703/17/160015-08-239/2/1500170806May-2-201522-March-2014
> I tried parse_date_time from lubridate library but it failed.Thanks so much. 
> Best,Farnoosh
>
>
>     [[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.

---
Jeff Newmiller                        The    .      .  Go Live...
DCN:<jdnew...@dcn.davis.ca.us>        Basics: ##.#.      ##.#.  Live Go...
                                      Live:  OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.      #.O#.  with
/Software/Embedded Controllers)              .OO#.      .OO#.  rocks...1k
---

   
[[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] Different date formats in one column

2017-06-29 Thread Farnoosh Sheikhi via R-help
Hi Christoph,
There is "," between dates.Many thanks. Best,Farnoosh

 

On Wednesday, June 28, 2017 9:05 PM, Christoph Puschmann 
<c.puschm...@student.unsw.edu.au> wrote:
 

 Hey,

Are all the dates connected? So no comma or space btw?

Regards,

Christoph

> On 29 Jun 2017, at 2:02 pm, Farnoosh Sheikhi via R-help 
> <r-help@r-project.org> wrote:
> 
> Hi, 
> I have a data set with various date formats in one column and not sure how to 
> unify it.Here is a few formats:
> 02091702/22/170221201703/17/160015-08-239/2/1500170806May-2-201522-March-2014
> I tried parse_date_time from lubridate library but it failed.Thanks so much. 
> Best,Farnoosh
> 
> 
>    [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

   
[[alternative HTML version deleted]]

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

[R] Different date formats in one column

2017-06-28 Thread Farnoosh Sheikhi via R-help
Hi, 
I have a data set with various date formats in one column and not sure how to 
unify it.Here is a few formats:
02091702/22/170221201703/17/160015-08-239/2/1500170806May-2-201522-March-2014
I tried parse_date_time from lubridate library but it failed.Thanks so much. 
Best,Farnoosh


[[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] unique dates per ID

2016-11-14 Thread Farnoosh Sheikhi via R-help
Hi, 
I have a data set like below:
Subject<- c("2", "2", "2", "3", "3", "3", "4", "4", "5", "5", "5", 
"5")dates<-c("2011-01-01", "2011-01-01", "2011-01-03" ,"2011-01-04", 
"2011-01-05", "2011-01-06" ,"2011-01-07", "2011-01-07", "2011-01-09" 
,"2011-01-10"         ,"2011-01-11" ,"2011-01-11")deps<-c("A", "B", "CC", "C", 
"CC", "A", "F", "DD", "A", "F", "FF", "D")df <- data.frame(Subject, dates, 
deps); df
I want to choose unique dates per ID in a way there are not duplicate dates per 
ID. I don't mind what department to pick. I really appreciate any help. 
Best,Farnoosh


[[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] Extracting dates to create a new variable

2016-08-10 Thread Farnoosh Sheikhi via R-help
 blockquote, div.yahoo_quoted { margin-left: 0 !important; border-left:1px 
#715FFA solid !important; padding-left:1ex !important; background-color:white 
!important; } 

Hi 
I have a data set like below and wanted to create a new date variable by 
extracting the dates for specific departments.I want to extract the dates for 
departments CC, DD, FF,  put it in a new column and repeat it for other unique 
IDs.
Subject<- c("2", "2", "2", "3", "3", "3", "4", "4", "5", "5", "5", 
"5")dates<-seq(as.Date('2011-01-01'),as.Date('2011-01-12'),by = 1) deps<-c("A", 
"B", "CC", "C", "CC", "A", "F", "DD", "A", "F", "FF", "D")df <- 
data.frame(Subject, dates, deps)df
The final data set should look like this:newdate<-c(" 2011-01-03",  
"2011-01-03",  "2011-01-03", "2011-01-05", "2011-01-05", "2011-01-05" , 
"2011-01-08", "2011-01-08", "2011-01-08", "2011-01-11", "2011-01-11", 
"2011-01-11")final<-data.frame(Subject, dates, deps, newdate)final
I really appreciate any help.
 Best,Farnoosh


 


[[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] Extracting dates to create a new variable

2016-08-08 Thread Farnoosh Sheikhi via R-help
Hi there, 
I have a data set like below and wanted to create a new date variable by 
extracting the dates for specific departments.I want to extract the dates for 
departments CC, DD, FF,  put it in a new column and repeat it for other unique 
IDs.
Subject<- c("2", "2", "2", "3", "3", "3", "4", "4", "5", "5", "5", 
"5")dates<-seq(as.Date('2011-01-01'),as.Date('2011-01-12'),by = 1) deps<-c("A", 
"B", "CC", "C", "CC", "A", "F", "DD", "A", "F", "FF", "D")df <- 
data.frame(Subject, dates, deps)df
The final data set should look like this:newdate<-c(" 2011-01-03",  
"2011-01-03",  "2011-01-03", "2011-01-05", "2011-01-05", "2011-01-05" , 
"2011-01-08", "2011-01-08", "2011-01-08", "2011-01-11", "2011-01-11", 
"2011-01-11")final<-data.frame(Subject, dates, deps, newdate)final
I really appreciate any help.
 Best,Farnoosh


[[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] Merging Issue

2016-06-17 Thread Farnoosh Sheikhi via R-help
Hi all, 
I have two data sets similar like below and wanted to merge them with variable 
"deps". As this is a sample data with small sample size, I don't have any 
problem using command merge. However, the actual data set has ~60,000 
observations with a lot of repeated measures. For example, for a given ID I 
have 100 different dates and groups. Thee problem is using "merge" command 
gives me a lot of duplicates that I can't even track. I was wondering if there 
is any other way to merge such a data.Any help is appreciated. Thanks.
## Data ASubject<- c("2", "2", "2", "3", "3", "3", "4", "4", "5", "5", "5", 
"5")dates<-seq(as.Date('2011-01-01'),as.Date('2011-01-12'),by = 1) deps<-c("A", 
"B", "C", "C", "D", "A", "F", "G", "A", "F", "A", "D")df <- data.frame(Subject, 
dates, deps)
## Data Bloc<-c("CA","NY", "CA", "NY", "WA", "WA")grp<-c("DE", "OC", "DE", 
"OT", "DE", "OC")deps<-c("A","B","C", "D", "F","G")df2<-data.frame(loc, grp, 
deps )
dat<-merge(df, df2, by="deps")
 


[[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] Filtering based on the occurrence

2016-03-31 Thread Farnoosh Sheikhi via R-help
Hi Jim, 
Thank you tons for your help. The code worked perfectly :) Best,Farnoosh

 

On Wednesday, March 30, 2016 1:13 AM, Jim Lemon <drjimle...@gmail.com> 
wrote:
 

 Hi Farnoosh,
Despite my deep suspicion that this answer will solve a useless
problem, try this:

last_subject<-0
keep_deps<-c("B","D","F")
keep_rows<-NULL
for(rowindex in 1:dim(df)[1]) {
 if(df[rowindex,"Subject"] != last_subject) {
  last_subject<-df[rowindex,"Subject"]
  start_keeping<-0
 }
 if(df[rowindex,"deps"] %in% keep_deps) start_keeping<-1
 if(start_keeping) keep_rows<-c(keep_rows,rowindex)
}
final<-matrix(unlist(lapply(df[keep_rows,],as.character)),ncol=3)

I find it terribly hard to ignore puzzles.

Jim


On Wed, Mar 30, 2016 at 10:52 AM, Farnoosh Sheikhi via R-help
<r-help@r-project.org> wrote:
> Hello,
> I have a data set similar to below and I wanted to keep the observations 
> after the first occurrence of these department: "B", "D", "F".For example for 
> ID=2, the observation with deps=B and anything after will be kept in the 
> data. For ID=3, observations with deps=D and anything after will be included.
> Subject<- c("2", "2", "2", "3", "3", "3", "4", "4", "5", "5", "5", 
> "5")dates<-seq(as.Date('2011-01-01'),as.Date('2011-01-12'),by = 1) 
> deps<-c("A", "B", "C", "C", "D", "A", "F", "G", "A", "F", "A", "D")df <- 
> data.frame(Subject, dates, deps)df
> The final data should look like this:final<-c("2 2011-01-02    B","2 
> 2011-01-03    C","3 2011-01-05    D","3 2011-01-06    A","4 2011-01-07    
> F","4 2011-01-08    G","5 2011-01-10    F","5 2011-01-11    A","5 2011-01-12  
>   D") Thank you tons for your help.
> Farnoosh
>
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

  
[[alternative HTML version deleted]]

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

[R] Filtering based on the occurrence

2016-03-29 Thread Farnoosh Sheikhi via R-help
Hello, 
I have a data set similar to below and I wanted to keep the observations after 
the first occurrence of these department: "B", "D", "F".For example for ID=2, 
the observation with deps=B and anything after will be kept in the data. For 
ID=3, observations with deps=D and anything after will be included.
Subject<- c("2", "2", "2", "3", "3", "3", "4", "4", "5", "5", "5", 
"5")dates<-seq(as.Date('2011-01-01'),as.Date('2011-01-12'),by = 1) deps<-c("A", 
"B", "C", "C", "D", "A", "F", "G", "A", "F", "A", "D")df <- data.frame(Subject, 
dates, deps)df
The final data should look like this:final<-c("2 2011-01-02    B","2 2011-01-03 
   C","3 2011-01-05    D","3 2011-01-06    A","4 2011-01-07    F","4 2011-01-08 
   G","5 2011-01-10    F","5 2011-01-11    A","5 2011-01-12    D") Thank you 
tons for your help. 
Farnoosh


[[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] Distance in miles btw Zipcodes

2015-09-17 Thread Farnoosh Sheikhi via R-help
 Hello,
I'm trying to get the distances between two Zipcode variables, but for some 
reason I get this error:
"matching was not perfect, returning what was found.Error: no such index at 
level 1"
Here is my code:

library(ggmap)mapdist(data$Zip.A, data$Zip.B, mode = "driving")
The Zip codes are all in 5 digits format.I really appreciate any help or 
suggestion.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.

Re: [R] Mixed Date Formats

2015-07-30 Thread farnoosh sheikhi via R-help
Thank you all for your help.I came to this conclusion that data needs to be 
verified by its source. Thanks again. 
 


 On Thursday, July 30, 2015 7:07 AM, John Kane jrkrid...@inbox.com wrote:
   

 That's what I get for reading without a cup of tea beside me. I looked at 5 
and my eye just slide over the last entries. 


I change my assessment : this looks bad. (Tea at hand).

So, presumably Farnoosh may not be able to guarantee the formats for 3  4 
either unless they are unambiguously dated.


John Kane
Kingston ON Canada


 -Original Message-
 From: sarah.gos...@gmail.com
 Sent: Thu, 30 Jul 2015 09:19:55 -0400
 To: jrkrid...@inbox.com
 Subject: Re: [R] Mixed Date Formats
 
 On Thu, Jul 30, 2015 at 9:14 AM, John Kane jrkrid...@inbox.com wrote:
 This does not look good. But not too bad
 
 Can we assume that the original data is in D-M-Y in all cases. The
 values at 3  4 in the sample data are ambigous, in that someone may be
 using the American dating system of M-D-Y.  Given the rest of the data
 it seems unlikely but possible.
 
 Take a look at 5 and 7:
  5  1375 31/12/2011 # dd/mm/
  7  3423 01/22/2011 # mm/dd/
 
 They're unambiguously different.
 
 Otherwise it looks possible, but probably not for me since I'm lousy at
 things like grep, to sort the data set into three parts based on the
 last three characters in the Year part of the date, convert and
 recombine.
 
 It would be easy if month and day were consistent, regardless of year
 format.
 
 
 SampleData
  id value      date
  1  5813  19-Dec-11
  2  8706  07-Dec-11
  3  4049  06/05/11
  4  5877  05/12/11
  5  1375 31/12/2011
  6  2223 10/19/2011
  7  3423 01/22/2011
 
 John Kane
 Kingston ON Canada
 
 
 -Original Message-
 From: r-help@r-project.org
 Sent: Wed, 29 Jul 2015 21:15:45 + (UTC)
 To: sarah.gos...@gmail.com
 Subject: Re: [R] Mixed Date Formats
 
 Hi Sarah,
 Thanks for getting back to me.Here is an example of my data:SampleData
 -
 structure(list(id = 1:7, value = c(5813L, 8706L, 4049L, 5877L,
 1375L, 2223L, 3423L), date = structure(c(4L, 3L, 2L, 1L, 7L,
 6L, 5L), .Label = c(05/12/11, 06/05/11, 07-Dec-11,
 19-Dec-11, 01/22/2011, 10/19/2011, 31/12/2011
 ), class = factor)), .Names = c(id, value, date), row.names =
 c(NA,
 -7L), class = data.frame)SampleData
 Thanks for your help:).
 
 
 
 
      On Wednesday, July 29, 2015 1:50 PM, Sarah Goslee
 sarah.gos...@gmail.com wrote:
 
 
  On Wed, Jul 29, 2015 at 2:45 PM, farnoosh sheikhi via R-help
 r-help@r-project.org wrote:
  Hi Arun,
 Hope all is well with you. I have a data with a column for date.The
 date
 format is mixed. There are date values with Month/Day/Year format and
 values with Day/Month/Year format.I don't know how to unify it.I
 really
 appreciate your help.Thanks.
 
 You sent this to the R-help list, not just to Arun, so I'm assuming
 this is an R question. The best way to get help is to provide a sample
 of your data using dput() and to clearly specify what you would like
 as the result - unify is a bit vague. paste(x, collapse=) could be
 considered unification, after all.
 
 Sarah
 
 --
 Sarah Goslee
 http://www.functionaldiversity.org
 
 
 
 
 
 
 --
 Sarah Goslee
 http://www.functionaldiversity.org


FREE ONLINE PHOTOSHARING - Share your photos online with your friends and 
family!
[[elided Yahoo spam]]



  
[[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] Mixed Date Formats

2015-07-29 Thread farnoosh sheikhi via R-help
 Hi Arun,
Hope all is well with you. I have a data with a column for date.The date format 
is mixed. There are date values with Month/Day/Year format and values with 
Day/Month/Year format.I don't know how to unify it.I really appreciate your 
help.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.

Re: [R] Mixed Date Formats

2015-07-29 Thread farnoosh sheikhi via R-help
Hi Sarah,
Thanks for getting back to me.Here is an example of my data:SampleData - 
structure(list(id = 1:7, value = c(5813L, 8706L, 4049L, 5877L,                  
                            1375L, 2223L, 3423L), date = structure(c(4L, 3L, 
2L, 1L, 7L,                                                                     
                  6L, 5L), .Label = c(05/12/11, 06/05/11, 07-Dec-11,      
                                                                                
                     19-Dec-11, 01/22/2011, 10/19/2011, 31/12/2011      
                                                                                
), class = factor)), .Names = c(id, value, date), row.names = c(NA,     
                                                                                
                                                                          -7L), 
class = data.frame)SampleData
Thanks for your help:).
 
 


 On Wednesday, July 29, 2015 1:50 PM, Sarah Goslee sarah.gos...@gmail.com 
wrote:
   

 On Wed, Jul 29, 2015 at 2:45 PM, farnoosh sheikhi via R-help
r-help@r-project.org wrote:
  Hi Arun,
 Hope all is well with you. I have a data with a column for date.The date 
 format is mixed. There are date values with Month/Day/Year format and values 
 with Day/Month/Year format.I don't know how to unify it.I really appreciate 
 your help.Thanks.

You sent this to the R-help list, not just to Arun, so I'm assuming
this is an R question. The best way to get help is to provide a sample
of your data using dput() and to clearly specify what you would like
as the result - unify is a bit vague. paste(x, collapse=) could be
considered unification, after all.

Sarah

-- 
Sarah Goslee
http://www.functionaldiversity.org


  
[[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] Difference in dates for unique ID

2015-02-15 Thread farnoosh sheikhi via R-help
That's exactly what I was thinking. Thanks tons.

Sent from Yahoo Mail on Android

From:arun smartpink...@yahoo.com
Date:Sun, Feb 15, 2015 at 2:47 AM
Subject:Re: Difference in dates for unique ID

HI Farnoosh,



Not sure I understand the expected output.� The difference between the first 2 
days is 136 days

May be this helps

� library(data.table)
� � � dcast.data.table(setDT(df)[, list(Visit=.N, Diff= 
as.numeric(abs(diff(as.Date(Date, format='%d-%b-%y') ,
� � � � by = ID], ID+Visit~ Diff, value.var='Diff', length)

� � ID Visit 136 255 857
� � 1:� 1� � 2� 1� 0� 0
� � 2:� 2� � 3� 0� 1� 1







On Wednesday, February 11, 2015 5:47 PM, farnoosh sheikhi 
farnoosh...@yahoo.com wrote:



Hi Arun,

I have a data set that look s like below. I wanted to get a difference in dates 
for each unique ID and record it as a new X and have binary input for each one. 

ID� Date
1� � � � 06-Sep-13
1� � � � 20-Jan-14
2� � � � 06-Mar-12
2� � � � 25-Jun-11
2� � � � 29-Oct-13



For example for the first two date for ID=1 ( 20-Jan-14 - 06-Sep-13 ~ 121) and 
I want the data to be like follow:

ID� Visit� 121
1� � � 2� � � � 1
2� � � 3� � � � 0


I really appreciate if you can help me with this. I know I need to write some 
kind of loop, but I don't know how to think of the logic behind it.
Thanks a lot.



Farnoosh


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