[R] Data Set

Stephen Tucker brown_emu at yahoo.com
Mon Jul 23 06:51:45 CEST 2007


It turns out that "-" and " " (space) are not valid variable names. You can
get around that in two ways:

==============
names(Monsoon)[2] <- "S.Sharif"
names(Monsoon)[8] <- "Islamabad.AP"
attach(Monsoon)
S.Sharif
Islamabad.AP
detach(Monsoon)

and do the same for other variable names that contain "-" or " " characters.

=============
The other way is to enclose the names in ``. For instance:
attach(Monsoon)
`S-Sharif`
`Islamabad AP`
detach(Monsoon)

Here is my example in which it works:
> x <- list(1:5,6:8)
> names(x) <- c("S-Sharif","Peshawar")
> str(x)
List of 2
 $ S-Sharif: int [1:5] 1 2 3 4 5
 $ Peshawar: int [1:3] 6 7 8
> attach(x)
> `S-Sharif`
[1] 1 2 3 4 5
> detach(x)



--- amna khan <amnakhan493 at gmail.com> wrote:

> Yes Sir
>  I am sending u the clue for data.
> 
> > str(Monsoon)
> List of 23
>  $ Dir           : num [1:40] 72.4 60.7 52.1.....
>  $ S-Sharif      : num [1:55] 23.6 93.5 36.3  ......
>  $ Peshawar      : num [1:57] 54.4 27.7 .......
>  $ Kakul         : num [1:54]  50.3 116.1 ...
>  $ Balakot       : num [1:47] 218.2  76.5 ...
>  $ Parachinar    : num [1:40] 41.4 37.6 62.2...
>  $ Kohat         : num [1:53] 50.8 93.2 94.5 ...
>  $ Islamabad AP  : num [1:48] 140.2  69.3...
>  $ Murree        : num [1:47] 130.0 131.3  74.4 ...
>  $ Islamabad SRRC: num [1:24] 172.2  82.3 150.1   ...
>  $ Mian Wali     : num [1:48] 80.5 48.5 56.6 43.2  ...
>  $ Jhelum        : num [1:57] 111.8  82.3  53.8  94.7  ...
>  $ Sialkot       : num [1:55]  62.7 126.0  90.7  ...
>  $ D-I Khan      : num [1:57] 24.9 40.6 34.3  ...
>  $ Faisalabad    : num [1:56] 79.2 43.9 55.4 ...
>  $ Lahore        : num [1:60] 32.5 81.5 28.7  ...
> 
> when I attach the data file and access the site "S-Sharif" or D-I Khan" or
> "Mian Wali" then error messages occur.
> 
> Please help in this regard.
> 
> Thank You
> 
> 
> On 7/23/07, Stephen Tucker <brown_emu at yahoo.com> wrote:
> >
> > Could you post the output from
> >
> > str(data)
> >
> > ?
> >
> > Perhaps that will give us a clue.
> >
> > --- amna khan <amnakhan493 at gmail.com> wrote:
> >
> > > Sir the station name "S.Sharif" exists in the data but still the error
> > is
> > > ocurring of being not found.
> > > Please help in this regard.
> > >
> > >
> > > On 7/22/07, Gavin Simpson <gavin.simpson at ucl.ac.uk> wrote:
> > > >
> > > > On Sun, 2007-07-22 at 03:25 -0700, amna khan wrote:
> > > > > Hi Sir
> > > > > I have made a data set having 23 stations of rainfall.
> > > > > when I use the attach function to approach indevidual stations then
> > > > > following error occurr.
> > > > >
> > > > > *>attach(data)*
> > > > > *>S.Sharif    #S.Sharif is the station  name which has 50 data
> > values*
> > > > > *Error: object "S.Sharif" not found*
> > > > > Now how to solve this problem.
> > > >
> > > > Then you don't have a column named exactly "S.Sharif" in your object
> > > > "data".
> > > >
> > > > What does str(data) and names(data) tell you about the columns in
> your
> > > > data set? If looking at these doesn't help you, post the output from
> > > > str(data) and names(data) and someone might be able to help.
> > > >
> > > > You should always check that R has imported the data in the way you
> > > > expect; just because you think there is something in there called
> > > > S.Sharif doesn't mean R sees it that way.
> > > >
> > > > You also seem to have included the R-Help email address twice in the
> > To:
> > > > header of your email - once is sufficient.
> > > >
> > > > G
> > > >
> > > > > Thank You
> > > > > Regards
> > > > >
> > > > --
> > > > %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
> > > > Gavin Simpson                 [t] +44 (0)20 7679 0522
> > > > ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
> > > > Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
> > > > Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
> > > > UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
> > > > %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
> > > >
> > > >
> > > >
> > >
> > >
> > > --
> > > AMINA SHAHZADI
> > > Department of Statistics
> > > GC University Lahore, Pakistan.
> > > Email:
> > > amnakhan493 at gmail.com
> > > amna_989 at hotmail.com
> > > amna_989 at yahoo.com
> > >
> > >       [[alternative HTML version deleted]]
> > >
> > > ______________________________________________
> > > 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
> > > and provide commented, minimal, self-contained, reproducible code.
> > >
> >
> >
> >
> >
> >
> >
>
____________________________________________________________________________________

> > news, photos & more.
> > http://mobile.yahoo.com/go?refer=1GNXIC
> >
> 
> 
> 
> -- 
> AMINA SHAHZADI
> Department of Statistics
> GC University Lahore, Pakistan.
> Email:
> amnakhan493 at gmail.com
> amna_989 at hotmail.com

> 



       
____________________________________________________________________________________
Pinpoint customers who are looking for what you sell.



More information about the R-help mailing list