[R] Error message with scan() function

2010-10-04 Thread Tariq Perwez
Hi Everyone,

I am new R user and am trying to learn by reading the online manual "An
Introduction to R" from the R web site. I am trying to practice using the
scan() function as explained in the manual. For this I first created three
vectors (one a character vector and two numeric one) and saved file
"input.dat" in my working directory as:

> label <- c("Bill", "Tom", "Pat", "Will", "Sue", "Sam")
> x <- 1:6
> y <- 6:1
> save(label, x, y, file = "input.dat")

Now, when I try the scan() function as explained in the manual as below, I
get the error message:

> inp <- scan("input.dat", list("",0,0))
Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,
:
  scan() expected 'a real', got 'X'

I have not been able to figure out what the problem is. I would appreciate
if someone could please guide me as to what I am doing wrong. Regards,

Tariq

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


[R] R packages and assess to data in packages

2009-12-05 Thread Tariq Perwez
Hi Everyone,

I have two very basic questions and would appreciate your help.
1. I would like to see/access the data that comes with a given R package by
using a function like read.table(). For example, I just installed car
package from CRAN. I know that somewhere within the package, there is
Duncan.txt file. I would not only like to look at it from file browser (or
using ls command in shell)  but also to access it as:

> Duncan <- read.table("path/to/data/Duncan.txt", header = T)

I can certainly use:

> data(Duncan)

and

> attach(Duncan)

after loading the package car. However, I would like to see all the data
that come with a package as separate files. Where are these files located? I
installed the car package under Mac OSX  under the user level (if this
detail is important). However, I do use R under Ubuntu linux also and
general solution to this problem will be great. I even downloaded the car
binaries and unpacked the zipped file on desktop but I just see .rda files
within the data folder; there are no .txt files anywhere.  I do see
Duncan.rda file (I believe this contains the Duncan.txt data). How can I
access the data files from such package, say using a text editor??

2. What is the safest/preferred place to install an R package that I want to
delete/remove once I do not need it. Sometimes, I just need to install a
package from a book's website so that I can work on the exercises etc but do
not need the package permanently hanging around. Removing such a package and
all the associated files etc would be nice.

I would appreciate any help and comments on my questions. Regards,

Tariq

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


[R] Help with unstack() function

2009-11-15 Thread Tariq Perwez
Hi Everyone,

I am trying to understand the unstack() function but after struggling for
two days, I have given up. More specifically, I am trying the exercises at
the end of  Chapter 1 of Data Analysis and Graphics Using R by Maindonald
and Braun, 2nd ed. Exercise 18 (p. 41) asks to unstack the Rabbit data frame
from the MASS package to get a certain data frame that is shown in the
exercise. Authors suggest to use the unstack() three times but I am so new
to R that I have absolutely no clue as to what is to be done each of those
times. Sadly for me, the help page for unstack() does not give much help
either. For example, the statement in the help page regarding the argument
form, "a two-sided formula whose left side evaluates to the vector to be
unstacked and whose right side evaluates to the indicator of the groups to
create" is very cryptic to me.  Basically, I have tried things like:

unstack(Rabbit, Dose ~ Animal)

but notice that what I get is a data frame in which other columns of the
Rabbit data frame disappear. I would appreciate if someone could help me
understand this function. On page 17 of the same book, there is an example
of unstack() function but that one uses a very simple data frame (only two
columns). I would like to know how to handle more complex data frames as in
the exercise. BTW, this is not a school assignment; I am learning R using
this book on my own. Thanks for any help. Regards,

Tariq

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


[R] Help with history() in Emacs/ESS

2009-10-25 Thread Tariq Perwez
Hi Everyone,

I am a beginner running R 2.9.2 under Ubuntu and typically use Emacs w/ESS.
However, I am confused with history() command. When I issue command
history() in Emacs within an R session, this is what get:

> history()
Error in savehistory(file) : no history available to save


Similarly, history(max=10) command gives the same error message.

However, there is this In/Out Menu in the Emacs when R is running, and if I
press List Input History from this menu, I see the entire history in a new
frame. Unfortunately, I cannot control how much history I can view by this
menu approach. I would greatly appreciate if someone could explain what is
going on with history() command under Emacs/ESS. Interestingly, history()
command seems to work fine in an R session within the terminal. Best
regards,

Tariq

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


[R] R binaries for linux on G4 Powerpc?

2008-08-26 Thread Tariq Perwez
Hi Everyone

I just installed Yellow Dog Linux (v 5.02) on an old G4 Powerpc replacing
the Mac OSX. The system is running beautifully. I would like to install R on
this system. I am not sure how to go about doing it. I have installed R on
my Ubuntu system as well as on Mac OSX but there are binaries available for
those systems from the  R Project site.  The Yellow Dog Linux is rpm based
and has a package management tool called yum. The distribution is derived
from Red Hat Linux but is specially designed for the G3/G4/G5 Powerpc
architecture. As far as I know, there are no repositories for this
particular distro to install R. I was wondering if there is a way to get
access to other repositories to install R on my system. I would appreciate
any suggestions and guidance. Regards,

