Re: [R] Create Arrays

2010-10-15 Thread Gerrit Eichner

Hi, Doug,

maybe


HH - c(0.88, 0.72, 0.89, 0.93, 1.23, 0.86, 0.98, 0.85, 1.23)
TT - c(7.14, 7.14, 7.49, 8.14, 7.14, 7.32, 7.14, 7.14, 7.14)
columnnumbers - c(0, 0, 0, 3, 0, 0, 0, 2, 0)

TMP - lapply( seq( columnnumbers),
   function( i, CN, M) {
if( CN[i] == 0) as.matrix( M[, i]) else
 matrix( -1, nrow( M), CN[i])
}, CN = columnnumbers, M = rbind( HH, TT))

do.call( cbind, TMP)



gets close to what you want (after some adaptation, of course).


 HTH  --  Gerrit

-
AOR Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Logical vectors

2010-11-04 Thread Gerrit Eichner

On Wed, 3 Nov 2010, Stephen Liu wrote:

[snip]


2)

x

[1] 1 2 3 4 5

temp - x  1
temp

[1] FALSE  TRUE  TRUE  TRUE  TRUE


Why NOT

temp

[1] TRUE  FALSE  FALSE FALSE  FALSE

?



Maybe because of the definition of  (greater (!) than)? Or do you 
expect 1 to be greater than 1 and not greater than 2, 3, 4, and 5?


 Regards  --  Gerrit

-
AOR Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Logical vectors

2010-11-04 Thread Gerrit Eichner

On Thu, 4 Nov 2010, Stephen Liu wrote:

[snip]


In;

2.4 Logical vectors
http://cran.r-project.org/doc/manuals/R-intro.html#R-and-statistics

It states:-

The logical operators are , =, , =, == for exact equality and != for
inequality 


   # exact equality

!=   # inequality


[snip]


Hello, Stephen,

in my understanding of the sentence

The logical operators are , =, , =, == for exact equality and != for 
inequality 


the phrase exact equality refers to the operator ==, i. e. to the last 
element == in the enumeration (, =, , =, ==), and not to its first.


 Regards  --  Gerrit

-
AOR Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] newbie question on importing and parsing file by row

2010-11-05 Thread Gerrit Eichner

Hello, Emily,

take a look at read.table() for importing (with or without header 
depending on your file which holds the data). Maybe


X - read.table( yourfilename, header = FALSE, row.names = 1)

and then

pvalues - apply( X, 1,
  function( x)
   fisher.test( matrix( x, 2, 2))$p.value
)

does the job (if all the data in your file are such that fisher.test() can 
cope with them ...).


Hth  --  Gerrit


On Fri, 5 Nov 2010, Emily Wong wrote:


Hi,

I'm new to R and I have a file with many rows of values. Each row 
contains a title and values for a contingency table e.g.


row 1= title8   0   37796   47
which is a table called 'title'
with values
8 0
37796 47

I would like to know how I can import this using R and for each row 
calculate a p value using the fisher test. Using each p value I will do 
multiple a correction.


I am unsure how to automate this process.

Many thanks,
Emily

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] About 5.1 Arrays

2010-11-05 Thread Gerrit Eichner

On Fri, 5 Nov 2010, Stephen Liu wrote:


[snip]


0 is counted as 1 object.

Of course! It is a number like any other.


Does object length mean the total number of objects/entries?

Yes.


Please help me to understand follow;

For example if the dimension vector for an array, say a, is c(3,4,2) then there
are 3 * 4 * 2 = 24 entries in a and the data vector holds them in the order
a[1,1,1], a[2,1,1], ..., a[2,4,2], a[3,4,2].

I don't understand;
a[1,1,1], a[2,1,1], ..., a[2,4,2]

[snip]

A[i, j, k] is the value of the element in position (i,j,k) of array A. In 
other words, it is the entry in row i, column j, and layer k (if one 
wants to think of A as a cuboidal grid).


Hth  -- Gerrit

-
AOR Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] The condition has length 1 and only the first element willbeused

2010-08-03 Thread Gerrit Eichner

Hello, Pablo,

if() doesn't accept a vector as its argument the way you may want it to; 
take a look at ifelse().


 Regards  --  Gerrit


On Tue, 3 Aug 2010, Pablo Cerdeira wrote:


Hi All,

I'm trying to run the following script in R, but I'm getting a warning saying:

Warning message:
In if (z  0) { :
 the condition has length  1 and only the first element will be used

As you can see, I'm sending a vector x to the function f without any
problem. The function f calculates the y value for each x.

But the function f needs to convert the x to positive values (the mod
function). And when it tries to convert, it always uses the first
value of x.

What I'm doing wrong here?

mod = function(x) {
 if (x  0) {
   mod - x*(-1)
 }
 else {
   mod - x
 }
}
f = function(x) {
 f - mod(x)/x
}
x - seq(-1,1,0.01)
x
y - f(x)
y
plot(f,xlim = c(-1,1))
remove(x,y,f,mod)

best regards,

--
Pablo de Camargo Cerdeira
pa...@fgv.br
pablo.cerde...@gmail.com
+55 (21) 3799-6065

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



-
AOR Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109  http://www.uni-giessen.de/~gcb7

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Create Arrays

2010-10-15 Thread Gerrit . Eichner

Hi, Doug,

maybe

columns - c( 0, 3, 0, 2, 0, 1)
lapply( columns[ columns  0],
function( o) array( -1, dim = c( 2, o)))

does what you want?

Regards -- Gerrit

-
AOR Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109  http://www.uni-giessen.de/~gcb7
-


Zitat von dpender d.pen...@civil.gla.ac.uk:



Hi,

For this example:

O - c(0 0 0 2 0 0 2 0)

I want to create an array every time O[i]  0.  The array should be in the
form;

R[j] - array(-1, dim=c(2,O[i]))

i.e. if O[i]  0 4 times I want 4 R arrays.

Does anyone have any suggestions?

Thanks,

Doug
--
View this message in context:  
http://r.789695.n4.nabble.com/Create-Arrays-tp2996706p2996706.html

Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Matrix package problem: dsyMatrix %*% vector gives error

2007-11-01 Thread Gerrit Eichner
Dear UseRs,

here is an example scenario presenting my problem:

Multiplying a dsyMatrix with a numeric vector results in an error 
(unfortunately in German due to my locale):

 (M1 - Matrix( c( 1, 2, 2, 2, 1, 2, 2, 2, 1), nrow = 3))
3 x 3 Matrix of class dsyMatrix
  [,1] [,2] [,3]
[1,]122
[2,]212
[3,]221

 M1 %*% 1:3
Fehler in x %*% as.matrix(y) : kann keinen Slot (Dim) von einem Objekt 
vom Typ integer bekommen


This does not happen when the multiplication is done with a dgeMatrix, for 
example:

 (M2 - Matrix( 1:9, nrow = 3))
3 x 3 Matrix of class dgeMatrix
  [,1] [,2] [,3]
[1,]147
[2,]258
[3,]369
Warning message:
integer matrices not yet implemented in 'Matrix'; using 'double' ones' in: 
Matrix(1:9, nrow = 3)

 M2 %*% 1:3
3 x 1 Matrix of class dgeMatrix
  [,1]
[1,]   30
[2,]   36
[3,]   42


(The warning message seems not important; the problem occurs also with 
non-integer entries.)


However, the problem can be avoided if the dsyMatrix is converted into a 
normal matrix beforehand (so the problem is not really a serious one):

 as.matrix( M1) %*% 1:3
  [,1]
[1,]   11
[2,]   10
[3,]9


However, does one have to use as.matrix()? (I could not find anything 
related despite reading the documentations and browsing the archives).

Thanks for any hint.

  Best regards  --  Gerrit


PS: Here is my session info:

 sessionInfo()
R version 2.5.1 (2007-06-27)
x86_64-unknown-linux-gnu

locale:
LC_CTYPE=de_DE.UTF-8;LC_NUMERIC=C;LC_TIME=de_DE.UTF-8;LC_COLLATE=de_DE.UTF-8;
LC_MONETARY=de_DE.UTF-8;LC_MESSAGES=de_DE.UTF-8;LC_PAPER=de_DE.UTF-8;LC_NAME=C;
LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=de_DE.UTF-8;LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics  grDevices utils datasets  methods
[7] base

other attached packages:
   Matrix  lattice
0.999375-10.15-11

-
AR Dr. Gerrit Eichner  Mathematical Institute
[EMAIL PROTECTED]   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32029   http://www.math.uni-giessen.de

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Row percentages for a table object

2008-02-08 Thread Gerrit Eichner
 Tom Backer Johnsen wrote:
 I an stumbling on something that is probably very simple, but I cannot
 see the solution.  I have an object generated by the table () function
 and want to recompute this table so each cell represents the
 percentage of the corresponding row sum.

 Of course a dedicated function can be written (which I have done),
 containing the necessary loops etc., but there should be a simpler
 way.  I'd prefer something simple and as transparent as possible since
 it is for use in a text I am writing for my students.  I have fiddled
 around with the apply () function but have so far been unable to find
 something that works.

Maybe a look at

?prop.table

and/or

?addmargins

could help you.

  Regards  --  Gerrit

-
AR Dr. Gerrit Eichner  Mathematical Institute
[EMAIL PROTECTED]   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32029   http://www.math.uni-giessen.de

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Evaluation conflict in combination of replicate() and rexp()as variable inside a function

2008-05-23 Thread Gerrit Eichner

Dear userRs,

playing around with combinations of replicate() and random number 
generating functions inside a self-defined wrapper function I encounterd 
a puzzling behaviour.


The following are intentionally simple (and rather nonsense-) examples to 
isolate the relevant aspects. Please, note the seemingly inconsistent 
behaviour for the second call of rdistr() (with distr = rexp) for which I 
have not found any explanation (yet):



rdistr - function( distr, ...) replicate( 1, distr( n = 1, ...))



rdistr( distr = rnorm)

[1] -0.8889223


rdistr( distr = rexp)

[1] NaN
Warning message:
In distr(n = 1, ...) : NAs produced


rdistr( distr = runif)

[1] 0.8444856


Trying to discover the reason for this observation, I looked into the code 
of replicate() and realized that this seems to be an issue of evaluation 
schemes (and maybe also of variable scoping), but I didn't delve deeper 
into it, yet. Can anybody more competent enlight me or give me a hint 
where to search, please? Thank you!


 Best regards  --  Gerrit

PS:


sessionInfo()

R version 2.6.2 (2008-02-08)
x86_64-unknown-linux-gnu

locale:
LC_CTYPE=de_DE.UTF-8;LC_NUMERIC=C;LC_TIME=de_DE.UTF-8;LC_COLLATE=de_DE.UTF-8;LC_MONETARY=de_DE.UTF-8;LC_MESSAGES=de_DE.UTF-8;LC_PAPER=de_DE.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=de_DE.UTF-8;LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base

loaded via a namespace (and not attached):
[1] rcompgen_0.1-17


-
AR Dr. Gerrit Eichner  Mathematical Institute
[EMAIL PROTECTED]   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32029   http://www.math.uni-giessen.de

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Function to Check Object's Memory Size

2009-01-06 Thread Gerrit Eichner

On Wed, 7 Jan 2009, Gundala Viswanath wrote:


Dear all,

Does R has any function that measures how much
memory hold by any particular object?

- Gundala Viswanath
Jakarta - Indonesia

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


See

?object.size

 Regards  --  Gerrit

-
AR Dr. Gerrit Eichner  Mathematical Institute
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32029   http://www.math.uni-giessen.de

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Help on efficiency/vectorization

2009-08-27 Thread Gerrit Eichner

Hi, Steven,

try

lapply( x, function( v) rownames(x)[ v == 1])

or

lapply( x, function( v, rn) rn[ v == 1], rn = rownames( x)))

which is faster.

 Regards  --  Gerrit

-
AOR Dr. Gerrit Eichner Mathematical Institute, Room 305 E
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109  http://www.uni-giessen.de/~gcb7
-

On Thu, 27 Aug 2009, Steven Kang wrote:


Dear R users,

I am trying to extract the rownames of a data set for which each columns
meet a certain criteria. (condition - elements of each column to be equal
1)

I have the correct result, however I am seeking for more efficient (desire
vectorization) way in implementing such problem as it can get quite messy
if
there are hundreds of columns.

Arbitrary data set and codes are shown below for your reference:

x - as.data.frame(matrix(round(runif(50),0),nrow=5))

rownames(x) - letters[1:dim(x)[1]]

 x
 V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
a  0  1   11   0   00   0   10
b  1  1   11   0   10   0   11
c  0  1   10   0   00   0   01
d  1  0   01   1   11   1   00
e  1  0   00   0   11   0   10

V1.ind - rownames(x)[x[,V1]==1]
V2.ind - rownames(x)[x[,V2]==1]
V3.ind - rownames(x)[x[,V3]==1]
V4.ind - rownames(x)[x[,V4]==1]
:
:
V10.ind - rownames(x)[x[,V10]==1]

 V1.ind
[1] b d e
 V2.ind
[1] a b c
 V3.ind
[1] a b c
:
:
 V10.ind
[1] b c



Your expertise in resolving this issue would be highly appreciated.


Steve

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Function for all 2^N subsets of N

2009-09-01 Thread Gerrit Eichner

Maybe

expand.grid( rep( list( 0:1), 10))

does what you want.

 Best regards  --  Gerrit

-
AOR Dr. Gerrit Eichner Mathematical Institute, Room 305 E
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109  http://www.uni-giessen.de/~gcb7
-

On Tue, 1 Sep 2009, 
ted.hard...@manchester.ac.uk wrote:



Greetings all!
I have been searching the Site for a function, say subsets,
such that for instance

 subsets(10)

would return a (say) matrix of indices to the 2^10 subsets of
N items -- perhaps in the form of 2^10 rows each of which is
10 entries each either TRUE or FALSE. Or 1 or 0. Or ...

I can of course write my own, using good old looping technology
or similar, but it would be good to find one which did it quick
and snappy, at the compiled level.

A Site Search in Function on all subsets didn't seem to yield
anything of the kind, which surprised me. Maybe I overlooked
something ...

(This is prompted by the recent OT discussion on HT vs. HH,
to which I want to respond later).

With thanks,
Ted.


E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk
Fax-to-email: +44 (0)870 094 0861
Date: 01-Sep-09   Time: 09:09:09
-- XFMail --

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Polynomial fitting

2011-07-07 Thread Gerrit Eichner

Hello, mfa (Matti?),

if x and y contain the coordinates of your data points and k is the wanted 
polynomial degree, then


fit - lm( y ~ poly( x, k))

fits orthonormal polynomials up to degree k to your data. Using

dummy.coef( fit)

should give the coefficients you are interested in.

 Hth  --  Gerrit

On Thu, 7 Jul 2011, mfa wrote:


Hello,

i'm fairly familiar with R and use it every now and then for math related
tasks.

I have a simple non polynomial function that i would like to approximate
with a polynomial. I already looked into poly, but was unable to understand
what to do with it. So my problem is this. I can generate virtually any
number of datapoints and would like to find the coeffs a1, a2, ... up to a
given degree for a polynomial a1x^1 + a2x^2 + ... that approximates my
simple function. How can i do this with R?

Your help will be highly appreciated!

--
View this message in context: 
http://r.789695.n4.nabble.com/Polynomial-fitting-tp3652816p3652816.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


-
Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to remove the double or single quote from a string(unquote?)?

2011-04-18 Thread Gerrit Eichner

Hi, Jing Jiang,

maybe

as.formula( paste( V12 ~ V, i, sep = ))

inside the call to glm() does what you need.

Hth  --  Gerrit


On Tue, 19 Apr 2011, JingJiang Yan wrote:


Is there a function to get a string without a pair of quotes around it?

I have several expressions like:
glm(V12 ~ V3, family=binomial, data=df1)
glm(V12 ~ V4, family=binomial, data=df1)
...
glm(V12 ~ V8, family=binomial, data=df1)

As you can see, the only differences among them are V3 ... V8.
Because sometimes several of these expressions are performed many times,
I want to use a variable i to change the V3 ... V8. I did this with:


i - 3:8
glm(V12 ~ paste(V, i, sep=), family=binomial, data=df1)


However, it seems the paste always returns a variable name with a pair of 
quotes, which were wrong in such condition.
I only find a function sQuote to add quotes to a string, and it looks I am 
looking for an opposite function of it.

Any advice will be appreciated.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



-
Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Entire part of number

2011-04-19 Thread Gerrit Eichner

What is the function to have the entire part of a number?


If entire refers to integer take a look at

?trunc


 Hth  --  Gerrit

-
Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Question on Import

2011-04-25 Thread Gerrit Eichner

Hi, Georgina,

using quotation marks around the file name like in


