Re: [R] elementary statistics with R (rkward?)

2007-07-11 Thread Sarah Goslee
I don't know anything about RKward, but there are many, many
tutorials, guides and other documents written for people learning R
available online.
Try the introduction to R at:
http://www.r-project.org/
under manuals, or some of the many fine contributions at:

http://cran.r-project.org/other-docs.html

Sarah

On 7/11/07, Donatas G. [EMAIL PROTECTED] wrote:
 Hi, I am trying to learn some basic statistics stuff but I cannot find any
 elementary statistics exercises using R language. Using RKward would be even
 better...

 I need that in analysing sociological data, obtained through questionnairres -
 findind corelations between variables, relations between different types of
 data, etc.

 Could anyone recommend simple tutorials/exercises, available on www for me to
 work on?

 I realize it would be much simple to do this introductory stuff with spss, 
 that
 everyone around me is using here in Lithuania, but I'd really like to learn to
 do it with R instead...

 --
 Donatas G.


-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] histogram with absolute figures

2007-07-09 Thread Sarah Goslee
Well, how about an example of what you are doing, and a
description of what the results you get and the results you
want are?

When I do a histogram, I get frequencies.

Sarah

On 7/9/07, Mag. Ferri Leberl [EMAIL PROTECTED] wrote:
 Meanwhile I have recognized, that the breaks-option enforces density as
 the default. But if I try to force frequencies (freq=TRUE) I get the
 following feedback:

 Warning message:
 the AREAS in the plot are wrong -- rather use freq=FALSE in:
 plot.histogram(r, freq = freq, col = col, border = border, angle =
 angle,

 And the machine hasn't promised too much: the result IS wrong.
 Yours,
 Mag. Ferri Leberl



 Am Freitag, den 06.07.2007, 16:17 -0400 schrieb Sarah Goslee:
  The default of hist() is counts rather than percentages.
 
  Sarah
 
  On 7/6/07, Mag. Ferri Leberl [EMAIL PROTECTED] wrote:
   Dear everybody!
   Is ist easily possible to make up a histogram with absolute numbers
   instead of percentages?
   Thank you in advance!
   Yours, Mag. Ferri Leberl
  
   ___




-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to calculate the index the number of species combinations?

2007-07-07 Thread Sarah Goslee
It should be the number of unique sites. In this case, the number of
unique columns in the data frame. See ?unique. (Interestingly,
convention is usually that species are columns and sites are rows.)

For your sample data you only see 10 of the 2^17 possible combinations
of 17 species (not 2n).

Sarah

On 7/7/07, Zhang Jian [EMAIL PROTECTED] wrote:
 I want to analyze the co-occurrence of some species. In some papers, the
 authors said that the indexthe number of species combinations (COMBO) is a
 good index. I try to calculate the index by R language. But I can not get
 the right value. I think that I do not understand the concept of the index
 because my english is not good.

 The concept:
 *The number of species combinations   *This index scans the columns of the
 presence-absence matrix and keeps track of the number of unique species
 combinations that are represented in different sites. For an assemblage of n
 species, there are 2n possible species combinations, including the
 combination of no species being present (Pielou and Pielou 1968). In most
 real matrices, the number of sites (= columns) is usually substantially less
 than 2n, which places an upper bound on the number of species combinations
 that can be found in both the observed and the simulated matrices.

 Presence-absence Data (Each row represents different species and each column
 represents a different site. A 1 indicates a species is present at a
 particular site, and a 0 indicates that a species is absent from a
 particular site):
 Species Cuba Hispaniola Jamaica Puerto_Rico Guadeloupe Martinique Dominica
 St._Lucia Barbados St._Vincent Grenada Antigua St._Croix Grand_Cayman
 St._Kitts Barbuda Montserrat St._Martin St._Thomas
 Carduelis_dominicensis 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 Loxia_leucoptera 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 Volatinia_jacarina 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
 Sporophila_nigricollis 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
 Melopyrrha_nigra 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0
 Loxigilla_portoricensis 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 Loxigilla_violacea 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 Loxigilla_noxis 0 0 0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 0
 Melanospiza_richardsoni 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
 Tiara_olivacea 1 1 1 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0
 Tiara_bicolor 0 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1
 Tiara_canora 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 Loxipasser_anoxanthus 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 Saltator_albicollis 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0
 Torreornis_inexpectata 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 Ammodramus_savannarum 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 Zonotrichia_capensis 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0


-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] histogram with absolute figures

2007-07-06 Thread Sarah Goslee
The default of hist() is counts rather than percentages.

Sarah

On 7/6/07, Mag. Ferri Leberl [EMAIL PROTECTED] wrote:
 Dear everybody!
 Is ist easily possible to make up a histogram with absolute numbers
 instead of percentages?
 Thank you in advance!
 Yours, Mag. Ferri Leberl

 ___
-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


[R] text display using expression or not

2007-06-15 Thread Sarah Goslee
Hello,

I imagine that I'm missing something straightforward, but a run thru
the help files didn't turn up an answer.

I noticed while formatting some figures for publication that text
enclosed in expression() and used for a title displays differently
than a string, regardless of the par options. On both postscript()
and x11() devices, the regular text is heavier than the expression text.

Here's an example. The real thing used expression() to
produce superscripts, but I boiled this down to the simplest possible
case.

par(mfrow=c(2,1))
plot(1:10, 1:10, main=Figure A)
plot(1:10, 1:10, main=expression(Figure B))

Is there some straightforward way to make them match, other
than putting expression() around all strings?


I'm currently using R 2.5.0 on Fedora core 5.

Thanks,
Sarah

-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Difference between prcomp and cmdscale

2007-06-14 Thread Sarah Goslee
On 6/14/07, michael watson (IAH-C) [EMAIL PROTECTED] wrote:

 ... I failed to find articles that compare and contrast PCA
 and MDS.  If you know of any, of course I would be happy to read them.

There's an excellent non-R discussion of a wide range of ordination methods
at http://ordination.okstate.edu/ (Mike Palmer's work).

If you look under distance-based ordination (like MDS/PCO),
you find:
Special case: for Euclidean distance, PCoA = PCA.

and much other useful information. He also gives an extensive list of
references from the literature, if you'd like something more rigorous.
For an overview text, I'm partial to _Numerical Ecology_ by Legendre
and Legendre (1998) because of its readability, but there are many
more good texts.

Sarah
-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Tools For Preparing Data For Analysis

2007-06-10 Thread Sarah Goslee
On 6/10/07, Ted Harding [EMAIL PROTECTED] wrote:

 ... a lot of the problems with data
 files arise at the data gathering and entry stages, where people
 can behave as if stuffing unpaired socks and unattributed underwear
 randomly into a drawer, and then banging it shut.

Not specifically R-related, but this would make a great fortune.

Sarah
-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] matrix and data frame

2007-06-08 Thread Sarah Goslee
I'm not at all certain I understand your question, but try
?cbind

Sarah

On 6/8/07, elyakhlifi mustapha [EMAIL PROTECTED] wrote:
 hello,
 I have just a question before the week end it's that I don't know how to do 
 to paste matrixs and these matrix they have one same column and I'd like to 
 paste its by this column
 and I wanna paste its not below but just at right side hand
 thanks good week end


-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R help

2007-06-06 Thread Sarah Goslee
On 6/5/07, scott flemming [EMAIL PROTECTED] wrote:

 Can R be used to draw 10 arrows in one line ?

Um, sure.

Assuming you actually also want to know how to do it, why don't
you take a look at the help for arrows().

Sarah

-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] sampling problem - new to R

2007-06-06 Thread Sarah Goslee
Claire,

Here's one way to do it:

# first, generate some sample data to try
 treedata - cbind.data.frame(Tree=1:25, Plot=sample(1:5, 25, replace=TRUE))
 treedata - treedata[order(treedata$Plot),]
 treedata
   Tree Plot
1 11
2 21
6 61
9 91
11   111
17   171
18   181
23   231
13   132
16   162
25   252
5 53
10   103
4 44
7 74
8 84
24   244
3 35
12   125
14   145
15   155
19   195
20   205
21   215
22   225

# then randomly choose one tree from each plot
# getting a different random set each time
 sapply(split(treedata$Tree, treedata$Plot), sample, 1)
 1  2  3  4  5
 2 25 10  4 21
 sapply(split(treedata$Tree, treedata$Plot), sample, 1)
 1  2  3  4  5
23 13  5  4 14


Hope that solves it for you,
Sarah

On 6/5/07, baldeck [EMAIL PROTECTED] wrote:

 I have a data set of individual trees and the plots that they are in:

 Tree  Plot
 567491
 634941
 873751
 374942
 927533
 348473
 387474 etc...

 So each plot is represented once for every individual that occurrs in it.
 Plots get different numbers of rows because there can be a different number
 of individuals in each plot.

 I want to make a data frame that consists of one individual from each plot.
 I would like to randomly choose one individual from each plot that is
 present in the data set.  I will have to do this to multiple data sets which
 may contain different plots, and may contain up to 1200 plots, so I can't
 choose the plots by hand.

 Please help me with this.  I'm an ecologist and I'm in Panama, with no one
 around who is educated in R.  Whoever solves this problem for me will be
 acknowledged in any resulting publications.

 Thanks!
 -Claire
 --


