Dear all: I am totally new to R, actually, statistics software.I get two very simple, even stupid question: 1) where I should put the data file in order to use it , I tried to build a work dir in library( package:base) and save the text file (data) there, then, I use read.table(filename), not work; I tried the full path, still not work. I must have done something wrong. 2) is it possible to create a data file in R instead of put data in a txt file and then save the file under R? I tried to find answer from the introduction, failed. I really appreciate your help, thank you very much. best
Yong Wang wrote:> Dear all: > I am totally new to R, actually, statistics software.I get two very > simple, even stupid question: > 1) where I should put the data file in order to use it , I tried to build > a > work dir in library( package:base) and save the text file (data) there,I'm not sure where such a work directory might be, but it sounds like you need to show a TA what you did. It sounds like you need to carefully read the FAQ. help.start() the follow the "Frequently Asked Questions" link, and (if you're using R on windows) the "FAQ for Windows Port"> then, I use read.table(filename), not work; I tried the full path, still > not work. I must have done something wrong.Quite likely. But without more details, there's no way to say more. There isn't only one way to make a mistake, so there isn't one answer to "it didn't work". Read the FAQ. It really does help. Read it carefully, and not in a frame of mind where you're saying to yourself "I'll never understand this, this can't possibly help." You will, it can.> 2) is it possible to create a data file in R instead of put data in a txt > file and then save the file under R?Yes, after you've got a grip on the above. *After* the above is clear, read the help pages for "save" and "load". Read the FAQ.> I tried to find answer from the introduction, failed.But not the FAQ, presumably.> I really appreciate your help, thank you very much.No problem. By the way, read the FAQ. Cheers Jason -- Indigo Industrial Controls Ltd. http://www.indigoindustrial.co.nz 64-21-343-545 jasont at indigoindustrial.co.nz
See the section called "Basic method" in http://www.psych.upenn.edu/~baron/rpsych/rpsych.html On 10/05/03 05:00, Yong Wang wrote:>Dear all: >I am totally new to R, actually, statistics software.I get two very >simple, even stupid question: >1) where I should put the data file in order to use it , I tried to build >a >work dir in library( package:base) and save the text file (data) there, >then, I use read.table(filename), not work; I tried the full path, still >not work. I must have done something wrong.I'm surprised that it didn't work with the full path. I assume the error message indicated that it could not find the file, as opposed to some other sort of error. Relative paths work too. You don't say what operating system you are using, and it probably matters. But on Linux/Unix I usually start R from the directory where the data files are, and I have several of these for different projects. (Actually I use ESS, so I start R from within (X)emacs. When I say alt-x, R, I'm asked for a directory, and, if I'm not already in that directory, I enter it using a relative path name.) In sum, at least in Unix/Linux, you can put your data anywhere, and either you start R from where the data are or you use a relative or full path name.>2) is it possible to create a data file in R instead of put data in a txt >file and then save the file under R?Yes, but this isn't the best way to do things unless the data file is pretty small. You can use c(). It is sometimes helpful to use matrix() with the argument "horiz=T" as in Example 2 in "Advanced analysis of variance examples" in http://www.psych.upenn.edu/~baron/rpsych/rpsych.html See also scan() - that is, look at the help for it. And you can also use edit(). For example: m1 <- matrix(0,5,5) m2 <- edit(m1) To save the object you've created, use write(), write.table(), write.matrix(), dput(), or save(). These differ in formatting and in how you read it back in. Jon -- Jonathan Baron, Professor of Psychology, University of Pennsylvania Home page: http://www.sas.upenn.edu/~baron R page: http://finzi.psych.upenn.edu/
Yong Wang wrote:> > Dear all: > I am totally new to R, actually, statistics software.I get two very > simple, even stupid question:But you are not new to e-mails. So, please don't specify a stupid subject line, but a sensible one. (OK, the rest of this message's body is unspecific as well, hence the subject might be quite sensible in a way, tough.)> 1) where I should put the data file in order to use it , I tried to build > a work dir in library( package:base) and save the text file (data) there, > then, I use read.table(filename), not work; I tried the full path, still > not work. I must have done something wrong.The working directory is the one you are starting R in, or what you have set with setwd(). It's not a good idea to create a working directory within the library section. Specifying the full path should always work. What you did wrong is: - not reading the manual "An Introduction to R" carefully - not reading the manual "R Data Import/Export" - beeing to unspecific. After having read the manuals and help pages, you may ask a specific question, but including error messages and code you used (we cannot help if we cannot look at your mistakes).> 2) is it possible to create a data file in R instead of put data in a txt > file and then save the file under R?Yes. Exporting Data (including ASCII formats) is also covered in the "R Data Import/Export" manual. Uwe Ligges> I tried to find answer from the introduction, failed. > I really appreciate your help, thank you very much. > best > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help