read.delim( ken_data_try_anova)


might help.

 Hth -- Gerrit


On Mon, 25 Apr 2011, Georgina Salazar wrote:


Hi!

I have the data in a tab delimited text file titled ken_data_try_anova. I
tried to import it into R entering


read.delim(ken_data_try_anova)


but received the error message

Error in read.table(file = file, header = header, sep = sep, quote = quote,  :
 object 'ken_data_try_anova' not found

I have another file called 10423nad.txt.

I tried

data-as.matrix(read.table(C:\Users\gtsalazar1979\Documents\TANOVA_1.0.0\10423nad.txt))
)


but got the error message
Error: unexpected input in data-as.matrix(read.table(C:\

How do I place the data where the import function can find it? Or, how do I
correct my use of the import functions?

Thank you for your time and patience! Any guidance toward a solution means a lot
to me :)
Cheers,
Georgina To'a Salazar


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Using functions/loops for repetitive commands

2011-05-05 Thread Gerrit Eichner

Hello, Derek,

see below.

On Thu, 5 May 2011, dereksloan wrote:

I still need to do some repetitive statistical analysis on some outcomes 
from a dataset.


Take the following as an example;

id  sex hiv age famsize bmi resprate
1   M   Pos 23  2   16  15
2   F   Neg 24  5   18  14
3   F   Pos 56  14  23  24
4   F   Pos 67  3   33  31
5   M   Neg 34  2   21  23

I want to know if there are statistically detectable differences in all 
of the continuous variables in my data set when subdivided by sex or hiv 
status (ie are age, family size, bmi and resprate different in my male 
and female patients or in hiv pos/neg patients) Of course I can use 
wilcoxon or t-tests e.g:


wilcox.test( age~sex)
wilcox.test(famsize~sex)
wilcox.test(bmi~sex)
wilcox.test(resprate~sex)
wilcox.test( age~hiv)
wilcox.test(famsize~hiv)
wilcox.test(bmi~hiv)
wilcox.test(resprate~hiv)
 [snip]



Define, e. g.,

my.wilcox.tests - function( var.names, groupvar.name, data) {
 lapply( var.names,
 function( v) {
  form - as.formula( paste( v, ~, groupvar.name))
  wilcox.test( form, data = data)
  } )
 }


and call something like

my.wilcox.test( character vector with relevant variable names,
character string with relevant grouping variable,
data = your data set as data frame)

Caveat: untested!

 Hth  --  Gerrit

-
Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Using functions/loops for repetitive commands

2011-05-06 Thread Gerrit Eichner

Hello, Derek,

first of all, be very aware of what David Winsemius said; you are about to 
enter the area of unprincipled data-mining (as he called it) with its 
trap -- one of many -- of multiple testing. So, *if* you know what the 
consequences and possible remedies are, a purely R-syntactic solution to 
your problem might be the (again not fully tested) hack below.



If so how can I change my code to automate the chisq.test in the same 
way I did for the wilcox.test?


Try

lapply( your_data_frame[selection_of_relevant_components],
function( y)
 chisq.test( y, your_data_frame$group_name)
  )

or even shorter:

lapply( your_data_frame[selection_of_relevant_components],
chisq.test, your_data_frame$group_name
  )


However, in the resulting output you will not be seeing the names of the 
variables that went into the first argument of chisq.test(). This is a 
little bit more complicated to resolve:


lapply( names( your_data_frame[selection_of_relevant_components]),
function( y)
 eval( substitute( chisq.test( your_data_frame$y0,
   your_data_frame$tension),
   list( y0 = y) ) )
   )



Still another possibility is to use xtabs() (with its summary-method) 
which has a formula argument.



 Hoping that you know what to do with the results  --  Gerrit

-
Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Running *slow*

2011-10-07 Thread Gerrit Eichner

Hi, Thomas,

if I'm not completely mistaken

Dat2 - match( t( Dat), ltable)

should do what you want.

 Hth -- Gerrit

On Fri, 7 Oct 2011, thomas.chesney wrote:


Thank you Michael and Patrick for your responses. Michael - your code ran in
under 5 minutes, which I find stunning, and Patrick I have sent the Inferno
doc to the copier for printing and reading this weekend.

I now have 8 million values in my lookup table and want to replace each
value in Dat with the index of that value in the lookup table. In line with
Chapter 2 in the Inferno doc, I created a list of appropriate size first,
rather than growing it, but still couldn't figure out how to do it without
looping in R, so it still runs extremely slowly, even just to process the
first 1000 values in Dat. My original code (before I tried specifiying the
size of Dat2) was:

Dat2 - c()

for (i in 1:nrow(Dat))
{
for (j in 1:2)
{
Dat2 - c(Dat2, match(Dat[i,j], ltable))
}}

write(t(edgelist), EL.txt, ncolumns=2)

Can anyone suggest a way of doing this without looping in R? Or is the
bottleneck the c function? I am looking at apply this morning, but Gentleman
(2009) suggests apply isn't very efficient.

--
View this message in context: 
http://r.789695.n4.nabble.com/Running-slow-tp3878093p3881365.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] binding all elements of list (character vectors) to a matrixasrows

2011-10-11 Thread Gerrit Eichner

Marion,

try

rbind( Mymatrix, do.call( rbind, Z))

Hth  --  Gerrit


On Tue, 11 Oct 2011, Marion Wenty wrote:


dear r-users,

i have got a problem which i am trying to solve:

i have got the following commands:

Mymatrix - matrix(1:9,ncol=3)
Z -
list(V1=c(a,,),V2=c(b,,),V3=c(c,,),V4=c(d,,))
Mymatrix - rbind(Mymatrix,Z[[1]],Z[[2]],Z[[3]],Z[[4]])

now this is working, but i would like to substitute

Z[[1]],Z[[2]],Z[[3]],Z[[4]]

for a command with which i could also use another list with a different
number of elements, e.g. 5 or 6 elements.

does anyone know the solution to this problem?
thank you very much in advance!

marion

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] replacing values in Array

2012-03-13 Thread Gerrit Eichner

Hello, uday,

e.g.,

(data - 1) %/% 3 + 1

would do the job in your very specific situation, but take a look at

?findInterval

for possibly more interesting (because more general) solutions.

Hth  --  Gerrit

On Tue, 13 Mar 2012, uday wrote:


I want to replace some values in my Array
e.g
data- c(1,2,3,4,5,6,7,8,9,10,11,12)
I would like to replace 1,2,3 by 1 , 4,5,6 by 2, 7,8,9 by 3 and 10,11,12 by
4
I am expecting out put
data- 1 1 1  2 2 2 3 3 3 4 4 4

I have tried replace function
replace(data, (data==1 |data==2| data==3),1)
replace(data, (data==4|data==5| data==6),2)
replace(data, (data==7|data==8| data==9),3)
replace(data, (data==10 |data==11| data==12),4)
but it changes only for individual operation it does not apply to whole
array.
So how I should replace values of whole array ?



--
View this message in context: 
http://r.789695.n4.nabble.com/replacing-values-in-Array-tp4468739p4468739.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] anova.lm F test confusion

2012-03-21 Thread Gerrit Eichner

Dear Ben, or anybody else, of course,