-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] random numbers selection - simple example

2007-06-06 Thread Sarah Goslee
Assuming you want only integers, see
?sample

Sarah

On 6/6/07, Jenny Barnes [EMAIL PROTECTED] wrote:
 Dear R-help,

 Which random number generator function would you recommend for simply picking 
 15
 random numbers from the sequence 0-42? I want to use replacement (so that the
 same number could potentially be picked more than once).

 I have read the R-help archives and the statistics and computing book on 
 modern
 Applied statistics with S but the advice seems to be for much form complicated
 examples, there must be a simpler way for what I am trying to do?

 If anybody can help me I would greatly appreciate your advice and time,

 Best Wishes,

 Jenny




-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] odfTable

2007-06-05 Thread Sarah Goslee
Hi,

There are a couple of steps, and it requires use of the newest version of
odfWeave.

First, you need to set up the table styles in R _before_ you run odfWeave.

Here's an example:

# Now to specify the styles themselves
# The default list has 10 styles in it right now.
existingStyles - getStyleDefs()

# Use one of the cell styles as a template for the new cell style
# The style definition contains information on background
# color, alignment, and borders.
# For style 1, I want a background color.
# Colors can be specified in hex format, or as transparent.
newStyle1 - existingStyles$noBorder
newStyle1$backgroundColor - #cc

# Finally, the new styles need to be set.
existingStyles - c(existingStyles, newStyle1=list(newStyle1))
setStyleDefs(existingStyles)

After that, you can use the new style when defining your table in an
odfWeave document:

Table1,echo=FALSE,results=xml=
### Conditional formatting based on the value of the table cell
x - data.frame(Var1=1:3, Var2=4:6, Var3=7:9, row.names=c(A, B, 
C))

# Here's a matrix specifying the desired styles for each cell in the 
table.
# This could be p-values for the correlations in x, for example. For
# this example, I'm just making it up.
# The style matrix must have an additional column for the row names.
y - matrix(c(0, 0, 0, 1,0,0,3,0,1,2,0,2), byrow=FALSE, nrow=3, ncol=4)
y - data.frame(y)
colnames(y) - c(rownames, Var1, Var2, Var3)

# Now, to specify when to use these new styles.
# tableStyles() will provide the default styles for each
# element of x
# note that I'm creating the styles for x based on y,
# which already has the extra column for row names.
x.styles - tableStyles(y, header=colnames(y))

# every element of x has two associated styles
# for the cells, text style is in text and cell style is in cell
# for headers, it is in header and headerCell

# newStyle1 and newStyle2 are cell styles, so they are set here:
x.styles$cell[y == 1] - newStyle1

odfTable(x, useRowNames = TRUE, styles = x.styles)
@

I have a more detailed explanation that I can send off-list if you are
interested. For your specific problem, you'd need to set the headerCell
style.

Sarah


On 6/5/07, Laurence Amilhat [EMAIL PROTECTED] wrote:
 Hello,

 I am using the odfWeave packages;
 I draw a table using the function odfTable:

 partCols - gsub(\\.,  , names(partenaires))
 odfTable(partenaires, useRowNames = FALSE, colnames=partCols)


 it's working as I have a table in my output file.
 I would like to know how to change the background color for the header
 cells.
 I assuming i have to use tableStyles, but I don't understand how.

 Does someone have an idea to help me?


-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] read table

2007-06-05 Thread Sarah Goslee
The default separator in read.table is white space, so the first
line (header) has 6 elements, the second line has 7 elements,
and the third has 8 elements.

Either delete the spaces in the car names, or use sep=\t
(or whatever is appropriate).

?read.table explains this.

Sarah

On 6/5/07, jiqiang yao [EMAIL PROTECTED] wrote:
 Hi,
 I'm a novice of R.

 I want to read the following table into R:
 names   mpgcyl  disp  hp  drat
 Mazda RX4   21.0   6160.0 110 3.90
 Mazda RX4 Wag   21.0   6160.0 110 3.90

 The command I used is:
  test - read.table(file.choose(),header=T)

 The result is:
 Error in read.table(file.choose(), header = T) :
 more columns than column names

 Can anybody tells me what is wrong?

 ___


-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] odfTable

2007-06-05 Thread Sarah Goslee

   3. To simply Sarah's approach, add the style definition via
 setStyleDefs(existingStyles) as suggested. Then, just before making the
 table, simply use

 current - getStyles()
 currrent$header - newStyle1
 setStyles(current)

  then produce the table. Unless I'm not understanding what you want,
 you shouldn't need to use tableStyles.


Ah, right. That example was cut from a longer document where the more
elaborate method was used for demonstration purposes.

Thanks for the hard work!
Sarah

-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Extracting lists in the dataframe $ format

2007-06-04 Thread Sarah Goslee
This is a subset problem, not a problem with plot or lm. You need to
read eg  help([.data.frame)


Here are two working examples:

# df already means something!
mydf - data.frame(out=1:4*3,pred1=1:4,pred2=1:4*2)

regression - function(tble,a,b)
{
   plot.new()
   plot(tble[,a]~tble[,b])
   lmm=lm(tble[,a]~tble[,b])
   abline(lmm)
   anova(lmm)
}

regression(mydf, 1, 3)

regression - function(tble,a,b)
{
   plot.new()
   plot(tble[[a]]~tble[[b]])
   lmm=lm(tble[[a]]~tble[[b]])
   abline(lmm)
   anova(lmm)
}

regression(mydf, 1, 3)

Sarah

On 6/4/07, Stan Hopkins [EMAIL PROTECTED] wrote:
 I'm new to R and am trying to extract the factors of a dataframe using 
 numeric indices (e.g. df[1]) that are input to a function definition instead 
 of the other types of references (e.g. df$out).  df[1] is a list(?) whose 
 class is dataframe.  These indexed lists can be printed successfuly but are 
 not agreeable to the plot() and lm() functions shown below as are their 
 df$out references.  Reading the documentation for plot and lm hasn't helped 
 yet.  Thanks in advance - Stan.

  df=data.frame(out=1:4*3,pred1=1:4,pred2=1:4*2)
  regression=function(tble,a,b)
 + {
 +plot.new()
 +plot(tble[a]~tble[b])
 +lmm=lm(tble[a]~tble[b])
 +abline(lmm)
 +anova(lmm)
 + }
  df[1]
   out
 1   3
 2   6
 3   9
 4  12
  df
   out pred1 pred2
 1   3 1 2
 2   6 2 4
 3   9 3 6
 4  12 4 8
  regression(df,1,3)
 Error in model.frame(formula, rownames, variables, varnames, extras, 
 extranames,  :
 invalid type (list) for variable 'tble[a]'
 



-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Biplot

2007-05-13 Thread Sarah Goslee
Hi,

If you check the help for princomp, you'll see that it returns all
sorts of information in the form of a list. The most convenient
way is to save your analysis
xresults - princomp(x, cor=TRUE)
then you can look at the scores, plot them yourself, anything
else you want
xscores - xresults$scores

and so on.

Sarah

On 5/13/07, Soare Marcian-Alin [EMAIL PROTECTED] wrote:
 Hello everybody,

 How could I extract the components of of a PCA to plot it into a biplot?
 I want to make pairwise biplots of the first three main components:

 biplot(princomp(x, cor=TRUE))
 biplot(princomp(x[,c(1,2)], cor=TRUE))
 biplot(princomp(x[,c(1,3)], cor=TRUE))
 biplot(princomp(x[,c(2,3)], cor=TRUE))

 Is this the only way, how I could plot them?
 I thought, that it could be possible to extract them of the full PCA ..

 KR,
 Alin

-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Newbie's question

2007-05-13 Thread Sarah Goslee
Sure, R can do anything. The first trick, though, is to learn
how to write clear-enough questions to the mailing list
that you get helpful answers back. A worked example of
what you want would be very useful, since I have no idea
what the index is, or what field2 is, or what kind of graph
you want. OS would also be helpful, since the example
I'm giving only works as written on linux.

Still, one approach

allfiles - system(ls *.csv, intern=TRUE) # linux only
allfield2 - numeric(length(allfiles))
for(i in 1:length(allfiles)) {
   allfield2 - read.table(allfiles[i])$field2
  # need read.table options, and correct way to get field2
}

hist(allfield2); sd(allfield2)

Sarah

On 5/12/07, onthetopo [EMAIL PROTECTED] wrote:

 Hi guys,
 I've brand new to the R scene.
 I have hundreds of csv files that has field 1 ,/MM/DD as index
 How to generate a graph of distribution and calculate the standard deviation
 of field2 for all of the files in a directory?

 I'm wondering if R could do this.
 Thanks a lot.


-- 
Sarah Goslee
http://www.stringpage.com

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] minimum of each row in a matrix

2007-05-08 Thread Sarah Goslee
Check out the help for apply, particularly the MARGIN argument:

minOfRows=apply(a, 1, function(x) min(x[x!=0]) )
maxOfRows=apply(a, 1, function(x) max(x) )

Sarah

On 5/8/07, Schmitt, Corinna [EMAIL PROTECTED] wrote:
 Hallo,

 I just followed the discussion of the title: minimum from matrix.
 I have a similar problem.

  a=matrix(c(0,2, 0, 0, 1, 3, 0, 3, 2, 0, 3, 5, 0, 4, 0, 0),ncol=4)
  a=rbind(a,1:4)
  a
  [,1] [,2] [,3] [,4]
 [1,]0120
 [2,]2304
 [3,]0030
 [4,]0350
 [5,]1234
 
  minOfColumns=apply(a, 2, function(x) min(x[x!=0]) )
  minOfColumns
 [1] 1 1 2 4
  maxOfColumns=apply(a, 2, function(x) max(x) )
  maxOfColumns
 [1] 2 3 5 4
 

 How looks like the command for the minimum of the rows? I tried several
 possibilities with apply but did not get the wanted result. The result
 should be minOfRows = 0 0 0 0 1

 Thanks,
 Corinna



-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] help interpreting the output of functions - any sources of information