Tariq

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


[R] Help Updating and Installing R Packages

2008-07-15 Thread Tariq Perwez
Hi Everyone,

I have a few fairly basic questions about upgrading and installing R
packages. First off, I am using Ubuntu Hardy Heron and have R 2.7.1
installed and working perfectly. I usually access R via Emacs ESS interface
which I am still trying to get the hang of. My questions and issues are as
follows:

Question 1:  I started R and wanted to upgrade the installed R packages. So,
I issue the command >upgrade.packages()
 and after selecting the CRAN mirror sites, I get the following message:

lattice :
 Version 0.17-8 installed in /usr/lib/R/library
 Version 0.17-10 available at http://www.ibiblio.org/pub/languages/R/CRAN
Update (y/N/c)?

(To this, I respond with  "y", but then I get the following:)


Warning in install.packages(update[instlib == l, "Package"], l, contriburl =
contriburl,  :
  'lib = "/usr/lib/R/library"' is not writable


(Off course, it is NOT writable because it did not ask for the
administrative password.

Would you like to create a personal library
'~/R/i486-pc-linux-gnu-library/2.7'
to install packages into?  (y/n)


I do not want to create new directories; I just want to upgrade where the
older version already exists. So I respond with "n" and get this:)


Error in install.packages(update[instlib == l, "Package"], l, contriburl =
contriburl,  :
  unable to install packages


My question is how do I go about upgrading AND installing packages from
within R by using administrative account? I must say that at least for now,
I was able to get around this issue by staring R as:

sudo R

and then using upgrade.packages(). But I would like a better solution when I
am already in an R session.


Question 2: When I started R via

sudo R

and issued >upgrade.packages()

I had problem upgrading lattice package. I got the following error message:

* Installing *source* package 'lattice' ...
** libs
gcc -std=gnu99 -I/usr/share/R/include  -fpic  -g -O2 -c init.c -o init.o
In file included from init.c:2:
/usr/share/R/include/R.h:28:20: error: stdlib.h: No such file or directory
/usr/share/R/include/R.h:29:19: error: stdio.h: No such file or directory
In file included from
/usr/lib/gcc/i486-linux-gnu/4.2.3/include/syslimits.h:7,
 from /usr/lib/gcc/i486-linux-gnu/4.2.3/include/limits.h:11,
 from /usr/share/R/include/R.h:30,
 from init.c:2:
/usr/lib/gcc/i486-linux-gnu/4.2.3/include/limits.h:122:61: error: limits.h:
No such file or directory
In file included from init.c:2:
/usr/share/R/include/R.h:32:18: error: math.h: No such file or directory
/usr/share/R/include/R.h:33:19: error: errno.h: No such file or directory
In file included from /usr/share/R/include/R.h:50,
 from init.c:2:
/usr/share/R/include/R_ext/RS.h:24:39: error: string.h: No such file or
directory
In file included from init.c:3:
/usr/share/R/include/Rinternals.h:770: error: expected declaration
specifiers or '...' before 'FILE'
/usr/share/R/include/Rinternals.h:773: error: expected declaration
specifiers or '...' before 'FILE'
make: *** [init.o] Error 1
ERROR: compilation failed for package 'lattice'
** Removing '/usr/lib/R/library/lattice'
** Restoring previous '/usr/lib/R/library/lattice'

The downloaded packages are in
/tmp/Rtmpj37zYN/downloaded_packages
Updating HTML index of packages in '.Library'
Warning message:
In install.packages(update[instlib == l, "Package"], l, contriburl =
contriburl,  :
  installation of package 'lattice' had non-zero exit status



Even >upgrade.packages(dependencies = TRUE) resulted in the same error. Does
anyone know if this is just a problem on my system or perhaps someone else
has run into the same issue. What does this all mean? What I do not
understand is why are there .h missing files? How the heck did lattice get
installed in the first place if these header files were missing?

Question 3: This is more of a general question that has been on my mind for
sometime. If I just want to install some packages/data base etc that I would
like to be "local", perhaps in my home directory, which library path would
be recommended? Sometimes I feel that I would like to download some database
or other packaged code that I want to play around with but would later like
to get rid of, a library in the home directory that is still in R's path
might be better. I would appreciate suggestions. What are others doing in
this situation? Currently I have the following outcome of .libPaths()
command:

> .libPaths()
[1] "/usr/local/lib/R/site-library" "/usr/lib/R/site-library"
[3] "/usr/lib/R/library"

Which library path should I choose?

Best regards,

Tariq

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


[R] Controlling the length of line with abline(lm())

2008-06-18 Thread Tariq Perwez
Hi
I just realized that when I use linear regression to draw a line through my
data points with something like the following:

abline(lm(y ~ x))


the length of the line is infinite, i.e., the line goes beyond the smallest
and the largest data values. This seems not very right to me (not to mention
it looks unaesthetic). I do not mean to imply that the straight-line
behavior of my system is maintained throughout. I would like to limit the
length of this line to the range of my data. However, I have not been able
to figure out how to. Very disconcertingly, I found out that all the books
that teach statistics using R seem to be drawing such infinite length-lines.
I would appreciate any advice or suggestions. Regards,


Tariq

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


[R] Help with axis labels

2008-06-18 Thread Tariq Perwez
Hi
I have patched together (from various sources) the following code to get
semi-logarithmic plot. Unfortunately, my labels come out also at
intermediate places between 10^2, 10^3, 10^4 etc. Since I put the code
together from various sources and do not understand fully how the code is
working, I have not been able to get rid of the labels like 10^1.69897,
10^2.69897 etc. I would appreciate if someone could modify the following
code to solve this problem for me. Regards,

Tariq

## Code follows


time <- c(0,30,60,90,120,150,180,210,240,270,300,330,360,390,410)

sk3222 <- c(19,46,73,130,190,358,632,1240,2340,4666,9422,17923,39448,72809,
149765)



plot(time,sk3222, yaxt="n",log ="y", xaxt="n", type= "o", las = 2,
main = "Semi-logarithmic
plot")


axis(1, c(0,60,120,180,240,300,360,420))



axis.at <- 10 ^ c(0:10)

axis(2, at = 1:10 * rep(axis.at[-1] / 10, each = 10), tcl = -0.5, labels =
FALSE)



at <- axTicks(2)

axis(2, c(1:20), at=at, labels=parse(text=paste("10^",log10(at))), las=2
)



rm(list=ls())

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


[R] Specifying fonts in R

2008-06-15 Thread Tariq Perwez
Hi
I am a novice user of R. I got hold of "R Graphics" by P. Murrell the other
day and am trying to follow examples in the book. In chapter 3, the section
on font specification gives 16 "basic" font families and face combinations
available in R (Figure 3.9). However, the book also warns that even if a
font specification is given, it does not mean that the font will always be
available. There can be significant differences between operating systems
and location  Hmm ... I am at a total loss as to what this means.
Anyhow, I tried to switch font family by call to the par() function as:

par(family="serif")

Following this, when I used plot() command, I got a bucketful of warning:
all to the effect that times font is not available. I am using R on Mac OSX,
Ubuntu linux as well as on Windows. As far as I know, I installed the full R
distribution on each of these systems. I am sure Times font is available on
these systems, at least in some form. For example, many type 1 PostScript
fonts are freely available on all systems. My question is, what do I have to
do to make the serif (in this case, times) font family available to R. I
would like to hear from others who might have done it. Or perhaps, this
cannot be done? I did check that Hershey fonts are available on my system. I
am so new to R that I am not yet even clear as to where the R-related stuff
is on the computer. I would appreciate any suggestions and advice. Regards,

Tariq

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


[R] Plotting multiple continuous lines with symbols

2008-06-10 Thread Tariq Perwez
Hi,
I am trying to plot multiple lines on one plot such that all lines are of
the same color (black) and continuous. I need to distinguish these multiple
plots from each other by using different symbols (I am using pch=). However,
all my lines are broken on both sides of the symbols. This unfortunate (and
unsightly) behavior seems to be the default. In my search of the help
archives for R over several days, I have not been able to solve this
problem. I would appreciate any help and suggestions. My code for the plot
is below (minus the data):

exa1.1 <- read.table("multcol.txt", header=T, sep='')# Total of 4
columns; first one to be on x-axis
attach(exa1.1)
names(exa1.1)
exa1.1


plot(exa1.1$Year, exa1.1$EM, ylim=range(exa1.1[,-1]), type = 'b' ,pch=16,
main = ""), las=1, cex.main=1.75,lab =c(12,8,10), ylab="", xlab="", )
lines(exa1.1$Year,exa1.1$IM,type='b', pch=1)
lines(exa1.1$Year,exa1.1$BM,type='b', pch=17)
mtext(side = 2, text = "Klett units", line = 3.5, cex=1.2)
mtext(side = 1, text = expression(Time~at~37*degree*C~(minutes)), line =
2.75,cex=1.2)


Regards,

Tariq

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


[R] Superscript/Subscript in main title

2008-06-04 Thread Tariq Perwez
I have been trying to figure out how to get superscript/subscript in the
main title for a plot. I have tried various approaches and suggestions but
none of them work. I am trying to get the following as the main title of my
plot:

Emission of CO2 with time

(but note that 2 is subscript.)

I have tried

plot(main="Emission of C"expression(O[2]) "with time")

and I get error message. I have also tried

plot(main="Emission of C"quote(O[2]) "with time")

I have also tried

plot(main"")
mtext("Emission of C"expression(O[2]) "with time")

I keep getting errors. I have searched the archives but none of the threads
seem to touch upon this. I would appreciate any suggestion. Regards,

Tariq

[[alternative HTML version deleted]]

__
R-help@r-project.org 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.