[R] getting started, reading listing and saving data

Don MacQueen macq at llnl.gov
Wed Nov 23 17:23:56 CET 2005


To use head() but restrict it to, say, the 5th through 9th variables, use

     head( x[ , 5:9] )

or variants of that idea. Further examples
    head( x[  , c(5,7,9,13)] )
or
    head( x[  , c('A','vname','var2')])
where 'A', 'vname', and 'var2' are column names.

Try also
     x[1:12, c(1, 4:6)]

I'm sure that methods of extracting portions of an object are in the 
intro documents, but you may not have recognized them for what they 
are. Try

   help('[')

at the prompt for more information.

-Don

At 11:27 AM +0100 11/23/05, Ronnie Babigumira wrote:
>Many thanks to Peter Alspach, Jim Porzak and Murray Pung for the help.
>Peter and Jim, head? and tail? was just what I needed to list a few
>observations. Peter, thanks for pointing out str? to me. I totally
>agree with you on its usefulness.
>
>Murray thanks for file > save workspace (and Peters save.image)
>addresses the third of my concerns
>
>One last question related to head and tails, this works best if you
>have a few variables (columns). Given more, how can I use the
>information on the variable names given after str to list the first
>few few observations for a set of variable.
>
>To make it clear. Say I load a dataset with n variables named v1 to
>vn. I use str(mydata) and I get a list of variable names..
>
>str(x)
>v1 ......
>.  ......
>.  ......
>.  ......
>.  ......
>Vn ......
>
>How do i list the first n observations of say v5 to v9
>
>Many thanks
>
>Ronnie
>
>______________________________________________
>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


-- 
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA




More information about the R-help mailing list