[R] Odp: Data manipulations with numbers which are in 'comma' format
Petr PIKAL
petr.pikal at precheza.cz
Mon Sep 24 11:24:24 CEST 2007
Hi
> Hi R,
>
>
>
> May be a trivial question, but struggling to find a solution...
>
>
>
> v=data.frame(a=c("1,234","2,345","5,567"))
>
> > v
>
> a
>
> 1 1,234
>
> 2 2,345
>
> 3 5,567
>
>
>
> I need a column 'b', which is just the addition of column 'a' with 5.
> How do I do it? And, entries in column 'a' are with commas, always.
> Also, class(v$a)=factor.
something like
> v$b <- as.numeric(gsub(",", ".", v$a)) + 5
> v
a b
1 1,234 6.234
2 2,345 7.345
3 5,567 10.567
Regards
Petr
>
>
>
> BR, Shubha
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
More information about the R-help
mailing list