Ronnie Babigumira
2005-Nov-23 01:38 UTC
[R] getting started, reading listing and saving data
Dear List I am new to R and to the list and will try best as I can be clear and concise. My apologies if anything I write contravenes the posting code on this list. I would also like to say I have run through most of the material on the R website before writing this email however, I am stuck. Here is what I want to do and what I have done 1. Read a comma seperated text file into R I have used read.csv and it seems to have worked 2. List the a few observations to make sure the right stuff came in I have failed to find a command that allows me to list a few observations and would appreciate some help on this (I have used edit which pops up an spreadsheet however, I would prefer a command that allows me to list a few observations for inspection) 3. Save this data as an r dataset I cant seem to figure this out (I tried save(mytextfile, file "myrdata") but when I try to load what I saved, I get an error message "Error: bad restore file magic number (file may be corrupted) -- no data loaded" 4. Load this r dataset and proceed to work on it I would appreciate some help.
Not sure about reading the first few lines, but summary(x) might be what you're after. Try using the menu to save the workspace. File > Save Workspace. You can then load the workspace at the start of your next session and continue working. Murray -----Original Message----- From: Ronnie Babigumira [mailto:r.babigumira at gmail.com] Sent: Wednesday, 23 November 2005 12:38 PM To: r-help at stat.math.ethz.ch Subject: [R] getting started, reading listing and saving data Dear List I am new to R and to the list and will try best as I can be clear and concise. My apologies if anything I write contravenes the posting code on this list. I would also like to say I have run through most of the material on the R website before writing this email however, I am stuck. Here is what I want to do and what I have done 1. Read a comma seperated text file into R I have used read.csv and it seems to have worked 2. List the a few observations to make sure the right stuff came in I have failed to find a command that allows me to list a few observations and would appreciate some help on this (I have used edit which pops up an spreadsheet however, I would prefer a command that allows me to list a few observations for inspection) 3. Save this data as an r dataset I cant seem to figure this out (I tried save(mytextfile, file "myrdata") but when I try to load what I saved, I get an error message "Error: bad restore file magic number (file may be corrupted) -- no data loaded" 4. Load this r dataset and proceed to work on it I would appreciate some help. ______________________________________________ R-help at stat.math.ethz.ch mailing list stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! R-project.org/posting-guide.html
Ronnie, try head? tail? and, I also fine useful after loading str? On 11/22/05, Ronnie Babigumira <r.babigumira at gmail.com> wrote:> Dear List > I am new to R and to the list and will try best as I can be clear and > concise. My apologies if anything I write contravenes the posting code > on this list. I would also like to say I have run through most of the > material on the R website before writing this email however, I am > stuck. > > Here is what I want to do and what I have done > > 1. Read a comma seperated text file into R > I have used read.csv and it seems to have worked > > 2. List the a few observations to make sure the right stuff came in > I have failed to find a command that allows me to list a few > observations and would appreciate some help on this (I have used edit > which pops up an spreadsheet however, I would prefer a command that > allows me to list a few observations for inspection) > > 3. Save this data as an r dataset > I cant seem to figure this out (I tried save(mytextfile, file > "myrdata") but when I try to load what I saved, I get an error message > "Error: bad restore file magic number (file may be corrupted) -- no data loaded" > > 4. Load this r dataset and proceed to work on it > > I would appreciate some help. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! R-project.org/posting-guide.html >-- HTH, Jim Porzak Loyalty Matrix Inc. San Francisco, CA
Ronnie Babigumira
2005-Nov-23 10:27 UTC
[R] getting started, reading listing and saving data
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
Thomas Schönhoff
2005-Nov-23 10:52 UTC
[R] getting started, reading listing and saving data
Hello, 2005/11/23, Ronnie Babigumira <r.babigumira at gmail.com>:> 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 v9Not sure if this is what you are looking for: str(myobject[ 5:9]) regards
Ronnie Babigumira
2005-Nov-23 12:44 UTC
[R] getting started, reading listing and saving data
Thomas many thanks, though str(myobject[ 5:9]) is not what I want, it prompted me to try head(myobject [3:4]) and this gets me really close to what I want, I get the first few observations of variables 3 and 4 in my data. What I would like to do however is to do the same thing but with the variable names explicitly (so instead of 3:4 I use something like varname3 and varname4) Any ideas Again, many thanks to all on the list who have helped (I promise I am frantically trying to read up everything I have been given and bring myself upto speed so I will not be consuming bandwidth with a lot of read the manual sort of questions) On 11/23/05, Thomas Sch??nhoff <tschoenhoff at gmail.com> wrote:> Hello, > > 2005/11/23, Ronnie Babigumira <r.babigumira at gmail.com>: > > 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 > > Not sure if this is what you are looking for: str(myobject[ 5:9]) > > regards >
Thomas Schönhoff
2005-Nov-23 13:14 UTC
[R] getting started, reading listing and saving data
Hi, 2005/11/23, Ronnie Babigumira <r.babigumira at gmail.com>:> Thomas many thanks, though str(myobject[ 5:9]) is not what I want, it > prompted me to try head(myobject [3:4]) and this gets me really close > to what I want, I get the first few observations of variables 3 and 4 > in my data. What I would like to do however is to do the same thing > but with the variable names explicitly (so instead of 3:4 I use > something like varname3 and varname4) > > Any ideas > > Again, many thanks to all on the list who have helped (I promise I am > frantically trying to read up everything I have been given and bring > myself upto speed so I will not be consuming bandwidth with a lot of > read the manual sort of questions) > > > > On 11/23/05, Thomas Sch??nhoff <tschoenhoff at gmail.com> wrote: > > Hello, > > > > 2005/11/23, Ronnie Babigumira <r.babigumira at gmail.com>: > > > 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 > > > > Not sure if this is what you are looking for: str(myobject[ 5:9])myobservs <-str(myobject, myobject$v5[1:n],...,...,... myobject$9[1:n]) where n = number of observations to be selected. Hmm, not sure if this works for your object (data.frame, matrix, multi-dimensional array?). Would be much easier to know more about your object! regards Thomas
Thomas Schönhoff
2005-Nov-23 13:16 UTC
[R] getting started, reading listing and saving data
Again, 2005/11/23, Thomas Sch??nhoff <tschoenhoff at gmail.com>:> Hi, > > 2005/11/23, Ronnie Babigumira <r.babigumira at gmail.com>: > > Thomas many thanks, though str(myobject[ 5:9]) is not what I want, it > > prompted me to try head(myobject [3:4]) and this gets me really close > > to what I want, I get the first few observations of variables 3 and 4 > > in my data. What I would like to do however is to do the same thing > > but with the variable names explicitly (so instead of 3:4 I use > > something like varname3 and varname4) > > > > Any ideas > > > > Again, many thanks to all on the list who have helped (I promise I am > > frantically trying to read up everything I have been given and bring > > myself upto speed so I will not be consuming bandwidth with a lot of > > read the manual sort of questions) > > > > > > > > On 11/23/05, Thomas Sch??nhoff <tschoenhoff at gmail.com> wrote: > > > Hello, > > > > > > 2005/11/23, Ronnie Babigumira <r.babigumira at gmail.com>: > > > > 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 v9Sorry for the typo, once again:> > myobservs <-str(myobject, myobject$v5[1:n],...,...,... myobject$v9[1:n]) > > where n = number of observations to be selected.Thomas
On 23 Nov 2005 at 13:44, Ronnie Babigumira wrote: Date sent:  From:  <r.babigumira at gmail.com> To: Subject: and saving data [DEL: > Thomas many thanks, though str(myo I want, it :DEL] [DEL: > prompted me to try head(myobject [3:4]) really close :DEL] [DEL: > to what I want, I get the first few obse variables 3 and 4 :DEL] [DEL: > in my data. What I would like to do howe same thing :DEL] [DEL: > but with the variable names explicitly ( use :DEL] [DEL: > something like varname3 and varname4) :DEL] [DEL: > :DEL] [DEL: > Any ideas :DEL] Hi qouote names head(myobject [, c("some.name", "some.other.name HTH Petr [DEL: > :DEL] [DEL: > Again, many thanks to all on the list wh promise I am :DEL] [DEL: > frantically trying to read up everything and bring :DEL] [DEL: > myself upto speed so I will not be consu a lot of :DEL] [DEL: > read the manual sort of questions) :DEL] [DEL: > :DEL] [DEL: > :DEL] [DEL: > :DEL] [DEL: > On 11/23/05, Thomas Sch?nhoff <tsch wrote: :DEL] [DEL: > > Hello, :DEL] [DEL: > > :DEL] [DEL: > > 2005/11/23, Ronnie Babigumira <r :DEL] [DEL: > > > Many thanks to Peter Alspach, for the :DEL] [DEL: > > > help. Peter and Jim, head? and needed to :DEL] [DEL: > > > list a few observations. Peter str? to :DEL] [DEL: > > > me. I totally agree with you o [DEL: > > > :DEL] [DEL: > > > Murray thanks for file > sa save.image) :DEL] [DEL: > > > addresses the third of my conc [DEL: > > > :DEL] [DEL: > > > One last question related to h best if :DEL] [DEL: > > > you have a few variables (colu I use the :DEL] [DEL: > > > information on the variable na list the :DEL] [DEL: > > > first few few observations for [DEL: > > > :DEL] [DEL: > > > To make it clear. Say I load a named v1 :DEL] [DEL: > > > to vn. I use str(mydata) and I names.. :DEL] [DEL: > > > :DEL] [DEL: > > > str(x) :DEL] [DEL: > > > v1 ...... :DEL] [DEL: > > > . ...... :DEL] [DEL: > > > . ...... :DEL] [DEL: > > > . ...... :DEL] [DEL: > > > . ...... :DEL] [DEL: > > > Vn ...... :DEL] [DEL: > > > :DEL] [DEL: > > > How do i list the first n obse :DEL] [DEL: > > :DEL] [DEL: > > Not sure if this is what you are lo str(myobject[ 5:9]) :DEL] [DEL: > > :DEL] [DEL: > > regards :DEL] [DEL: > > :DEL] [DEL: > :DEL] [DEL: > ________________________________________ [DEL: > R-help at stat.math.ethz.ch mailing list :DEL] [DEL: > stat.ethz.ch/mailman/listinfo/r- [DEL: > PLEASE do read the posting guide! :DEL] [DEL: > R-project.org/posting-guide.h Petr Pikal petr.pikal at precheza.cz