[R] please help me on this problem
Jonathan Baron
baron at psych.upenn.edu
Sun Oct 5 12:26:57 CEST 2003
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/
More information about the R-help
mailing list