Hi, I need help with two related issues: 1. I wish to drop repeating text "BST" from the below 'dates' string: [1] "2005-04-01 BST" "2005-04-04 BST" "2005-04-05 BST" "2005-04-06 BST" "2005-04-07 BST" "2005-04-08 BST" "2005-04-11 BST" "2005-04-12 BST" "2005-04-13 BST" "2005-04-14 BST" " 2. I then wish to add this (cleaned-up) 'dates' string as the row names to a matrix (same length as 'dates' string) Any expertise greatly appreciated, kevj -- View this message in context: http://r.789695.n4.nabble.com/Help-with-adding-dates-string-as-rownames-to-matrix-tp4656611.html Sent from the R help mailing list archive at Nabble.com.
PIKAL Petr
2013-Jan-25 11:01 UTC
[R] Help with adding 'dates' string as rownames to matrix
Hi> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of kevj1980 > Sent: Friday, January 25, 2013 11:22 AM > To: r-help at r-project.org > Subject: [R] Help with adding 'dates' string as rownames to matrix > > Hi, I need help with two related issues: > > 1. I wish to drop repeating text "BST" from the below 'dates' string: > > [1] "2005-04-01 BST" "2005-04-04 BST" "2005-04-05 BST" "2005-04-06 > BST" > "2005-04-07 BST" "2005-04-08 BST" "2005-04-11 BST" "2005-04-12 BST" > "2005-04-13 BST" "2005-04-14 BST" "You can use regular expressions but if your string is like you showed us, dates1 <-substr(dates, 1, 10)> > 2. I then wish to add this (cleaned-up) 'dates' string as the row names > to a matrix (same length as 'dates' string)rownames(mat) <- dates1 Regards Petr> > Any expertise greatly appreciated, > kevj > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Help-with- > adding-dates-string-as-rownames-to-matrix-tp4656611.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at 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.
Thank you Petr! -- View this message in context: http://r.789695.n4.nabble.com/Help-with-adding-dates-string-as-rownames-to-matrix-tp4656611p4656617.html Sent from the R help mailing list archive at Nabble.com.
Hi,
Try this:
Dates1<-c("2005-04-01 BST","2005-04-04
BST","2005-04-05 BST")
Dates2<-as.Date(gsub("\\s+\\w+$","",Dates1))
?mat1<-matrix(1:9,nrow=3)
library(zoo)
?z1<-zoo(mat1,Dates2)
?z1
#???????????????
#2005-04-01 1 4 7
#2005-04-04 2 5 8
#2005-04-05 3 6 9
#if you use:
? mat2<-matrix(1:9,nrow=3)
?row.names(mat2)<- Dates2
?mat2
#????? [,1] [,2] [,3]
#12874??? 1??? 4??? 7
#12877??? 2??? 5??? 8
#12878??? 3??? 6??? 9
A.K.
----- Original Message -----
From: kevj1980 <kevin.kidney at cameronhume.com>
To: r-help at r-project.org
Cc:
Sent: Friday, January 25, 2013 5:22 AM
Subject: [R] Help with adding 'dates' string as rownames to matrix
Hi, I need help with two related issues:
1. I wish to drop repeating text "BST" from the below 'dates'
string:
[1] "2005-04-01 BST" "2005-04-04 BST" "2005-04-05
BST" "2005-04-06 BST"
"2005-04-07 BST" "2005-04-08 BST" "2005-04-11 BST"
"2005-04-12 BST"
"2005-04-13 BST" "2005-04-14 BST" "
2. I then wish to add this (cleaned-up) 'dates' string as the row names
to a
matrix (same length as 'dates' string)
Any expertise greatly appreciated,
kevj
--
View this message in context:
http://r.789695.n4.nabble.com/Help-with-adding-dates-string-as-rownames-to-matrix-tp4656611.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________
R-help at 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.