I'd be grateful if you could point me to a reference (different from ch. 4 
Linear models in Statistical Models in S (Chambers  Hastie (1992))) 
regarding the (asserted F-)distributional properties of the test statistic 
(used, e.g., by anova.lm()) to compare model 1 with model 2 using the MSE 
of model 3 in a sequence of three nested (linear) models? (A short 
RSiteSearch() and a google search didn't lead me far ...)


Thx in advance!

 Best regards  --  Gerrit

-
Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner
-

On Wed, 21 Mar 2012, Ben Bolker wrote:


msteane michellesteane at hotmail.com writes:



I am using anova.lm to compare 3 linear models.  Model 1 has 1 variable,
model 2 has 2 variables and model 3 has 3 variables.  All models are fitted
to the same data set.


 (I assume these are nested models, otherwise the analysis doesn't
make sense ...)



anova.lm(model1,model2) gives me:

  Res.DfRSS Df Sum of Sq  FPr(F)
1135 245.38
2134 184.36  161.022 44.354 6.467e-10 ***

anova.lm(model1,model2,model3) gives me:

  Res.DfRSS Df Sum of Sq  FPr(F)
1135 245.38
2134 184.36  161.022 50.182 7.355e-11 ***
3133 161.73  122.628 18.609 3.105e-05 ***

Why aren't the 2nd row F values from each of the anova tables the same??? I
thought in each case the 2nd row is comparing model 2 to model 1?


From ?anova.lm:

Normally the F statistic is most appropriate, which compares the mean
square for a row to the residual sum of squares for the largest model
considered.



I figured out that for anova.lm(model1,model2)
F(row2)=Sum of Sq(row2)/MSE of Model 2

and for anova.lm(model1,model2,model3)
 F(row2)=Sum of Sq(row 2)/MSE of Model 3  -- I don't get why the MSE of
model 3 is being included if we're comparing Model 2 to Model 2


  See above ...

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Supperscript, subscript and double lines in the main/subtitle and using greekletters

2012-03-27 Thread Gerrit Eichner

Hi, HJ,

see

?plotmath

 Hth  --  Gerrit

-
Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner
-

On Tue, 27 Mar 2012, HJ YAN wrote:


Dear R-help,

I am trying to express myself as best as I can here. If you also use Latex
to edit math reports or other languages with similar editing method,
you'll see what I'm talking about. My sincere appologies if my question is
not clear enough to some extend, as also I'm not able to provide my code
here because I don`t know which one I can use...

When editing the title in R plots, such as using 'plot', or 'xyplot' in
'lattic', what method do you use to write greek letters and make use of
superscript and subscript, e.g. to write mathematical expressions like
using Latex:

\sigma^2
\tau^{2s}
\mu_i
\pi_{2s}

Also I would like to learn how to make two lines in the main title or sub
title if the text I need it too long for putting in a single line, e.g. are
there some R code/syntax allowing me to do something like in Latex to make
two lines in the title, for example using '//' or '\\' to seperate the two
parts of the text I want to put in two lines??

I heard about using something like

plot(x,y, main=expression())

but from neither '?plot' or '?expression' could I find comprehensive
information about what I need...

Many thanks!
HJ

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] reading files from two folders

2012-03-28 Thread Gerrit Eichner

Hello, uday,

there's presumably a typo in your code because you use path1t in


data2  - read.table(paste(path1t, file_wasaux2[i],header=TRUE))


and not path which you defined above.

 Hth -- Gerrit

-
Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner
-

On Tue, 27 Mar 2012, uday wrote:


I would like to read data from two different folder and then combine this
together
the code which I have tried are as follows
setwd(/Groups/data_first/)
file_was - list.files(path = ., pattern = v2.0.2.was, all.files =
FALSE, full.names = FALSE, recursive = FALSE, ignore.case = FALSE)
path-c(/Groups/data_second/)
file_wasaux2 -list.files(path,pattern=v2.0.2.wasaux2)
files- 1
for ( i in files){
data1  - read.table(file_was[i],header=TRUE)
data2  - read.table(paste(path1t, file_wasaux2[i],header=TRUE))
data   - cbind (data1,data2)
}
but I get error
(Error in read.table(SCI_WFMD_L2_w6002_200301_v2.0.2.wasaux2, header = TRUE)
:
 object 'SCI_WFMD_L2_w6002_200301_v2.0.2.wasaux2' not found)

could somebody please tell me how to solve this problem?


--
View this message in context: 
http://r.789695.n4.nabble.com/reading-files-from-two-folders-tp4511493p4511493.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] fast subsetting of lists in lists

2010-12-07 Thread Gerrit Eichner

Hello, Alexander,

does

utest - unlist(test)
utest[ names( utest) == a]

come close to what you need?

Hth,

Gerrit


On Tue, 7 Dec 2010, Alexander Senger wrote:


Hello,


my data is contained in nested lists (which seems not necessarily to be
the best approach). What I need is a fast way to get subsets from the data.

An example:

test - list(list(a = 1, b = 2, c = 3), list(a = 4, b = 5, c = 6),
list(a = 7, b = 8, c = 9))

Now I would like to have all values in the named variables a, that is
the vector c(1, 4, 7). The best I could come up with is:

val - sapply(1:3, function (i) {test[[i]]$a})

which is unfortunately not very fast. According to R-inferno this is due
to the fact that apply and its derivates do looping in R rather than
rely on C-subroutines as the common [-operator.

Does someone now a trick to do the same as above with the faster
built-in subsetting? Something like:

test[somesubsettingmagic]


Thank you for your advice


Alex

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Question about cut()

2010-12-14 Thread Gerrit Eichner

Tianchan, why aren't you just using


col_no - cut(r,c(0,2,4,6,8,10,100))
levels(col_no) - c(2%,2-4%,4-6%,6-8%,8-10%,10%)


?

Your use of as.numeric() is nonsensical; check step by step what is
happening with that.

Hth,

Gerrit

On Tue, 14 Dec 2010, Tianchan Niu wrote:


Dear all,
I would like to use cut() to make numerics to factors, the sample codes are as follows. However, the 
result is not what I want, since r[3] = 9 should be in the interval of 8-10% rather than 
2-4%. Maybe cut() is not the right function to use for my situation. Please help.  r 
- c(1,1,9,1,1,1)

col_no - as.factor(as.numeric(cut(r,c(0,2,4,6,8,10,100
levels(col_no) - c(2%,2-4%,4-6%,6-8%,8-10%,10%)
col_no

[1] 2%  2%  2-4% 2%  2%  2%
Levels: 2% 2-4% 4-6% 6-8% 8-10% 10%Thanks,
Tianchan


 Best regards  --  Gerrit
 Best regards  --  Gerrit Eichner
 Viele Grüße  --  Gerrit
 Viele Grüße  --  Gerrit Eichner
 Viele Grüße  --  GE
 Freundliche Grüße  --  Gerrit Eichner
 Freundliche Grüße  --  GE
 Grüße  --  Gerrit
 Grüße  --  Gerrit Eichner
 Grüße  --  GE
 Gruß  --  G

-
AOR Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner
-__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Question

2010-12-14 Thread Gerrit Eichner

On Tue, 14 Dec 2010, Matthew Rosett wrote:


How do I determine if my data deviate from the normal distribution?
The sample size is 1000 (weights of people).


See

?qqnorm

and/or

?shapiro.test

and/or

a text book on applied statistics

and/or

google for testing normality.


Hth,

Gerrit

PS: With n = 1000 your data will almost inevitably deviate from the normal 
distribution.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Can the by() function return a single column?

2010-12-15 Thread Gerrit Eichner

Hello, Vassilis,

maybe


with( test.df, ave( vector, factor, FUN = function( x) x - mean( x)))


does what you want.


-- Gerrit


On Wed, 15 Dec 2010, Vassilis wrote:



I would like to de-mean the 'vector' column of the following dataframe by
factor:

set.seed(5444)
vector  - rnorm(1:10)
factor  - rep(1:2,5)
test.df - data.frame(factor, vector)

which is:

  factor vector
1   1 -0.4963935
2   2 -2.0768182
3   1 -1.584
4   2  0.8025474
5   1  0.3504199
6   2  0.2358464
7   1 -0.3989443
8   2 -0.3692544
9   1 -0.3174586
10  2  1.4305431

Using the by() command, I get:


by(test.df$vector, test.df$factor, function(x) {x - mean(x)})

test.df$factor: 1
[1] -0.007473699 -1.093302612  0.839339673  0.089975488  0.171461151
--
test.df$factor: 2
[1] -2.0813911  0.7979745  0.2312735 -0.3738272  1.4259702




My question is: Is there a way to have this output put back to the
dataframe? I.e to make by(), or some other command, return me a vector of
length 10 whose values x' correspond to x'_1 = x_1 - mean(x | factor1), x'_2
= x_2 - mean(x | factor2),...

Thanks in advance for the help, and apologies for the poor notation.

Vassilis

--
View this message in context: 
http://r.789695.n4.nabble.com/Can-the-by-function-return-a-single-column-tp3089231p3089231.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to arrange the data

2010-12-17 Thread Gerrit Eichner

Hello, Amy,

take a look at

?reshape


In your case, I think,

reshape( yourdatafame, varying = c( value1, value2, value3),
 v.name = amount, times = c( value1, value2, value3),
 timevar = name, direction = long)

should work.

Hth -- Gerrit

On Fri, 17 Dec 2010, Amy Milano wrote:


Dear R helpers

I have one data as given below.

date value1  value2 value3
30-Nov-2010   100 40 61
25-Nov-2010   108 31 88
14-Sep-2010    11 180   56

I want the following output

date name       amount
30-Nov-2010  value1        100
30-Nov-2010  value2 40
30-Nov-2010  value3 61
25-Nov-2010  value1   108
25-Nov-2010  value2     31
25-Nov-2010      value3         88 
14-Sep-2010  value1    11
14-Sep-2010  value2  180
14-Sep-2010      value3      56
...__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] tabulating 2 factors weighting by a third var

2010-12-19 Thread Gerrit Eichner

Hi, Luca,

if V is you data frame, maybe

with( V, tapply( v3, list( v1, v2), sum))

does what you want.

Hth  --  Gerrit


On Mon, 20 Dec 2010, Luca Meyer wrote:


Hi,

This must be an easy one but so far I haven't find a way out...

I have a data frame such as:

$ v1: Factor w/ 5 levels
$ v2: Factor w/ 2 levels
$ v3: Class 'difftime'  atomic [1:]

basically v1 and v2 are factors, while v3 is a variable containing the 
duration of certain activities (values ranging from 11 to 45000 sec, no 
missing values)


How can I get a table such that v1 levels will show as rows, v2 levels 
as columns and v3 is the weight by which table(v1,v2) is weighted? That 
is, instead of getting the count of occurences in each of the 10 cells 
of table(v1,v2) I would like to get the sum(v3), how can it be done?


Thanks,
Luca

Luca Meyer
www.lucameyer.com
IBM SPSS Statistics release 19.0.0
R version 2.12.1 (2010-12-16)
Mac OS X 10.6.5 (10H574) - kernel Darwin 10.5.0

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] labels and barchart

2010-12-21 Thread Gerrit Eichner

Hello, Robert,

see hints below.

On Tue, 21 Dec 2010, Robert Ruser wrote:


Hello,
I'm wondering how to set a value of mar ( par( mar=c(...)) ) in
order to allow labels to be visible in barplot. Is there any relation
between the number of characters in a label and the second value of
mar? Look at my example.

x - seq(20, 100, by=15)
ety - rep( Effect on treatment group, times=length(x))
barplot(x, names.arg=ety, las=1, horiz=TRUE)

Labels are not visible. But trial and error method with the second mar
argument I get what I want.

par(mar=c(3,12,2,1), cex=0.8)
barplot(x, names.arg=ety, las=1, horiz=TRUE)

I would like something like that: second.mar = max( nchar(ety) )/2


Can't help with that really, but ...


Taking the opportunity I have 2 another question:
1. Space between labels and bars is too big - how to change it to the
value of 1 character?
2. In the example above the x axis is too short. How to make R draw a
line little longer then maximum bar length. I know that I could set
xlim=c(0,max(x)) but because of main increase equals 20 and the last
value 95 it doesn't solve the problem. The increase is ok. but only
line should be longer.


You could take a look at par()'s argument mgp, but it affects both axes at 
the same time. I have the impression that you want more control of the 
style of each axis separately; axis() might than be useful, like



par( mar = c( 3, 13, 2, 1), cex = 0.8)

barplot( x, names.arg = NULL, horiz = TRUE, axes = FALSE)

axis( side = 1, at = c( seq( 0, 80, by = 20), 95))

axis( side = 2, at = 1:length(ety), line = -1, las = 1, tick = FALSE,
  labels = ety)



Hth,

Gerrit





Thank you
Robert

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to integrate a function with additional argument beingavector or matrix?

2010-12-22 Thread Gerrit Eichner

On Wed, 22 Dec 2010, Marius Hofert wrote:


Dear expeRts,

I somehow don't see why the following does not work:

integrand - function(x, vec, mat, val) 1 # dummy return value
A - matrix(runif(16), ncol = 4)
u - c(0.4, 0.1, 0.2, 0.3)
integrand(0.3, u, A, 4)
integrate(integrand, lower = 0, upper = 1, vec = u, mat = A, val = 4)

I would like to integrate a function (integrand) which gets an x value (the running variable), a vector 
(vec), a matrix (mat), and a value (val). This function returns a number (set to 1 here). Of 
course, pointwise evaluation works without flaws. But why does integration not work? I obtain:

Error in integrate(integrand, lower = 0, upper = 1, vec = u, mat = A,  :
 evaluation of function gave a result of wrong length


Because your function isn't vectorized, i.e., does not *return* a vector. 
Instead,



integrand - function(x, vec, mat, val) rep( 1, length( x)) # dummy return value


should work.

Hth  --  Gerrit



Cheers,

Marius

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] puzzled with plotmath II

2011-01-20 Thread Gerrit Eichner

Try


plot (1, 1, ylab = expression (Z[list(i,i)]))


Hth  --  Gerrit



 Original Message 
Subject: puzzled with plotmath
Date: Thu, 20 Jan 2011 12:48:18 +0100
From: Claudia Beleites cbelei...@units.it
To: R Help r-help@r-project.org

Dear all,

I'm puzzled with matrix indices in plotmath.

I'm plotting matrix elements: Z [i, i], and I'd like to put that as label. 
I'll

describe what I want and what I get in LaTeX-notation.

The output should look like Z_{i, i}, and my first try was
plot (1, 1, ylab = expression (Z[i, i]))

That, however, gives me Z_{i} (no comma, no second i) although the expression
looks OK to me:

a - expression (Z[i, i])
a [[1]]

Z[i, i]

str (as.list (a [[1]]))

List of 4
$ : symbol [
$ : symbol Z
$ : symbol i
$ : symbol i

I'm able to tweak the ouput looking as I want:
plot (1, 1, ylab = expression (Z[i][, ][i]))
which is, however, logically very far from what I want to express.

What am I missing?

I'm almost sure this has been discussed before, but I can't find it: can 
anyone

point me to good search terms? Is it possible to search for the terms being
close to each other in RSiteSearch and/or RSeek? I get lots of introductory
documents as they point to plotmath and discuss matrices...

Thanks a lot for your help,

Claudia


sessionInfo ()

R version 2.12.1 (2010-12-16)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
[1] LC_CTYPE=en_US.utf8   LC_NUMERIC=C  LC_TIME=en_US.utf8
[4] LC_COLLATE=en_US.utf8 LC_MONETARY=C 
LC_MESSAGES=en_US.utf8

[7] LC_PAPER=en_US.utf8   LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=CLC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C

attached base packages:
[1] grid  stats graphics  grDevices utils datasets  methods 
base


other attached packages:
[1] ggplot2_0.8.8 proto_0.3-8   reshape_0.8.3 plyr_1.2.1

loaded via a namespace (and not attached):
[1] digest_0.4.2 tools_2.12.1

--
Claudia Beleites
Dipartimento dei Materiali e delle Risorse Naturali
Università degli Studi di Trieste
Via Alfonso Valerio 6/a
I-34127 Trieste

phone: +39 0 40 5 58-37 68
email: cbelei...@units.it

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] puzzled with plotmath for matrix indices

2011-01-20 Thread Gerrit Eichner

Claudia,

Mittelhessen! ;-)


thanks  viele Grüße nach Oberhessen :-)



plot (1, 1, ylab = expression (Z[list(i,i)]))

though that cannot be evaluated, either (due to [ not knowing what to do
with an index list)


Something is missing; this last sentence of yours appears to be not 
complete, does it?



Regarding Uwe's remark and Peter's nice aesthetic suggestion:


plot( 1, 1, xlab = substitute( Z[list(~i, j)], list( i = 1, j = 2)))


should solve both problems.

This does work even in R as old as 2.7.1 (and, of course, for a more 
recent version as Uwe already stated).


 Best regards / Beste Grüße  --  Gerrit__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Bug in options(digits=n)??

2011-11-18 Thread Gerrit Eichner

No bug. See ?options or ?print.default and note *significant* digits.

 Hth  --  Gerrit

On Fri, 18 Nov 2011, Ravi Kulkarni wrote:


This is in version 2.10.1


sqrt(3)

[1] 1.732051

6/7

[1] 0.8571429

options(digits=3)
sqrt(3)

[1] 1.73

6/7

[1] 0.857

sqrt(7)

[1] 2.65

7/9

[1] 0.778

Ravi

--
View this message in context: 
http://r.789695.n4.nabble.com/Bug-in-options-digits-n-tp4082537p4082537.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Need to calculate standard deviation by groups

2011-12-09 Thread Gerrit Eichner

Hello, Zsuzsa,

does ave() with its argument FUN supplied with sd not do what you want?
Something like

with( Dataset, ave( x = B, C, D, FUN = sd))

should do it.

Hth  --  Gerrit


On Fri, 9 Dec 2011, Zsuzsanna Papp wrote:


Hello,

please help me with this basic question, I already spent two days on the
internet and textbooks trying to come up with an answer...
I will simplify my question to an example, rather than base it on the
original variable names.
I have a Dataset with 4 variables, 2 cases. Variable A is an ID.
Variable B is a continuous numerical variable, unique to each A.
Variable C is categorical factor, has 6 possible levels. Variable D is
also categorical factor, has 300 different levels.

I would like to create a new variable=E, which is the standard deviation
of B around the group means of B, groups defined by C and D.

I had no problem creating such column to get group means (with the ave()
function), but can not find a solution for another function like sd that
would assign proper group value to each case.

I tried

Dataset$E - with(Dataset, tapply(B, list(C,D),FUN=sd))

but it is wrong, as it takes the 1800 different SD values, puts them in
column E, then puts the same array of numbers there below it, repeats as
many times as possible until the column is filled. The SD values are not
corresponding to the proper groups.

How can I match these data (1800 different SD values) to their
corresponding cases in my original data?
Is there a shortcut to do this all in one line, as for the means with
the ave() function?

I also tried ddply but I am doing something wrong (my R is on Linux and
do not yet know how to get error messages, so I do not know what is
wrong with my lines).

Thank you for any help! Please give me as detailed script as possible.

Zsuzsa

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



-
Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Other ways to lm() regression? (non-loop?)

2011-12-26 Thread Gerrit Eichner

Hello, iliketurtles (?),

for whatever strange reasons you want to regress all y-columns on all 
x-columns, maybe


reg - apply( x, 2, function( xx) lm( y ~ xx))
do.call( cbind, lapply( reg, coef))

does what you want. (To understand what the code above does, check the 
documentation for lm(): If response is a matrix a linear model is fitted 
separately by least-squares to each column of the matrix.)


Hth  --  Gerrit


On Mon, 26 Dec 2011, iliketurtles wrote:


Hi, I'm quite new to R (1 month full time use so far). I have to run loop
regressions VERY often in my work, so I would appreciate some new
methodology that I'm not considering.

#-
y-matrix(rnorm(100),ncol=10,nrow=10)
x-matrix(rnorm(50),ncol=5,nrow=10)

#Suppose I want to run the specification y=A+Bx+error, for each and every
y[,n] onto each and every x[,n].
#So with:
ncol(y);ncol(x)
#I should end up with 10*5=50 regressions in total.

#I know how to do this fine:
MISC1-0
for(i in 1:ncol(y)){
for(j in 1:ncol(x)){
reg-lm(y[,i]~x[,j])
MISC1-cbind(MISC1,coef(reg)) #for coefficients
}}
coef-matrix(MISC1[,-1],ncol=50)

coef[,1];coef(lm(y[,1]~x[,1])) #test passed
ncol(coef)#as desired, 50 regressions.
#-

Now for my question: Is there easier or better methods of doing this? I know
of a lapply method, but the only lapply way I know of for lm(..) is
basically doing a lapply inside of a lapply, meaning it's exactly the same
as the double loop above... I'm looking to escape from loops.

Also, if any of you could share your top R tips that you've learned over the
years, I'd really appreciate it. Tiny things like learning that array() and
matrix() can have a 3rd dimension, learning of strsplit, etc.. have helped
me immeasurably. (Not that I'm also googling for this stuff! I'm doing R 14
hours a day!).

Thanks.

--
View this message in context: 
http://r.789695.n4.nabble.com/Other-ways-to-lm-regression-non-loop-tp4234487p4234487.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] manipulating data of several columns simultaneously

2012-01-18 Thread Gerrit Eichner

Hello, Nerak,

maybe

rbind( NA, head( results, -1))

does what you want (for all columns at once)?

Hth,
Gerrit



On Wed, 18 Jan 2012, Nerak wrote:


Dear all,
I have a question concerning manipulating data of several columns of a 
dataframe at the same time. I manage to do it for one column (with the 
use of the specific name for this column). In each columns, I have 60 
values. But I should reorganize the values (because I created this as an 
output before and I want to compare it with an other dataset). I want 
that the value on row 2 becomes the value of row 1, value 3 value 2 and 
so on.  The first value would be NA.


If I would do this for 1 column (with the name depth_1), I would do it 
like this:


for (t in 2:60)
{
results$depth[t]-new$depth_1[t-1]
}


[ ... snip ... ]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Split values in vector

2012-01-19 Thread Gerrit Eichner

Hi, Johannes,

maybe

X - unlist( strsplit( as.character( x$ART), split = ;, fixed = TRUE))
X - strsplit( X, split = -, fixed = TRUE)

X - sapply( X, function( x)
 if( length(x) == 2)
  rep( x[1], as.numeric( x[2])) else x[1]
)

table(X, useNA = always)


comes close to what you want.

 Hth  --  Gerrit


On Thu, 19 Jan 2012, Johannes Radinger wrote:


Hello,

I have a vector which looks like

x$ART
...



[35415] 0001-1;02-1;05-1;
[35417] 01-1; 01-1;02-1;
[35419] 01-1; 00
[35421] 01-1;04-1;05-1;
[35423] 02-1; 01-1;02-1;
[35425] 01-1;02-1;NA
[35427] 01-1; NA
...


This is a vector I got in this format. To explain it:
there are several categories (00,01,02 etc) and its counts (values after -)
So I have to split each value and create new dataframe-columns/vectors
for each categories one column and the value should be then in the
corresponding cell. I know that this vector has 7 categories (00-06)
and NA values but each case (row) has not all the categories (as you can see).  
How can do such as split?

In the end I should get:
x$ART_00, x$ART_01, x$ART_03,... with its values. In the case of NA all the 
categories should have also NA.

Maybe someone can help.

Thank you,

Best regards

Johannes



--
Feel free - 10 GB Mailbox, 100 FreeSMS/Monat ...

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] extracting from data.frames for survival analysis

2012-01-26 Thread Gerrit Eichner

Hi, Philip,

counter-questions:

1. Which/where is the grouping variable for the test of differences in 
survival?


2. Assume the grouping variable is Gend in B27.vec. Then, why aren't you 
using


survdiff( Surv( AgeOn, UV) ~ Gend, rho = 0, data = B27.vec)

?

Hth  -- Gerrit

On Thu, 26 Jan 2012, Philip Robinson wrote:


Hi,

I have a data frame:


class(B27.vec)

[1] data.frame


head(B27.vec)


 AGE Gend B27 AgeOn DD uveitis psoriasis IBD CD UC InI BASDAI BASFI Smok UV
1  571   119 38   2 1   1  1  1   1   5.40  8.08   NA  1
2  351   133  2   2 1   1  1  1   1   1.69  2.28   NA  1
3  492   140  9   1 1   1  1  1   1   8.30  9.40   NA  0
4  321   121 11   1 1   1  1  1   1   5.10  9.10   NA  0
5  311   124  7   1 1   1  1  1   1   6.63  6.52   NA  0
6  271   123  4   1 2   1  1  1   1   7.19  6.51   NA  0

I am trying to perform survival analysis but continually get errors
when extracting from this data.frame:

attempt 1:

X - Surv(B27.vec$AgeOn,B27.vec$UV)
survdiff(X,rho=0,data=uvf)

Error in x$terms : $ operator is invalid for atomic vectors

attempt 2:

X - Surv(B27.vec[,4],B27.vec[,15])
survdiff(X,rho=0,data=uvf)

Error in x$terms : $ operator is invalid for atomic vector

attempt 3:

AO - B27.vec[[AgeOn, exact = TRUE]]
UV - B27.vec[[UV,exact=TRUE]]
X - Surv(AO,UV)
survdiff(X,rho=0,data=uvf)

Error in x$terms : $ operator is invalid for atomic vectors

I have read ?data.frame  extract.data.frame but I cannot understand
how I might structure this differently so it extracts the required
columns from this dataframe. For the second 2 attempts I am not using
the $ term. Sorry if this seems basic but cannot understand why
attempt 1 or 2 doesn't work.

thanks
Philip

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Inserting a character into a character string XXXX

2012-01-26 Thread Gerrit Eichner

Hello, Dan,

you could probably use a combination of nchar(), substr() (or substring()) 
and paste(). Take a look at their online help pages.


Hth  --  Gerrit



Hello everyone,

I have a character vector of 24 hour time values in the format hm
without the delimiting :. How can I insert the : immediately to
the left of the second digit from the right?

mytimes-scan(what=)
1457
1457
1310
1158
137
1855


Thanks!

Dan

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] converting a matrix or data.frame into an html table

2011-05-09 Thread Gerrit Eichner

Hello, Samuel,

take a look at the package R2HTML.

 Hth  --  Gerrit


On Mon, 9 May 2011, Samuel Le wrote:


Dear all,

Is there a function in R to convert a matrix or a data.frame into an html table?

Many thanks,

Samuel



-
Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Logical operator and lists

2013-01-08 Thread Gerrit Eichner

Hello, Dominic,

untested:

data - lapply( data, function( x) x[ x == ] - NA

 Hth  --  Gerrit


On Tue, 8 Jan 2013, Dominic Roye wrote:


Hello R-Helpers,

I have a slight problem with the expresion data[data==] - NA which works
well for a data.frame. But now i must use the same for a list of
data.frames.

My idea is data[[]][data==] but it don´t work.

Thanks!!

Dominic__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Making an aggregated factor variable from an existing one

2013-01-17 Thread Gerrit Eichner

Hi, Antti,

you should look at

?levels

(and particular its Examples section) to find out how to use

levels( X) - c( new1, ..., newk)

to achieve what you want.

 Regards  --  Gerrit


On Thu, 17 Jan 2013, Antti Simola wrote:


Hi,

This is quite simple data manipulation task and I need help for it. I want to 
make new factor variable that is an aggregation of an existing factor.


This works as I intended:

X[Y == original label] -  new label

How to make following work then (to make coding more convenient):

original.labels - c(ol.1,ol.2,ol.3)

X[Y == original.labels] - new label

Cheers,

Antti

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to align group based on the common values of two columnsinr

2013-01-22 Thread Gerrit Eichner

Hi, Tammy,

maybe you find something interesting looking at

?interaction

and/or try (with df being your data frame)

df$Group - as.integer( with( df, interaction( Feature, OS)[, drop = 
TRUE]))


 HtH  --  Gerrit

On Tue, 22 Jan 2013, Tammy Ma wrote:



HI,

I met this problem:

I have the feature data frame:


  Feature OS
4  2
4  1
4  3
1  2
4  1


what I want to do is to autimatically create one more column called group:

  Feature OS  Group
4  2 1
4  1 2
4  3 3
1  2 4
4  1 2



I don't want Ifelse, because I have so many combination of feature and OS, I 
even can not account.  I just want to have sth to autimatically create group indicator 
based on the difference combination of feature and OS.

Thanks for your help.


Kind regards,
Tammy



[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Simple use of dcast (reshape2 package)

2013-01-22 Thread Gerrit Eichner

Hi, Patrick,

I think (with reshape from the stats package)

reshape( aa, idvar = ID, v.names = Eaten, timevar = Target,
 direction = wide)

does the trick (followed by renaming the columns of the resulting data 
frame).


 Hth  --  Gerrit


On Tue, 22 Jan 2013, Patrick Connolly wrote:


Suppose I have a small dataframe


aa

Target Eaten ID
50  TPP 0  1
51  TPP 1  2
52  TPP 3  3
53  TPP 1  4
54  TPP 2  5
50.1GPA 9  1
51.1GPA11  2
52.1GPA 8  3
53.1GPA 8  4
54.1GPA10  5

And I want to reshape it into

 ID TPP GPA
1  1   0   9
2  2   1  11
3  3   3   8
4  4   1   8
5  5   2  10

I realise that dcast function in the reshape2 package can handle much
more complicated tasks than that, but I can't make it do a simple one.

If I simply tried


dcast(aa, ... ~ Target)

Using ID as value column: use value.var to override.
Aggregation function missing: defaulting to length
 Eaten GPA TPP
1 0   0   1
2 1   0   2
3 2   0   1
4 3   0   1
5 8   2   0
6 9   1   0
710   1   0
811   1   0

As per the help file, it's giving counts of the numbers in the Eaten
column since that's the default fun.aggregate value.

My questions are: what fun.aggregate would work?  Alternatively, can
value.var be set to something useful?

TIA

--
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
  ___Patrick Connolly
{~._.~}   Great minds discuss ideas
_( Y )_  Average minds discuss events
(:_~*~_:)  Small minds discuss people
(_)-(_)   . Eleanor Roosevelt

~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] long format with reshape

2013-01-24 Thread Gerrit Eichner

Hi, Daisy,

try

dat2 - reshape( dat, varying = c( species1, species2, species3),
 v.name = presence, timevar = species,
 times = c( species1, species2, species3),
 direction=long)
dat2[ rev( order( dat2$region)), ]


 Hth  --  Gerrit


On Thu, 24 Jan 2013, Daisy Englert Duursma wrote:


Hello,

I tried using reshape to rearrange my data to long format but I could
not get the output the table they way I wanted it. Anyway I came up
with a hack that does works, but I still would like to know if I can
do it with reshape.

Here is my code and a dummy set of data. It returns the data in the
format I would like it.


dat - read.table(text=region state species1 species2 species3
   sydney nsw 0 1 1
   canberra act 1 1 0, header=T)

nonspecvars - c(region,state)

dats - split(dat, 1:nrow(dat))
dat2 - lapply(dats,function(x){

 datspec - x[,-match(nonspecvars,names(x))]
 specnames - names(datspec)
 presence - unname(unlist(datspec))

 x2 - x[rep(1,length(specnames)),match(nonspecvars,names(x))]
 x2$species - specnames
 x2$presence - presence
 return(x2)

})

do.call(rbind, dat2)


Cheers,
Daisy



--
Daisy Englert Duursma
Department of Biological Sciences
Room E8C156
Macquarie University, North Ryde, NSW 2109
Australia

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] If cycle takes to much time...

2013-01-25 Thread Gerrit Eichner

Hello, Marco,

I am not quite sure if understand correctly what you want, but maybe


DF - data.frame( Artist, Begin, End, Istitution)
AtSameInst - outer( DF$Istitution, DF$Istitution, ==)
Simultaneously - with( DF, outer( Begin, End, =) |
outer( End, Begin, =))
AtSameInst  Simultaneously


gives what you want. (Note that redundant information is computed since 
all resulting matrices are symmetric. The algorithm could certainly be 
optimized.)


 Hth  --  Gerrit

On Fri, 25 Jan 2013, marcoguerzoni wrote:


dear all,

thank you for reading.

I have a dataset of artists and where and when they had an exhibition.
I'd like to create an affiliation network in the form of matrix, telling me
which aritist have been in the same at the same time.
I manage to do it, but given that I have 96000 observation the program takes
30 months to complete.
her what i have done.
the data look like this

Artist -c(1,2,3,2,4,4,5)
Begin - as.Date(c('2006-08-23', '2006-03-21', '2006-03-06', '2006-01-13',
'2006-05-20', '2006-07-13', '2006-07-20'))
End - as.Date(c('2006-10-23', '2006-11-30', '2006-05-06', '2006-12-13',
'2006-09-20', '2006-08-13', '2006-09-20'))
Istitution - c(1, 2, 2, 1, 1, 2, 1)

artist is the name of the artist, Begin and End is the when and Istitutionis
the where.

my IF is working,


#number of unique artist
c - unique(Artist)
d - length(c)
a -length(Artist)

B - mat.or.vec(d,d)

for(i in 1:d) {
for(j in 1:d) {
if (Istitution[i]  == Istitution[j]) {


if (Begin[i] = End[j])
{
if (End[i]-Begin[j] = 0) {
B[i,j] - B[i,j]+1
B[i,i] - 0

}


}
else{
if (End[j]-Begin[i] = 0) {
B[i,j] - B[i,j]+1
B[i,i] - 0


}
}
 }
  }
print(i)
   }


do you have a way to make the programm simpler and faster?

thank you very much

Marco Guerzoni,
Department of Economics
University of Turin


--
View this message in context: 
http://r.789695.n4.nabble.com/If-cycle-takes-to-much-time-tp4656601.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] NA and Character(0) in List Element

2013-01-29 Thread Gerrit Eichner

Hi, Benjamin,

have you tried for your list with NA-components to use is.na() as follows 
(where x is assumed to be your list)?


x[ !is.na(x)]


 Hth  --  Gerrit

On Tue, 29 Jan 2013, Benjamin Ward (ENV) wrote:

Hi, This is probably a small query but one I'm struggling with: I have a 
list in which I had elements which were NA, I removed them, by doing: 
list2 - lapply(list, na.omit),


However this leaves the element there with 'character(0)' in place as 
well as attributes:


e.g.
[[978]]
character(0)
attr(,na.action)
[1] 1
attr(,class)
[1] omit


I want to get rid of these elements/positions in the list, since a 
function is supposed to sample the list for elements (each element is a 
collection of about 20 numbers each).


Thanks,

Ben W.

UEA (ENV) - b.w...@uea.ac.uk



[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] appending and merging data frames

2013-02-07 Thread Gerrit Eichner

Hello, John,

as a start take a look at

?merge

And to (maybe) get a bit overwhelmed at first sight use

RSiteSearch( merge)


 Hth  --  Gerrit

On Thu, 7 Feb 2013, John Smith wrote:


I know that the basic approach to append or merge data frames is using the 
rbind and merge commands.
However, if I understand things correctly, for both commands one needs to do 
quite some additional programming to get e.g. behavior as with the Stata append 
and morge commands or to achieve some things which I think users need quite 
frequently.

E.g. for appending, the data frame must have identical column names. In order 
to rename columns or in order to add columns with missing values if necessary, 
additional programming is needed.
For merging, all matches get combined, so it is not easily possible to check 
for 1:1 or 1:n matches or limit the join to such kind of matches, is it?
Those are just examples, there are a number of additional details that would be 
useful to be able to control for merging/appending (maybe at the expense of 
restricting the operation to just data frames).

So my question is: are there any packages or existing utility functions which 
would provide append and merge functionality at a slightly higher 
(user-friendly) level?

Although I am quite a noob, I would be prepared to give it a try and program 
these myself, but I have the feeling that this must be so common that maybe it 
would mean re-inventing the wheel?


GET FREE SMILEYS FOR YOUR IM  EMAIL - Learn more at 
http://www.inbox.com/smileys
Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talkÿÿ and 
most webmails

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Error in sort(abs(diff(genomdat)))[1:n.keep] : only 0's maybemixed with negative subscripts

2012-06-12 Thread Gerrit Eichner

Hello, sanshine,

maybe you should check the value of n.keep and make sure that it is 
non-negative.


Hth  --  Gerrit

On Tue, 12 Jun 2012, sanshine wrote:


Hello everyone,

I`m trying to normalize and analize an illumina SNP array.
But when i`m trying to segmentate i`m getting an error:
Error in sort(abs(diff(genomdat)))[1:n.keep] :
 only 0's may be mixed with negative subscripts.
I`ve tried everything to fix this but the error still occours.

Can anybody give me a tip?

Thanks in advance!


--
View this message in context: 
http://r.789695.n4.nabble.com/Error-in-sort-abs-diff-genomdat-1-n-keep-only-0-s-may-be-mixed-with-negative-subscripts-tp4633091.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] formula version of sunflowerplot() fails when axis label specified

2012-06-27 Thread Gerrit Eichner

Hello, R-help,

does anybody have already a work-around for the problem that the formula 
version of sunflowerplot() throws an error when provided with a value for 
xlab (or ylab) different from NULL:



sunflowerplot( Sepal.Length ~ Sepal.Width, data = iris, xlab = A)

Error in model.frame.default(formula = Sepal.Length ~ Sepal.Width, data = iris, 
 :
  variable lengths differ (found for '(xlab)')

And are you -- the one with the work-around -- willing to share it? :)

 Best regards  --  Gerrit

-
Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] formula version of sunflowerplot() fails when axis labelspecified

2012-06-28 Thread Gerrit Eichner

Thank you, Sina,
thank you, David,

I knew how to access the code of sunflowerplot.formula() and that 
sunflowerplot() does work in the default version, i.e., w/o formula (but 
your suggestions triggered my ambition ;-)).


Below is my -- slightly commented -- version (the search for which was 
inspired by Sina's approach) which results from studying the code of 
various other plotting functions with formula interface (e.g., 
boxplot.fomula(), stripchart.formula, and, in particular, plot.formula().)


 Hth and best regards  --  Gerrit

-
Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner
-

sunflowerplot.formula - function( formula, data = NULL,
   xlab = NULL, ylab = NULL, ...,
   subset, na.action = NULL) {
 if(missing(formula) || (length(formula) != 3L))
  stop(formula missing or incorrect)

 m - match.call(expand.dots = FALSE)
 if (is.matrix(eval(m$data, parent.frame(
  m$data - as.data.frame(data)

 m$... - NULL
 m$xlab - m$ylab - NULL   # New: Deleting xlab and ylab from m to
# avoid hindrance of the computation of
# the model frame below.
 m$na.action - na.action

 require(stats, quietly = TRUE)
 m[[1L]] - as.name(model.frame)
 mf - eval(m, parent.frame()) # Here used to lie the problem.

 if (NCOL(mf) != 2L)
  stop('formula' should specify exactly two variables)
 if (is.null(xlab))
  xlab - names(mf)[2L]
 if (is.null(ylab))
   ylab - names(mf)[1L]
 sunflowerplot(mf[[2L]], mf[[1L]],
   xlab = xlab, ylab = ylab, # New: To make sure that possibly
 # user defined labels are used.
   ...)
 }

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Side by side strip charts

2012-07-13 Thread Gerrit Eichner

Hi, Arnold,

looking at the example section of

?stripchart

may help you.

 Hth  --  Gerrit

On Thu, 12 Jul 2012, darnold wrote:


Hi,

I'm looking for some ideas on how to reproduce the attached image in R.
There are three samples, each of size n = 10. The first is drawn from a
normal distribution with mean 60 and standard deviation 3. The second is
drawn from a normal distribution with mean 65 and standard deviation 3. The
third is drawn from a normal distribution with mean 70 and standard
deviation 3.

http://r.789695.n4.nabble.com/file/n4636399/IMG_1306.jpg

Any ideas?

Thanks.

David.

--
View this message in context: 
http://r.789695.n4.nabble.com/Side-by-side-strip-charts-tp4636399.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Adjusting format of boxplot

2012-07-13 Thread Gerrit Eichner

Hello, Ivan,

you'll find argument frame (actually frame.plot) explained in

?plot.default

 Regards  --  Gerrit



Hi Peter,

I had never heard of this 'frame' argument and it's a breakthrough for me to 
be finally able to get rid of this frame!


But where is this argument explained? I couldn't find it in plot(), 
boxplot(), bxp() or par().


Thank you for your answer :)
Ivan

--
Ivan CALANDRA
Université de Bourgogne
UMR CNRS/uB 6282 Biogéosciences
6 Boulevard Gabriel
21000 Dijon, FRANCE
+33(0)3.80.39.63.06
ivan.calan...@u-bourgogne.fr
http://biogeosciences.u-bourgogne.fr/calandra

Le 13/07/12 04:48, Peter Ehlers a écrit :

On 2012-07-12 18:39, David L Carlson wrote:
Sorry about that. I got rid of the box another way and then switched to 
using pars=

without making sure it worked. This works:

flies$group - factor(flies$group, 5:1) # 1
levels(flies$group) - paste0(Group , 5:1) # 2

oldpar - par(bty=n)
boxplot(long ~ group,
 data = flies,
 pars=list(las=1, ylim=c(10, 110), xaxt=n),
 horizontal = TRUE,
 col = red)

axis(1, at=seq(10, 110, 20))
par(oldpar)


Or you could add 'frame = FALSE' to the boxplot() call.

Peter Ehlers



-
David

-
David L Carlson
Associate Professor of Anthropology
Texas AM University
College Station, TX 77840-4352


- Original Message -

From: darnold dwarnol...@suddenlink.net
To: r-help@r-project.org
Sent: Thursday, July 12, 2012 7:53:33 PM
Subject: Re: [R] Adjusting format of boxplot

Added your code:


flies - read.table(example12_1.dat,header=TRUE,sep=\t)

flies$group - factor(flies$group,5:1)

levels(flies$group) - paste0(Group ,5:1)

boxplot(long ~ group,
data = flies,
pars = list(las=1, ylim=c(10,110), xaxt=n, bty=n),
horizontal = TRUE,
col = red)

axis(1,at=seq(10,110,20))

Almost worked perfectly, except the frame around the plot remains, which 
is

strange as you have bty=n.

http://r.789695.n4.nabble.com/file/n4636381/Rplot11.png

David



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.




__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Running different Regressions using for loops

2012-09-28 Thread Gerrit Eichner

Hello, Krunal,

try


summ.list[[2]]$coefficients[2]


Note the double square brackets (as summ.list is a list)!

Hth,

Gerrit


On Fri, 28 Sep 2012, Krunal Nanavati wrote:


Hi Rui,

Excellent!!  This is what I was looking for. Thanks for the help.

So, now I have stored the result of the 10 regressions in  summ.list
- lapply(lm.list2, summary)

And now once I enter sum.list it gives me the output for all
the 10 regressions...

I wanted to access a beta coefficient of one of the regressionssay
Price2+Media1+Trend+Seasonality...the result of which is stored in 
sum.list[2] 

I entered the below statement for accessing the Beta coefficient for
Price2...


summ.list[2]$coefficients[2]

NULL

But this is giving me  NULL  as the output...

What I am looking for, is to access a beta value of a particular variable
from a particular regression output and use it for further analysis.



snip

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R-Help: nparLD Package Non-parametric Repeated Measures

2013-05-16 Thread Gerrit Eichner

Hello, James,

see my comments inline.

... Main issue/question: In R the nparLD ANOVA-type Test showed a 
significant p-value for diel period, no effect of season, and no 
interaction between diel period and season. But a post-hoc Wilcoxon 
Signed-Rank Test did NOT find a significant difference (p = 0.054) for 
diel period (day vs night) body temperature.


How is it possible to have a significant effect for day vs night, based on
the nparLD package, but NO significant difference between day and night for
the post-hoc Wilcoxon test?


Those tests -- in general -- test different hypotheses and use different 
test statistics, the first one, in addition, using a distributional 
approximation to obtain a p-value. You may want to look at the references 
cited in the respective online help pages for technical details.



Also, if I only have two levels of the fixed effect (day vs night), do I
need to run a post-hoc test or just look at the mean values after the
ANOVA-type test?


Hm, actually no (of course depending on your scientific question) since 
the ANOVA-table -- if you believe its p-value -- already tells you that 
there is a (marginally) significant main Diel-period-effect, i.e., a 
difference between day and night.


However, I recommend that you consult with a local statistician since this 
is actually not an R-problem and since I have the impression that there 
exist some uncertainties in your statistical expertise.


 Hth  --  Gerrit


Data info:

The repeated measurements on the 7 subjects had 2 fixed effects:

1. Diel period (day or night)
2. Season (Spring, summer, and fall)(Subplot Factor)

Mean values for body temperature and for diel period are below. Diel column
(D=Day, N = Night). State column (RT=Spring, RF = Summer, PT = Fall).
Subject, N=7. NA = missing value.

All comments (good and bad) are greatly appreciated!

Thanks,
James



-- output of sessionInfo():

[code]

data=read.csv(file.choose(), header=TRUE)
attach(data)
data

 stp diel state subject
1  26.2DRT   1
2  26.4NRT   1
3  24.1DRT   2
4NANRT   2
5NADRT   3
6  25.2NRT   3
7  27.1DRT   4
8  26.5NRT   4
9  26.9DRT   5
10 27.1NRT   5
11 26.2DRT   6
12 26.0NRT   6
13 26.3DRT   7
14 26.7NRT   7
15 26.0DRF   1
16 26.6NRF   1
17 24.2DRF   2
18 25.6NRF   2
19 25.6DRF   3
20 26.6NRF   3
21 26.1DRF   4
22 26.9NRF   4
23 27.2DRF   5
24 27.4NRF   5
25 26.2DRF   6
26 26.7NRF   6
27 27.2DRF   7
28 27.5NRF   7
29 25.0DPT   1
30 24.8NPT   1
31   NADPT   2
32   NANPT   2
33   NADPT   3
34   NANPT   3
35 26.7DPT   4
36 26.9NPT   4
37 27.6DPT   5
38 27.5NPT   5
39 25.2DPT   6
40 24.9NPT   6
41 27.1DPT   7
42 27.0NPT   7



ex.f2-ld.f2(y=stp, time1=diel, time2=state, subject=subject,

time1.name=Diel, time2.name=State, description=FALSE)


ex.f2$ANOVA.test

  Statistic   dfp-value
Diel   4.9028447 1.00 0.02681249
State  0.2332795 1.374320 0.70586274
Diel:State 2.1937783 1.062943 0.13717393
[/code]

[code]

detach(data)
data=read.csv(file.choose(), header=TRUE)
attach(data)
data

   day night
1  26.2  26.4
2  26.0  26.6
3  25.0  24.8
4  24.2  25.6
5  25.6  26.6
6  27.1  26.5
7  26.1  26.9
8  26.7  26.9
9  26.9  27.1
10 27.2  27.4
11 27.6  27.5
12 26.2  26.0
13 26.2  26.7
14 25.2  24.9
15 26.3  26.7
16 27.2  27.5
17 27.1  27.0


library(coin)



wilcoxsign_test(day ~ night, distribution=exact)


   Exact Wilcoxon-Signed-Rank Test

data:  y by x (neg, pos)
stratified by block
Z = -1.9234, p-value = 0.05482
alternative hypothesis: true mu is not equal to 0

[/code]

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Loop FOR with histogram() from lattice

2013-06-05 Thread Gerrit Eichner

Hi, Xochitl,

wrapping the call to histogram() inside your loop in a call to print() 
should solve your problem:


print( histogram( .))


 Regards --  Gerrit


On Wed, 5 Jun 2013, Xochitl CORMON wrote:


Hi all,

I'm encountering a problem I do not understand on my data:

library (lattice)

Mpool1 - Table[Table$Subarea %in% c(52E9, 51E9),]
Mpool2 - Table[Table$Subarea %in% c(53F0, 52F0),]
Mpool3 - Table[Table$Subarea %in% c(51F0, 50F0),]
Mpool4 - Table[Table$Subarea %in% c(51F1, 52F1),]

Mpool - list(Mpool1, Mpool2, Mpool3, Mpool4)


histogram(~ Mpool[[2]]$LngtClas | Mpool[[2]]$SpCode, type = count, col = 
lightgrey, xlab= LngtClas, main = paste(Length distribution per species 
for Mpool, 2, sep = _))


 This part works perfectly and I obtain the graph reprensenting Mpool2 
length class count per species.

 Now when I want to automatize this with a for loop nothing is plotted.

for (i in c(2)){
windows()
histogram(~ Mpool[[i]]$LngtClas | Mpool[[i]]$SpCode, type = count, col = 
lightgrey, xlab= LngtClas, main = paste(Length distribution per species 
for Mpool, i, sep = _))

print (i)
}

### Running this loop I obtained  windows filled grey (no plot drawn at all) 
but the print (i) print a 2 as expected. I really dont understand what's 
wrong with the loop. There is no error message and no notification in R. You 
can find enclosed my data in txt file.


Thank you very much for any help,

Xochitl C.

   

Xochitl CORMON
+33 (0)3 21 99 56 84

Doctorante en sciences halieutiques
PhD student in fishery sciences

   

IFREMER
Centre Manche Mer du Nord
150 quai Gambetta
62200 Boulogne-sur-Mer

   



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] regression in 3D space

2013-06-18 Thread Gerrit Eichner

Dear Eliza,

the more unspecific a question is formulated, the more is the poster in an 
urgent need for a statistical consultant nearby and -- at the same time -- 
the less likely is is to get a useful answer on this list ...


I suggest you to read the posting guide, look at CRAN's Task Views and/or 
to find a (patient) stats consultant near you, and then to come back to 
this list.


 No harm meant  --  Gerrit


On Tue, 18 Jun 2013, eliza botto wrote:

Dear UseRs,I need to know that is there a way in R for a 3D regression 
analysis?i actually have a data in 3 dimensional space showing 
differences between regimes in 3D space and i want to do its regression 
analysis with another data which is also in 3D space.

thanks in advance for your help,
Eliza
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] create index for tapply or by

2013-06-27 Thread Gerrit Eichner

Hi, Witold,

take a look at

?findIntervals

It might give want you need.

 Hth  --  Gerrit

On Thu, 27 Jun 2013, Witold E Wolski wrote:


Is there a build in function to create an index for tapply or by given a
a numeric vector x an a vector of breaks?

What I want to do is:

x - 1:100
breaks - c(0,10,20,50,99,110)

y - rep(0,length(x))
for(i in 2:length(breaks)){
 y[which(xbreaks[i-1]  x = breaks[i])] - i
}

by(x,y,sum)

but I find the code especially th for loop unneRving.


--
Witold Eryk Wolski

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Sweave: cat() in a chunk with option results=tex doesn't producelinebreaks at the end of a character string anymore

2014-03-05 Thread Gerrit Eichner

Hello, everyone,

I am struggling with an Sweave-problem that didn't occur sofar (and I have 
no clue what I might have changed in my system; see below). The following 
example *.Rnw file's only task is (for simplicity) to output text with a 
little bit of TeX-code with linebreaks (e. g., to be better readable):



\documentclass{article}
\begin{document}
Text 1 (not through cat()) followed by a double-backslash and
a blank line, i.e., a linebreak.\\

echo=FALSE, results=tex=
cat( Text 2 (through cat()) with a respected newline here\n,
 and likewise two tabs here\t\t followed by two double-backslashes ,
 and IGNORED newline escape characters at the end. \n \n,
 sep = )

cat( Text 3 (through cat()) just to finish this example and ,
 with also IGNORED newline escapes at its end. \n \n, sep = )
@
\end{document}



When processed by Sweave I obtain the following TeX file:


\documentclass{article}
\usepackage{Sweave}
\begin{document}
Text 1 (not through cat()) followed by a double-backslash and
a blank line, i.e., a linebreak.\\

Text 2 (through cat()) with a respected newline here
and likewise two tabs here		 followed by two 
double-backslashes and IGNORED newline escape characters at the end.\\ 
Text 3 (through cat()) to finish this example and with also IGNORED 
newline escapes at its end. \end{document}



the point being that the linebreaks (\n) at the ends of the output 
character strings have been completely ignored.


I wasn't successful in searching the archive, RSeek, SE and the like. Any 
idea where and how to continue to search, or what to do to get back 
Sweave's old behavior (except for reinstalling R ... which of course is 
still an option)? Thanks for any hint!


 Best regards  --  Gerrit

PS:

sessionInfo()

R version 3.0.2 (2013-09-25)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252

attached base packages:
[1] graphics  grDevices utils datasets  stats methods   base

other attached packages:
[1] fortunes_1.5-2

loaded via a namespace (and not attached):
[1] grid_3.0.2  lattice_0.20-27 tools_3.0.2



-
Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Sweave: cat() in a chunk with option results=texdoesn'tproducelinebreaks at the end of a character string anymore

2014-03-05 Thread Gerrit Eichner

Thanks, Duncan,

but, sorry, including

\SweaveOpts{strip.white=true}

doesn't help. Have tried that before and forgot to mention; sorry!

BTW: using \SweaveOpts{strip.white=true}, i.e., with quotation marks as 
requested in RweaveLatex()'s help file, throws out


Error in match.arg(options$strip.white, c(true, false, all)) :
  'arg' should be one of true, false, all

which used to happen before (on my system) so that I used to use it w/o 
quotes successfully. (!?)



Still big question marks ... Any further ideas?

 Regards -- Gerrit


On Wed, 5 Mar 2014, Duncan Murdoch wrote:


On 05/03/2014 7:32 AM, Gerrit Eichner wrote:

Hello, everyone,

I am struggling with an Sweave-problem that didn't occur sofar (and I have
no clue what I might have changed in my system; see below). The following
example *.Rnw file's only task is (for simplicity) to output text with a
little bit of TeX-code with linebreaks (e. g., to be better readable):


\documentclass{article}
\begin{document}
Text 1 (not through cat()) followed by a double-backslash and
a blank line, i.e., a linebreak.\\

echo=FALSE, results=tex=
cat( Text 2 (through cat()) with a respected newline here\n,
   and likewise two tabs here\t\t followed by two double-backslashes 
,

   and IGNORED newline escape characters at the end. \n \n,
   sep = )

cat( Text 3 (through cat()) just to finish this example and ,
   with also IGNORED newline escapes at its end. \n \n, sep = )
@
\end{document}



When processed by Sweave I obtain the following TeX file:


\documentclass{article}
\usepackage{Sweave}
\begin{document}
Text 1 (not through cat()) followed by a double-backslash and
a blank line, i.e., a linebreak.\\

Text 2 (through cat()) with a respected newline here
and likewise two tabs here   followed by two
double-backslashes and IGNORED newline escape characters at the end.\\
Text 3 (through cat()) to finish this example and with also IGNORED
newline escapes at its end. \end{document}


the point being that the linebreaks (\n) at the ends of the output
character strings have been completely ignored.


See the strip.white option in ?RweaveLatex.

Duncan Murdoch



I wasn't successful in searching the archive, RSeek, SE and the like. Any
idea where and how to continue to search, or what to do to get back
Sweave's old behavior (except for reinstalling R ... which of course is
still an option)? Thanks for any hint!

   Best regards  --  Gerrit

PS:
 sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252

attached base packages:
[1] graphics  grDevices utils datasets  stats methods   base

other attached packages:
[1] fortunes_1.5-2

loaded via a namespace (and not attached):
[1] grid_3.0.2  lattice_0.20-27 tools_3.0.2



-
Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Sweave: cat() in a chunk with option results=texdoesn'tproducelinebreaksatthe end of a character string anymore

2014-03-05 Thread Gerrit Eichner

Thanks, Duncan,

I got it! I missread/-understood strip.white's meaning and thought it 
would refer only to blank lines within real code chunks (i.e., to those 
between \begin{Schunk} and \end{Schunk}), but not to the (TeX-)output 
which was generated by code chunks with results=tex.


My goal: I don't want blank lines at the beginning or end of real R 
output between \begin{Schunk} and \end{Schunk}), but want to be able to 
create linebreaks using cat( \n) explicitly in chunks with results=tex


The solution appears to be: use strip.white=false locally in case of 
need, i.e., as the option for the respective code chunks (which also have 
results=tex, and from which I want only linebreaks in the TeX-output).


Actually, embarrassingly simple.

 Thanks again -- Gerrit


On Wed, 5 Mar 2014, Duncan Murdoch wrote:


On 05/03/2014 9:29 AM, Gerrit Eichner wrote:

Thanks, Duncan,

but, sorry, including

\SweaveOpts{strip.white=true}

doesn't help. Have tried that before and forgot to mention; sorry!


true is the default.  You want false.

Duncan Murdoch



BTW: using \SweaveOpts{strip.white=true}, i.e., with quotation marks as
requested in RweaveLatex()'s help file, throws out

Error in match.arg(options$strip.white, c(true, false, all)) :
'arg' should be one of true, false, all

which used to happen before (on my system) so that I used to use it w/o
quotes successfully. (!?)


Still big question marks ... Any further ideas?

   Regards -- Gerrit


On Wed, 5 Mar 2014, Duncan Murdoch wrote:

 On 05/03/2014 7:32 AM, Gerrit Eichner wrote:
 Hello, everyone,

 I am struggling with an Sweave-problem that didn't occur sofar (and I 
have
 no clue what I might have changed in my system; see below). The 
following

 example *.Rnw file's only task is (for simplicity) to output text with a
 little bit of TeX-code with linebreaks (e. g., to be better readable):


 \documentclass{article}
 \begin{document}
 Text 1 (not through cat()) followed by a double-backslash and
 a blank line, i.e., a linebreak.\\

 echo=FALSE, results=tex=
 cat( Text 2 (through cat()) with a respected newline here\n,
and likewise two tabs here\t\t followed by two 
double-backslashes

 ,
and IGNORED newline escape characters at the end. \n \n,
sep = )

 cat( Text 3 (through cat()) just to finish this example and ,
with also IGNORED newline escapes at its end. \n \n, sep = )
 @
 \end{document}



 When processed by Sweave I obtain the following TeX file:


 \documentclass{article}
 \usepackage{Sweave}
 \begin{document}
 Text 1 (not through cat()) followed by a double-backslash and
 a blank line, i.e., a linebreak.\\

 Text 2 (through cat()) with a respected newline here
 and likewise two tabs here  followed by two
 double-backslashes and IGNORED newline escape characters at the end.\\
 Text 3 (through cat()) to finish this example and with also IGNORED
 newline escapes at its end. \end{document}


 the point being that the linebreaks (\n) at the ends of the output
 character strings have been completely ignored.

 See the strip.white option in ?RweaveLatex.

 Duncan Murdoch


 I wasn't successful in searching the archive, RSeek, SE and the like. 
Any

 idea where and how to continue to search, or what to do to get back
 Sweave's old behavior (except for reinstalling R ... which of course 
is

 still an option)? Thanks for any hint!

Best regards  --  Gerrit

 PS:
  sessionInfo()
 R version 3.0.2 (2013-09-25)
 Platform: x86_64-w64-mingw32/x64 (64-bit)

 locale:
 [1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252
 [3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
 [5] LC_TIME=German_Germany.1252

 attached base packages:
 [1] graphics  grDevices utils datasets  stats methods   base

 other attached packages:
 [1] fortunes_1.5-2

 loaded via a namespace (and not attached):
 [1] grid_3.0.2  lattice_0.20-27 tools_3.0.2



 -
 Dr. Gerrit Eichner   Mathematical Institute, Room 212
 gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
 Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
 Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] format of output of residual standard errors of manova()

2014-03-18 Thread Gerrit Eichner

Dear all,

I wasn't successful in finding any related bug or wish report on 
bugs.r-project.org, svn.R-project.org/R/trunk/doc/NEWS.Rd, or RSeek 
regarding the following:


The code of stats:::print.aov contains the two commands

cat(Residual standard error: , sapply(sqrt(ss/rdf), format), \n, sep = 
)


and

cat(Residual standard error: , sapply(rs, format), \n, sep = )

which provide the output of the RSEs. However, the RSE-values are glued 
together because of sep =  in the call to cat(), which makes them hard 
or even impossible to read off free of doubt. (See the respective output 
of npk.aov2 in example( manova) or of fit in example( summary.manova).)


Is it intended to change those lines of code into something like

cat(Residual standard error: , paste( sapply(sqrt(ss/rdf), format), 
collapse = ; ), \n, sep = )


and

cat(Residual standard error: , paste( sapply(rs, format), collapse = ; 
), \n, sep = )


respectively? (Of course, any other sep-value would be accepted. :))

If not, I would suggest this modification as a wish (and was wondering 
if my next step should indeed be submitting a wish report on 
bugs.r-project.org ...)



 Best regards  --  Gerrit

PS:


sessionInfo()

R version 3.0.2 (2013-09-25)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base

other attached packages:
[1] fortunes_1.5-2

loaded via a namespace (and not attached):
[1] tools_3.0.2


-
Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] transform variables

2013-08-26 Thread Gerrit Eichner

Hello, Catalin,

assume your data frame is as simple as


A - data.frame( year = years, month01 = values01, ,

+  month12 = values12)

then, e.g.,


reshape( A, varying = c( month01, , month12),

+  v.names = Values, timevar = Month, direction = long)

should do what you want. For details see ?reshape

Hth  -- Gerrit


On Mon, 26 Aug 2013, catalin roibu wrote:


Dear all!

I have a data frame composed by 13 columns (year, and 12 months). I want to
transform this data base in another like this
year month values
1901 1
1901 2
1901 3
.
1901 12
1902  1
1902  2

1902  12

Is there a possibility to succeed that in R?

Thank you!

best regards!
CR

--
---
Catalin-Constantin ROIBU
Lecturer PhD, Forestry engineer
Forestry Faculty of Suceava
Str. Universitatii no. 13, Suceava, 720229, Romania
office phone +4 0230 52 29 78, ext. 531
mobile phone   +4 0745 53 18 01
  +4 0766 71 76 58
FAX:+4 0230 52 16 64
silvic.usv.ro

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] transform variables

2013-08-26 Thread Gerrit Eichner

Catalin,

first, keep the communication on the list, so it gets documented also for 
others.


Second, my code does work for an example I made up myself, but if you 
don't provide commented, minimal, self-contained, reproducible code (as 
the posting guide asks you to; see last line of this e-mail), it is 
unlikely that someone could be of further help.


Regards  -- Gerrit

On Mon, 26 Aug 2013, catalin roibu wrote:


Hello!
Your code give me the same month values for each year from interval. I want
12 month for each year!.
Eg
year month value
1901 1  3.5
1901 2  2.5


On 26 August 2013 14:35, Gerrit Eichner
gerrit.eich...@math.uni-giessen.dewrote:


Hello, Catalin,

assume your data frame is as simple as

 A - data.frame( year = years, month01 = values01, ,



+  month12 = values12)

then, e.g.,

 reshape( A, varying = c( month01, , month12),



+  v.names = Values, timevar = Month, direction = long)

should do what you want. For details see ?reshape

Hth  -- Gerrit



On Mon, 26 Aug 2013, catalin roibu wrote:

 Dear all!


I have a data frame composed by 13 columns (year, and 12 months). I want
to
transform this data base in another like this
year month values
1901 1
1901 2
1901 3
.
1901 12
1902  1
1902  2

1902  12

Is there a possibility to succeed that in R?

Thank you!

best regards!
CR

--
---
Catalin-Constantin ROIBU
Lecturer PhD, Forestry engineer
Forestry Faculty of Suceava
Str. Universitatii no. 13, Suceava, 720229, Romania
office phone +4 0230 52 29 78, ext. 531
mobile phone   +4 0745 53 18 01
  +4 0766 71 76 58
FAX:+4 0230 52 16 64
silvic.usv.ro

[[alternative HTML version deleted]]

__**
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/**
posting-guide.html http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.






--
---
Catalin-Constantin ROIBU
Lecturer PhD, Forestry engineer
Forestry Faculty of Suceava
Str. Universitatii no. 13, Suceava, 720229, Romania
office phone +4 0230 52 29 78, ext. 531
mobile phone   +4 0745 53 18 01
  +4 0766 71 76 58
FAX:+4 0230 52 16 64
silvic.usv.ro


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Product of certain rows in a matrix without loop

2013-09-03 Thread Gerrit Eichner

Hello, Edouard,

taking logs of A's elements (so that * turns into +, so to say), using a 
left-multiplication with a certain band matrix of the package Matrix, and 
exponentiating the result again could provide a solution (see below).



I know have the following problem:
I have a matrix :
A =
1  2  3
4  5  6
7  8  9
9  8  7
4  5  6
3  2  1

And I would like to have :
B =
1*4*7  2*5*8  3*6*9
4*7*9  5*8*8  6*9*7
7*9*4  8*8*5  9*7*6
9*4*3  8*5*2  7*6*1

Here I took the product of 3 rows each time. And 3 needs to be a parameter.

Is it possible to do so without any loop ?



Caveat: Not very carefully tested!

library( Matrix)

k - 3
ones - lapply( 1:k, function( j) rep( 1, nrow( A) - j + 1)))
leftmatrix - bandSparse( n = nrow(A) - k + 1, m = nrow(A),
  k = 0:(k-1), diagonals = ones)

exp( leftmatrix %*% log(A))

 Hth  --  Gerrit

-
Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Product of certain rows in a matrix without loop

2013-09-03 Thread Gerrit Eichner
Thank you very much for your answer. Unfortunately, I cannot use any 
package...

Er, ... this is quite unusual! (Is this is homework?)


Do you have a solution ?
Well, take a look at the resulting bandmatrix leftmatrix. Yould can 
certainly build it yourself by hand somehow. I used the Matrix package 
just for convenience.


 Regards -- Gerrit


Thank you in advance


Edouard Hardy


On Tue, Sep 3, 2013 at 11:49 AM, Gerrit Eichner 
gerrit.eich...@math.uni-giessen.de wrote:


Hello, Edouard,

taking logs of A's elements (so that * turns into +, so to say), using a
left-multiplication with a certain band matrix of the package Matrix, and
exponentiating the result again could provide a solution (see below).


 I know have the following problem:

I have a matrix :
A =
1  2  3
4  5  6
7  8  9
9  8  7
4  5  6
3  2  1

And I would like to have :
B =
1*4*7  2*5*8  3*6*9
4*7*9  5*8*8  6*9*7
7*9*4  8*8*5  9*7*6
9*4*3  8*5*2  7*6*1

Here I took the product of 3 rows each time. And 3 needs to be a
parameter.

Is it possible to do so without any loop ?




Caveat: Not very carefully tested!

library( Matrix)

k - 3
ones - lapply( 1:k, function( j) rep( 1, nrow( A) - j + 1)))
leftmatrix - bandSparse( n = nrow(A) - k + 1, m = nrow(A),
  k = 0:(k-1), diagonals = ones)

exp( leftmatrix %*% log(A))

 Hth  --  Gerrit


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] probability of occurrence of an event and the probabilityof anevent upon the occurrence of another event

2013-09-06 Thread Gerrit Eichner

Hello, Francesco,

these could be considered as two of the central questions in statistics in 
general ... but they do not necessarily have anything to do with R.


 Regards -- Gerrit

On Fri, 6 Sep 2013, Francesco Miranda wrote:

how can i calculate the probability of occurrence of an event and the 
probability of an event upon the occurrence of another event.

 P (A) and P (A | B) ..
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Formula in a model

2013-09-11 Thread Gerrit Eichner

Hello, Paulito,

first, I think you haven't received an answer yet because you did not 
provide commented, minimal, self-contained, reproducible code as the 
posting guide does request it from you.


Second, see inline below.

On Wed, 11 Sep 2013, Paulito Palmes wrote:


Hi,

I have a data.frame with dimension 336x336 called *training*, and 
another one called *observation* which is 336x1. I combined them as one 
table using table=data.frame(training, observation). table now has 
336x337 dimension with the last column as the observation to learn using 
the training data of the rest of the column in the table. For 
prediction, i combined the testing data and observation and pass it like 
predict(model,testingWTesingObservation)



I've used the formula: rpart(table[,337] ~ ., data=table) or 
svm(table[,337] ~ ., data=table).


I am not familiar with rpart() nor with svm() but table[,337] ~ ., data = 
table has the consequence that table[,337] is also in the right hand side 
of the formula, so that your observations are also in the training 
data. That doesn't seem to make sense to me, and is different from the 
call to svm() below.


 Hth  --  Gerrit

I recently discovered that this formulation produces different model 
from the: svm(training, observation) formulation. Which is correct and 
why one of them is not correct? I thought that syntactically, both are 
the same. I hope that R should be able to detect the error in one of the 
formulation to avoid the possibility of using it.


Regards,
Paul
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] substituting string variable in expression with its value

2013-09-12 Thread Gerrit Eichner

Hi, Jannis,

maybe

plot( 1, 1, main = bquote( paste( .(a),  [, .(b), ])))


comes close to what you want, but I think you may even have to use the 
following to get a varying exponent really printed elevated:


a - speed
b - m * s
cc - -2

plot( 1, 1, main = bquote( paste( .(a),  [, .(b)^{.(cc)}, ])))



 Hth  --  Gerrit



plot(1,1, main=expression(paste(speed [, m * s^{-1}, ])))


I would, however, like to be able to supply the value speed and m*s^{-a} by 
variables, e.g. do something like:



a = 'speed'
b = 'm*s^{-2}'

plot(1,1, main=expression(paste(a,  [, b, ])))

This, however, does not work as a and b are not treated as variable names in 
this case. Does anyone have a solution for this?



Cheers
jannis

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to write a wrapper function which can honor defaultvalues, when the target function has ones?

2013-09-13 Thread Gerrit Eichner

Hello, Adam,

I'm rather uncertain about your goal (and consequently even more so about 
how to reach it), but anyway, maybe the function match.call() with its 
argument expand.dots is of some help for you. From its help page:


match.call is most commonly used in two circumstances:

To record the call for later re-use: for example most model-fitting 
functions record the call as element call of the list they return. Here 
the default expand.dots = TRUE is appropriate.


To pass most of the call to another function, often model.frame. Here 
the common idiom is that expand.dots = FALSE is used, and the ... element 
of the matched call is removed. An alternative is to explicitly select the 
arguments to be passed on, as is done in lm.



 Hth  --  Gerrit

On Fri, 13 Sep 2013, Adam Ryczkowski wrote:



  (This is crosspost from
  [1]http://stackoverflow.com/questions/18670895/how-to-write-a-wrapper-functi
  on-which-can-honour-default-values-when-the-target, posted week ago, where
  although the question did receive some attention, nobody was able to help
  me.)
  I'd like to write a more-or-less generic caller to `targetf` that retains
  its default parameters.
  Suppose we have a provided by some 3rd party library `targetf`:
  targetf-function(x=1,...){
  print(paste(x =,x))
  }
  How to write `wrapperf`, that will respect `targetf`s default arguments, so
  calling `wrapperf()` would not yield the error massage `Error in paste(x
  =, x) : argument x is missing, with no default`?
  The obvious candidate
  wrapperf1-function(x,y) {
  targetf(x=x)
  }
   doesn't seem to respect targetf's default value for parameter `x`.
  OTH the
  wrapperf2-function(...) {
  targetf(...)
  }
   behaves correctly, but it doesn't work for me, because I only care to pass
  the `x` argument, (and possibly reserve the `...` to other functions in
  `wrapperf` body).
  Maybe to solve the issue I'd have to play with ellipsis filtering, which is
  a *terra incognita* for me at the moment...
  ***
  One idea on how to solve the problem: maybe I'd need to create a specially
  crafted `...` object from scratch in `wrapperf` to do pseudo code like this:
  wrapperfX-function(x,y,...)
  {
  ...-if(missing(x){
  list()
  }else{
  list(x=x)
  }
  targetf(...)
  }
  But I have no idea how to even start doing assignments into ellipsis... is
  it possible at all?
  kind regards,
  Adam Ryczkowski

  [2]www.statystyka.net
  [3]+48505919892
  [4]Skype:sisteczko

References

  1. 
http://stackoverflow.com/questions/18670895/how-to-write-a-wrapper-function-which-can-honour-default-values-when-the-target
  2. http://www.google.com/
  3. callto:+48505919892
  4. skype:sisteczko
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] bug(?) in str() with strict.width = cut when applied to dataframe with numeric component AND factor or character component with longerlevels/strings

2013-10-15 Thread Gerrit Eichner

Dear list subscribers,

here is a small artificial example to demonstrate the problem that I 
encountered when looking at the structure of a (larger) data frame that 
comprised (among other components)


a numeric component of elements of the order of  1, and

a factor or character component with longer levels/strings:


k - 43  # length of levels or character strings
n - 11  # number of rows of data frame
M - 1   # order of magnitude of numerical values

set.seed( 47) # to reproduce the following artificial character string
longer.char.string - paste( sample( letters, k, replace = TRUE),
 collapse = )

X - data.frame( A = 1:n * M,
 B = rep( longer.char.string, n))


The following call to str() gives apparently a wrong result

str( X, strict.width = cut)

'data.frame':   11 obs. of  2 variables:
 $ A: num  1e+04 2e+04 3e+04 4e+04 5e+04 6e+04 7e+04 8e+04 9e+04 1e+..
 $ A: num  1e+04 2e+04 3e+04 4e+04 5e+04 6e+04 7e+04 8e+04 9e+04 1e+..


whereas the correct result appears for str( X) or if you decrease k to 42 
(isn't that the answer? ;-) ) or n to 10 or M to 1000 (or smaller, 
respectively).



I tried to dig into the entrails of str.default(), where the cause may 
lie, but got lost pretty soon. So, I am hoping that someone may already 
have a work-around or patch (or dares to dig further)? Thank you for any 
feedback!


 Best regards  --  Gerrit

PS:


sessionInfo()


R version 3.0.2 (2013-09-25)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252

attached base packages:
[1] splines   stats graphics  grDevices utils datasets
[7] methods   base

other attached packages:
[1] nparcomp_2.0 multcomp_1.2-21  mvtnorm_0.9-9996
[4] car_2.0-19   Hmisc_3.12-2 Formula_1.1-1
[7] survival_2.37-4  fortunes_1.5-0

loaded via a namespace (and not attached):
[1] cluster_1.14.4  grid_3.0.2  lattice_0.20-23 MASS_7.3-29
[5] nnet_7.3-7  rpart_4.1-3 stats4_3.0.2tools_3.0.2

-
Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] extract regression coefficients

2013-10-15 Thread Gerrit Eichner

Hello, Catalin,

check out

?coef

 Regards -- Gerrit


On Tue, 15 Oct 2013, catalin roibu wrote:


Hello all!
I have a problem with R. I want to extract regression coefficients from
summary and use it for compute the theoretical values.

How can I do that in R?

thank you!

best regards,

--
---
Catalin-Constantin ROIBU
Lecturer PhD, Forestry engineer
Forestry Faculty of Suceava
Str. Universitatii no. 13, Suceava, 720229, Romania
office phone +4 0230 52 29 78, ext. 531
mobile phone   +4 0745 53 18 01
  +4 0766 71 76 58
FAX:+4 0230 52 16 64
silvic.usv.ro

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] extract regression coefficients

2013-10-15 Thread Gerrit Eichner

Hello, Catalin,

fist: keep the reply on-list so that others can follow.

second: (see below)

On Tue, 15 Oct 2013, catalin roibu wrote:


Hello!
I try that! But I want to use them forward in the equation and I don't want
to write every time when I change the values.


This way to unspecific to give you any hint. So, PLEASE do read the 
posting guide http://www.R-project.org/posting-guide.html and provide 
commented, minimal, self-contained, reproducible code.


 Regards  --  Gerrit



On 15 October 2013 14:59, Gerrit Eichner gerrit.eich...@math.uni-giessen.de

wrote:



Hello, Catalin,

check out

?coef

 Regards -- Gerrit



On Tue, 15 Oct 2013, catalin roibu wrote:

 Hello all!

I have a problem with R. I want to extract regression coefficients from
summary and use it for compute the theoretical values.

How can I do that in R?

thank you!

best regards,

--
---
Catalin-Constantin ROIBU
Lecturer PhD, Forestry engineer
Forestry Faculty of Suceava
Str. Universitatii no. 13, Suceava, 720229, Romania
office phone +4 0230 52 29 78, ext. 531
mobile phone   +4 0745 53 18 01
  +4 0766 71 76 58
FAX:+4 0230 52 16 64
silvic.usv.ro

[[alternative HTML version deleted]]

__**
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/**
posting-guide.html http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.






--
---
Catalin-Constantin ROIBU
Lecturer PhD, Forestry engineer
Forestry Faculty of Suceava
Str. Universitatii no. 13, Suceava, 720229, Romania
office phone +4 0230 52 29 78, ext. 531
mobile phone   +4 0745 53 18 01
  +4 0766 71 76 58
FAX:+4 0230 52 16 64
silvic.usv.ro


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] bug(?) in str() with strict.width = cut when appliedtodataframe with numeric component AND factor or character component withlongerlevels/strings

2013-10-16 Thread Gerrit Eichner

Thanks, Duncan,

for the good (indirect) hint: after a restart of R the problem is -- 
fortunately :-) -- not reproducible anymore for me either. The R session 
had been running for a longer time and I recall doing some 
(system-related) things outside of R that may have interfered with it; I 
just forgot to take that possibility into consideration. :(


 Regards  --  Gerrit

On Tue, 15 Oct 2013, Duncan Murdoch wrote:


On 15/10/2013 7:53 AM, Gerrit Eichner wrote:

Dear list subscribers,

here is a small artificial example to demonstrate the problem that I
encountered when looking at the structure of a (larger) data frame that
comprised (among other components)

a numeric component of elements of the order of  1, and

a factor or character component with longer levels/strings:


k - 43  # length of levels or character strings
n - 11  # number of rows of data frame
M - 1   # order of magnitude of numerical values

set.seed( 47) # to reproduce the following artificial character string
longer.char.string - paste( sample( letters, k, replace = TRUE),
   collapse = )

X - data.frame( A = 1:n * M,
   B = rep( longer.char.string, n))


The following call to str() gives apparently a wrong result

str( X, strict.width = cut)

'data.frame':   11 obs. of  2 variables:
   $ A: num  1e+04 2e+04 3e+04 4e+04 5e+04 6e+04 7e+04 8e+04 9e+04 1e+..
   $ A: num  1e+04 2e+04 3e+04 4e+04 5e+04 6e+04 7e+04 8e+04 9e+04 1e+..


whereas the correct result appears for str( X) or if you decrease k to 42
(isn't that the answer? ;-) ) or n to 10 or M to 1000 (or smaller,
respectively).


I tried to dig into the entrails of str.default(), where the cause may
lie, but got lost pretty soon. So, I am hoping that someone may already
have a work-around or patch (or dares to dig further)? Thank you for any
feedback!


I can't reproduce this.  I don't have a 64 bit copy of 3.0.2 handy, but I 
don't see it in 64 bit 3.0.1, or 64 bit 3.0.2-patched, or various 32 bit 
versions.


Is it reproducible for you?  It looks to me as though (if it isn't just 
something weird on your system, e.g. an old copy of str() in your workspace), 
it might be a memory protection problem:  something needed to be duplicated 
but wasn't.  But unless I can see it happen, I can't start to fix it.


Duncan Murdoch



   Best regards  --  Gerrit

PS:

 sessionInfo()

R version 3.0.2 (2013-09-25)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252

attached base packages:
[1] splines   stats graphics  grDevices utils datasets
[7] methods   base

other attached packages:
[1] nparcomp_2.0 multcomp_1.2-21  mvtnorm_0.9-9996
[4] car_2.0-19   Hmisc_3.12-2 Formula_1.1-1
[7] survival_2.37-4  fortunes_1.5-0

loaded via a namespace (and not attached):
[1] cluster_1.14.4  grid_3.0.2  lattice_0.20-23 MASS_7.3-29
[5] nnet_7.3-7  rpart_4.1-3 stats4_3.0.2tools_3.0.2

-
Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Where is element 30?

2013-10-22 Thread Gerrit Eichner

Hi, Alaios,

check out

?which

and in particular its Examples and See Also section.

 Hth -- Gerrit

On Tue, 22 Oct 2013, Alaios wrote:


Hi I have a vector like that

readCsvFile$V1
 [1]  30  31  32  33  34  35  36  37  38  39 310 311 312 313 314 315 316 317 318
[20] 319 320 321  20  21  22  23  24  25  26  27  28  29 210 211 212 213 214 215
[39] 216 217 218 219 220 221 222 223  40  41  42  43  44  45  46  47  48  49 410
[58] 411 412 413 414 415 416 417 418 419 420 421


and I am looking to find where the number 31 is located. So I need one function 
to return me the index of where the number 31 is.
Is there a function for that in R?

Regards
Alex__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Nonparametric k-way ANOVA

2013-10-25 Thread Gerrit Eichner

Hello, Vincent,

you may want to take a look at Nonparametric methods in factorial 
designs by Edgar Brunner and Madan L. Puri in Statistical Papers 42, 1-52 
(2001).


There is the R-package nparcomp for one-way layouts, but the paper goes 
further (and mentions another software) and is maybe a starting point for 
you.


 Hth -- Gerrit

On Thu, 24 Oct 2013, Vicent Giner-Bosch wrote:


Sorry if this subject has been already dealt here.

Which are some common tests for nonparametric k-way ANOVA?

I have read about Kruskal-Wallis test as a kind of nonparametric one-way
ANOVA, but I have not found anything about a general-setting (I mean k-way)
nonparametric ANOVA.

Can you recommend me a good R package (or other reliable software) for that?

Looking forward to your answers,


--
vicent
@vginer_upv
about.me/vginer_upv

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Select fixed number of elements

2013-10-30 Thread Gerrit Eichner

Hello, Alaois,

if x is your vector maybe

n - length( x)
positions - trunc( quantile( seq( n), prob = 0:5/5))
x[ positions]

comes close to what you want.

 Hth  --  Gerrit

Hi all, I have in my code some vectors that are not of equal size. I 
would like to be able for each of these vectors select 6 elements that 
are (almost) equally spaced. So the first one would be at (or close) to 
the beginning the last one at (or close) to the end and the other 4 
equally spaced between first and last element.


How can I do something like that on a vector of not known size?

I would like to thank you in advance for your help

Regards
Alex
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] omitting integer(0) rows from data frame

2013-10-30 Thread Gerrit Eichner

Hi, Jack,

well, I disagree: What do you expect to grab out of a bucket (= data 
frame) if you do not at all grab into it (indexing with an _empty_ index, 
i.e. with nothing)? And changing the sign of nothing is still nothing ...


 Hth --  Gerrit

On Wed, 30 Oct 2013, Jack Tanner wrote:


I'm not sure if this is correct behavior or not, but it seems counterintuitive
to me:

dat - data.frame(id=1:5, let=letters[1:5])
# A. omits the first row
dat[- 1, ]

# B. unexpectedly omits ALL rows
dat[- integer(0), ]

It would be less surprising if there were no rows omitted in the (B) case.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] remap values from one vector to the other

2013-10-31 Thread Gerrit Eichner

Alex,

it is a bit unclear what you mean by remap etc., but maybe

y0 - 880e6;   y1 - 1020e6
x0 - 1;   x1 - ncol(x)

y0 + (x0-1):x1 * (y1 - y0)/(x1 - (x0-1))

gives what you want.

 Hth  --  Gerrit


On Thu, 31 Oct 2013, Alaios wrote:


Hi everyone,
I am plotting some legend and I am using the axis(at=..) to specify the place 
to plot the marks I want.

My plotted data have ncol(x) so the at places have values that span from 1 to 
ncol(x)

there I would like to be able to map values that go from 880e6 to 1020e6.
so
880e6 remaps to 1


1020e6 repams to ncol(x)

what I do not know how to do is to remap the values that are between 880e6 and 
1020e6 between then 1 and ncol(x).

Can someone help me find an appropriate function for that?

I would like to thank you in advance for your help

Regards
Alex
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] difference percentile R vs SPSS

2012-11-08 Thread Gerrit Eichner

Hi, David,

I think you're confusing the q-th percentile of your data, i. e., the 
empirical q-th percentile, which is -- roughly -- the value x_q for which 
q * 100 % of the data are less than or equal to x_q, with the q-th 
percentile of a distribution (here the normal distribution) that has as 
population mean the arithmetic mean of the data and as population standard 
deviation the standard deviation of the data. Those are different things. 
Your SPSS code seems to compute the empirical quantile, but you R code 
produces the other quantile. To get empirical quantiles of your data in R 
see


?quantile



 Hth  --  Gerrit

On Thu, 8 Nov 2012, David A. wrote:



Dear list,

I am calculating the 95th percentile of a set of values with R and with SPSS

In R:


normal200-rnorm(200,0,1)
qnorm(0.95,mean=mean(normal200),sd=sd(normal200),lower.tail =TRUE)

[1] 1.84191

In SPSS, if I use the same 200 values and select Analyze - Descriptive Statistics 
- Frequencies

and under Statistics, I type in '95' under Percentiles, then the output is

Percentile 95  1.9720



I think the main difference is that SPSS only calculates critical values within 
the range of values in the data, while R fits a normal and calculates the 
critical value using the fitted distribution. This is more obvious if the size 
of the data is much lower:


normal20

[1]  0.27549020  0.87994304 -0.23737370  0.04565484 -1.10207183 -0.68035949  
0.01698773 -2.15812038  0.26296513  0.21873981  0.03266598 -0.01318572
[13]  0.83492830  0.54652613  0.73993948 -0.31937556 -0.03060194 -0.96028421  
0.27745331 -1.01292410

max(normal20)

[1] 0.879943

qnorm(0.95,mean=mean(normal20),sd=sd(normal20),lower.tail =TRUE)

[1] 1.118065

And in SPSS

Percentile 95 0.8777



Can anyone comment on my statement? and thus, is R more exact? The differences 
are quite large and this is important for setting thresholds.


Cheers,

Dave

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


-
Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] General function to substitute values in a data frame

2012-11-09 Thread Gerrit Eichner

Hello, Fabricius,

does


as.data.frame( lapply( df, function( x) LETTERS[ x-9]))


what you want?

Other (here maybe less flexible) ways:


transform( df, y = LETTERS[y - 9], z = LETTERS[ z - 9])



within( df, {y - LETTERS[y - 9]; z - LETTERS[ z - 9]})


Hth  --  Gerrit


On Fri, 9 Nov 2012, Fabricius Domingos wrote:


Hi R users,

I need a way to substitute the values 10:31 to the letters A:V (i.e 10=A,
11=B, ..., 31=V) in a data frame.

For example:

y-c(10,11,12,13)
z-c(28,29,30,31)
df-data.frame(y,z)
df

  y  z
1 10 28
2 11 29
3 12 30
4 13 31

Then I would substitute it and obtain a data frame like this as a result of
the function:

w-c(A,B,C,D) # without actually writing this part down, of

course.

x-c(S,T,U,V) # without actually writing this part down, of

course.

df2-data.frame(w,x)
df2

 w x
1 A S
2 B T
3 C U
4 D V

Apparently the function replace can do the job:

attach(df)
replace(y, y==10,A)

[1] A  11 12 13

But then I would have to do it letter by letter and build the data frame
again. I would not mind doing this for one small data frame but I do have
several large ones, so I was wondering if that's a way that I can write
only one function to perform the action?

I found another way, but it looks kind of silly:

ifelse(y==10,A, ifelse(y==11,B, ifelse(y==12,C, ... )))


Anyway, I would have to rewrite this for every column as well. So what I
really want is something that I could use for the whole data frame (or at
least lapply it), like:

change.to.letters-function (x) {if x==7 replace(x, x==7, A)

 if (x==6) replace(x,x==6,B)
   ...}

 # and so on... but of course this one does not work,
I just wrote down what I suppose it should looks like. Then I could use:

change.to.letters(y)  # or
lapply(df, FUN=change.to.letters)


Any help would be much appreciated!

Thanks!

   Fabricius

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



-
Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how to enter a string value

2012-11-12 Thread Gerrit Eichner

Alen, look at

?scan

and there particularly at the argument 'what'.

 Hth  --  Gerrit


On Mon, 12 Nov 2012, alen wrote:


hi,


I want to know just enter a string value

entering a numeric value is make with the function scan () or scan (nmax =
..)

but it does not work for string

my goal is to enter three string: name and surname and date of birth

I try with this code but it shows me errors


print (enter the name)
name - scan (nmax = 1)
print (enter the first name)
firstName - scan (nmax = 1)
print (enter the date of birth)
BirthDate - scan (nmax = 1)




best regards

alen



--
View this message in context: 
http://r.789695.n4.nabble.com/how-to-enter-a-string-value-tp4649313.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] column name prefix 'x' after data import via read.delim

2012-11-23 Thread Gerrit Eichner

Hello, e-letter,

check

?read.delim

and look for the argument check.names and from there you'll should end up 
reading


?make.names



 Hth  --  Gerrit


On Fri, 23 Nov 2012, e-letter wrote:


Readers,

The function 'read.delim' was used to import data into R:

columnnamea columnnameb columnnamec
1 2 3
2 3 4
3 4 5

After import, the column names were:

X.columnnamea columnnameb columnnamec

Why did this occur?

--
r2151

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Accessing List within a List in a for Loop

2012-11-28 Thread Gerrit Eichner

Hello, Mono,

your description of your problem is a bit overwhelming. You might get an 
answer if you provide (simplified) reproducible code (maybe with example 
data).


I can only guess that -- instead of factor( x[[1]]) -- you maybe should 
use


factor( x[[1]][1])

in some place.

 Hth  --  Gerrit

On Tue, 27 Nov 2012, m.dr wrote:


My question is regards accessing complex lists. I am new to R, but
experienced in Java, Python, SQL.

I am working with an object: Dataprocess and in it slot: data that is a
list.
Also I am creating generic functions to perform on the slot: data which is
the list.
I am working with the Airline dataset - so the data slot is a list of the
years 1987, 1988, ..
I am trying to perform factor and such operations on the column elements of
each year.
So - for purposes of this discussion we will refer to the column: dayOfWeek
in each of the years.

My issue is that while I get to the list I need I cannot directly access the
list elements to apply the factor function to. I can print the list
directly. I try to explain as follows:
...
So the data has several columns. And in the method I can get to a column
using:
x - list(lapply(this@data, '[[', ÿÿdayOfWeekÿÿ))
print(x) OR print(x[1])  gives:
[[1]]
[[1]]$`1987`
[1] 3 4 6 7 1 3 4 5 6 7 1 3 4 6 4 5 ...

print(x[[1]])  gives:
$`1987`
[1] 3 4 6 7 1 3 4 5 6 7 1 3 4 6 4 5 ...

If I do: z - factor(x) OR z - factor(x[1]) OR z - factor(x[[1]]) I get
Error in sort.list(y) : 'x' must be atomic for 'sort.list'
Have you called 'sort' on a list?
...
I have also tried:
y - list(sapply(this@data, '[', ÿÿdayOfWeekÿÿ))
print(y) OR print (y[1])  gives:
[[1]]
[[1]]$`1987.dayOfWeek`
[1] 3 4 6 7 1 3 4 5 6 7 1 3 4 6 4 5 ...

print(y[[1]])  gives:
$`1987.dayOfWeek`
[1] 3 4 6 7 1 3 4 5 6 7 1 3 4 6 4 5 ...

Again If I do: z - factor(y) OR z - factor(y[1]) OR z - factor(y[[1]]) I
get
Error in sort.list(y) : 'x' must be atomic for 'sort.list'
Have you called 'sort' on a list?

I have tried accessing the list directly as y[[1]]$ÿÿ1987.dayOfWeekÿÿ which
gives me the list elements.
And then factor(y[[1]]$ÿÿdayOfWeekÿÿ) works fine!

Gives me:
[1] 3 4 6 7 1 3 4 5 6 7 1 3 4 6 4 5 ...
Levels: 1 2 3 4 5 6 7

But I do not have this flexibility as I am doing the lapply or sapply as
part of a for loop.
So the functions are really:
x - list(lapply(this@data, '[[', each))
y - list(sapply(this@data, '[', each))

So it is not possible for me to access in a hard-coded manner as
y[[1]]$ÿÿ1987.dayOfWeekÿÿ
So I do not understand how to access the list elements directly to apply
factor and not just the list.
None of the accesses as x, x[1], x[[1]] OR y, y[1] or y[[1]] work.
It gives me access to the list for print and such - but not to the list
elements to apply factor.
The only way to access the list elements directly is by
y[[1]]$ÿÿ1987.dayOfWeekÿÿ and then I can factor.

However I do not have this option as I am in a loop.

I hope I have explained this clearly.
If not please let me know and I can try again or post the code.

Thank you for your help.

Mono



--
View this message in context: 
http://r.789695.n4.nabble.com/Accessing-List-within-a-List-in-a-for-Loop-tp4651086.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] simple subset question

2012-12-02 Thread Gerrit Eichner

Hi, Felipe,

two typos? See below!

On Sun, 2 Dec 2012, Felipe Carrillo wrote:


 Hi,
Consider the small dataset below, I want to subset by two variables in
one line but it wont work...it works though if I subset separately. I have
to be missing something obvious that I did not realize before while using 
subset..

fish - structure(list(IDWeek = c(27L, 28L, 29L, 30L, 31L, 32L, 33L,



... [snip]



2011L)), .Names = c(IDWeek, Total, Fry, Smolt, FryEq,
Year), row.names = c(NA, 52L), class = data.frame)
fish
#  Subset to get the max Total for 2012
  x - subset(winter,Year==2012  Total==max(Total));b  # How come one line 
doesn't work?


Don't you want *fish* instead of *winter* and *x* instead of *b*, as in

x - subset(  fish,Year==2012  Total==max(Total));x

?

 Hth  --  Gerrit


 
  # It works if I subset the year first and then get the Total max from it
  xx - subset(winter,Year==2012) 
xxx - subset(xx,Total==max(Total));xxx  
xxx
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] question about sum of (column) elements in R

2012-12-04 Thread Gerrit Eichner

Hi, T. Bal,

homework? Take a look at

?tapply


 Regards  --  Gerrit


On Tue, 4 Dec 2012, T Bal wrote:


Hi,
I have the following data:

0   12
1   10
1   4
1   6
1   7
1   13
2   21
2   23
2   20
3   18
3   17
3   16
3   27
3   33
4   11
4   8
4   19
4   16
4   9


In this data file I would like to sum the numbers of second column which
belong to the same number in the first column.
So the output would be:

0 12
1 40
2 64
   3 111
   etc.

Thank you.

Kind regards,
T. Bal

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] computing marginal values based on multiple columns?

2012-12-04 Thread Gerrit Eichner

Hello, Simon,

see below!


On Tue, 4 Dec 2012, Simon wrote:


Hello all,

I have what feels like a simple problem, but I can't find an simple
answer. Consider this data frame:


x - data.frame(sample1=c(35,176,182,193,124),

sample2=c(198,176,190,23,15), sample3=c(12,154,21,191,156),
class=c('a','a','c','b','c'))


x

 sample1 sample2 sample3 class
1  35 198  12 a
2 176 176 154 a
3 182 190  21 c
4 193  23 191 b
5 124  15 156 c

Now I wish to know: for each sample, for values  20% of the sample mean,
what percentage of those are class a?

I want to end up with a table like:

  sample1 sample2 sample3
1  1.0 0 0.5



I can't reproduce this result from your description above, but if I 
understand the latter correctly, maybe the following does what you want:


x.wo.class - subset( x, select = -class)
  # extract only the sample-columns

x.small.and.a - x.wo.class  0.2 * colMeans( x.wo.class)  x$class == a

apply( x.small.and.a, 2, function( xx) mean( x$class[ xx] == a))


 Hth  --  Gerrit



I can calculate this for an individual sample using this rather clumsy
expression:

length(which(x$sample1  mean(x$sample1)  x$class=='a')) /
length(which(x$sample1  mean(x$sample1)))

I'd normally propagate it across the data frame using apply, but I
can't because it depends on more than one column.

Any help much appreciated!

Cheers,

Simon

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Help with manipulation of matrix object

2012-12-06 Thread Gerrit Eichner

Hi, Jeremy!


... I have a matrix, measuring m X n. An example matrix will be this:
... [snip] ...


What I want to do is actually statistical manipulation of this matrix. 
To be more precise, I want to calculate the probability of each value, 
based on the assumption of a normal distribution, based on the row mean 
and standard deviation.


Hm, I think you have to be more precise since the probability to observe a 
specific value under the assumption of a continuous distribution (e.g., 
the normal distribution) is zero -- always.


And you presumably do not want the first column to be included in the 
calculation of the median, the sd, and finally the probability, do you?



However, if I understand correctly, you could maybe proceed as follows: 
With



row.median - apply( sample[, -1], 1, median)
row.sd - apply( sample[, -1], 1, sd)


you could standardize the rows of your matrix by


rowwise.standardized.sample - (sample[, -1] - row.median) / row.sd


(utilizing the way matrices and vectors are handled in arithmetic 
expression), and then use relations within the family of normal 
distributions to compute density or cumulative probability values by



dnorm( rowwise.standardized.sample) / row.sd



pnorm( rowwise.standardized.sample)



 Hth  --  Gerrit



For example,

sample[2,2] = 4.37914 - This value is derived from the matrix, row 2

column 2.
To calculate the median (which i am using in place of the mean in the
normal distribution), I know I have to use the apply function;


the same goes for the standard deviation:


sd-apply(sample,1, sd)


With both the median and the sd in hand, I want to write the probability of
observing the value reported at sample[2,2]

I can do this manually, but as the dataframe gets larger and larger, this
becomes more time consuming; and furthermore, I wish to write the
probability as a matrix of the exact same dimensions, except that instead
of a matrix reporting the values I now have a matrix of reporting the
probabilities.

The median and sd is calculated for each row.

Any help/ thoughts on this will be greatly appreciated!

Jeremy

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] remove NA in df results in NA, NA.1 ... rows

2012-12-13 Thread Gerrit Eichner

Hi Raphael,

see below.


I have the following data frame (df):
...
 df2

X.PAD2 Y.PAD2
73 574618.3 179650
74 574719.0 179688
75 574719.0 179688
76 574723.5 179678
77 574724.9 179673
78 574747.1 179598
79 574641.8 179570
80 574639.6 179573
81 574618.3 179650
82   NA NA
83   NA NA
...
44   NA NA
45   NA NA
46   NA NA

followed by removing the NA's using

 df2 - df2[!is.na(df2),]

...


is.na( df2) produces a logical matrix (!), and you are then indexing the 
rows of your data frame with a matrix which is converted into a vector 
of its elements producing far too many logical indices for your task (so 
to say).


I assume you should be using


na.omit( df2)


instead.

 Hth  --  Gerrit

-
Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] In which column and in which row a number is in a matrix

2013-01-02 Thread Gerrit Eichner

Hi, Charles,

see

?which

and learn about the argument arr.ind.

 Happy new year  --  Gerrit


On Wed, 2 Jan 2013, Charles Novaes de Santana wrote:


Dear all, Happy New Year for all of you! I hope we have an year of
essential freedom for everyone!

I am trying to manipulate a matrix in order to know in which column
and in which row a number is allocated. But, when we use the function
which it returns the position of the number in the vector
representation of the matrix. For example:


mata-matrix(2:7,nrow=2,ncol=3)
mata

[,1] [,2] [,3]
[1,]246
[2,]357

matb-matrix(2:7,nrow=3,ncol=2)
matb

[,1] [,2]
[1,]25
[2,]36
[3,]47

which(mata==4)

[1] 3

which(matb==4)

[1] 3

The function which returns the position 3 for both, mata and matb,
but If I didn't know that mata is a 2x3 matrix and matb is a 3x2, I
wouldn't know that the number 4 is at the column 2 and row 1 of the
mata and at the column 1 and row 3 of the matb. Do you know any way to
know the column and the row of a number in a matrix automatically?

Thanks, best regards,

Charles


--
Um axé! :)

--
Charles Novaes de Santana
http://www.imedea.uib-csic.es/~charles
PhD student - Global Change
Laboratorio Internacional de Cambio Global
Department of Global Change Research
Instituto Mediterráneo de Estudios Avanzados(CSIC/UIB)
Calle Miquel Marques 21, 07190
Esporles - Islas Baleares - España

Office phone - +34 971 610 896
Cell phone - +34 660 207 940

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Make a column from columns

2013-01-03 Thread Gerrit Eichner

Hi, Aseem,

you may want to look at

?stack

or

?reshape

(and transform your matrix into a data frame).

  Hth  --  Gerrit

On Wed, 2 Jan 2013, Aseem Sharma wrote:


Hi,
I have a data matrix with 13 columns and 55 rows.  First coulmn is year and
other are monthly values for 55 years.
Now i want to create a single column of all the values ( i e  a single time
series column from column 2 to 13 ).
Is it the for loop that works here ...how ?
or how i can rearrange the data so that it becomes a times series column.
hope i made the question clear .
thank you,


--

Namaste नमस्ते

Aseem Sharma

Graduate Research Assistant

Northern Hydrometeorology Group(NHG)

Natural Resources and Environmental Studies Institute(NRESi)

University of Northern British Columbia

Prince George, BC, V2N 4Z9, Canada

Tel: 250-960-5427

Web: http://www.unbc.ca/


All know the Way, but few actually walk it.
सबैको कल्याण होस् ।

[[alternative HTML version deleted]]__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] add error bars in a plot

2011-02-08 Thread Gerrit Eichner

Hello, Maria,

take a look at

?errbar

in the package Hmisc.


Hth  -- Gerrit



Dear all

I have a dataset of how metal concentrations change through time. I have 
made a plot of date versus metal concentration. However I want to add 
error bars in the plot.


Could you help me?

Thanks
Maria


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] read a text file with variable number of spaces

2011-03-03 Thread Gerrit Eichner

Hello, Gregory,

for your first data set see

?read.table

and for you second

?read.fwf

may help solving your problem.

Hth  --  Gerrit


On Thu, 3 Mar 2011, Gregory Ryslik wrote:


Hi,


I seem to be having somewhat of an unusual data input problem with some 
of the data sets I'm working with and want to run a simulation on.


in the first data set I'm looking at, I have a text file where the 
spacing between columns varies. I've attached a snippet. Is there a way 
to read this into R? Basically, I want to ignore all the spaces to make 
new columns. In a slightly different case, I have a long sequence of 
nucleotides (the letters are always either g,a,t,c). Is there a way to 
get each letter into it's own column so that I can then use it as a data 
set?


I'm kind of loathe to program a java/C program to do this if I don't 
have to and was wondering if a way in R exists for this.


Thanks!
Greg

Case1:
ACE2_YEAST  0.42  0.37  0.59  0.20  0.50  0.00  0.52  0.29  NUC
ACH1_YEAST  0.40  0.42  0.57  0.35  0.50  0.00  0.53  0.25  CYT
ACON_YEAST  0.60  0.40  0.52  0.46  0.50  0.00  0.53  0.22  MIT
ACR1_YEAST  0.66  0.55  0.45  0.19  0.50  0.00  0.46  0.22  MIT
ACT_YEAST   0.46  0.44  0.52  0.11  0.50  0.00  0.50  0.22  CYT
ACT2_YEAST  0.47  0.39  0.50  0.11  0.50  0.00  0.49  0.40  CYT
ACT3_YEAST  0.58  0.47  0.54  0.11  0.50  0.00  0.51  0.26  NUC
ACT5_YEAST  0.50  0.34  0.55  0.21  0.50  0.00  0.49  0.22  NUC

Case2:
gtacagtacgtacgtacgatcgatctagcatgcatgcatgcatgcta
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] random sampling steps in R with replacement

2011-03-10 Thread Gerrit Eichner

Hello, Taby,

for your (first) problem take a look at

?sample

and its argument replace.


Regards -- Gerrit


On Thu, 10 Mar 2011, taby gathoni wrote:


Please note is with replacement


From: taby gathoni tab...@yahoo.com
To: R help r-help@r-project.org
Sent: Thursday, March 10, 2011 11:53 AM
Subject: [R] random sampling steps in R

Dear all,

Could someone assist me in random sampling steps/code in R? I have a 
main sample of 42 males and 165 females and I want to come up with about 
1000 samples of 20 males and 20 females from this main sample. While at 
it, i would also like to come up Accuracy Ratios (ARs) with 
corresponding confidence intervals.


Please assist.


Thanks so much,

Taby



   [[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Data Frame Variable Names

2011-03-15 Thread Gerrit Eichner

Hello, Indrajit,

a quick and dirty solution could be to loop over the names of the 
relevant variables of the data frame (in your case over the first three 
variables) and use [[ ]] for indexing:


for (i in names( df)[ 1:3]) {
 z - glm( df[[ i]] ~ df$Independent1)
 print( z)
 }



An output that is a little bit more informative w. r. t. the actually used 
model formula is obtained by


for( i in names( df)[ 1:3]) {
 modelform - formula( paste( i, ~ Independent1))
 z - eval( substitute( lm( f, data = airquality),
list( f = modelform) ))
 print( z)
 }



Hth,

Gerrit


On Tue, 15 Mar 2011, Indrajit Chatterjee wrote:


Hi,

I have created a dataframe (lets call is df) that contains the following
variables

Dependent1 Dependent2 Dependent3 Independent1

I want to do the following regressions:

z- glm( df$Dependent1 ~ df$Independent1)
z- glm( df$Dependent2 ~ df$Independent1)
z- glm( df$Dependent3 ~ df$Independent1)

and so on

I wanted to put this in a for loop e.g.

for (i in 1:3) {

z- glm( df$ColumnName_i ~ df$Independent1)
print(z)

}


How do I specify the column name in the regression above for the dependent
variable

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


-
Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] expression exponent labeling

2013-03-13 Thread Gerrit Eichner

Hi, Berry,

I think


for(i in -8:-3) axis(1, i, substitute(10^j, list( j = i)))


achieves what you want.

 Regards --  Gerrit


On Wed, 13 Mar 2013, Berry Boessenkool wrote:




Hi all,

I want to label an axis with exponents, but can't get it done with expression.
Any hints would be very welcome!

# simulated data, somewhat similarly distributed to my real data:
set.seed(12); d - rbeta(1e6, 0.2,2)*150 ; d - d[d1e-8]
hist( d  , breaks=100)
# now on a logarithmically scaled axis:
hist(log10(d), breaks=100, xaxt=n)
abline(v= log10(1:10*10^rep(-9:3, each=10)), col=darkgrey ); box()
hist(log10(d), breaks=100, col=forestgreen, add=T)
axis(1, log10(1:10*10^rep(-9:3, each=10)), labels=F)
axis(1, -2:2, format(10^(-2:2), scient=3, drop0trailing=T) )
# the labels with lower values should be in the form of 10^x:
axis(1, -8:-3, expression( 10^(-8:-3)) )# doesn't work, because expression 
returns only one output
for(i in -8:-3) axis(1, i, expression(10^i)  ) # writes i at all locations

expression does exactly what it should, but I want something different here...
I've tried I(10^i) instead, but that's not right either.

Thanks ahead,
Berry



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how to search a list that contains multiple dissimilarvectors?

2013-03-28 Thread Gerrit Eichner

Hi, Eric,

as a quick hack, does

spots - sapply( alist,
 function( listcomp)
  which( listcomp == value.to.look.for) )

spots[ sapply( spots, length) == 0] - NULL

do what you want?


Regards  --  Gerrit


On Thu, 28 Mar 2013, Eric Rupley wrote:



Dear All,

This is a simple question, but I'm stumped about the simplest way to 
search a list object such as the following:


This randomish snippet:

n - c(round(runif(round(runif(1,1,10),0),1,10),0))
alist - new(list)
for (i in seq_along(n)) {
alist[[i]] - c(round(runif(round(runif(1,1,10),0),1,10),0))
}
names(alist) - sample(letters[1:length(n)])
rm(n);c(alist)


...produces something like this:

$d
[1] 4

$b
[1] 3 5 3

$a
[1]  2  5  7  3 10  3  4  9  9

$c
[1]  6  3  7  4  5 10  8 10  3

My question is how does one search the list for a given value, in a most 
compressed set of commands, in order two return two separate indices: a) the 
index of the list element(s) containing the value, and b) the index of the 
matching value(s) within the vector.

Right now, I'm writing cumbersome loops to iterate though the elements, but 
there must be a simple, effective method to which I have not found a reference.

Many thanks in advance, and apologies if I have overlooked a reference passage.
Best,
Eric

--
Eric Rupley
University of Michigan, Museum of Anthropology
1109 Geddes Ave, Rm. 4013
Ann Arbor, MI 48109-1079


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


  1   2   >