Print

Print


Well spotted, Hao Ye.  That's a lesson for me to pay more attention to what I'm reading!


Massimiliano S. Tagliamonte
DVM, MSc, PhD
Postdoc Associate
Emerging Pathogens Institute
Department of Pathology
College of Medicine
University of Florida
________________________________
From: UF R Users List <[log in to unmask]> on behalf of Hao Ye <[log in to unmask]>
Sent: Friday, July 27, 2018 3:42 PM
To: [log in to unmask]
Subject: Re: Regular expression

Hi,

Not sure if this is the issue or not, but it looks like the code you're using overwrites `geno_time` with the output of `str_extract`. So if `geno_time` starts out as your data.frame with a `time` column, the code will run the first time, but the next time you try it, you'll get that error.

Maybe you meant to add a date column?
```
geno_time$date <- str_extract(geno_time$time,"[0-9]+\\/[0-9]+\\/[0-9]+[:blank:]?")
```

Best,
--
Hao Ye
[log in to unmask]<mailto:[log in to unmask]>

On Fri, Jul 27, 2018 at 3:31 PM, El Rouby,Nihal M <[log in to unmask]<mailto:[log in to unmask]>> wrote:
Dear All-

Trying to extract dates from a variable in a data frame and then make a new column with these dates. I'm using regular expression along str_extract command from package stringr.

I'm getting the error  "Error in geno_time$time : $ operator is invalid for atomic vectors" when I used this command below on my dataframe.

geno_time<-str_extract(geno_time$time,"[0-9]+\\/[0-9]+\\/[0-9]+[:blank:]?")

I'm attaching example of my data and what I want to accomplish.

I appreciate your input and have a great weekend.

Best,
Nihal
This list strives to be beginner friendly. However, we still ask that you PLEASE do read the posting guide http://www.R-project.org/posting-guide.html<https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org_posting-2Dguide.html&d=DwMGaQ&c=pZJPUDQ3SB9JplYbifm4nt2lEVG5pWx2KikqINpWlZM&r=SEmRVMqAFbH_Cx3K2dozZfH2QG2rALCjx8XkDKdS6dE&m=T6R-RSm5riVLS3uc4XkFK3DKka0OBHS_xTyuBQFWZEI&s=09WZYsfZUOMxABjBMdwqhoWEJYAjHasn3xzv7Ym38Zg&e=> and provide commented, minimal, self-contained, reproducible code.

This list strives to be beginner friendly. However, we still ask that you PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.

This list strives to be beginner friendly.  However, we still ask that you
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.