[R] strsplit

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


On Tue, 15 Nov 2005, tom wright wrote:

> Peter, Your correct I did mean to say
> mode(wave.data)
> but mode is still numeric???

That is because it is a factor, and they have mode = "numeric".

Don't use mode() for this: use str() or typeof(). mode() is a rather 
confusing piece of code, written I think for S-compatibility.

Use as.is, as I suggested a few minutes ago.

> I've made some changes so I can show you a trucated value for the data,
> please see the following code...
> getWave<-function(connection,id=NULL){
>    if(is.null(id)){
>        stop('Must supply record#')
>    }
>    s_sql1<-'SELECT
> Samplerate,Sampleswave,Prestimbaseline,Numberaveraged,LEFT(Data,100) as
> wavedata'
>    s_sql2<-'FROM [Patient Information]'
>    s_sql3<-paste('WHERE [Record#]=',id,sep='')
>
>    s_sql<-paste(s_sql1,s_sql2,s_sql3)
>
>    wave<-sqlQuery(connection,s_sql)
>    return(wave)
> }
>> owave<-getWave(oConn,89)
>> owave$wavedata
> [1] 161.1328\r158.6914\r162.3535\r159.9121\r158.6914\r159.9121\r153.8086
> \r151.3672\r146.4844\r142.8223\r140.3809\r1
> Levels: 161.1328\r158.6914\r162.3535\r159.9121\r158.6914\r159.9121
> \r153.8086\r151.3672\r146.4844\r142.8223\r140.3809\r1
>
>> mode(owave$wavedata)
> [1] "numeric"
>
>
>
>
> On Tue, 2005-15-11 at 18:03 +0100, 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...
>>
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

-- 
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