[R] strsplit

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Nov 15 18:29:43 CET 2005


On Tue, 15 Nov 2005, Peter Dalgaard wrote:

> tom wright <tom at maladmin.com> writes:
>
>> I'm stuck on what I feel should be a minor problem.
>> I have a dataseries obtained from a MS Access database that consists of
>> a series of numbers seperated by carridge returns (\r)
>> Currently this data is in R as mode numeric???
>>
>> I want to separate this into a vector of the componant numbers.
>> Perhaps a little code will help describe what I've got here!!
>>
>> library(rodbc)
>> s_sql<-'SELECT Data from table where id=1' #only one record returned
>> oWave<-sqlQuery(oConn,s_sql)
>>
>> wave.data<-oWave$data
>>
>>> mode(data)
>> [1] "numeric"
>>
>> Any clues will be much appreciated
>
> Er, did you mean to say mode(wave.data)?
>
> Anyways, you say that you want to obtain a vector of numbers, and you
> got an object of mode numeric, which means that it is a vector of
> numbers. So what was the problem in the first place?
>
> If you had data with carriage returns inside, then you should have
> them as mode "character".
>
> So there seems to be something that you're not telling us...

or Access is not telling R.  One possibility is that Access is reporting 
this field as numeric:  use sqlColumns() to find out.  If so, you need to 
sort this out in Access.  If not, you can use the as.is argument: see 
?sqlGetResults referenced from ?sqlQuery (although I would be surprised if 
type.convert was getting confused).

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list