[R] new comer's question

Chang Shen Chang_Shen at progressive.com
Mon Jan 16 21:30:25 CET 2006


I am new to R.  I try to search the web but could not find the answer so I
post it here asking for help.



I have a csv file looks like this: (between two ==== lines)
===========================

Machine Name,"Resource, Type","Resource, Sub-type","Resource,
Instance",Date,,Data ->,,,,,,
,0.041666667,,,,,,,,,,,

Time (HH:MM) ->,,,,,,0:00,0:15,0:30,0:45,1:00,1:15,1:30
SCINFR06,Cache,Copy Read Hits %,,10-Jan-06,Cache->Copy Read Hits
%,0.99,1,1,1,1,1,0.99
SCINFR06,Cache,Data Map Hits %,,10-Jan-06,Cache->Data Map Hits
%,1,1,1,1,1,1,1

Time (HH:MM) ->,,,,,,0:00,0:15,0:30,0:45,1:00,1:15,1:30
SCINFR06,LogicalDisk,% Disk Read Time,C:,10-Jan-06,LogicalDisk->% Disk Read
Time->C:,2.14,1.52,1.94,1.68,2.52,2.05,2.66
SCINFR06,LogicalDisk,% Disk Read Time,D:,10-Jan-06,LogicalDisk->% Disk Read
Time->D:,0.04,0,0,0.08,0,0,0
SCINFR06,LogicalDisk,% Disk Read
Time,HarddiskVolume1,10-Jan-06,LogicalDisk->% Disk Read
Time->HarddiskVolume1,0,0,0,0,0,0,0
SCINFR06,LogicalDisk,% Disk Read Time,_Total,10-Jan-06,LogicalDisk->% Disk
Read Time->_Total,0.72,0.51,0.65,0.59,0.84,0.68,0.89

==============================


First I load it by read.table call:

myArray <- read.table("c:/mydata.csv",sep=",");

After this,  the array element myArray[1,2] looks like this

>myArray[1,2]
[1] Resource, Type
Levels:  0.041666667 Cache LogicalDisk Resource, Type

Here are the questions:
(1) What does Levels mean?
(2) When I try to split the string "Resource, Type", which is myArray[1,2],
using function strsplit(), I got error:

> w<-strsplit(myArray[1,2],",")
Error in strsplit(x, as.character(split), as.logical(extended),
as.logical(fixed),  :
        non-character argument in strsplit()

Then I tried this:

> y<-myArray[1,2]
> y
[1] Resource, Type
Levels:  0.041666667 Cache LogicalDisk Resource, Type
> w<-strsplit(y,",")
Error in strsplit(x, as.character(split), as.logical(extended),
as.logical(fixed),  :
        non-character argument in strsplit()


But the following call does not cause any error.

>  y<-"Resource, Type"
> w<-strsplit(y,",")
> w
[[1]]
[1] "Resource" " Type"



what is wrong?


Thanks

Chang




More information about the R-help mailing list