[R] Read in alphanumeric column without decimals

Steven Ranney steven.ranney at gmail.com
Thu Nov 29 20:53:00 CET 2012


All -

How can I read in a column of alphanumeric values without including
".0" on the numeric values?

Original column:

TeamLeaderID
258
342
316
U8
331
279
D1
116
235
296
...
[truncated]

leaders = read.xlsx2('FILE', sheetIndex = 1, header = T)

Column after it's been read in:

leaders$TeamLeaderID
258.0
342.0
316.0
U8
331.0
279.0
D1
116.0
235.0
296.0
...
[truncated]

If I try

as.numeric(leaders$TeamLeaderID), everything gets converted:

leaders$TeamLeaderID
11
27
19
54
23
13
28
2
8
15
...
[truncated]

as.character() and as.vector() leave the ".0" in place.

These data are being used to merge two files, one whose
data$TeamLeaderID is identical to the original column of values above.
 When I try to merge the dataframes by "TeamLeaderID," R can't match
the numbers without decimal to the ones that have decimal points.  The
alphanumeric TeamLeaderID values merge without a problem.  As a
result, I get a dataframe filled with the proper values for those
TeamLeaderID values that are alphanumeric, but "NA" values for those
whose values are strictly numeric.

How can I read in the values without R adding the ".0" to the end of
the numerals?  If there isn't a way, how can I automate the removal of
the ".0," as I have several 10s of TeamLeaderID values?

I'm using 64-bit R v. 2.15.1 on a Windows 7 machine.

Thank you -

Steven H. Ranney



More information about the R-help mailing list