2007-04-24 Thread Sarah Goslee
Hi,

If you look at the documentation for the function you are interested
in, in this case ?cor.test, it will generally give you an explanation
of the return values (often brief, and not too helpful if you aren't
already familiar with the test), but also one or more references
that you can turn to for further information.

Most likely, though, you'll want to absorb a general
introductory stats book before you delve into the
gory details of many of those references.

Sarah

On 4/24/07, Y G [EMAIL PROTECTED] wrote:
 Hi,

 I am looking for documentation, reference guides, etc. that explain the
 output of functions... For example using cor.test(, method=pearson)
 with Pearson's corr coeff the output is:


 Pearson's product-moment correlation

 data:  a and b
 t = 0.2878, df = 14, p-value = 0.
 alternative hypothesis: true correlation is not equal to 0
 95 percent confidence interval:
  -0.4355690  0.5514366
 sample estimates:
cor
 0.07669612


 What are all these? Apologies but I am new in R and statistics in
 general but a textbook I was looking at, regarding SPSS, explains only
 the r coeff and the conf interval Any help with sources I can refer to?
 Particularly in a broader context as it would not be nice to post all the
 time such questions...

 Thanks in advance,
 GM


-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] crosstabs in R?

2007-04-11 Thread Sarah Goslee
I don't know what the S-Plus crosstabs() does, but there's
a simple crosstab() function in the ecodist package.

Sarah

On 4/10/07, A.R. Criswell [EMAIL PROTECTED] wrote:
 Hello All,

 I looked through the archives and I've seen this question asked
 before, but with no answer: Is there an R equivalent to crosstabs() in
 S-Plus?


-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Confidence-Intervals.... help...

2007-04-08 Thread Sarah Goslee
Hm... sounds like a homework problem to me...

Maybe start by figuring out how to do it without R -
what's the approach, and how would you calculate it?
Then search R help for the possible key words you
came up with.

Sarah

On 4/8/07, Jochen.F [EMAIL PROTECTED] wrote:

 Hi...

 I have to use R to find out the 90% confidence-interval for the sensitivity
 and specificity of the following diagnostic test:

 A particular diagnostic test for multiple sclerosis was conducted on 20 MS
 patients and 20 healthy subjects, 6 MS patients were classified as healthy
 and 8 healthy subjects were classified as suffering from the MS.

 Furthermore, I need to find the number of MS patients required for a
 sensitivity of 1%...

 Is there a simple R-command which can do that for me?

 I am completely new to R...

 Help please!

 Jochen
 --
-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Abundance data ordination in R

2007-04-01 Thread Sarah Goslee
Hi,

There's a very good ordination web page by Mike Palmer aimed at
ecologists (and since you have a species x site matrix, I'm assuming
that describes you) at http://ordination.okstate.edu/

My recommendation is generally nonmetric multidimensional scaling
(principal coordinates analysis is a metric scaling ordination), with a
dissimilarity metric that doesn't consider joint absences, for example
Bray-Curtis/Sorensen. Treating absent species as missing data is
not a good idea, because while it may not be possible to say
that they are truly missing from that site (depending on taxa and
sampling methods), you at least know they aren't common at that
site. Ecological data are messy enough without discarding information!

There are several R packages that may be helpful, including
ecodist and vegan.

Sarah

On 4/1/07, Milton Cezar Ribeiro [EMAIL PROTECTED] wrote:
 Dear R-gurus

 I have a data.frame with abundance data for species and sites which looks 
 like:
 mydf-data.frame(
  sp1=sample(0:10,5,replace=T),
  sp2=sample(0:20,5,replace=T),
  sp3=sample(0:4,5,replace=T),
  sp4=sample(0:2,5,replace=T))
 rownames(mydf)-paste(sites,1:5,sep=)

 I would like make an ordination analysis of these data and my worries is 
 about the zeros (absence of species) into the matrix. Up to I read (Gotelli 
 - A primir of ecological statistics, 2004), when I have abundance data I 
 can´t compute Euclidian Distances because the zeros have the meaning of 
 absence of the species and not as zero counting. Gotelli suggests one make 
 principal coordinates analysis. I would like to here from you what you 
 think about and what is the best packages and functions to I compute my 
 distance matrices and do my ordination analysis. Can I considere zero as NA 
 on my data.frame? Is there a good PDF book available about Multivariate 
 Analysis for abundance data available on the web?

 Kind regards

 Miltinho
 Brazil


-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Wikibooks

2007-03-30 Thread Sarah Goslee
On 3/30/07, Alberto Monteiro [EMAIL PROTECTED] wrote:
 Deepayan Sarkar wrote:
 
  I was just looking at this page, and it makes me curious: what gives
  anyone the right to take someone else's mailing list post and include
  that in a Wiki?
 
 Thinks there were posted to public mailing lists are freely
 copied and distributed. It's a scary thought; I may have posted
 things in 10 or 12 years ago that might cause me problems today,
 but I was pretty aware that I was posting to the whole world.

It's not that simple. Dealing with international contributors it's even worse.
Under US law (the only one I'm familiar with), the author of a mailing list
post or any other written work _automatically holds copyright_ to that
post (although not to the ideas contained therein, but to that particular
description of the ideas). (Of course, if the ideas are original to the author,
it's good form to acknowledge that regardless of whether the exact words
are used).

So, in the US, nobody has the right to take one person's words and put
them in another form. The mailing list archive is one thing, but putting
material from that archive into a wiki (rather than linking to it) requires
the author's permission, at least technically.

I'm by no means an expert on copyright, but this is something that
comes up periodically on many email lists.

Sarah
-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] matrix similarity comparison

2007-03-19 Thread Sarah Goslee
Hi Carlos,

 I want to see the similarity between them, and to be able to extract the
 differences between them.

You need to explain a bit more. Are you looking for number of elements in
common? How are your data set up? (eg species as columns and sites
as rows)

One way to get number of joint presences is this (although there are
certainly more elegant ways), assuming that columns are species

 m1 - matrix(c(1,0,0,0,1,0,1,1,1,1,1,1), 3,4)
 m2 - matrix(c(1,0,1,0,1,0,0,1,0,1,0,1), 3,4)

 apply((m1 + m2), 1, function(x)sum(x == 2))
[1] 2 2 1

 I tried with the function cor2m() [package=edodist] but it didn't worked
 and my matrices are much bigger than the ones from the example.

Didn't work? That's a bit vague, but anyway this won't help, since
cor2m is intended for use with a matrix of environmental variables as
the second matrix, and not for binary data (the first matrix can be
binary). I doubt that correlations are really the measure you want
anyway - if they are, then you can use simply
cor(m1, m2)

Sarah


-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] matrix similarity comparison

2007-03-19 Thread Sarah Goslee
On 3/19/07, Sarah Goslee [EMAIL PROTECTED] wrote:
 Hi Carlos,

  I want to see the similarity between them, and to be able to extract the
  differences between them.

 You need to explain a bit more. Are you looking for number of elements in
 common? How are your data set up? (eg species as columns and sites
 as rows)

I thought of something else. If you want similarity, you could always do

m12.dist - dist(cbind(m1, m2), binary)
and just look at the elements of the result that correspond to columns
of m1 vs m2 (rather than m1 vs m2 or m2 vs m2).

Sarah
-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to add obj to a list?

2007-02-15 Thread Sarah Goslee
The Introduction to R, available thru the documentation link at
www.r-project.org has some nice material on creating and modifying
lists that should answer your question.

Sarah

On 2/15/07, Perez Alvarez, Susana [EMAIL PROTECTED] wrote:
 Hello everybody!

 I'm quite new using R and i'm trying to develope a function, but i have
 a problem.
 What i want to build is something like an objects vector. I have a list
 with two tables, and after or next to them, I want to add more tables or
 vectors to that list one by one.  But i cannot find how to do it!
 Does someone can help me?

 I will be very grateful for any of your help!

 Thank you in advance,
 susana.

--
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Fatigued R

2007-02-13 Thread Sarah Goslee
Hi Shubha,

Perhaps you haven't gotten any help because you haven't provided a
reproducible example, or even told us what you are trying to do (specifically)
or what errors you are receiving. Frankly, your problem statement doesn't
make any sense to me, and I can't provide advice without more information.

As the footer of every email says:
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Sarah

