Split

1 view
Skip to first unread message

kris

unread,
Apr 8, 2008, 11:21:19 AM4/8/08
to CorpLing with R
I have data in the form of a column such as
1234.
2345.
3435.
4343.
I want to have the data in this form ..i.e to remove the "dot" at the
end of each number above.
1234
2345
3435
4343

I am trying to use split but I have failed. any suggestion.

Stefan Th. Gries

unread,
Apr 8, 2008, 11:53:00 AM4/8/08
to corplin...@googlegroups.com
# if you're data are in the form of a vector
a.vector<-c("1234.", "2345.", "3435.", "4343.")
gsub("\\.", "", a.vector)

# if you're data are in the form of a factor
a.factor<-factor(a.vector)
levels(a.factor)<-gsub("\\.", "", a.vector)
a.factor

HTH,
STG
--
Stefan Th. Gries
-----------------------------------------------
University of California, Santa Barbara
http://www.linguistics.ucsb.edu/faculty/stgries
-----------------------------------------------

Ken Williams

unread,
Apr 9, 2008, 9:27:29 AM4/9/08
to corplin...@googlegroups.com


On 4/8/08 10:21 AM, "kris" <math...@gmail.com> wrote:

>
> I have data in the form of a column such as
> 1234.
> 2345.
> 3435.
> 4343.
> I want to have the data in this form ..i.e to remove the "dot" at the
> end of each number above.
> 1234
> 2345
> 3435
> 4343

If they're all in that format, you can just use as.numeric() :

> as.numeric("1234.")
[1] 1234

--
Ken Williams
Research Scientist
The Thomson Corporation
Eagan, MN

Reply all
Reply to author
Forward
0 new messages