[R] Removing colon from numerical data

David Winsemius dwinsemius at comcast.net
Thu Mar 4 20:07:23 CET 2010


On Mar 4, 2010, at 12:12 PM, LCOG1 wrote:

>
> Basic question, looked through the forum and documentation but didnt  
> see a
> solution.
>
> So consider
>
> O<-c(1:20)
> D<- 
> c 
> ("1 
> :","2 
> :","3 
> :","4 
> :","5:","6:","7:","8:","9:","10:","11:","12:","13:","14:","15:","16:",
> "17:","18:","19:","20:")
> Time<-c(51:70)
>
> AveTT<-data.frame(O,D,Time)

 > AveTT$D <- gsub(":", "", AveTT$D)

>
>
> I would like to remove the colon from the "D" column's data.  This  
> is how
> the data is being given to me and its too big to put into excel to  
> remove
> the colons.  I tried the below but neither returns what i want.
>
> AveTT$D<-as.numeric(AveTT$D)
>
> AveTT$D<-substr(AveTT$D,1,nchar(AveTT$D)-1)
>
> so i want
>  O   D Time
> 1   1  1:   51
> 2   2  2:   52
> 3   3  3:   53
> 4   4  4:   54
> 5   5  5:   55
> 6   6  6:   56
> 7   7  7:   57
> 8   8  8:   58
> 9   9  9:   59
> 10 10 10:   60
>
> to become
>
>  O   D Time
> 1   1  1   51
> 2   2  2   52
> 3   3  3   53
> 4   4  4   54
> 5   5  5   55
> 6   6  6   56
> 7   7  7   57
> 8   8  8   58
> 9   9  9   59
> 10 10 10   60
>
> while maintaining the data's integrity.  Thanks
>
> JR
>
> -- 
> View this message in context: http://n4.nabble.com/Removing-colon-from-numerical-data-tp1578397p1578397.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.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT



More information about the R-help mailing list