On 2/13/07, Shubha Vishwanath Karanth [EMAIL PROTECTED] wrote:
 Hi R,



 Please solve my problem...



 I am extracting Bloomberg data from R, in a loop. R is getting fatigued
 by doing this process and gives some errors. I introduced sleep
 function. Doing this sometimes I get the results and sometimes not. I
 even noticed that if I give complete rest for R (don't open R window)
 for 1 day and then run my code with the sleep function, then the program
 works. But if I keep on doing this with on R, repeatedly I get errors.



 Please can anyone do something for this? Is there any function of
 refreshing R completely.Or any other techniques?...I am really
 getting bugged with this...



 Thanks,

 Shubha


-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Fatigued R

2007-02-13 Thread Sarah Goslee
That's a help. It isn't actually reproducible since I have no idea where
for example blpConnect() comes from, but it's still an improvement.

Moving the important bit to the top:

 The error message I get if the program is not run is:

 Error in dimnames(x) - dn : length of 'dimnames' [2] not equal to array
 extent
 In addition: Warning message:
 Index vectors are of different classes: chron chron dates in:
 merge(d_mer,cdaily)

These seem to mean that your data don't (always?) look like you are
expecting, and have nothing to do with fatigue or sleepiness. Except
maybe yours?

I would suggest going through your function one command at a time
(without the loop, but set the loop index manually if needed), and check
carefully the format of the data. If it works sometimes and not others,
identify a loop index for which it doesn't work and repeat the process.

Someone familiar with Bloomberg data might be able to provide more
assistance.

Sarah

On 2/13/07, Shubha Vishwanath Karanth [EMAIL PROTECTED] wrote:
 OhkkkI will try to do that now

 This is my download function...


 download-function(fil)
 {
 con-blpConnect(show.days=show_day, na.action=na_action,
 periodicity=periodicity)
 for(i in 1:lent)
 {
 Sys.sleep(3)
 cdaily-blpGetData(con,unique(t[,i]),fil,start=as.chron(as.Date(1/1/199
 6, %m/%d/%Y)),end=as.chron(as.Date(12/28/2006, %m/%d/%Y)))
 #Sys.sleep(3)
 if(!exists(d_mer)) d_mer=cdaily else d_mer=merge(d_mer,cdaily)
 rm(cdaily)
 }
 dat-data.frame(Date=index(d_mer),d_mer)
 dat$ABCDEFG=NULL
 path1-paste(D:\\SAS\\Project2\\Daily\\,fil,_root.sas7bdat,sep=)
 path2-paste(D:\\SAS\\Project2\\Daily\\CODEFILES\\,fil,.sas,sep=)
 sasname-paste(x1,fil,',sep=)
 write.foreign(dat,path1,path2,package=SAS,dataname=sasname)
 blpDisconnect(con)
 }

 for(j in 1:lenf)
 {
 fname-paste(D:\\SAS\\Project2\\Daily\\,filename[j],_root.sas7bdat,s
 ep=)
 Sys.sleep(600)
 if(!file.exists(fname)) download(fil=filename[j])
 }

 And lent=58 and lenf=8... 8 text files will be generated in this process
 if the program would have run properly, and each would be of size 4,000
 KB.

 The error message I get if the program is not run is:

 Error in dimnames(x) - dn : length of 'dimnames' [2] not equal to array
 extent
 In addition: Warning message:
 Index vectors are of different classes: chron chron dates in:
 merge(d_mer,cdaily)



 Please could any one help on this?

 -Original Message-
 From: Sarah Goslee [mailto:[EMAIL PROTECTED]
 Sent: Tuesday, February 13, 2007 7:09 PM
 To: Shubha Vishwanath Karanth
 Cc: r-help@stat.math.ethz.ch
 Subject: Re: [R] Fatigued R

 Hi Shubha,

 Perhaps you haven't gotten any help because you haven't provided a
 reproducible example, or even told us what you are trying to do
 (specifically)
 or what errors you are receiving. Frankly, your problem statement
 doesn't
 make any sense to me, and I can't provide advice without more
 information.

 As the footer of every email says:
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

 Sarah

 On 2/13/07, Shubha Vishwanath Karanth [EMAIL PROTECTED] wrote:
  Hi R,
 
 
 
  Please solve my problem...
 
 
 
  I am extracting Bloomberg data from R, in a loop. R is getting
 fatigued
  by doing this process and gives some errors. I introduced sleep
  function. Doing this sometimes I get the results and sometimes not. I
  even noticed that if I give complete rest for R (don't open R window)
  for 1 day and then run my code with the sleep function, then the
 program
  works. But if I keep on doing this with on R, repeatedly I get errors.
 
 
 
  Please can anyone do something for this? Is there any function of
  refreshing R completely.Or any other techniques?...I am really
  getting bugged with this...
 
 
 
  Thanks,
 
  Shubha


-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] remove component from list or data frame

2007-02-08 Thread Sarah Goslee
Hi Jason,

On 2/8/07, Jason Horn [EMAIL PROTECTED] wrote:
 Sorry to ask such a simple question, but I can't find the answer after
 extensive searching the docs and the web.

 How do you remove a component from a list?  For example say you have:


You use the - operator for both your vector and data frame
examples.

 lst - c(5,6,7,8,9)
# which by the way isn't a list
 is.list(lst)
[1] FALSE
 lst
[1] 5 6 7 8 9
 lst - lst[-3]
 lst
[1] 5 6 8 9

 lst1-c(1,2,3,4,5)
 lst2-c(6,7,8,9,10)
 frame-data.frame(lst1,lst2)
 frame
  lst1 lst2
116
227
338
449
55   10
 frame[-2,]
  lst1 lst2
116
338
449
55   10


-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] unique/subset problem

2007-01-26 Thread Sarah Goslee
Without knowing more about your data, it is hard to say for certain,
but might you be confusing unique _values_ with _factor levels_?

 mydata - as.factor(sort(rep(1:5, 2)))
# mydata has 10 values, 5 unique values, and 5 factor levels
 mydata
 [1] 1 1 2 2 3 3 4 4 5 5
Levels: 1 2 3 4 5
 unique(mydata)
[1] 1 2 3 4 5
Levels: 1 2 3 4 5
 mydata.subset - mydata[1:4]
# the subset now has only 2 unique values, but the output
# still lists all five factor levels
 unique(mydata.subset)
[1] 1 2
Levels: 1 2 3 4 5

# try drop=TRUE as an option to subset
 mydata.subset - mydata[1:4, drop=TRUE]
 unique(mydata.subset)
[1] 1 2
Levels: 1 2

Alternatively, if this is the problem and you don't need those
data to be factors, you could always convert them to a more
appropriate form.

Sarah

  On 1/25/07, lalitha viswanath
  [EMAIL PROTECTED] wrote:
   Hi
   I am new to R programming and am using subset to
   extract part of a data as follows
  
   names(dataset) =
   c(genome1,genome2,dist,score);
   prunedrelatives - subset(dataset, score  -5);
  
   However when I use unique to find the number of
  unique
   genomes now present in prunedrelatives I get
  results
   identical to calling unique(dataset$genome1)
  although
   subset has eliminated many genomes and records.
  
   I would greatly appreciate your input about using
   unique correctly  in this regard.
  
   Thanks
   Lalitha
  

-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Regression lines

2007-01-12 Thread Sarah Goslee
Fortune?

On 1/12/07, Peter Dalgaard [EMAIL PROTECTED] wrote:
 Prof Brian Ripley wrote:
 
  Where did you tell it 'x' was the abscissa and 'y' the ordinate?
  (Nowhere: R is lacking a mind_read() function!)
 Please stop complaining about missing features. Patches will be considered.

 Oh, it's you, Brian. Never mind then. You'll get to it, I'm sure.

 ;-)


-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] odfWeave problem

2006-12-22 Thread Sarah Goslee
Hi,

Doesn't work is kind of vague... what is or isnt' happening?

But in this case, I think it might be easy:


On 12/22/06, Abhijit Dasgupta [EMAIL PROTECTED] wrote:
 Hi,

 StyleDefs$ArialNormalRight$textAlign='end'

I think this should be 'right' rather than 'end.

The ODF XML specification is available online, but you can also make
a toy example in OpenOffice and then look at its XML if you want to find
out what a particular format code is.
http://www.oasis-open.org/committees/tc_home.php?wg_abbrev=office

For example, make a small table in OpenOffice with one of the cells
aligned right, and save it. Find the file, and unzip it into its components.
The XML code for your applied formatting will be in content.xml. If you
used styles instead of direct formatting, some kinds of styles go in styles.xml
and some in content.xml. The same is true for styles applied through
odfWeave.

Sarah
-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] odfWeave problem

2006-12-22 Thread Sarah Goslee
Sorry, I zipped you off a reply without actually having OpenOffice
available - never wise.

First, both right and end work for me as alignment specifications,
though OpenOffice itself seems to use end.

Here's the R code I'm using to define the styles:


# Now to specify the styles themselves
# The default list has 10 styles in it right now.
existingStyles - getStyleDefs()

# Use one of the cell styles as a template for the new cell style
# The style definition contains information on background
# color, alignment, and borders.


# Style 3 is a bit different. Here I want to change the text color,
# which is specified in a different style definition.
newStyle3 - existingStyles$ArialCentered
newStyle3$fontColor - #cc
   newStyle3$textAlign - right


