Hi, I have the following data that looks like this:
names(dat)
[1] "(-2329,-2319]" "(-1399,-1389]" "(-669.4,-659.4]" How can I modify those names into just this? [1] -2329 -1399 -669.4 - Gundala Viswanath Jakarta - Indonesia
4 messages · Gundala Viswanath, David Winsemius, Rolf Turner +1 more
Hi, I have the following data that looks like this:
names(dat)
[1] "(-2329,-2319]" "(-1399,-1389]" "(-669.4,-659.4]" How can I modify those names into just this? [1] -2329 -1399 -669.4 - Gundala Viswanath Jakarta - Indonesia
dat <- c(1,2,3)
> names(dat) <- c(-2329, -1399, -669.4)
> dat
-2329 -1399 -669.4
1 2 3
David Winsemius On Feb 25, 2009, at 9:55 PM, Gundala Viswanath wrote: > Hi, > > I have the following data that looks like this: > >> names(dat) > [1] "(-2329,-2319]" "(-1399,-1389]" "(-669.4,-659.4]" > > How can I modify those names into just this? > > [1] -2329 -1399 -669.4 > > > > > - Gundala Viswanath > Jakarta - Indonesia > > ______________________________________________ > 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.
dat <- c(1,2,3)
names(dat) <- c(-2329, -1399, -669.4) dat
-2329 -1399 -669.4
1 2 3
--
David Winsemius
On Feb 25, 2009, at 9:55 PM, Gundala Viswanath wrote:
Hi, I have the following data that looks like this:
names(dat)
[1] "(-2329,-2319]" "(-1399,-1389]" "(-669.4,-659.4]" How can I modify those names into just this? [1] -2329 -1399 -669.4
I would imagine that what is wanted is slightly (!) more general.
Something
along the lines of:
sapply(strsplit(names(dat),","),function(x){gsub("\\(","",x[1])})
Someone who knows more about regular expressions could doubtless do this
much more slickly, just using gsub() and without recourse to strsplit(),
but the foregoing works.
cheers,
Rolf Turner
######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090226/1b6fe244/attachment-0001.pl>