Skip to content
Prev 279898 / 398506 Next

question about spaces in r

First of all, it's R, not r, and on this mailing list people care about
this kind of thing.

Second, you will need to provide more information in order to get better
help. Please read the posting guide.

There are a number of introductory level documents available via CRAN,
please pick one and study the basics.

That said, here are a few basics:

When R reads data that is a mixture of letters and digits, as yours is, it
will interpret all of them as characters. (Possibly converting to
something called a "factor", depending on exactly how the data is being
input.)

read.csv() produces data frames, not matrices. In a matrix, all values
must be the same type, numeric or character. In a data frame, different
columns can be different types, but each column must be all the same type.
Your column has a mixture of tyeps. Your input column apparently has a
mixture of types, violating the data frame rule, so read.csv() treats the
numbers as characters.

You can use as.numeric() on this column to convert to numeric. The
elements that look like numbers will become numeric, and the elements that
have letters will be converted to NA for missing.

Just guessing, but from what you've shown in looks like maybe your input
data (outside R) is structured in a way that is not conducive to reading
into R. This is quite common when the input data is a spreadsheet.

-Don