# Finally, the new styles need to be set.
existingStyles - c(existingStyles, newStyle1=list(newStyle1),
newStyle2=list(newStyle2), newStyle3=list(newStyle3))
setStyleDefs(existingStyles)

And here's the code block from the ODF document:


Table1,echo=FALSE,results=xml=
# here's the same example data as in table 1
x - data.frame(Var1=1:3, Var2=4:6, Var3=7:9, row.names=c(A, B, 
C))

# Here's a matrix specifying the desired styles for each cell in the 
table
# This could be p-values for the correlations in x, for example. For
# this example, I'm just making it up. There are three possible styles,
# as well as the default style.
# The style matrix must have an additional column for the row names.
y - matrix(c(0, 0, 0, 1,0,0,3,0,1,2,0,2), byrow=FALSE, nrow=3, ncol=4)
y - data.frame(y)
colnames(y) - c(rownames, Var1, Var2, Var3)


# Now, to specify when to use these new styles.
# tableStyles() will provide the default styles for each
# element of x
# note that I'm creating the styles for x based on y,
# which already has the extra column for row names.
x.styles - tableStyles(y, header=colnames(y))

# every element of x has two associated styles
# for the cells, text style is in text and cell style is in cells
# for headers, it is in header and headerCell

# newStyle3 is a text style.
x.styles$text[y == 3] - newStyle3


odfTable(x, useRowNames = TRUE, styles = x.styles)
@

I hope this example is more helpful than my previous email!

If you are interested, I have a longer, heavily-commented, example
of figure and table styles for odfWeave that I'm planning to put
online shortly. I'd be happy to send you a copy.

Sarah

-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] writing R extension

2006-12-20 Thread Sarah Goslee
For a very simple library, you really only need chapter 1 of the manual
on writing R extensions, which even describes the helper functions
that take some of the work out of making a proper package.

If that's still too complex, you could also save your function to a file
and load it as needed with source(). That will give the user the
same effect.

source(/path/to/my/stuff/myfiles.R)

Since you didn't tell us OS or anything else about your system,
it's hard to be more specific.

Sarah

On 12/20/06, michele de meo [EMAIL PROTECTED] wrote:
 I'd like to develop a simple library in R in which to save my
 particular functions.
 I have read the manual on Writing R Extensions but it's too
 difficult. Someone could help me?

 I want only save my personal function (recorded in R-code, not in C) in
 myLibrary and I want to call it with:

  library (myLibrary).

 After this, the functions should be available directly in R.

 I know that it's possible to save functions in the workspace, but I
 need this functions in a library.



-- 
Sarah Goslee
http://www.stringpage.com
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] writing R extension

2006-12-20 Thread Sarah Goslee
Hi,

 I am dealing with the same issue here and I was wondering whether it would be 
 possible to just save
 the R compliled function objects in a directory and just attach the directory 
 to the search path.
 (I am using R2.4.0+ESS+Xemacs in windows XP).


The other method that I'm familiar with uses save() and load() rather than
attach. It may be possible to use attach() in some other method.

 temp1 - function(x) {x * x}
 temp2 - function(x) {x + x}
 temp1(3)
[1] 9
 temp2(3)
[1] 6
 save(list=ls(), file=testfns)
 q(save=no)

# start R
 ls()
character(0)
 load(testfns)
 ls()
[1] temp1 temp2


My personal preference is the text source file approach, but opinions
obviously vary on that. I do keep final versions in a package.

And yes, the proper term is package, but it seems that if the entity
in question is stored in  /usr/lib/R/library (on my linux system), and
loaded with the function library() the occasional slip might be forgiven?

Sarah
-- 
Sarah Goslee
http://www.stringpage.com
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Replacing labels with symbols in biplot

2006-12-18 Thread Sarah Goslee
Hi Mat,

You can more-or-less do what you want with the xlabs argument to
biplot. It only takes characters, rather than the normal plot symbol
codes, though. If you need symbols, you can cheat with things like
+ o x. I usually use letters for the different groups within the data:

 temp - matrix(runif(50), nrow=10)
 temp.pca - princomp(temp)
 biplot(temp.pca, xlabs=c(A, A, B, B, B, C, C, C, D, D))


Sarah

On 12/17/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Dear all
 I would like to replace labels for x in biplot() with symbols (points)
 that will visually illustrate different classes/groups.

-- 
Sarah Goslee
http://www.stringpage.com
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Delete all dimnames

2006-12-14 Thread Sarah Goslee
On 12/14/06, Serguei Kaniovski [EMAIL PROTECTED] wrote:
 Hello, how can I get rid of all dimnames so that:

 test
  a b c
A 1 4 7
B 2 5 8
C 3 6 9
 dimnames(test) - list(NULL, NULL)
  test
 [,1] [,2] [,3]
[1,]147
[2,]258
[3,]369

Sarah

-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problems with principal components analysis PCA with prcomp

2006-11-16 Thread Sarah Goslee
Hello Carlos,

# let me save you a couple steps here
 x-read.table(test.txt, header=T, row.names=1)

 pca-prcomp(x, scale=T)
 names(pca)

 ## here begin my problems… know what…??##

Try this for a graphical view of your data:
biplot(pca)
You might also want to work through the examples given
in ?prcomp and ?princomp.

 My questions are:
 1. How can I group my samples (rows) in a graphical way?
 2. How can I extract the samples related to each group? …or… How can I
 create a new column with n values corresponding to each group created?

Here I see a problem... if you are interested in _groups_ in the data, you
might be better off with a clustering method, of which R has an abundance.
Ordination is generally about _gradients_ rather than groups - continuous
change vs discrete groups.

If you are determined to divide your ordination into groups, one possibility
is to use conditional subsetting on the ordination values.

 3. Is it possible to extract/export the information in an object into a file
 with a dbf extension (e.g. test.dbf)?

help.search(dbf) finds the function write.dbf - sounds suspiciously useful.


Sarah

-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] question about capscale (vegan)

2006-11-16 Thread Sarah Goslee
Hi Alicia,


On 11/16/06, Alicia Amadoz [EMAIL PROTECTED] wrote:

 'comm' argument. I don't understand what type of data must be referred
 as 'species scores' and 'community data frame' since my data refer to
 nucleic distances between different sequences.

comm would be the original data from which you calculated the
dissimilarity matrix, so that scores can be calculated for the
individual variables. These analyses were designed for use
with vegetation data in the form of a matrix with sites as rows
and species as columns, and containing some measure of
abundance for each species at each site.

If you don't have an original data frame, that is, your data come only
in the form of distances, you will need a different implementation
of constrained ordination. Alternately, you could possibly modify
the function to skip the species scores step.

Sarah


-- 
Sarah Goslee
http://www.stringpage.com
http://www.astronomicum.com
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] question about capscale (vegan)

2006-11-16 Thread Sarah Goslee
Sorry, one additional note:

You don't need to specify comm to use capscale. Ignore what I said about
modifying the function.

Sarah
-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] question about capscale (vegan)

2006-11-16 Thread Sarah Goslee
Nice catch, Gavin - I missed that part of the original post. The
nucleic distances need to be included as the left-hand-side of
the formula, not as the distance argument.

comm is still optional, though, but it's not a good idea to omit
it if there's any way you can provide the original data. From the
help:
  If this
  is not supplied, the ``species scores'' are the axes of
  initial metric scaling ('cmdscale') and may be confusing.

I don't know if it's true in this case, but there are applications
where there is no data matrix - the distances themselves are the
original data. I don't know offhand of any other constrained ordination
functions in R that will easily accomodate a precalculated distance
matrix, but I expect there are some somewhere.

My usual approach is to use metric or nonmetric multidimensional
scaling plus vector fitting, but the assumptions behind that are
different than those underlying a constrained ordination.

Sarah

-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Converting Character Strings to Numerical Values

2006-11-13 Thread Sarah Goslee
?as.numeric

 x - 3
 y - 3.5

 x
[1] 3
 as.numeric(x)
[1] 3

 y
[1] 3.5
 as.numeric(y)
[1] 3.5

Sarah

On 11/13/06, Peter Lauren [EMAIL PROTECTED] wrote:
 Does R have anything like strtod, atoi, atod, etc. in
 C?  I would like to covert 3 to 3 and 3.5 to 3.5 .

 Thanks,
 Peter Lauren.

 __
 R-help@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
 and provide commented, minimal, self-contained, reproducible code.



-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Translation of R code required

2006-11-03 Thread Sarah Goslee
 I am a complete novice when it comes to R.  I have been sent some code
 which I need to run on a dataset.  I have downloaded  and installed R
 but I dont seem to be able to get the code to run.

It would be very helpful if you would tell us your OS, version of R, and
if you would copy and paste the errors into your email so we can see
what went wrong.

Sarah

-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Translation of R code required

2006-11-03 Thread Sarah Goslee
On 11/3/06, Sarah White [EMAIL PROTECTED] wrote:

 I am using Windows XP, R version 2.4.

 The code works until I get to the fourth line starting

 model.effect

 and I receive the following Error message.

 Error in eval(expr, envir, enclos) : object Centre not found



It sounds like the variable names aren't what you think they are.
Try this:

mental - read.csv(dataextract.csv)
colnames(mental)

If the names don't match exactly, R won't know what you mean.

Since this step works,

mental$Rx - factor(mental$Rx, levels=c(VS,IPS))

I think that some of the names are right, but perhaps that
one is spelled differently (Centre vs centre, maybe, since
R is case-sensitive?).

The easiest thing to do with no R knowledge is probably
to change the name in the csv file to match your code,
if that turns out to be the problem.

Sarah

-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Translation of R code required

2006-11-03 Thread Sarah Goslee
On 11/3/06, Barry Rowlingson [EMAIL PROTECTED] wrote:

   How do you know that step works? If the dataframe 'mental' doesnt have
 an 'Rx' column then mental$Rx will be 'NULL', and the factor() function
 will make a factor out of that...

Good point. I rarely use factors and missed that one.

Happily, my inaccurate solution turned out to solve the problem anyway.

Sarah

-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] one row matrix

2006-11-03 Thread Sarah Goslee
On 11/3/06, Waverley [EMAIL PROTECTED] wrote:
 Hi,

 For example:

  a = matrix (12, 3, 4)
  b = a[1,]
  b
 [1] 12 12 12 12


It doesn't have anything to do with one-row matrices, at least in your example,
since that isn't what you made. Instead, you created a matrix with 3 rows,
4 columns, and all values equal to 12.

 a - matrix(12, 3, 4)
 a
 [,1] [,2] [,3] [,4]
[1,]   12   12   12   12
[2,]   12   12   12   12
[3,]   12   12   12   12

 a[1,]
[1] 12 12 12 12

You probably intended
 a - matrix(c(12, 3, 4), nrow=1)

 a
 [,1] [,2] [,3]
[1,]   1234

But to solve what I think you were actually asking, even though it
wasn't reflected in your example... By default, R drops unused
dimensions when subsetting. You can override this behavior

 b - a[1, ,drop=FALSE]

 b
 [,1] [,2] [,3]
[1,]   1234

See:
?subset
help('[')
?matrix

Sarah
-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R gams

2006-10-27 Thread Sarah Goslee
On 10/27/06, Wensui Liu [EMAIL PROTECTED] wrote:
 I am so surprised to hear gams is specialised in dealing with huge,
 hevy-weight linear and non-linear modelling . That is not what I know
 of about GAM, which means generalized additive model.


That would be because the original question was not about GAM, but
rather GAMS, which is a software package, not a single statistical
technique.

From the web page (www.gams.com):
The General Algebraic Modeling System (GAMS) is a high-level modeling
system for mathematical programming and optimization. It consists of a
language compiler and a stable of integrated high-performance solvers.
GAMS is tailored for complex, large scale modeling applications, and
allows you to build large maintainable models that can be adapted
quickly to new situations.


I would guess that it's _possible_ to do all of the included analyses
in R, but it
most likely won't be as easy as in a prearranged commercial package.

Sarah

-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] variables in object names

2006-09-12 Thread Sarah Goslee
Hi Ken,

Not quite the way you're thinking about it, but yes, there is,
and it is very useful. See ?get for more information, but here's
the basics:

for(i in 2:5) {
  thismodel - get(paste(model, i, sep=))
  rsq - c(rsq, summary(thismodel)$r.squared)
}


Also see ?assign for the opposite effect.


On 9/12/06, Pierce, Ken [EMAIL PROTECTED] wrote:
 Is there any way to put an argument into an object name. For example,
 say I have 5 objects,  model1, model2, model3, model4 and model5.

 I would like to make a vector of the r.squares from each model by code
 such as this:


 rsq - summary(model1)$r.squared
 for(i in 2:5){
 rsq - c(rsq, summary(model%i%)$r.squared)
 }


-- 
Sarah Goslee
USDA-ARS PSWMRU
University Park, PA 16802
[EMAIL PROTECTED]

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Bioconductor installation errors

2006-08-29 Thread Sarah Goslee
Hi,

You don't say, but the errors make me think you are using Linux.
(Please specify your OS when you have problems). It sounds like
you are missing some of the Essential programs under Unix -
they really are essential.

I think you need to reread the R admin manual, as instructed
on the bioconductor download page
http://cran.r-project.org/doc/manuals/R-admin.html
and in particular this part:
http://cran.r-project.org/doc/manuals/R-admin.html#Essential-and-useful-other-programs-under-Unix

Sarah

On 8/29/06, Ge, Weigong* [EMAIL PROTECTED] wrote:
 Hello,

 I follow the Bioconductor instruction (http://www.bioconductor.org/download
 http://www.bioconductor.org/download ) to install Biocoductor, there have
 some errors:

 /usr/lib/R/bin/SHLIB: line 115: make: command not found



-- 
Sarah Goslee
http://www.stringpage.com

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Quickie : unload library

2006-08-25 Thread Sarah Goslee
Hi,

There are two ways that I know of:
detach(package:zoo)
or use detach() with the number of that package's
place in the search list.

 library(zoo)
 search()
 [1] .GlobalEnvpackage:zoo   package:methods
 [4] package:graphics  package:grDevices package:utils
 [7] package:datasets  package:ecoutils  package:ecodist
[10] package:stats package:gtkDevice Autoloads
[13] package:base
 detach(package:zoo)
 search()
 [1] .GlobalEnvpackage:methods   package:graphics
 [4] package:grDevices package:utils package:datasets
 [7] package:ecoutils  package:ecodist   package:stats
[10] package:gtkDevice Autoloads package:base

OR

 library(zoo)
 search()
 [1] .GlobalEnvpackage:zoo   package:methods
 [4] package:graphics  package:grDevices package:utils
 [7] package:datasets  package:ecoutils  package:ecodist
[10] package:stats package:gtkDevice Autoloads
[13] package:base
 detach(2)
 search()
 [1] .GlobalEnvpackage:methods   package:graphics
 [4] package:grDevices package:utils package:datasets
 [7] package:ecoutils  package:ecodist   package:stats
[10] package:gtkDevice Autoloads package:base

Sarah

-- 
Sarah Goslee
http://www.stringpage.com

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to interrupt running computation?

2006-08-22 Thread Sarah Goslee
On 8/22/06, Lothar Schmid [EMAIL PROTECTED] wrote:
 If I start a computation in R, how can I interrupt it?
 I' using R 2.1.0.

Hi Lothar,

What do you mean by interrupt - cancel completely and
return to the prompt? Or pause, then resume? Your operating
system would be helpful too.

If the former, try Esc on Windows or Ctrl-C on Linux.
If the latter, Ctrl-Z will send your R session to the background
on Linux, and fg will bring it back. I don't think there's a
Windows equivalent.

Sarah


-- 
Sarah Goslee
http://www.stringpage.com

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to interrupt running computation?

2006-08-22 Thread Sarah Goslee
Then Ctrl-C should do the trick.

Sarah

On 8/22/06, Lothar Schmid [EMAIL PROTECTED] wrote:
 I'm using Linux.
 And I'd like just to cancel a running computation, not the entire R prompt.

 Lothar


-- 
Sarah Goslee
http://www.stringpage.com

__
R-help@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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Way to convert data frame to matrix

2006-06-30 Thread Sarah Goslee
Hi Wade,

On 6/30/06, Wade Wall [EMAIL PROTECTED] wrote:
   I have a text file that I have imported into R.  It contains 3 columns and
 316940 rows.  The first column is vegetation plot ID, the second species
 names and the third is a cover value (numeric).  I imported using the
 read.table function.

 My problem is this.  I need to reformat the information as a matrix, with
 the first column becoming the row labels and the second the column labels
 and the cover values as the matrix cell data.

Try crosstab(mydata$plotID, mydata$species, mydata$cover) from the
ecodist package.

Sarah
-- 
Sarah Goslee

__
R-help@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


Re: [R] Finding a color code.

2006-06-26 Thread Sarah Goslee
Well, rgb(185, 35, 80, max=255) seems like a good place
to start.

help.search(rgb)
turns up all kinds of color-related functions.

Sarah

On 6/26/06, A Ezhil [EMAIL PROTECTED] wrote:
 Hi,

 Is it possible to find corresponding color code in R
 for the following RGB (R185, G35  B80)?

 Thanks in advance.

 Best regards,
 Ezhil


-- 
Sarah Goslee

__
R-help@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


Re: [R] scatterplot but a little tricky

2006-06-16 Thread Sarah Goslee
On 6/16/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 i have two vectors of numbers x and y and of course i
 can do the standard scatterplot plot(x,y)
 and it looks fine. But, I was hoping there was a way to
 do the scatterplot so that each point plotted is a number
 where the number represents the index in the dataset.


plot(x, y, type=n)
text(x, y, 1:length(x))

i doubt this is possible but i figured i would ask anyway.
 thanks.



This is R... everything is possible, just not always easy.

Sarah


-- 
Sarah Goslee

[[alternative HTML version deleted]]

__
R-help@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


Re: [R] if syntax error :(

2006-06-13 Thread Sarah Goslee
You need more brackets:

if(blah) {
  do something
} else {
  do something different
}

Sarah

PS Using underscores in variable names is not encouraged, and
can cause you problems in certain contexts.

On 6/13/06, H. Paul Benton [EMAIL PROTECTED] wrote:

 Umm sorry to bother everyone again but I'm having trouble with my if
 statement. I come from a perl background so that's probably my problem! :)
 So here is my code:

 if (any(lgAB4) | any(lgAB-4)){
 freq_AB-hist(lgAB, type=o, plot=F)
 else
 freq_AB-hist(lgAB, breaks=br,type =o, plot=F)
 }



-- 
Sarah Goslee

[[alternative HTML version deleted]]

__
R-help@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


Re: [R] underscores

2006-06-13 Thread Sarah Goslee
Since several people have commented to me, on and off list:

On 6/13/06, Sarah Goslee [EMAIL PROTECTED] wrote:
 
  PS Using underscores in variable names is not encouraged, and
  can cause you problems in certain contexts.


I realize that it is now legal in R to use underscores, since they no longer
represent the same thing as -. But I don't consider legal the same as
encouraged, do you?


Probably the context most important is if you need to be able to share code
with S-Plus. I work exclusively in R, but have academic colleagues who use
S-Plus. As far as I know, S-Plus still restricts the use of _, and for me,
that possibility is enough to justify suggesting that people not use _. I
personally find that syntax hard to read, as well.

I don't consider it all that important an issue, especially as I know that
many people disagree with me, and never use S-Plus, and don't care about
appearance as long as it works. I would never have brought it up as an issue
on its own, but did feel inclined to tack it on as a postscript to a
question I did answer appropriately.

I shan't mention it again!

Sarah

-- 
Sarah Goslee

[[alternative HTML version deleted]]

__
R-help@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


Re: [R] multiple data sets on one plot

2006-06-07 Thread Sarah Goslee
Without more inormation about what you are specifically trying
to do, see
?line
?points

Sarah

On 6/7/06, Mark L Sessing [EMAIL PROTECTED] wrote:

 Hello,

 I am learning how to use R, and I cannot figure out how to plot more
 than one data set on a single plot.  Can you help me out?

 Cheers,
 Mark




-- 
Sarah Goslee

[[alternative HTML version deleted]]

__
R-help@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


Re: [R] Strange behaviour of cbind

2006-06-06 Thread Sarah Goslee
Hi,

It doesn't have anything to with cbind, but rather with
as.ordered - you converted it to a factor in that step.

In the cbind step, you are actually getting the position of
that ordered factor, rather than anything to do with the values
themselves.

 a - c(1,7,5,3)
 a - as.ordered(a)
 a
[1] 1 7 5 3
Levels: 1  3  5  7
 cbind(a)
 a
[1,] 1
[2,] 4
[3,] 3
[4,] 2

The original values could be letters, or anything, and you'd
still get the same result with the same ordering.

Sarah


On 6/6/06, Dirk Vandekerckhove [EMAIL PROTECTED] wrote:

 Hi,

 Is this intended behaviour of cbind?

  a-c(0,1,2,3)
  a
 [1] 0 1 2 3
  a-as.ordered(a)
  a
 [1] 0 1 2 3
 Levels: 0  1  2  3
  a-a[a!=0] #remove the zero from a
  a
 [1] 1 2 3
 Levels: 0  1  2  3
  cbind(a)
  a
 [1,] 2
 [2,] 3
 [3,] 4

 #cbind adds +1 to each element

  a-as.ordered(as.vector(a))
  a
 [1] 1 2 3
 Levels: 1  2  3
  cbind(a)
  a
 [1,] 1
 [2,] 2
 [3,] 3

 #now it works...

 I am running R 2.3.0 on a windows system.



 Regards,

 Dirk Vandekerckhove

 __
 R-help@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




-- 
Sarah Goslee

[[alternative HTML version deleted]]

__
R-help@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


Re: [R] for loops and counter interpolation

2006-05-17 Thread Sarah Goslee
Hello,

I think you are trying to combine too many things into one.

for(i in 1:100){
points(cor(v$logA[v$idi], v$logB[v$idi], use=complete.obs), i))
 }
 (i created a plot object already)


For points() you need to have x and y, but you are giving the output of
cor()

This will plot your data and print the correlations on the plot (lathough
maybe not in the best place):

for(i in 1:100){
   points(v$logA[v$idi], v$logB[v$idi], pch=i)
   text(0, i, cor(v$logA[v$idi], v$logB[v$idi], use=complete.obs))
}

 Hopefully that gives you an idea of how to get the output you actually
want.

Sarah

-- 
Sarah Goslee

[[alternative HTML version deleted]]

__
R-help@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


Re: [R] Finding out the format of an object

2006-04-06 Thread Sarah Goslee
Hi Tom,

If you assume that's a common question, and so likely to be in base,
help.search(object, package=base) calls up a list of functions relating
to objects. (Leaving off the package argument calls up a much longer one).
Browsing thru the list gets you the intriguing line:
class(base) Object Classes

?class gets you more information about that function, which sounds
promising.

class(myobject) will tell you what class(es) myobject belongs to.

names(myobject) will show you the named subcomponents, which can
be accessed with myobject$somename

The object in question is of the class gam (Generalized Additive
 Model). I know how to pull out some data with the predict function,
 but, when I try to print the value of the predict function, all I get
 is a bunch of numbers.


I'm not sure what you mean by value of the predict function, but you
could try typing just
predict.gam
at the prompt to get some idea of what it's doing (although not necessarily
the complete source).

Sarah
--
Sarah Goslee
http://www.stringpage.com

[[alternative HTML version deleted]]

__
R-help@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


[R] package docs: examples format

2006-04-05 Thread Sarah Goslee
Hello,

The package I'm finishing up contains a series of functions
intended to be run one after the other, as in:
do data-prep using A()
run complicated, slow, analysis B()
do complicated, slow additional analysis C()
plot the results with D() and E()

Now, in the documentation for each of those functions,
I put the entire sequence to illustrate the proper sequence.
But this means that the time-consuming B() and C() run several
times during package checking, taking far too long.

I know that I can use
\dontrun{B()}
to show the sequence in the help without actually executing it each time.

Is that the preferred approach, or is there something nicer?
Ideally, I'd like to include one global example that covers all related
functions, but I can't find a way to do that neatly (other than possibly
a vignette?).

Thanks,
Sarah

--
Sarah Goslee
http://www.stringpage.com

[[alternative HTML version deleted]]

__
R-help@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


Re: [R] package docs: examples format

2006-04-05 Thread Sarah Goslee
On 4/5/06, Gabor Grothendieck [EMAIL PROTECTED] wrote:

 On 4/5/06, Uwe Ligges [EMAIL PROTECTED] wrote:

 
  What about an additional help page that relates to the whole package
  rather than to a single function and contains the examples? Each
  function's help page can point with a \link{} to that help page.
 

 And that page would be of the form: mypkg-package.Rd and you
 could use the R promptPackage command to generate an outline
 for it.


That would be perfect, thank you for the suggestion. The discussion of
package help in the Writing R Extension manual led me to believe that
this was the wrong approach:
More extensive documentation is better placed into a package vignette
(see Writing
package 
vignetteshttp://cran.r-project.org/doc/manuals/R-exts.html#Writing-package-vignettes)
and referenced from this page, or into individual man pages for the
functions, datasets, or classes.

The other suggestion given, by Prof. Ripley,  was to include examples(B) as
part of the documentation for C, and so on.

Thank you all,
Sarah

--
Sarah Goslee
http://www.stringpage.com

[[alternative HTML version deleted]]

__
R-help@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


Re: [R] Bin by bin histogram comparisons

2006-04-05 Thread Sarah Goslee
Hi,

Assuming you mean the hist2d function from the gplots package,
you can save the results of the histogram as an object, and do
whatever you want with the counts.

myhist - hist2d(gps2, nbins=200)

myhist$counts # shows you the values of the counts for each bin

You can for example take the difference between counts from your
two histograms and plot them as an image, or whatever.

Sarah

On 4/5/06, Philipp H. Mohr [EMAIL PROTECTED] wrote:

 Hello,

 I have created two histograms with:

  hist2d(gps2, nbins=200, col = c(white,heat.colors(16)))

 Both of them have the same range and the same number of bins.
 Now I would like to compare them bin by bin and plot the results.
 Could someone please tell me how to do that. I searched the man pages and
 the web, but couldn't find anything.

 Thank you very much.

 Phil



--
Sarah Goslee
http://www.stringpage.com

[[alternative HTML version deleted]]

__
R-help@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


Re: [R] How to create a directoy with R

2006-03-27 Thread Sarah Goslee
I think you need to use system(mkdir) or whatever is appropriate
for your OS. Making directories is a function of the OS, not of R. If
you need to make a truly cross-platform solution, you might need
to check within your code what OS is being used, and call the
appropriate system statement. (I think you can do this, but have
never needed to.) That would be particularly important if you need to
specify paths.

Sarah

On 3/27/06, pau carre [EMAIL PROTECTED] wrote:

 Hello, I am trying to create directories with R. I would like R to
 create directories because it is platform independent. I tried using
 file() and searching in R Data Import/Export but I did not succeed.
 I think it must be some function since exists the unlink to remove
 directories (and files).

 Pau

 __
 R-help@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




--
Sarah Goslee
http://www.stringpage.com

[[alternative HTML version deleted]]

__
R-help@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


Re: [R] merge two vectors of the same length into one?

2006-03-26 Thread Sarah Goslee
What about this:

 X - c(A, B, C, A, D, A)
 Y - c(B, A, C, A, C, B)

 XY - paste(X, Y, sep=)

 sort(table(XY), decreasing=TRUE)
XY
AB AA BA CC DC
 2  1  1  1  1



On 3/26/06, Zhiqiang Ye [EMAIL PROTECTED] wrote:

 Dear all,

I have a question about merge two character vectors of the same
 length into one.


--
Sarah Goslee
http://www.stringpage.com

[[alternative HTML version deleted]]

__
R-help@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


Re: [R] Use of the index of a for loop to assign values to the rows of a series of variables

2006-03-22 Thread Sarah Goslee
Hi Domenico,

If I understand correctly, you are missing a step. See also ?get

Something like this should do what you want:


for(i in 1:length(posfix)) {
   matname - paste(matX.,posfix[i], sep=) # store the filename
currently needed
   thismat - get(matname) # get the matrix matching that filename
   # do whatever assignment you'd like
   assign(matname, thismat) # copy thismat back into matname
}


--
Sarah Goslee
USDA-ARS

[[alternative HTML version deleted]]

__
R-help@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


Re: [R] partial mantel test

2006-02-23 Thread Sarah Goslee
Hi Alexandra,

I have an R package that includes a partial Mantel function that
can handle multiple partials. We're doing the final testing of this
package, and are about ready to submit it to CRAN. I can email you
the current version if you'd like. (What OS?)

Sarah

On 2/23/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 I would like to know how to run  a partial mantel test controlling for
 spatial
 autocorrelation and correlation with other environmental variables. It
 seems that
 with function included in vegan for partial mantel test I can only test
 for the
 relationship between two variables controlling for the effect of a third
 one.
 Thanks a lot
 Alexandra
 ---


--
Sarah Goslee
http://www.stringpage.com

[[alternative HTML version deleted]]

__
R-help@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


Re: [R] Plotting 27 line plots in one page

2006-02-09 Thread Sarah Goslee

 I want to plot all these elements in 9x3 plot (9 rows
 and 3 columns)
 par(9,3)


You need to specify what par you want - see ?par for details.
In this case, either

par(mfrow=c(9,3))
or
par(mfcol=c(9, 3))

will do what you want.

Sarah
--
Sarah Goslee
http://www.stringpage.com

[[alternative HTML version deleted]]

__
R-help@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


Re: [R] R newbie...

2005-12-06 Thread Sarah Goslee
First of all, you might try reading the manual.

Second, you might try something like this:

calculate - function(x,y)
{
z - x + yz
}

recalculate(z)
{
   a - z^2
   a
}

z - calculate(x, y)
recalculate(z)

You need to return some value from your functions,
and you need to assign that value to a variable.

Sarah

--
Sarah Goslee
http://www.stringpage.com

[[alternative HTML version deleted]]

__
R-help@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


Re: [R] R newbie...

2005-12-06 Thread Sarah Goslee
calculate - function(x,y)
{
   a - x + yb - x - y
   list(a=a, b=b)
}

myresult - calculate(x, y)

myresult$a
myresult$b

Please at least read the Introduction to R at
http://www.r-project.org/

It covers all of this very basic material.

Sarah






--
Sarah Goslee
http://www.stringpage.com

[[alternative HTML version deleted]]

__
R-help@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


Re: [R] help with PCA and classical scaling

2005-06-24 Thread Sarah Goslee
On 6/24/05, Domenico Cozzetto [EMAIL PROTECTED] wrote:
 Furthermore I
 was not able to find on the web any satisfactory tutorial. So even though
 this may be not the most appropriate place to discuss about this issues, I'd
 be very grateful to those who will reply.

http://ordination.okstate.edu
http://www.nicholas.duke.edu/landscape/classes/env358/env358.html

Neither are R tutorials, but if you understand the method, you can
better understand how to use the tools available.

Sarah
-- 
Sarah Goslee
http://www.stringpage.com

__
R-help@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


Re: [R] Bucketting data

2005-06-20 Thread Sarah Goslee
I'm not certain what buckets are, but based on your example try
?unique

On 6/20/05, Uzuner, Tolga [EMAIL PROTECTED] wrote:
 Hi,
 
 Am sure this is a trivial question but for some reason, haven't been able to 
 figure it out.
 
 I want to bucket data in a vector, and then iterate over the buckets.
 
 Say the data set is:
 
  cleandata[,4]
  [1]  26  26  26  26  26  26  26  26  26  26  26  26  61  61  61  61  61  61  
 61  61  61  61  61  89  89  89  89  89  89  89 180 180 180 180 362 544 544 544
 [39] 544 544 544 544 544 544 544
 
 This has the buckets:
 
 26 61 89 180 362 544
 
 I'd like something which gives me a vector of these buckets, i.e. 
 bucket(cleandata[,4])=vector of 26 61 89 180 362 544
 
 and length(bucket(cleandata[,4]))=6
 
 Thanks,
 Tolga
 
 
 
 


-- 
Sarah Goslee 
http://www.stringpage.com

__
R-help@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


Re: [R] an operator for contains

2005-06-17 Thread Sarah Goslee
On 6/17/05, Mike R [EMAIL PROTECTED] wrote:
 k = c(1:9)
 if( length( which(k==3) ) ){ print(contained) }else{ print(not contained) 
 }
 
 is therre a simple way to test if a vector/list contains a particular value?

Yes, several. Here's one:
k - 1:9
if(any(k == 3)) {
cat(is an element\n) } else {
cat(not an element\n) }

I don't recommend that for floating point numbers, though.

 more generally, is the a documentaion page that lists/describes all
 such operators?

help(==) would get you the help page for the actual binary
operators. Since any() isn't an operator, that won't help.

 lastly, if you didn't know the answer to my question, how would you have
 gone about searching for an answer? 

There are a variety of ways to find answers in R, although if you
aren't certain what your keyword should be, it may take a few tries.

help(), help.search(), and apropos() may all be useful.

Sarah

-- 
Sarah Goslee
http://www.stringpage.com

__
R-help@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


[R] Re: dir() and RegEx and gsub()

2005-06-09 Thread Sarah Goslee
Hi,

 The command dir( fold, pattern = \.csv ) gives back *all* the 3 files 
 With dir( fold, pattern = \\.csv ) I get back only VorlageTradefile.csv. 
 I don't understand this behaviour, IMHO the regex expression \.csv
 becomes the string .csv and \\.csv becomes \.csv. So the first
 string should catch it. This is also consistent with the result when I
 tried with the TRegExpr Tool. Could somebody explain what's going on
 here?

Under R, for reasons I've never quite understood,

\\. evaluates to . 
(the double backslash is needed to match a single period)
while \. is the single-character wild card (which seems to be the same as .)

This is explained in ?strsplit but not in the help for other commands
that use regex.

 b)
 I need to handle a copied windows file path. This is certainly often
 asked but I didn't find a solution.

If you mean you want to change the \ to either \\ or / I'm
really not sure.
On my linux system, it doesn't seem possible (which I'm sure is wrong). I'd
try sub() or at worst a combination of strsplit() and paste(), except that:

 test - D:\UebungenNDK\DataMining\DataMiningSeries.r
 test
[1] D:UebungenNDKDataMiningDataMiningSeries.r

Regular expressions under R have always perplexed me just a bit. When
I've run into problems of this sort, I've always just processed the
strings in vim or similar, rather
than fight with R. I'm sure someone here understands them - hopeully
we will both
be enlightened.

Sarah

-- 
Sarah Goslee 
http://www.stringpage.com

__
R-help@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


Re: [R] how to generate pairwise plots with data frames - tia

2005-06-06 Thread Sarah Goslee
Peter,

Please read the intro to R available on the R web page - you've run
into a subsetting problem. The code you specified doesn't select a
column from your matrix.

 plot(test[1], test[2)

Try:

plot(test[,1], test[,2])

since test is a two-dimensional construct.

Also see

?pairs


-- 
Sarah Goslee
http://www.stringpage.com

__
R-help@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


Re: [R] plot/lm/abline

2005-06-02 Thread Sarah Goslee
On 6/2/05, Mathias Hunskår Furevik [EMAIL PROTECTED] wrote:
 Hi,
 
 when I run
 
  plot.default(z1, z2, xlab = x, ylab = y, main = , pch = +)
  abline(lm(z1 ~ z2))

I think you have the independent and dependent variables switched:

abline(lm(z2 ~ z1))

Sarah
-- 
Sarah Goslee
http://www.stringpage.com

__
R-help@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


Re: [R] merge large matrices

2005-06-02 Thread Sarah Goslee
On 6/2/05, Stefan Mischke [EMAIL PROTECTED] wrote:
 Dear List
 
 I have two large matrices A and B. Both have the same dimensions, let's
 say 20k x 30k. About half the cells of B are missing. Now I'm looking
 for an efficient way to merge them, so that the missing values in B are
 replaced by the corresponding values of A.

How about:
B[is.na(B)] - A[is.na(B)]


Sarah

-- 
Sarah Goslee
http://www.stringpage.com

__
R-help@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