[R] average among one factor in a nested dataframe

2011-04-25 Thread Junqian Gordon Xu
I have two nested data frames:

a-rnorm(6)
b-rnorm(9)
f1-c(x1,x2,x3))
f2-c(y1,y2)
id-c(1:6)
a_df-data.frame(cbind(id,f1,y1,a))
id-c(1:9)
b_df-data.frame(cbind(id,f1,y2,b))

I want to preserve id and f1, but want to collapse f2 and take the
corresponding mean values of a and b. Missing value in either dataframe
should be handled properly (i.e., just take the non-missing number
without dividing by 2).

I had a look at rowSum/Means and s/l/tapply, but couldn't figure out how
to handle this case cleanly. Any suggestions?

Thanks
Gordon

__
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] Question on Import

2011-04-25 Thread Georgina Salazar
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] Retrieve model from R without save

2011-04-25 Thread Raji
Hi,

  Thank you.I would also like to know if there is a way in which we can
store R model object as a binary in memory and read the binary contents back
into R model object?

--
View this message in context: 
http://r.789695.n4.nabble.com/Retrieve-model-from-R-without-save-tp3465495p3472682.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.


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] Question on Import

2011-04-25 Thread Alexander Engelhardt

Am 25.04.2011 09:58, schrieb Georgina Salazar:

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))
)


You shall escape filenames with quotes:
read.delim(ken_data_try_anova)

Otherwise R thinks you have a variable named ken_data_try_anova. But you 
need a string containing the filename (and the difference between 
strings and variables are the quotes).

The following, for example, would also work:

derp - ken_data_try_anova
read.delim(derp)

What you also want to do, is not only read the table, but also store it 
in a data frame:


mydata - read.delim(ken_data_try_anova)

Have fun,
 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] Question on Import

2011-04-25 Thread Jim Lemon

On 04/25/2011 05:58 PM, 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


Try

read.delim(ken_data_try_anova)

If that doesn't work, turn off the Hide extensions for known file 
types option in Windows Explorer and find out what the extension for

this file is.


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:\


The single backslash doesn't work as a path delimiter in R. Try:

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

or

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

That is, replace the backslashes with forward slashes (and don't forget 
the quotes)



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



Jim

__
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] return code 10 in the R documentation

2011-04-25 Thread peter dalgaard

On Apr 25, 2011, at 05:53 , Jim Lemon wrote:

 On 04/25/2011 12:26 PM, swarna14 wrote:
 Hi Everyone,
 
 I have group of R jobs that should be submitted to the condor when I submit
 the jobs to the condor, they don't run and when I checked the Sched Log
 files the jobs are exiting with status code 10. Previously, the jobs ran
 well on condor but now when I submit the jobs on condor they aren't
 running.Can anyone explain the meaning of this?
 
 The condor in question appears to be a top level directory on a PC, not the 
 iconic scavenger that was rescued from extinction in southern California. We 
 will charitably assume that it directs your R script to an R interpreter at 
 the address shown below.

More likely, it's http://www.cs.wisc.edu/condor/. 

Anyways, the point remains: An R script returns an error code. As long as we 
have no clue to what the R script does or what the error code means, how are we 
supposed to help?

According to the help for q(), failures in R itself or its front-ends, would 
give single digit return codes, so return codes of 10 or more would be 
generated by the script itself, as in q(status=10).

Or it is something in Condor itself that is failing, in which case you are 
barking up the completely wrong tree.

-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.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] Defining origin for rotation in RGL device

2011-04-25 Thread Mark Heckmann
Hi all,

How can I tell RGL to set the center for the rotation to the origin of  the 
coordinate system (0,0,0).
It seems that the default is to use the center of the display not the origin of 
the coordinate system.

open3d()
lines3d(c(0, 1), c(0,0), c(0,0))
lines3d(c(0,0), c(0, 1), c(0,0))
lines3d(c(0,0), c(0,0), c(0, 1))

TIA
Mark

–––
Mark Heckmann
Blog: www.markheckmann.de
R-Blog: http://ryouready.wordpress.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.


Re: [R] Random Normal Variable Correlated to an Existing Binomial Variable

2011-04-25 Thread Petr Savicky
On Sun, Apr 24, 2011 at 07:00:26PM -0400, Shane Phillips wrote:
 Hi, R-Helpers!
 
 I have a dataframe that contains a binomial variable.  I need to add another 
 random variable drawn from a normal distribution with a specific mean and 
 standard deviation.  This variable also needs to be correlated with the 
 existing binomial variable with a specific correlation (say .75).  Any ideas?

Hi.

If X, Y are dependent random variables and we want to generate y, so
that (x, y) is a pair from their joint distribution with known x,
then y should be generated from the conditional distribution P(Y|X=x).
If the probability P(X=x) is not too small, then this may be done by
rejection sampling: Generate pairs (X, Y) until the condition X=x is
satisfied and use the corresponding Y.

It remains to generate pairs (X, Y), where Y is a normal variable
and X a binomial one. The parameters of Y are known, the parameters
of X should be chosen somehow and the correlation of X and Y is
known. I suggest the following. Compute the distribution of X as a
vector of probabilities p_0, ..., p_n (see ?dbinom). Find a nondecreasing
function f() from reals to {0, .., n} such that f(Y) has distribution
p_0, ..., p_n. The function may be determined by a sequence of
cutpoints a_1, ..., a_n defining f(y) as follows

  y  f(y)  
  (-infty, a_1)  0
  [a_1, a_2) 1
  ...
  [a_n, infty)   n

For each i, the cutpoint a_i is the (p_0 + ... + p_{i-1})-quantile of Y
(see ?qnorm). See ?cut for computing f().

The pair (f(Y), Y) has the required marginal distributions and, in my
opinion, the maximal possible correlation. If this correlation is lower
than the requested one, then i think there is no solution.

If the correlation of (f(Y), Y) is at least the required one, then use
a mixture of the distribution (f(Y), Y) and (X, Y), where X has the 
required marginal distribution of X, but is generated independently
from Y. The mixture parameter may be determined as a solution of an
equation with one variable.

Hope this helps.

Petr Savicky.

__
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] regular expression for nth character in a string

2011-04-25 Thread Gonçalo Ferraz
Hi, I have a string

InTrouble

and want to extract, say, the first two characters: In
or the last three: blee
or the 3rd, 4th, and 5th: Trou

Is there an easy way of doing this quickly with regular expressions in gsub, 
grep or similar?

Thank you for any help.

Gonçalo

__
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] regular expression for nth character in a string

2011-04-25 Thread jim holtman
will this do it:


 x - InTrouble
 sub(^(..).*, \\1, x)  # first two
[1] In
 sub(.*(...)$, \\1, x)  # last three
[1] ble
 sub(^..(...).*, \\1, x)  # 3rd,4th,5th char
[1] Tro



2011/4/25 Gonçalo Ferraz gferra...@gmail.com:
 Hi, I have a string

 InTrouble

 and want to extract, say, the first two characters: In
 or the last three: blee
 or the 3rd, 4th, and 5th: Trou

 Is there an easy way of doing this quickly with regular expressions in gsub, 
 grep or similar?

 Thank you for any help.

 Gonçalo

 __
 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.




-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?

__
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] regular expression for nth character in a string

2011-04-25 Thread Jim Lemon

On 04/25/2011 08:17 PM, Gonçalo Ferraz wrote:

Hi, I have a string

InTrouble

and want to extract, say, the first two characters: In
or the last three: blee
or the 3rd, 4th, and 5th: Trou

Is there an easy way of doing this quickly with regular expressions in gsub, 
grep or similar?


Hi Gonçalo,
You could always try:

Im-InTrouble
paste(unlist(strsplit(Im,))[c(7,4,1,2,9,8,5,6,3)],collapse=)

Jim

__
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] regular expression for nth character in a string

2011-04-25 Thread David Winsemius


On Apr 25, 2011, at 6:17 AM, Gonçalo Ferraz wrote:


Hi, I have a string

InTrouble

and want to extract, say, the first two characters: In
or the last three: blee
or the 3rd, 4th, and 5th: Trou

Is there an easy way of doing this quickly with regular expressions  
in gsub, grep or similar?



Not greppish but seems to be the obvious approach:

 substr(Trouble, 1,2)
[1] Tr
 substr(Trouble, 3,5)
[1] oub

The greppish ways:

 sub((^..)(.*$), \\1, Troubles)
[1] Tr

 sub((^..)(...)(.*$), \\2, Troubles)
[1] oub
 sub((^..)(.{3})(.*$), \\2, Troubles)
[1] oub

--

David Winsemius, MD
West Hartford, CT

__
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] filling array with functions

2011-04-25 Thread derek
Richard,

that way I will have to write functions manually and that is not possible
for large number of functions.

derek

--
View this message in context: 
http://r.789695.n4.nabble.com/filling-array-with-functions-tp3468313p3472885.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.


Re: [R] filling array with functions

2011-04-25 Thread peter dalgaard

On Apr 25, 2011, at 12:15 , derek wrote:

 Richard,
 
 that way I will have to write functions manually and that is not possible
 for large number of functions.
 

Well do what he means:

fv - vector(list,10) 
for (i...
{
  ...
  fv[[i]] - ...
  ...
}

(Your code still won't work as written; V[i] will not be evaluated until you 
call the function(s), likely to V[10]. Try something like fv[[i]] - local({zz 
- V[i]; function(x) zz - b*a*x}), or play around with eval(substitute()) )


 derek
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/filling-array-with-functions-tp3468313p3472885.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.

-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.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.


Re: [R] average among one factor in a nested dataframe

2011-04-25 Thread Kenneth Roy Cabrera Torres
Hi Junquian:

I try your code (there is a typo, I believe)

a-rnorm(6)
b-rnorm(9)
f1-c(x1,x2,x3)
f2-c(y1,y2)
id-c(1:6)
a_df-data.frame(cbind(id,f1,y1,a))
id-c(1:9)
b_df-data.frame(cbind(id,f1,y2,b))

But I don't understand the nested databases.
I see that both have f1 variable but I do not see f2 variable in any of
them. So, what do you mean with collapse f2?

Maybe you need to first merge() de databases and then aggregate()
them.

Have a nice day!

El dom, 24-04-2011 a las 23:42 -0500, Junqian Gordon Xu escribió:
 I have two nested data frames:
 
 a-rnorm(6)
 b-rnorm(9)
 f1-c(x1,x2,x3))
 f2-c(y1,y2)
 id-c(1:6)
 a_df-data.frame(cbind(id,f1,y1,a))
 id-c(1:9)
 b_df-data.frame(cbind(id,f1,y2,b))
 
 I want to preserve id and f1, but want to collapse f2 and take the
 corresponding mean values of a and b. Missing value in either dataframe
 should be handled properly (i.e., just take the non-missing number
 without dividing by 2).
 
 I had a look at rowSum/Means and s/l/tapply, but couldn't figure out how
 to handle this case cleanly. Any suggestions?
 
 Thanks
 Gordon
 
 __
 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] average among one factor in a nested dataframe

2011-04-25 Thread Junqian Gordon Xu
Never mind, I find a generic solution:

require(reshape)
melted-melt(dataframe, id=c(id,f1,f2))
averaged=cast(melted,id+f1~variable,mean)

which collapses away f2, and it's easy to generalize this to collapse
any factors.

Thanks anyway
Gordon

On 4/25/11 6:14 AM, Kenneth Roy Cabrera Torres wrote:
 Hi Junquian:
 
 I try your code (there is a typo, I believe)
 
 a-rnorm(6)
 b-rnorm(9)
 f1-c(x1,x2,x3)
 f2-c(y1,y2)
 id-c(1:6)
 a_df-data.frame(cbind(id,f1,y1,a))
 id-c(1:9)
 b_df-data.frame(cbind(id,f1,y2,b))
 
 But I don't understand the nested databases.
 I see that both have f1 variable but I do not see f2 variable in any of
 them. So, what do you mean with collapse f2?
 
 Maybe you need to first merge() de databases and then aggregate()
 them.
 
 Have a nice day!
 
 El dom, 24-04-2011 a las 23:42 -0500, Junqian Gordon Xu escribió:
 I have two nested data frames:

 a-rnorm(6)
 b-rnorm(9)
 f1-c(x1,x2,x3))
 f2-c(y1,y2)
 id-c(1:6)
 a_df-data.frame(cbind(id,f1,y1,a))
 id-c(1:9)
 b_df-data.frame(cbind(id,f1,y2,b))

 I want to preserve id and f1, but want to collapse f2 and take the
 corresponding mean values of a and b. Missing value in either dataframe
 should be handled properly (i.e., just take the non-missing number
 without dividing by 2).

 I had a look at rowSum/Means and s/l/tapply, but couldn't figure out how
 to handle this case cleanly. Any suggestions?

 Thanks
 Gordon

 __
 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] regular expression for nth character in a string

2011-04-25 Thread Gabor Grothendieck
2011/4/25 Gonçalo Ferraz gferra...@gmail.com:
 Hi, I have a string

 InTrouble

 and want to extract, say, the first two characters: In
 or the last three: blee
 or the 3rd, 4th, and 5th: Trou

 Is there an easy way of doing this quickly with regular expressions in gsub, 
 grep or similar?


strapply in gsubfn can readily do that.  It returns the matched part
or, if parentheses are used, only the part in parentheses:

 library(gsubfn)
 strapply(InTrouble, ^.., simplify = TRUE)
[1] In
 strapply(InTrouble, ...$, simplify = TRUE)
[1] ble
 strapply(InTrouble, ^..(...), simplify = TRUE)
[1] Tro
 strapply(InTrouble, ^.{2}(.{3}), simplify = TRUE)
[1] Tro


-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.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.


Re: [R] Defining origin for rotation in RGL device

2011-04-25 Thread Duncan Murdoch

On 25/04/2011 5:46 AM, Mark Heckmann wrote:

Hi all,

How can I tell RGL to set the center for the rotation to the origin of  the 
coordinate system (0,0,0).
It seems that the default is to use the center of the display not the origin of 
the coordinate system.

open3d()
lines3d(c(0, 1), c(0,0), c(0,0))
lines3d(c(0,0), c(0, 1), c(0,0))
lines3d(c(0,0), c(0,0), c(0, 1))



You can attach any transformation you like to a mouse button.  See the 
mouseCallbacks demo for R implementations of the standard ones, and 
modify the mouseTrackball function there to choose the position of the 
origin of the coordinate system as the centre of rotation.


Duncan Murdoch

__
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 \ in strings

2011-04-25 Thread Nutter, Benjamin
Depending on what else you're writing around the %, you might consider
using the latexTranslate() function in Hmisc.

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of viostorm
Sent: Sunday, April 24, 2011 8:48 AM
To: r-help@r-project.org
Subject: Re: [R] help with \ in strings

Josh,

Thank you so much!!! Works perfectly!

-Rob


Robert Schutt III, MD, MCS
Resident - Department of Internal Medicine University of Virginia,
Charlottesville, Virginia 

--
View this message in context:
http://r.789695.n4.nabble.com/help-with-in-strings-tp3470964p3471386.htm
l
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.


===

 Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S.News  World Report (2010).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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 Java methods in R

2011-04-25 Thread hill0093
So the first few posts show that I found out how to 
get Java functions to return type double numbers to R.
The arrays are still a problem.

Here is another of my attempts to understand how to get java arrays into R.
The Java code in class CalqsLin for an array 
of constants named conArr and for a function returning an array is:
public static double[][]conArr=new double[][] { { 10001,10002,10003,10004
},{ 20001,20002,20003,20004 },{ 30001,30002,30003,30004 } }; 
public final static double[][] arReturnTEST() { 
  double[][]retArr=new double[3][4]; for(int i=0;i3;i++)for(int
j=0;j4;j++)retArr[i][j]=i*1000+j; return(retArr); 
} 

I evidently do not know how to retrieve them in R, even with .jevalArray():
 arj34Ret - .jcall(qsLin,returnSig=[[D,arReturnTEST)
 ar34Ret - .jevalArray(arj34Ret)
Error in .jevalArray(arj34Ret) : 
  object is not a Java object reference (jobjRef/jarrayRef).
 connArr - .jevalArray(qsLin.conArr)
Error in .jevalArray(qsLin.conArr) : object 'qsLin.conArr' not found

I need help from someone who calls Java from R.
The whole session was:
 library(rJava)
 .jinit()
 .jaddClassPath(C:/ad/j)
 print(.jclassPath())
[1] C:\\Users\\ENVY17\\Documents\\R\\win-library\\2.12\\rJava\\java
[2] C:\\ad\\j  
 qsLin - .jnew(CalqsLin)
 calStg - 20110424235959
 print(calStg)
[1] 20110424235959
 dblTim -
 .jcall(qsLin,returnSig=D,linTimOfCalqsStgIsLev,calStg,as.integer(-4))
 print(dblTim,digits=20)
[1] 63470908799
 calStg -
 .jcall(qsLin,returnSig=S,calqsStgOfLinTimIsLev,dblTim,as.integer(-4))
 print(calStg)
[1] 20110424235959
 dblTim -
 .jcall(qsLin,returnSig=D,linTimOfCalqsStgIsLev,calStg,as.integer(-4))
 print(dblTim,digits=20)
[1] 63470908799
 arj34Ret - .jcall(qsLin,returnSig=[[D,arReturnTEST)
 ar34Ret - .jevalArray(arj34Ret)
Error in .jevalArray(arj34Ret) : 
  object is not a Java object reference (jobjRef/jarrayRef).
 connArr - .jevalArray(qsLin.conArr)
Error in .jevalArray(qsLin.conArr) : object 'qsLin.conArr' not found
 


--
View this message in context: 
http://r.789695.n4.nabble.com/Using-Java-methods-in-R-tp3469299p3473023.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.


Re: [R] random typing over text

2011-04-25 Thread Kenn Konstabel
On Mon, Apr 25, 2011 at 4:22 AM, Jim Lemon j...@bitwrit.com.au wrote:
 On 04/24/2011 08:13 AM, derek wrote:

 Thank you very much. It was the Insert key. It was very annoying. Actually
 is
 this owerwrite function of any use?

 Hi derek,
 As Duncan mentioned, it is very useful when one wishes to type over existing
 text. However, this is a fairly uncommon wish in the typical GUI user
 environment, where the typist can highlight a group of characters and then
 begin typing. The highlighted characters disappear and the replacement is
 accomplished without changing the behavior of the keyboard. Many
 applications now attempt to guess what you want to highlight by performing
 the operation on words. To me this is not an advantage, for it often means
 that I delete one or more characters beyond what I wish. As Rolf noted, the
 adjacency of the Insert and Delete keys makes it far too easy to switch
 unwittingly to Insert mode. I sometimes wonder whether keyboard designers
 ever have to type, or whether they simply dictate their design inspirations
 into a microphone as some non-typists of my acquaintance do. When I received
 a new PC at work, some bright spark had placed an extra Backslash key next
 to the left Shift key _and_ reduced the size of the Shift key. After a few
 days of typing backslashes every time I wanted a capital letter, I popped
 both keys off and extended the Shift key to mostly cover the useless
 Backslash. I once programmed a special keyboard for a one-handed typist that
 allowed one to reprogram the meaning of keys, thereby accommodating
 individual preference rather than the lumbering Frankenstein of the average
 user. Now that would be a worthwhile innovation.

A reprogrammable Lego keyboard would be good, thanks in advance. If
you do it, would you please consider adding an extra safety feature
for windows users: every time the victim either holds Shift for 8
seconds or presses Shift for 5 times in a row, there would be a nice
voice saying: You just pressed Shift for N times. Ordinarily that
means that Windows will activate StickyKeys(TM) which will make your
keyboard useless until you restart the computer. If you really wish to
activate StickyKeys(TM), press Ctrl-Backspace-Esc for 12 times, then
RightAlt-Tab-F8 for 3 times, and then smile in your webcam for at
least 45 seconds without making any facial movements not directly
required to perform the aforementioned task..

KK

__
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] problem with library tseriesChaos

2011-04-25 Thread Fukushima Shintaro
Hello.

 Is it possible to determine time delay with other function's output or I
 can choose any random value? 

There are several ways to estimate time delay in chaotic time series
analysis.
Please refer to the book Nonlinear time series analysis by Holger Kantz
and Thomas Shreiber.
http://www.amazon.com/Nonlinear-Time-Analysis-Holger-Kantz/dp/0521529026
http://www.amazon.com/Nonlinear-Time-Analysis-Holger-Kantz/dp/0521529026 

For example, time delay is defined as the time when average mutual
information reaches the first local minimum.

Using the package tseriesChaos, it is estimated as follows:

 library(tseriesChaos)
 x.mu - mutual(x, plot=FALSE)
 x.mu.d - diff(x.mu)
 d - min(which(x.mu.d  0)) - 1 

The last two can also be simplied.
 d - which.min(x.mu) - 1

Recently, in Japan, a book has been published on useful packages of R.
http://www.amazon.co.jp/R%E3%83%91%E3%83%83%E3%82%B1%E3%83%BC%E3%82%B8%E3%82%AC%E3%82%A4%E3%83%89%E3%83%96%E3%83%83%E3%82%AF-%E5%B2%A1%E7%94%B0-%E6%98%8C%E5%8F%B2/dp/448902097X
http://www.amazon.co.jp/R%E3%83%91%E3%83%83%E3%82%B1%E3%83%BC%E3%82%B8%E3%82%AC%E3%82%A4%E3%83%89%E3%83%96%E3%83%83%E3%82%AF-%E5%B2%A1%E7%94%B0-%E6%98%8C%E5%8F%B2/dp/448902097X
 

I wrote an article on the packages RTisean and tseriesChaos.
There, I showed an example of estimating the maximum Lyapunov exponent,
using the NH3 laser data.
The source code is available from the following website.
https://gist.github.com/4efa66686c24f158f7e9
https://gist.github.com/4efa66686c24f158f7e9 

I would be happy to be of any service to you.

--
View this message in context: 
http://r.789695.n4.nabble.com/problem-with-library-tseriesChaos-tp3449830p3473028.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] probit regression marginal effects

2011-04-25 Thread Quark
Dear R-community,

I am currently replicating a study and obtain mostly the same results as the 
author. At one point, however, I calculate marginal effects that seem to be 
unrealistically small. I would greatly appreciate if you could have a look at 
my reasoning and the code below and see if I am mistaken at one point or 
another.

My sample contains 24535 observations, the dependent variable x028bin is a 
binary variable taking on the values 0 and 1, and there are furthermore 10 
explaining variables. Nine of those independent variables have numeric levels, 
the independent variable f025grouped is a factor consisting of country names.

I would like to run a probit regression including country dummies and then 
compute marginal effects. In order to do so, I first eliminate missing values 
and use cross-tabs between the dependent and independent variables to verify 
that there are no small or 0 cells. Then I run the probit model which works 
fine and I obtain reasonable results:

 probit4AKIE - glm(x028bin ~ x003 + x003squ + x025secv2 + x025terv2 + x007bin 
 + x04chief + x011rec + a009bin + x045mod + c001bin + f025grouped, 
 family=binomial(link=probit), data=wvshm5red2delna, na.action=na.pass) 

 summary(probit4AKIE)


However, when calculating marginal effects with all variables at their means 
from the probit coefficients and a scale factor, the marginal effects I obtain 
are much too small (e.g. 2.6042e-78). My code looks like this:

 ttt - cbind(wvshm5red2delna$x003,
wvshm5red2delna$x003squ,
wvshm5red2delna$x025secv2,
wvshm5red2delna$x025terv2,
wvshm5red2delna$x007bin,
wvshm5red2delna$x04chief,
wvshm5red2delna$x011rec,
wvshm5red2delna$a009bin,
wvshm5red2delna$x045mod,
wvshm5red2delna$c001bin,
wvshm5red2delna$f025grouped,
wvshm5red2delna$f025grouped,
wvshm5red2delna$f025grouped,
wvshm5red2delna$f025grouped,
wvshm5red2delna$f025grouped,
wvshm5red2delna$f025grouped,
wvshm5red2delna$f025grouped,
wvshm5red2delna$f025grouped,
wvshm5red2delna$f025grouped) #I put variable f025grouped 9 times because this 
variable consists of 9 levels

 ttt - as.data.frame(ttt)

 xbar - as.matrix(mean(cbind(1,ttt[1:19]))) #1:19 position of variables in 
 dataframe ttt

 betaprobit4AKIE - probit4AKIE$coefficients

 zxbar - t(xbar) %*% betaprobit4AKIE

 scalefactor - dnorm(zxbar)

 marginprobit4AKIE - scalefactor * betaprobit4AKIE[2:20] #2:20 are the 
 positions of variables in the output of the probit model 'probit4AKIE' 
 (variables need to be in the same ordering as in data.frame ttt), the 
 constant in the model occupies the first position

 marginprobit4AKIE #in this step I obtain values that are much too small


I apologize that I can not provide you with a working example as my dataset is 
much too large. Any comment would be greatly appreciated. Thanks a lot.

Best,

Tobias
-- 
GMX DSL Doppel-Flat ab 19,99 Euro/mtl.! Jetzt mit 
gratis Handy-Flat! http://portal.gmx.net/de/go/dsl

__
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] Two Copies of Each Message

2011-04-25 Thread david.jessop
I have the same problem - it's happened before and then just fixed itself.  But 
rather annoying. 

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Thomas Lumley
Sent: 23 April 2011 00:34
To: Stephen P Molnar
Cc: R-help
Subject: Re: [R] Two Copies of Each Message

On Sat, Apr 23, 2011 at 12:25 AM, Stephen P Molnar s.mol...@sbcglobal.net 
wrote:
 I receive two copies of every message posted to this list.



 How can I stop this?  I have read the Primary Help web page and 
 searched the achieves without finding an answer.



Unsubscribe from the list.  You will then either receive one copy (because you 
have another address subscribed), in which case you are done, or no copies, in 
which case you should be able to resubscribe and get just one copy.

-thomas

--
Thomas Lumley
Professor of Biostatistics
University of Auckland

__
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.

Issued by UBS AG or affiliates to professional investors...{{dropped:30}}

__
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] blank space escape sequence in R?

2011-04-25 Thread Mark Heckmann
Is there a blank space escape sequence in R, i.e. something like \sp etc. to 
produce a blank space?

TIA
Mark
–––
Mark Heckmann
Blog: www.markheckmann.de
R-Blog: http://ryouready.wordpress.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.


Re: [R] blank space escape sequence in R?

2011-04-25 Thread Duncan Murdoch

On 25/04/2011 9:01 AM, Mark Heckmann wrote:

Is there a blank space escape sequence in R, i.e. something like \sp etc. to 
produce a blank space?


You need to give some context.  A blank in a character vector will be 
printed as a blank, so you are probably talking about something else, 
but what?


Duncan Murdoch

__
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] blank space escape sequence in R?

2011-04-25 Thread Mark Heckmann
I use a function that inserts line breaks (\n as escape sequence) according 
to some criterion when there are blanks in the string.
e.g. some text \nand some more text.

What I want now is another form of a blank, so my function will not insert a 
”\n at that point.
e.g. some text\spaceand some more text

Here \space stands for some escape sequence for a  blank, which is what I am 
looking for. 
So what I need is something that will appear as a blank when printed but not in 
the string itself.

TIA

Am 25.04.2011 um 15:05 schrieb Duncan Murdoch:

 On 25/04/2011 9:01 AM, Mark Heckmann wrote:
 Is there a blank space escape sequence in R, i.e. something like \sp etc. to 
 produce a blank space?
 
 You need to give some context.  A blank in a character vector will be printed 
 as a blank, so you are probably talking about something else, but what?
 
 Duncan Murdoch

–––
Mark Heckmann
Blog: www.markheckmann.de
R-Blog: http://ryouready.wordpress.com





[[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] Survival analysis: same subject with multiple treatments

2011-04-25 Thread Terry Therneau
---Begin inclusion --
I need some help to figure out what is the proper model in survival
analysis
for my data.
Subjects were randomized to 3 treatments in trial 1, some of them
experience
the event during the trial;
After period of time those subjects were randomized to 3 treatments
again in
trial 2, but different from what they got in 1st trial, some of them
experience the event during the 2nd trial (I think the carryover effect
can
be ignored since the time between two trials is long enough.)
---end inclusion --

If it were me I would add cluster(subject) to the model. Multiple
events/subject is not simple, however, and you should find a book
chapter to read.

Terry Therneau

__
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] blank space escape sequence in R?

2011-04-25 Thread Duncan Murdoch

On 25/04/2011 9:13 AM, Mark Heckmann wrote:

I use a function that inserts line breaks (\n as escape sequence) according 
to some criterion when there are blanks in the string.
e.g. some text \nand some more text.

What I want now is another form of a blank, so my function will not insert a 
”\n at that point.
e.g. some text\spaceand some more text

Here \space stands for some escape sequence for a  blank, which is what I am 
looking for.
So what I need is something that will appear as a blank when printed but not in 
the string itself.


I don't think R has anything like that built in.   You'll need to attach 
a class to your vector of strings, and write a print method for it that 
does the substitution before printing.


Duncan Murdoch


TIA

Am 25.04.2011 um 15:05 schrieb Duncan Murdoch:

  On 25/04/2011 9:01 AM, Mark Heckmann wrote:
  Is there a blank space escape sequence in R, i.e. something like \sp etc. 
to produce a blank space?

  You need to give some context.  A blank in a character vector will be 
printed as a blank, so you are probably talking about something else, but what?

  Duncan Murdoch

–––
Mark Heckmann
Blog: www.markheckmann.de
R-Blog: http://ryouready.wordpress.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] R workshop in Hamilton, Ontario, May 24 and 25

2011-04-25 Thread John Fox
Dear r-help list members,

I'll be teaching a two-day introductory R workshop at McMaster University in
Hamilton, Ontario, on May 24 and 25. The workshop will largely be based on
materials from Fox and Weisberg, An R Companion to Applied Regression,
Second Edition (Sage, 2011). Further information about the workshop is
available at
https://www.socialsciences.mcmaster.ca/registrations/john-fox-introduction-
to-r/fg_base_view_p3. I've asked that a few spaces in the workshop be
reserved for non-McMaster attendees and made available at a modest cost.

Regards,
 John


John Fox
Senator William McMaster
  Professor of Social Statistics
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
http://socserv.mcmaster.ca/jfox

__
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 typing over text

2011-04-25 Thread peter dalgaard

On Apr 25, 2011, at 14:52 , Kenn Konstabel wrote:
...
 means that Windows will activate StickyKeys(TM) which will make your
 keyboard useless until you restart the computer. 

...or, apparently, press both shift keys simultaneously, whichever comes first.

Now, whoever decided that CapsLock should be 3rd or 4th largest key on my 
keyboard

-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.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.


Re: [R] blank space escape sequence in R?

2011-04-25 Thread Jan van der Laan

There exists a non-breaking space:

http://en.wikipedia.org/wiki/Non-breaking_space

Perhaps you could use this. In R on Linux under gnome-terminal I can 
enter it with CTRL+SHIFT+U00A0. This seems to work: it prints as a 
space, but is not equal to ' '. I don't know if there are any 
difficulties using, for example, utf8 encoding in source files (which 
you'll probably need).


Jan



On 04/25/2011 03:28 PM, Duncan Murdoch wrote:

On 25/04/2011 9:13 AM, Mark Heckmann wrote:
I use a function that inserts line breaks (\n as escape sequence) 
according to some criterion when there are blanks in the string.

e.g. some text \nand some more text.

What I want now is another form of a blank, so my function will not 
insert a ”\n at that point.

e.g. some text\spaceand some more text

Here \space stands for some escape sequence for a  blank, which is 
what I am looking for.
So what I need is something that will appear as a blank when printed 
but not in the string itself.


I don't think R has anything like that built in.   You'll need to 
attach a class to your vector of strings, and write a print method for 
it that does the substitution before printing.


Duncan Murdoch


TIA

Am 25.04.2011 um 15:05 schrieb Duncan Murdoch:

  On 25/04/2011 9:01 AM, Mark Heckmann wrote:
  Is there a blank space escape sequence in R, i.e. something like 
\sp etc. to produce a blank space?


  You need to give some context.  A blank in a character vector will 
be printed as a blank, so you are probably talking about something 
else, but what?


  Duncan Murdoch

–––
Mark Heckmann
Blog: www.markheckmann.de
R-Blog: http://ryouready.wordpress.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] blank space escape sequence in R?

2011-04-25 Thread Jan van der Laan

There exists a non-breaking space:

http://en.wikipedia.org/wiki/Non-breaking_space

Perhaps you could use this. In R on Linux under gnome-terminal I can 
enter it with CTRL+SHIFT+U00A0. This seems to work: it prints as a 
space, but is not equal to ' '. I don't know if there are any 
difficulties using, for example, utf8 encoding in source files (which 
you'll probably need).


Jan




On 04/25/2011 03:28 PM, Duncan Murdoch wrote:

On 25/04/2011 9:13 AM, Mark Heckmann wrote:
I use a function that inserts line breaks (\n as escape sequence) 
according to some criterion when there are blanks in the string.

e.g. some text \nand some more text.

What I want now is another form of a blank, so my function will not 
insert a ”\n at that point.

e.g. some text\spaceand some more text

Here \space stands for some escape sequence for a  blank, which is 
what I am looking for.
So what I need is something that will appear as a blank when printed 
but not in the string itself.


I don't think R has anything like that built in.   You'll need to 
attach a class to your vector of strings, and write a print method for 
it that does the substitution before printing.


Duncan Murdoch


TIA

Am 25.04.2011 um 15:05 schrieb Duncan Murdoch:

  On 25/04/2011 9:01 AM, Mark Heckmann wrote:
  Is there a blank space escape sequence in R, i.e. something like 
\sp etc. to produce a blank space?


  You need to give some context.  A blank in a character vector will 
be printed as a blank, so you are probably talking about something 
else, but what?


  Duncan Murdoch

–––
Mark Heckmann
Blog: www.markheckmann.de
R-Blog: http://ryouready.wordpress.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] problem with library tseriesChaos

2011-04-25 Thread Uwe Ligges

Dear Fukushima Shintaro,

please also reply to the person who asked the question (she or he might 
not be subscribed to the mailing list). Additionally, please always 
quote the original question. Other mailing list readers won't lerned 
from an answer without corresponding question.


Thank you for providing help, best wishes,
Uwe Ligges



On 25.04.2011 14:32, Fukushima Shintaro wrote:

Hello.


Is it possible to determine time delay with other function's output or I
can choose any random value?


There are several ways to estimate time delay in chaotic time series
analysis.
Please refer to the book Nonlinear time series analysis by Holger Kantz
and Thomas Shreiber.
http://www.amazon.com/Nonlinear-Time-Analysis-Holger-Kantz/dp/0521529026
http://www.amazon.com/Nonlinear-Time-Analysis-Holger-Kantz/dp/0521529026

For example, time delay is defined as the time when average mutual
information reaches the first local minimum.

Using the package tseriesChaos, it is estimated as follows:


library(tseriesChaos)
x.mu- mutual(x, plot=FALSE)
x.mu.d- diff(x.mu)
d- min(which(x.mu.d  0)) - 1


The last two can also be simplied.

d- which.min(x.mu) - 1


Recently, in Japan, a book has been published on useful packages of R.
http://www.amazon.co.jp/R%E3%83%91%E3%83%83%E3%82%B1%E3%83%BC%E3%82%B8%E3%82%AC%E3%82%A4%E3%83%89%E3%83%96%E3%83%83%E3%82%AF-%E5%B2%A1%E7%94%B0-%E6%98%8C%E5%8F%B2/dp/448902097X
http://www.amazon.co.jp/R%E3%83%91%E3%83%83%E3%82%B1%E3%83%BC%E3%82%B8%E3%82%AC%E3%82%A4%E3%83%89%E3%83%96%E3%83%83%E3%82%AF-%E5%B2%A1%E7%94%B0-%E6%98%8C%E5%8F%B2/dp/448902097X

I wrote an article on the packages RTisean and tseriesChaos.
There, I showed an example of estimating the maximum Lyapunov exponent,
using the NH3 laser data.
The source code is available from the following website.
https://gist.github.com/4efa66686c24f158f7e9
https://gist.github.com/4efa66686c24f158f7e9

I would be happy to be of any service to you.

--
View this message in context: 
http://r.789695.n4.nabble.com/problem-with-library-tseriesChaos-tp3449830p3473028.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] Random Relabelling

2011-04-25 Thread kmatthews
Thanks to everyone... this helps a lot.  Just a quick question about
etiquette in this forum (as it my first time questioning)... are notes of
gratitude usually given in these forums?

On Wed, Apr 20, 2011 at 1:26 PM, jthetzel [via R] 
ml-node+3463799-950416470-231...@n4.nabble.com wrote:

 Kevin,

 The following follows John's suggestion, but without the loop.  It's quick
 for me.

 Jeremy


 Jeremy T. Hetzel
 Boston University



 ## Generate sample data
 n - 4000
 rep - 1000
 rate - rnorm(n, mean = 15, sd = 2) / 10 # Mortality rates around
 15/100k

 ## Create an empty matrix with appropriate dimensions
 permutations - matrix(ncol = n, nrow = rep)

 ## Use apply() to resample
 permutations - apply(permutations, 1, function(x)
 {
 sample(rate, size = n, replace = F)
 })

 ## Look at the matrix
 dim(permutations)
 head(permutations)

 ## Find the column means
 means - apply(permutations, 1, mean)
 means





 On Wednesday, April 20, 2011 1:56:35 PM UTC-4, John Kane wrote:

 
  There is probably a better way to do this but a for loop like this should

  work. You would just need to change the numbers to yours and then add on
 the
  locations
  =
 
  scores  - 1:5
  mydata - matrix(data=NA, nrow=5, ncol=10)
 
  for(i in 1:10) {
  mydata[,i] - sample(scores, 5, replace=FALSE)
  }
 
  =
  --- On Wed, 4/20/11, Kevin Matthews [hidden 
  email]http://user/SendEmail.jtp?type=nodenode=3463799i=0by-user=t
 wrote:
 
  From: Kevin Matthews [hidden 
  email]http://user/SendEmail.jtp?type=nodenode=3463799i=1by-user=t

  Subject: Re: [R] Random Relabelling
  To: John Kane [hidden 
  email]http://user/SendEmail.jtp?type=nodenode=3463799i=2by-user=t

  Cc: [hidden 
  email]http://user/SendEmail.jtp?type=nodenode=3463799i=3by-user=t
  Received: Wednesday, April 20, 2011, 1:22 PM
 
  I have a map of Iowa of with 4000 locations.  At each location, I have a
  cancer mortality rate.  I need to test my null hypothesis; that the
 spatial
  distribution of the mortality rates is  random.  For this test, I need to

  establish a spatial reference distribution.
 
 
  My reference distribution will be created by some random relabelling
  algorithm.  The 4000 locations would remain fixed, but the observed
  mortality rates would be randomly redistributed.  Then, I want 1000
  permutations of the same algorithm.  For each of those 1000 times, I
 would
  record the redistributed mortality rate at each location.  Then,  I would

  calculate the mean of the 1000 points.  The result would be a spatial
  reference distribution with a mean value of the random permutations at
 each
  of the 4000 locations.
 
  Thanks for the response,Kevin
 
  On Wed, Apr 20, 2011 at 11:08 AM, John Kane [hidden 
  email]http://user/SendEmail.jtp?type=nodenode=3463799i=4by-user=t
 wrote:
 
 
  Can you explain this a bit more. At the moment I don't see what you are
  trying to achieve.   calculate the mean of the 1000 values at each of
 the
  4000 points does not seem to make sense.
 
  --- On Wed, 4/20/11, kmatthews [hidden 
  email]http://user/SendEmail.jtp?type=nodenode=3463799i=5by-user=t
 wrote:
 
   From: kmatthews [hidden 
   email]http://user/SendEmail.jtp?type=nodenode=3463799i=6by-user=t

 
   Subject: [R] Random Relabelling
 
   To: [hidden 
   email]http://user/SendEmail.jtp?type=nodenode=3463799i=7by-user=t
 
   Received: Wednesday, April 20, 2011, 10:04 AM
 
   I have 4000 observations that I need
 
   to randomly relabel 1000 times and then
 
   calculate the mean of the 1000 values at each of the 4000
 
   points.  Any ideas
 
   for where to begin?
 
  
 
   Thanks
 
   Kevin
 
  
 
 
  [[alternative HTML version deleted]]
 
  __
  [hidden 
  email]http://user/SendEmail.jtp?type=nodenode=3463799i=8by-user=tmailing
   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.
 
 
 __
 [hidden 
 email]http://user/SendEmail.jtp?type=nodenode=3463799i=9by-user=tmailing 
 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.
 Jeremy T. Hetzel
 Boston University


 --
  If you reply to this email, your message will be added to the discussion
 below:
 http://r.789695.n4.nabble.com/Random-Relabelling-tp3463100p3463799.html
  To unsubscribe from Random Relabelling, click 
 herehttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_codenode=3463100code=a2V2aW4tbWF0dGhld3NAdWlvd2EuZWR1fDM0NjMxMDB8MTg3NTE4Mzk1OA==.




--
View this message in context: 
http://r.789695.n4.nabble.com/Random-Relabelling-tp3463100p3473298.html

Re: [R] blank space escape sequence in R?

2011-04-25 Thread Mike Miller

On Mon, 25 Apr 2011, Mark Heckmann wrote:

I use a function that inserts line breaks (\n as escape sequence) 
according to some criterion when there are blanks in the string. e.g. 
some text \nand some more text.


What I want now is another form of a blank, so my function will not 
insert a ?\n at that point. e.g. some text\spaceand some more text


Here \space stands for some escape sequence for a blank, which is what 
I am looking for. So what I need is something that will appear as a 
blank when printed but not in the string itself.



Is it possible to use \x20 or some similar way to evoke the hexadecimal 
ascii form of blank?  That works in perl as does \040 for the octal form.


Mike

__
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] filling array with functions

2011-04-25 Thread derek
Still I haven't had any luck yet.
How about defining new function and its domain, is it somehow possible?
Like this:
a-function(x) x beolongs to natural numbers 0,100

--
View this message in context: 
http://r.789695.n4.nabble.com/filling-array-with-functions-tp3468313p3473300.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.


Re: [R] Questions about lrm, validate, pentrace (Re: BMA, logistic regression, odds ratio, model reduction etc)

2011-04-25 Thread Frank Harrell
You've done a lot of good work on this.  Yes I would say you have moderate
overfitting with the first model.  The only thing that saved you from having
severe overfitting is that there seems to be a signal present [I am assume
this model is truly pre-specified and was not developed at all by looking at
patterns of responses Y.]

The use of backwards stepdown demonstrated much worse overfitting.  This is
in line with what we know about the damage of stepwise selection methods
that do not incorporate shrinkage.  I would throw away the stepwise
regression model.  You'll find that the model selected is entirely
arbitrary.  And you can't use the selected variables in any re-fit of the
model, i.e., you can't use lrm pretending that the two remaining variables
were pre-specified.  Stepwise regression methods only seem to help.  When
assessed properly we see that is an illusion.

You are using penalizing properly but you did not print the full table of
penalties vs. effective AIC.  We don't have faith that you penalized enough. 
I tend to run pentrace using a very wide range of possible penalties to make
sure I've found the global optimum.

Penalization somewhat solves the EPV problem but there is no substitute for
getting more data.

You can run validate specifying your final penalty as an argument.

Frank



細田弘吉 wrote:
 
 According to the advice, I tried rms package.
 Just to make sure, I have data of 104 patients (x6.df), which consists 
 of 5 explanatory variables and one binary outcome (poor/good) (previous 
 model 2 strategy). The outcome consists of 25 poor results and 79 good 
 results. Therefore, My events per variable (EPV) is only 5 (much less 
 than the rule of thumb of 10).
 
 My questions are about validate and pentrace in rms package.
 I present some codes and results.
 I appreciate anybody's help in advance.
 
   x6.lrm - lrm(outcome ~ stenosis+x1+x2+procedure+ClinicalScore, 
 data=x6.df, x=T, y=T)
 
   x6.lrm
 ...
 Obs  104LR chi2  29.24R2   0.367C   0.816
   negative 79d.f. 5g1.633Dxy 0.632
   positive 25Pr( chi2) 0.0001   gr5.118gamma   0.632
 max |deriv| 1e-08gp0.237tau-a   0.233
   Brier   0.127
 
 CoefS.E.   Wald Z Pr(|Z|)
 Intercept  -5.5328 2.6287 -2.10  0.0353
 stenosis   -0.0150 0.0284 -0.53  0.5979
 x1  3.0425 0.9100  3.34  0.0008
 x2 -0.7534 0.4519 -1.67  0.0955
 procedure   1.2085 0.5717  2.11  0.0345
 ClinicalScore   0.3762 0.2287  1.65  0.0999
 
 It seems not too bad. Next, validation by bootstrap ...
 
   validate(x6.lrm, B=200, bw=F)
index.orig trainingtest optimism index.corrected   n
 Dxy   0.6324   0.6960  0.5870   0.1091  0.5233 200
 R20.3668   0.4370  0.3154   0.1216  0.2453 200
 Intercept 0.   0. -0.2007   0.2007 -0.2007 200
 Slope 1.   1.  0.7565   0.2435  0.7565 200
 Emax  0.   0.  0.0999   0.0999  0.0999 200
 D 0.2716   0.3368  0.2275   0.1093  0.1623 200
 U-0.0192  -0.0192  0.0369  -0.0561  0.0369 200
 Q 0.2908   0.3560  0.1906   0.1654  0.1254 200
 B 0.1272   0.1155  0.1384  -0.0229  0.1501 200
 g 1.6328   2.0740  1.4647   0.6093  1.0235 200
 gp0.2367   0.2529  0.2189   0.0341  0.2026 200
 
 The apparent Dxy is 0.63, and bias-corrected Dxy is 0.52. The maximum 
 absolute error is estimated to be 0.099. The changes in slope and 
 intercept are also more substantial. In all, there is evidence that I am 
 somewhat overfitting the data, right?.
 
 Furthermore, using step-down variable selection ...
 
   validate(x6.lrm, B=200, bw=T)
 
   Backwards Step-down - Original Model
 
   DeletedChi-Sq d.f. P  Residual d.f. P  AIC
   stenosis   0.28   10.5979 0.28 10.5979 -1.72
   ClinicalScore  2.60   10.1068 2.88 20.2370 -1.12
   x2 2.86   10.0910 5.74 30.1252 -0.26
 
 Approximate Estimates after Deleting Factors
 
   Coef   S.E. Wald Z P
 Intercept  -5.865 1.4136 -4.149 3.336e-05
 x1  2.915 0.8685  3.357 7.889e-04
 procedure   1.072 0.5590  1.918 5.508e-02
 
 Factors in Final Model
 
 [1] x1 procedure
index.orig trainingtest optimism index.corrected   n
 Dxy   0.5661   0.6755  0.5559   0.1196  0.4464 200
 R20.2876   0.4085  0.2784   0.1301  0.1575 200
 Intercept 0.   0. -0.2459   0.2459 -0.2459 200
 Slope 1.   1.  0.7300   0.2700  0.7300 200
 Emax  0.   0.  0.1173   0.1173  0.1173 200
 D 0.2038   0.3130  0.1970   0.1160  0.0877 200
 U-0.0192  -0.0192  0.0382  -0.0574  0.0382 200
 Q 

Re: [R] Random Relabelling

2011-04-25 Thread David Winsemius


On Apr 25, 2011, at 10:53 AM, kmatthews wrote:


Thanks to everyone... this helps a lot.  Just a quick question about
etiquette in this forum (as it my first time questioning)... are  
notes of

gratitude usually given in these forums?


The practice varies, some people do appreciate it. Doing so when one  
is not subscribed, however, adds many additional mouse-maneuvers to  
the moderator workload, ...  wasted time in my opinion. I would  
suggest a private thank you message in that instance (or even more to  
be preferred ... subscribing.)


--
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] R equivalent to (D)QDAWO in Fortran?

2011-04-25 Thread Bao, Wenkai
Hi useRs,

I have a set of fortran code that was passed down from previous students, and I 
am converting its algorithm into R codes.

I encounter this function in Fortran (D)QDAWO, which numerically integrates a 
function f with a user-specified cosine or sine weight. It is used because the 
original function that I want to integrate is f(x)*cos(x).

I tried in R to directly integrate by integrate(g(x)), where g(x)=f(x)*cos(x), 
but a lot of error messages and warnings were given. So is there some function 
in R that is equivalent to this QDAWO in Fortran, to specifically integrate a 
function with a sine or cosine component?

Thank you very much!

__
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] Problem with grid's text-based units and TrueType fonts

2011-04-25 Thread Al Roark

Hi all:
I'm using grid to create a layout in R that will include text mixed with 
graphics.  In the layout, the positions of certain graphical elements depend on 
the number of lines in adjacent text blocks (which will vary from case to 
case).  I was hoping to use grid's built in functions to automate the placement 
of the graphical elements.  I can get this to work if I use the standard pdf 
device, but when using the Cairo_pdf device (from the cairoDevice package), I 
run into problems.  I need the TrueType functionality of Cairo.
The example below illustrates my problem. The rectangle in SizeMatch.pdf 
matches the size of the text block, while the rectangle in SizeMismatch.pdf 
is too small.  Why is this the case?  I'm using R-2.13.0 (32bit) on Windows 7.  
Thanks a bunch.  Cheers, Al
---
library(cairoDevice)library(grid)
Cairo_pdf(SizeMismatch.pdf,11,8.5,pointsize=10)pushViewport(viewport(gp=gpar(fontfamily=Arial,font=1,fontsize=8,lineheight=0.9)))grid.text(The
 quick\nbrown fox\njumps\nover\nthe lazy 
dog)grid.rect(width=0.5,height=unit(5,lines))dev.off()
pdf(SizeMatch.pdf,11,8.5,pointsize=10)pushViewport(viewport(gp=gpar(fontfamily=Times,font=1,fontsize=8,lineheight=0.9)))grid.text(The
 quick\nbrown fox\njumps\nover\nthe lazy 
dog)grid.rect(width=0.5,height=unit(5,lines))dev.off()   
   
[[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] Defining origin for rotation in RGL device

2011-04-25 Thread Duncan Murdoch

On 25/04/2011 7:54 AM, Duncan Murdoch wrote:

On 25/04/2011 5:46 AM, Mark Heckmann wrote:
  Hi all,

  How can I tell RGL to set the center for the rotation to the origin of  the 
coordinate system (0,0,0).
  It seems that the default is to use the center of the display not the origin 
of the coordinate system.

  open3d()
  lines3d(c(0, 1), c(0,0), c(0,0))
  lines3d(c(0,0), c(0, 1), c(0,0))
  lines3d(c(0,0), c(0,0), c(0, 1))


You can attach any transformation you like to a mouse button.  See the
mouseCallbacks demo for R implementations of the standard ones, and
modify the mouseTrackball function there to choose the position of the
origin of the coordinate system as the centre of rotation.


This was a little trickier than I was thinking because of the weird 
coordinate system.  You have to remember to transpose translationMatrix 
when you're planning to work in the coordinates of userMatrix.   Here's 
a function (modified from mouseTrackball in the demo) that I think does 
what you want.


Just call

mouseTrackballOrigin()

to set it up on button 1 on the current device with center of rotation 
at (0,0,0).


Duncan Murdoch

mouseTrackballOrigin - function(button = 1, dev = rgl.cur(), 
origin=c(0,0,0) ) {

width - height - rotBase - NULL
userMatrix - list()
cur - rgl.cur()
offset - NULL
scale - NULL

screenToVector - function(x, y) {
  radius - max(width, height)/2
  centre - c(width, height)/2
  pt - (c(x, y) - centre)/radius
  len - vlen(pt)

  if (len  1.e-6) pt - pt/len

  maxlen - sqrt(2)
  angle - (maxlen - len)/maxlen*pi/2
  z - sin(angle)
  len - sqrt(1 - z^2)
  pt - pt * len
  return (c(pt, z))
}

trackballBegin - function(x, y) {
vp - par3d(viewport)
width - vp[3]
height - vp[4]
cur - rgl.cur()
bbox - par3d(bbox)
center - c(sum(bbox[1:2])/2, sum(bbox[3:4])/2, sum(bbox[5:6])/2)
scale - par3d(scale)
offset - (center - origin)*scale
for (i in dev) {
if (inherits(try(rgl.set(i, TRUE)), try-error)) dev - 
dev[dev != i]

else userMatrix[[i]] - par3d(userMatrix)
}
rgl.set(cur, TRUE)
rotBase - screenToVector(x, height - y)
}

trackballUpdate - function(x,y) {
rotCurrent - screenToVector(x, height - y)
angle - angle(rotBase, rotCurrent)
axis - xprod(rotBase, rotCurrent)
mouseMatrix - rotationMatrix(angle, axis[1], axis[2], axis[3])
for (i in dev) {
if (inherits(try(rgl.set(i, TRUE)), try-error)) dev - 
dev[dev != i]
else par3d(userMatrix = t(translationMatrix(-offset[1], 
-offset[2], -offset[3])) %*% mouseMatrix  %*% 
t(translationMatrix(offset[1], offset[2], offset[3])) %*%userMatrix[[i]])

}
rgl.set(cur, TRUE)
}

for (i in dev) {
rgl.set(i, TRUE)
rgl.setMouseCallbacks(button, begin = trackballBegin, update = 
trackballUpdate, end = NULL)

}
rgl.set(cur, TRUE)
}

__
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] Pass String from R to C

2011-04-25 Thread Jaimin Dave
I tried using char ** but it is printing some random string.

On Sat, Apr 23, 2011 at 6:08 PM, Duncan Murdoch murdoch.dun...@gmail.comwrote:

 On 11-04-23 7:04 PM, Jaimin Dave wrote:

 Hi,
 I am using a function which accepts the string from R and prints it.
 But when I am calling .C(main,hello);
 it is printing any random thing.
 My C function is
 void main(char *str)


 See Writing R Extensions.  The declaration should be char **str.

 Duncan Murdoch

  {
 Rprintf(%s,str);
 }

 Can you help how to achieve this using .C interface?

 Thanks
 Jaimin

[[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.htmlhttp://www.r-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible 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.


Re: [R] Pass String from R to C

2011-04-25 Thread Duncan Murdoch

On 25/04/2011 12:51 PM, Jaimin Dave wrote:

I tried using char ** but it is printing some random string.


str is a pointer to an array of pointers to strings.  That's what char** 
means.  So you need to declare it that way, and use it that way.


This works for me:

File test.c:

void test(char **str)
{
  Rprintf(%s,*str);
}

Duncan Murdoch

On Sat, Apr 23, 2011 at 6:08 PM, Duncan Murdochmurdoch.dun...@gmail.comwrote:

  On 11-04-23 7:04 PM, Jaimin Dave wrote:

  Hi,
  I am using a function which accepts the string from R and prints it.
  But when I am calling .C(main,hello);
  it is printing any random thing.
  My C function is
  void main(char *str)


  See Writing R Extensions.  The declaration should be char **str.

  Duncan Murdoch

   {
  Rprintf(%s,str);
  }

  Can you help how to achieve this using .C interface?

  Thanks
  Jaimin

 [[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.htmlhttp://www.r-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible 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] Pass String from R to C

2011-04-25 Thread Duncan Murdoch

On 25/04/2011 1:03 PM, Duncan Murdoch wrote:

On 25/04/2011 12:51 PM, Jaimin Dave wrote:
  I tried using char ** but it is printing some random string.

str is a pointer to an array of pointers to strings.  That's what char**
means.  So you need to declare it that way, and use it that way.

This works for me:

File test.c:

void test(char **str)
{
Rprintf(%s,*str);
}


Oops, I just noticed that the include was missing.  The full file should 
have


#include R.h

at the beginning.

Duncan Murdoch



Duncan Murdoch
  On Sat, Apr 23, 2011 at 6:08 PM, Duncan 
Murdochmurdoch.dun...@gmail.comwrote:

 On 11-04-23 7:04 PM, Jaimin Dave wrote:
  
 Hi,
 I am using a function which accepts the string from R and prints it.
 But when I am calling .C(main,hello);
 it is printing any random thing.
 My C function is
 void main(char *str)
  
  
 See Writing R Extensions.  The declaration should be char **str.
  
 Duncan Murdoch
  
  {
 Rprintf(%s,str);
 }
  
 Can you help how to achieve this using .C interface?
  
 Thanks
 Jaimin
  
[[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.htmlhttp://www.r-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible 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] merge with origin information in new variable names

2011-04-25 Thread Eric Fail
Is there anyone out there who can suggest a way to solve this problem?

Thanks,
Esben

On Sun, Apr 24, 2011 at 8:53 PM, Jeff Newmiller
jdnew...@dcn.davis.ca.us wrote:
 Merge only lets you combine two tables at a time, but it does have a
 suffix argument that is intended to address your concern, but only for
 variable names that would conflict.

 In your example, the id variables are all sequenced exactly the same, so you
 could actually use cbind rather than merge.

 However, whether you use merge or cbind, I think the most direct route to
 your desired result is to rename the data columns before you combine them,
 using the names function on the left hand side of an assignment with a
 vector of new names on the right.
 ---
 Jeff Newmiller The . . Go Live...
 DCN:jdnew...@dcn.davis.ca.us Basics: ##.#. ##.#. Live Go...
 Live: OO#.. Dead: OO#.. Playing
 Research Engineer (Solar/Batteries O.O#. #.O#. with
 /Software/Embedded Controllers) .OO#. .OO#. rocks...1k
 ---
 Sent from my phone. Please excuse my brevity.

 Eric Fail eric.f...@gmx.com wrote:

 Dear R-list,

 Here is my simple question,

 I have n data frames that I would like to merge, but I can't figure out
 how to add information about the origin of the variable(s).

 Here is my problem,

 DF.wave.1 - data.frame(id=1:10,var.A=sample(letters[1:4],10,TRUE))
 DF.wave.2 - data.frame(id=1:10,var.M=sample(letters[5:8],10,TRUE))
 DF.wave.3 - data.frame(id=1:10,var.A=sample(letters[5:8],10,TRUE))

 Now; I would like to merge the three dataframes into one, but append a
 suffix to the individual variables names about thir origin.

 DF.wave.all - merge(DF.wave.1,DF.wave.2,DF.wave.3,by=id, [what to do
 here])

 In other words, I would like it to loook like this.

 DF.wave.all
id var.A.wave.1 var.M.wave.2 var.A.wave.3
 1   1chj
 2   2cej
 3   3cgk
 4   4cej
 5   5cgi
 6   6dek
 7   7chk
 8   8bgj
 9   9bfi
 10 10dhi


 Is there a command I can use directly in merge? 'suffixes' isn't really
 handy here.

 Thanks,
 Eric
 
 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] Problem with ddply in the plyr-package: surprising output of a date-column

2011-04-25 Thread Christoph Jäckel
Hi Together,

I have a problem with the plyr package - more precisely with the ddply
function - and would be very grateful for any help. I hope the example
here is precise enough for someone to identify the problem. Basically,
in this step I want to identify observations that are identical in
terms of certain identifiers (ID1, ID2, ID3) and just want to save
those observations (in this step, without deleting any rows or
manipulating any data) in a separate data.frame. However, I get the
warning message below and the column with dates is messed up.
Interestingly, the value column (the type is factor here, but if you
change that with as.integer it doesn't make any difference) is handled
correctly. Any idea what I do wrong?

df - 
data.frame(cbind(ID1=c(1,2,2,3,3,4,4),ID2=c('a','b','b','c','d','e','e'),ID3=c(v1,v1,v1,v1,v2,v1,v1),

Date=c(1985-05-1,1985-05-2,1985-05-3,1985-05-4,1985-05-5,1985-05-6,1985-05-7),
 Value=c(1,2,3,4,5,6,7)))
df[,1] - as.character(df[,1])
df[,2] - as.character(df[,2])
df$Date   - strptime(df$Date,%Y-%m-%d)

#Apparently there are two observation that have the same IDs: ID1=2 and ID1=4
ddply(df,.(ID1,ID2,ID3),nrow)
#I want to save those IDs in a separate data.frame, so the desired output is:
df[c(2:3,6:7),]

#My idea: Write a custom function that only returns observations with
multiple rows.
#Seems to work except that the Date column doesn't make any sense anymore
#Warning message: In output[[var]][rng] - df[[var]]: number of items
to replace is not a multiple of replacement length
ddply(df,.(ID1,ID2,ID3),function(df) if(nrow(df)=1){NULL}else{df})

#Notice that it works perfectly if I only have one observation with
multiple rows
ddply(df[1:6,],.(ID1,ID2,ID3),function(df) if(nrow(df)=1){NULL}else{df})

Thanks in advance,

Christoph



Christoph Jäckel (Dipl.-Kfm.)



Research Assistant

Chair for Financial Management and Capital Markets | Lehrstuhls für
Finanzmanagement und Kapitalmärkte

TUM School of Management | Technische Universität München

Arcisstr. 21 | D-80333 München | Germany

__
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] blank space escape sequence in R?

2011-04-25 Thread Matt Shotwell
You can embed hex escapes in strings (except \x00). The value(s) that
you embed will depend on the character encoding used on you platform. If
this is UTF-8, or some other ASCII compatible encoding, \x20 will work:

 foo\x20bar
[1] foo bar


For other locales, you might try charToRaw( ) to see the binary (hex)
representation for the space character on your platform, and substitute
this sequence instead.

On Mon, 2011-04-25 at 15:01 +0200, Mark Heckmann wrote:
 Is there a blank space escape sequence in R, i.e. something like \sp etc. to 
 produce a blank space?
 
 TIA
 Mark
 –––
 Mark Heckmann
 Blog: www.markheckmann.de
 R-Blog: http://ryouready.wordpress.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] merge with origin information in new variable names

2011-04-25 Thread Phil Spector

Eric -
As others have said, you should change the names of the variables
in the data frames before you merge them.  Here's one implementation
of that idea:

   DF.wave.1 - data.frame(id=1:10,var.A=sample(letters[1:4],10,TRUE))
   DF.wave.2 - data.frame(id=1:10,var.M=sample(letters[5:8],10,TRUE))
   DF.wave.3 - data.frame(id=1:10,var.A=sample(letters[5:8],10,TRUE))

   nms = paste('wave',1:3,sep='.')
   dfs = list(DF.wave.1,DF.wave.2,DF.wave.3)
   names(dfs) = nms

   changenm = function(nm){
   df = dfs[[nm]]
   wh = names(df) != 'id'
   names(df)[wh] = paste(names(df)[wh],nm,sep='.')
   df
   }

   Reduce(function(x,y)merge(x,y,by='id'),lapply(names(dfs),changenm))

- Phil Spector
 Statistical Computing Facility
 Department of Statistics
 UC Berkeley
 spec...@stat.berkeley.edu




On Mon, 25 Apr 2011, Eric Fail wrote:


Is there anyone out there who can suggest a way to solve this problem?

Thanks,
Esben

On Sun, Apr 24, 2011 at 8:53 PM, Jeff Newmiller
jdnew...@dcn.davis.ca.us wrote:

Merge only lets you combine two tables at a time, but it does have a
suffix argument that is intended to address your concern, but only for
variable names that would conflict.

In your example, the id variables are all sequenced exactly the same, so you
could actually use cbind rather than merge.

However, whether you use merge or cbind, I think the most direct route to
your desired result is to rename the data columns before you combine them,
using the names function on the left hand side of an assignment with a
vector of new names on the right.
---
Jeff Newmiller The . . Go Live...
DCN:jdnew...@dcn.davis.ca.us Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---
Sent from my phone. Please excuse my brevity.

Eric Fail eric.f...@gmx.com wrote:


Dear R-list,

Here is my simple question,

I have n data frames that I would like to merge, but I can't figure out
how to add information about the origin of the variable(s).

Here is my problem,

DF.wave.1 - data.frame(id=1:10,var.A=sample(letters[1:4],10,TRUE))
DF.wave.2 - data.frame(id=1:10,var.M=sample(letters[5:8],10,TRUE))
DF.wave.3 - data.frame(id=1:10,var.A=sample(letters[5:8],10,TRUE))

Now; I would like to merge the three dataframes into one, but append a
suffix to the individual variables names about thir origin.

DF.wave.all - merge(DF.wave.1,DF.wave.2,DF.wave.3,by=id, [what to do
here])

In other words, I would like it to loook like this.

DF.wave.all
   id var.A.wave.1 var.M.wave.2 var.A.wave.3
1   1chj
2   2cej
3   3cgk
4   4cej
5   5cgi
6   6dek
7   7chk
8   8bgj
9   9bfi
10 10dhi


Is there a command I can use directly in merge? 'suffixes' isn't really
handy here.

Thanks,
Eric

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.


[R] Help with objects

2011-04-25 Thread Russ Abbott
Hi all,

I would appreciate some help in understanding how to find out about objects.
For example, to the extent that I understand R it seems to treat everything
as an object even without declaring them as objects. Everything has
attributes, for example, which are like instance variables in objects. In
addition, there are S3 and S3 category objects.  Is there a good
introductory description of how these are different from standard R objects
and how they are different from each other?

Also, how does one find out more about how objects are declared. For
example, Data Mining with
Rhttp://www.liaad.up.pt/~ltorgo/DataMiningWithR/code3.htmluses the
quantmod package. I am used to Java's JavaDoc where one can see how
classes are declared, what the instance variables and methods are, etc. I
don't see anything similar for this package.  How, for example, would one
find out what the instance variables are in a quantmod object and what the
methods are that are defined on quantmod objects? I know that there is the
standard quantmod documentation, but that doesn't seem
to distinguish between standard functions and class-based methods. Nor, as
far as I can see, does it describe the instance variables in a quantmod
object.

Thanks.

*-- Russ Abbott*
*_*
***  Professor, Computer Science*
*  California State University, Los Angeles*

*  Google voice: 747-*999-5105
*  blog: *http://russabbott.blogspot.com/
  vita:  http://sites.google.com/site/russabbott/
*_*

[[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] blank space escape sequence in R?

2011-04-25 Thread Matt Shotwell
I may have misread your original email. Whether you use a hex escape or
a space character, the resulting string in memory is identical:

 identical(a\x20b, a b)
[1] TRUE

But, if you were to read a file containing the six characters a
\x20b (say with readLines), then the six characters would be read into
memory, and printed like this:

a\\x20b

That is, not with a space character substituted for \x20. So, now I'm
not sure this is a solution.

On Mon, 2011-04-25 at 12:24 -0500, Matt Shotwell wrote:
 You can embed hex escapes in strings (except \x00). The value(s) that
 you embed will depend on the character encoding used on you platform. If
 this is UTF-8, or some other ASCII compatible encoding, \x20 will work:
 
  foo\x20bar
 [1] foo bar
 
 
 For other locales, you might try charToRaw( ) to see the binary (hex)
 representation for the space character on your platform, and substitute
 this sequence instead.
 
 On Mon, 2011-04-25 at 15:01 +0200, Mark Heckmann wrote:
  Is there a blank space escape sequence in R, i.e. something like \sp etc. 
  to produce a blank space?
  
  TIA
  Mark
  –––
  Mark Heckmann
  Blog: www.markheckmann.de
  R-Blog: http://ryouready.wordpress.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-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] blank space escape sequence in R?

2011-04-25 Thread Petr Savicky
On Mon, Apr 25, 2011 at 04:37:15PM +0200, Jan van der Laan wrote:
 There exists a non-breaking space:
 
 http://en.wikipedia.org/wiki/Non-breaking_space
 
 Perhaps you could use this. In R on Linux under gnome-terminal I can 
 enter it with CTRL+SHIFT+U00A0. This seems to work: it prints as a 
 space, but is not equal to ' '.

This character may be specified as \u00A0.

  a - abc\u00A0def
  a
  [1] abc def
  
The utf-8 representation of the obtained string is

  charToRaw(a)
  [1] 61 62 63 c2 a0 64 65 66

Using Unicode package, the string may be analyzed as follows 

  library(Unicode)
  u_char_inspect(as.u_char_seq(a, ))

  Code Name Char
  1 U+0061 LATIN SMALL LETTER Aa
  2 U+0062 LATIN SMALL LETTER Bb
  3 U+0063 LATIN SMALL LETTER Cc
  4 U+00A0   NO-BREAK SPACE 
  5 U+0064 LATIN SMALL LETTER Dd
  6 U+0065 LATIN SMALL LETTER Ee
  7 U+0066 LATIN SMALL LETTER Ff

Hope this helps.

Petr Savicky.

__
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] extracting names from matrix according to a condition

2011-04-25 Thread ivan
Dear Community,

I have a matrix with assigned colnames and rolnames as follows:

AB
NR0.15  0,05
AL 0,05  0,05
.   ..
.   ..
.   ..

I want to extract the names of the rows for which A0,1 and B0,1. In
the above example this would be observation NR only. Hence the output
should write for instance:

names:
NR

Is this possible? Thank you very much for your help.

Best Regards

__
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] Problem with ddply in the plyr-package: surprising output of a date-column

2011-04-25 Thread Brian Diggs

On 4/25/2011 10:19 AM, Christoph Jäckel wrote:

Hi Together,

I have a problem with the plyr package - more precisely with the ddply
function - and would be very grateful for any help. I hope the example
here is precise enough for someone to identify the problem. Basically,
in this step I want to identify observations that are identical in
terms of certain identifiers (ID1, ID2, ID3) and just want to save
those observations (in this step, without deleting any rows or
manipulating any data) in a separate data.frame. However, I get the
warning message below and the column with dates is messed up.
Interestingly, the value column (the type is factor here, but if you
change that with as.integer it doesn't make any difference) is handled
correctly. Any idea what I do wrong?

df- 
data.frame(cbind(ID1=c(1,2,2,3,3,4,4),ID2=c('a','b','b','c','d','e','e'),ID3=c(v1,v1,v1,v1,v2,v1,v1),

Date=c(1985-05-1,1985-05-2,1985-05-3,1985-05-4,1985-05-5,1985-05-6,1985-05-7),
  Value=c(1,2,3,4,5,6,7)))
df[,1]- as.character(df[,1])
df[,2]- as.character(df[,2])
df$Date- strptime(df$Date,%Y-%m-%d)

#Apparently there are two observation that have the same IDs: ID1=2 and ID1=4
ddply(df,.(ID1,ID2,ID3),nrow)
#I want to save those IDs in a separate data.frame, so the desired output is:
df[c(2:3,6:7),]

#My idea: Write a custom function that only returns observations with
multiple rows.
#Seems to work except that the Date column doesn't make any sense anymore
#Warning message: In output[[var]][rng]- df[[var]]: number of items
to replace is not a multiple of replacement length
ddply(df,.(ID1,ID2,ID3),function(df) if(nrow(df)=1){NULL}else{df})

#Notice that it works perfectly if I only have one observation with
multiple rows
ddply(df[1:6,],.(ID1,ID2,ID3),function(df) if(nrow(df)=1){NULL}else{df})


Works for me:

 df[c(2:3,6:7),]
  ID1 ID2 ID3  Date Value
2   2   b  v1 1985-05-2 2
3   2   b  v1 1985-05-3 3
6   4   e  v1 1985-05-6 6
7   4   e  v1 1985-05-7 7
 ddply(df,.(ID1,ID2,ID3),function(df) if(nrow(df)=1){NULL}else{df})
  ID1 ID2 ID3  Date Value
1   2   b  v1 1985-05-2 2
2   2   b  v1 1985-05-3 3
3   4   e  v1 1985-05-6 6
4   4   e  v1 1985-05-7 7
 sessionInfo()
R version 2.13.0 (2011-04-13)
Platform: x86_64-pc-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

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

other attached packages:
[1] plyr_1.5.2

loaded via a namespace (and not attached):
[1] tools_2.13.0

A couple of things: there was just an update of plyr to 1.5.2; maybe 
that fixes what you are seeing?  Also, your df consists of only factors. 
 cbind-ing the data before turning it into a data.frame makes it a 
character matrix which gets converted to factors.


 str(df)
'data.frame':   7 obs. of  5 variables:
 $ ID1  : Factor w/ 4 levels 1,2,3,4: 1 2 2 3 3 4 4
 $ ID2  : Factor w/ 5 levels a,b,c,d,..: 1 2 2 3 4 5 5
 $ ID3  : Factor w/ 2 levels v1,v2: 1 1 1 1 2 1 1
 $ Date : Factor w/ 7 levels 1985-05-1,1985-05-2,..: 1 2 3 4 5 6 7
 $ Value: Factor w/ 7 levels 1,2,3,4,..: 1 2 3 4 5 6 7

Maybe that has something to do with the odd dates since they are not 
really dates at all, just string representations of factor levels. 
Compare with:


DF - data.frame(ID1=c(1,2,2,3,3,4,4),
ID2=c('a','b','b','c','d','e','e'),
ID3=c(v1,v1,v1,v1,v2,v1,v1),
Date=as.Date(c(1985-05-1,1985-05-2,1985-05-3,
1985-05-4,1985-05-5,1985-05-6,1985-05-7)),
Value=c(1,2,3,4,5,6,7))
str(DF)
#'data.frame':   7 obs. of  5 variables:
# $ ID1  : num  1 2 2 3 3 4 4
# $ ID2  : Factor w/ 5 levels a,b,c,d,..: 1 2 2 3 4 5 5
# $ ID3  : Factor w/ 2 levels v1,v2: 1 1 1 1 2 1 1
# $ Date : Date, format: 1985-05-01 1985-05-02 ...
# $ Value: num  1 2 3 4 5 6 7

This version also works for me.

ddply(DF,.(ID1,ID2,ID3),function(df) if(nrow(df)=1){NULL}else{df})
#  ID1 ID2 ID3   Date Value
#1   2   b  v1 1985-05-02 2
#2   2   b  v1 1985-05-03 3
#3   4   e  v1 1985-05-06 6
#4   4   e  v1 1985-05-07 7


Thanks in advance,

Christoph



Christoph Jäckel (Dipl.-Kfm.)



Research Assistant

Chair for Financial Management and Capital Markets | Lehrstuhls für
Finanzmanagement und Kapitalmärkte

TUM School of Management | Technische Universität München

Arcisstr. 21 | D-80333 München | Germany




--
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health  Science University


Re: [R] blank space escape sequence in R?

2011-04-25 Thread Mark Heckmann
Thanks, Matt!
\x20 works great for me!

Am 25.04.2011 um 19:42 schrieb Matt Shotwell:

 I may have misread your original email. Whether you use a hex escape or
 a space character, the resulting string in memory is identical:
 
 identical(a\x20b, a b)
 [1] TRUE
 
 But, if you were to read a file containing the six characters a
 \x20b (say with readLines), then the six characters would be read into
 memory, and printed like this:
 
 a\\x20b
 
 That is, not with a space character substituted for \x20. So, now I'm
 not sure this is a solution.
 
 On Mon, 2011-04-25 at 12:24 -0500, Matt Shotwell wrote:
 You can embed hex escapes in strings (except \x00). The value(s) that
 you embed will depend on the character encoding used on you platform. If
 this is UTF-8, or some other ASCII compatible encoding, \x20 will work:
 
 foo\x20bar
 [1] foo bar
 
 
 For other locales, you might try charToRaw( ) to see the binary (hex)
 representation for the space character on your platform, and substitute
 this sequence instead.
 
 On Mon, 2011-04-25 at 15:01 +0200, Mark Heckmann wrote:
 Is there a blank space escape sequence in R, i.e. something like \sp etc. 
 to produce a blank space?
 
 TIA
 Mark
 –––
 Mark Heckmann
 Blog: www.markheckmann.de
 R-Blog: http://ryouready.wordpress.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.
 
 

–––
Mark Heckmann
Blog: www.markheckmann.de
R-Blog: http://ryouready.wordpress.com





[[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] Problem with ddply in the plyr-package: surprising output of a date-column

2011-04-25 Thread Peter Ehlers

On 2011-04-25 10:19, Christoph Jäckel wrote:

Hi Together,

I have a problem with the plyr package - more precisely with the ddply
function - and would be very grateful for any help. I hope the example
here is precise enough for someone to identify the problem. Basically,
in this step I want to identify observations that are identical in
terms of certain identifiers (ID1, ID2, ID3) and just want to save
those observations (in this step, without deleting any rows or
manipulating any data) in a separate data.frame. However, I get the
warning message below and the column with dates is messed up.
Interestingly, the value column (the type is factor here, but if you
change that with as.integer it doesn't make any difference) is handled
correctly. Any idea what I do wrong?

df- 
data.frame(cbind(ID1=c(1,2,2,3,3,4,4),ID2=c('a','b','b','c','d','e','e'),ID3=c(v1,v1,v1,v1,v2,v1,v1),

Date=c(1985-05-1,1985-05-2,1985-05-3,1985-05-4,1985-05-5,1985-05-6,1985-05-7),
  Value=c(1,2,3,4,5,6,7)))
df[,1]- as.character(df[,1])
df[,2]- as.character(df[,2])
df$Date- strptime(df$Date,%Y-%m-%d)

#Apparently there are two observation that have the same IDs: ID1=2 and ID1=4
ddply(df,.(ID1,ID2,ID3),nrow)
#I want to save those IDs in a separate data.frame, so the desired output is:
df[c(2:3,6:7),]

#My idea: Write a custom function that only returns observations with
multiple rows.
#Seems to work except that the Date column doesn't make any sense anymore
#Warning message: In output[[var]][rng]- df[[var]]: number of items
to replace is not a multiple of replacement length
ddply(df,.(ID1,ID2,ID3),function(df) if(nrow(df)=1){NULL}else{df})

#Notice that it works perfectly if I only have one observation with
multiple rows
ddply(df[1:6,],.(ID1,ID2,ID3),function(df) if(nrow(df)=1){NULL}else{df})


I would characterize your problem as:
a) using strptime - this is what gives ddply() fits;

b) not using str() to check whether R agrees with
   you with respect to your data;

c) using cbind() inside data.frame(). This isn't
   wrong, but is rarely (in my experience) useful.

If you use as.Date (or even nothing) on your Date
variable, you'll find that ddply does what you want.
To see why it doesn't work with strptime, check
str(df) and then ?Posixlt. You've converted Date
values to lists.

My comment about cbind() is to warn you that your
Values variable, as you have constructed it, is
a factor.

Peter Ehlers



Thanks in advance,

Christoph



Christoph Jäckel (Dipl.-Kfm.)



Research Assistant

Chair for Financial Management and Capital Markets | Lehrstuhls für
Finanzmanagement und Kapitalmärkte

TUM School of Management | Technische Universität München

Arcisstr. 21 | D-80333 München | Germany

__
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 objects

2011-04-25 Thread Duncan Murdoch

Russ Abbott wrote:

Hi all,

I would appreciate some help in understanding how to find out about objects.
For example, to the extent that I understand R it seems to treat everything
as an object even without declaring them as objects.


That's correct.

 Everything has

attributes, for example, which are like instance variables in objects.


That's not quite true.  There are a few special kinds of objects which 
can't have attributes.  The NULL object is the only one you're likely to 
meet in regular code.


 In

addition, there are S3 and S3 category objects.  Is there a good
introductory description of how these are different from standard R objects
and how they are different from each other?


S3 and S4 are layers put on top of the regular system for handling 
objects.  S3 objects just have a class attribute, which causes some 
functions to handle them specially; this is introduced in An 
Introduction to R, and more fully described in the R Language 
Definition.  S4 is a more complex system, partly described in the 
?Methods help topic, more completely in the references listed on that page.


Duncan Murdoch


Also, how does one find out more about how objects are declared. For
example, Data Mining with
Rhttp://www.liaad.up.pt/~ltorgo/DataMiningWithR/code3.htmluses the
quantmod package. I am used to Java's JavaDoc where one can see how
classes are declared, what the instance variables and methods are, etc. I
don't see anything similar for this package.  How, for example, would one
find out what the instance variables are in a quantmod object and what the
methods are that are defined on quantmod objects? I know that there is the
standard quantmod documentation, but that doesn't seem
to distinguish between standard functions and class-based methods. Nor, as
far as I can see, does it describe the instance variables in a quantmod
object.

Thanks.

*-- Russ Abbott*
*_*
***  Professor, Computer Science*
*  California State University, Los Angeles*

*  Google voice: 747-*999-5105
*  blog: *http://russabbott.blogspot.com/
  vita:  http://sites.google.com/site/russabbott/
*_*

[[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] extracting names from matrix according to a condition

2011-04-25 Thread Peter Ehlers

On 2011-04-25 10:58, ivan wrote:

Dear Community,

I have a matrix with assigned colnames and rolnames as follows:

 AB
NR0.15  0,05
AL 0,05  0,05
.   ..
.   ..
.   ..

I want to extract the names of the rows for which A0,1 and B0,1. In
the above example this would be observation NR only. Hence the output
should write for instance:

names:
NR

Is this possible? Thank you very much for your help.


Call the matrix m. Then

 rownames(m[ m[, A]  0.1  m[, B]  0.1, , drop=FALSE ])

should do what you want.

Peter Ehlers

__
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] [SPAM] - R equivalent to (D)QDAWO in Fortran? - Found word(s) list error in the Text body

2011-04-25 Thread David Reiner
dqdawo is an IMSL routine which is similar to QUADPACK's dqawo. (The initial d 
is for double precision),
and maybe similar to NAG's d01anf.
If you search for 'imsl qdawo' you should find some more description.

On the other hand, the error messages may give someone enough information to 
help you directly.
Maybe your function f() is not vectorized?
See the posting guide linked to at the bottom of every posting here.
Follow it well to get incredible help here; don't follow it to get guesses or 
no response.

HTH,
-- David

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Bao, Wenkai
Sent: Monday, April 25, 2011 11:04 AM
To: r-help@r-project.org
Subject: [SPAM] - [R] R equivalent to (D)QDAWO in Fortran? - Found word(s) list 
error in the Text body

Hi useRs,

I have a set of fortran code that was passed down from previous students, and I 
am converting its algorithm into R codes.

I encounter this function in Fortran (D)QDAWO, which numerically integrates a 
function f with a user-specified cosine or sine weight. It is used because the 
original function that I want to integrate is f(x)*cos(x).

I tried in R to directly integrate by integrate(g(x)), where g(x)=f(x)*cos(x), 
but a lot of error messages and warnings were given. So is there some function 
in R that is equivalent to this QDAWO in Fortran, to specifically integrate a 
function with a sine or cosine component?

Thank you very much!

__
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.


This e-mail and any materials attached hereto, including, without limitation, 
all content hereof and thereof (collectively, XR Content) are confidential 
and proprietary to XR Trading, LLC (XR) and/or its affiliates, and are 
protected by intellectual property laws.  Without the prior written consent of 
XR, the XR Content may not (i) be disclosed to any third party or (ii) be 
reproduced or otherwise used by anyone other than current employees of XR or 
its affiliates, on behalf of XR or its affiliates.

THE XR CONTENT IS PROVIDED AS IS, WITHOUT REPRESENTATIONS OR WARRANTIES OF ANY 
KIND.  TO THE MAXIMUM EXTENT PERMISSIBLE UNDER APPLICABLE LAW, XR HEREBY 
DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS AND IMPLIED, RELATING TO THE XR 
CONTENT, AND NEITHER XR NOR ANY OF ITS AFFILIATES SHALL IN ANY EVENT BE LIABLE 
FOR ANY DAMAGES OF ANY NATURE WHATSOEVER, INCLUDING, BUT NOT LIMITED TO, 
DIRECT, INDIRECT, CONSEQUENTIAL, SPECIAL AND PUNITIVE DAMAGES, LOSS OF PROFITS 
AND TRADING LOSSES, RESULTING FROM ANY PERSON'S USE OR RELIANCE UPON, OR 
INABILITY TO USE, ANY XR CONTENT, EVEN IF XR IS ADVISED OF THE POSSIBILITY OF 
SUCH DAMAGES OR IF SUCH DAMAGES WERE FORESEEABLE.

__
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] Problem with ddply in the plyr-package: surprising output of a date-column

2011-04-25 Thread William Dunlap


Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com  

 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of Brian Diggs
 Sent: Monday, April 25, 2011 11:05 AM
 To: christoph.jaec...@wi.tum.de
 Cc: r-help@r-project.org
 Subject: Re: [R] Problem with ddply in the plyr-package: 
 surprising output of a date-column
 
 On 4/25/2011 10:19 AM, Christoph Jäckel wrote:
  Hi Together,
 
  I have a problem with the plyr package - more precisely 
 with the ddply
  function - and would be very grateful for any help. I hope 
 the example
  here is precise enough for someone to identify the problem. 
 Basically,
  in this step I want to identify observations that are identical in
  terms of certain identifiers (ID1, ID2, ID3) and just want to save
  those observations (in this step, without deleting any rows or
  manipulating any data) in a separate data.frame. However, I get the
  warning message below and the column with dates is messed up.
  Interestingly, the value column (the type is factor here, but if you
  change that with as.integer it doesn't make any difference) 
 is handled
  correctly. Any idea what I do wrong?
 
  df- 
 data.frame(cbind(ID1=c(1,2,2,3,3,4,4),ID2=c('a','b','b','c','d
','e','e'),ID3=c(v1,v1,v1,v1,v2,v1,v1),
 
  
 Date=c(1985-05-1,1985-05-2,1985-05-3,1985-05-4,1985-0
 5-5,1985-05-6,1985-05-7),
Value=c(1,2,3,4,5,6,7)))
  df[,1]- as.character(df[,1])
  df[,2]- as.character(df[,2])
  df$Date- strptime(df$Date,%Y-%m-%d)
 
  #Apparently there are two observation that have the same 
 IDs: ID1=2 and ID1=4
  ddply(df,.(ID1,ID2,ID3),nrow)
  #I want to save those IDs in a separate data.frame, so the 
 desired output is:
  df[c(2:3,6:7),]
 
  #My idea: Write a custom function that only returns 
 observations with
  multiple rows.
  #Seems to work except that the Date column doesn't make any 
 sense anymore
  #Warning message: In output[[var]][rng]- df[[var]]: number of items
  to replace is not a multiple of replacement length
  ddply(df,.(ID1,ID2,ID3),function(df) if(nrow(df)=1){NULL}else{df})
 
  #Notice that it works perfectly if I only have one observation with
  multiple rows
  ddply(df[1:6,],.(ID1,ID2,ID3),function(df) 
 if(nrow(df)=1){NULL}else{df})
 
 Works for me:
 
   df[c(2:3,6:7),]
ID1 ID2 ID3  Date Value
 2   2   b  v1 1985-05-2 2
 3   2   b  v1 1985-05-3 3
 6   4   e  v1 1985-05-6 6
 7   4   e  v1 1985-05-7 7
   ddply(df,.(ID1,ID2,ID3),function(df) if(nrow(df)=1){NULL}else{df})
ID1 ID2 ID3  Date Value
 1   2   b  v1 1985-05-2 2
 2   2   b  v1 1985-05-3 3
 3   4   e  v1 1985-05-6 6
 4   4   e  v1 1985-05-7 7
 [ ... version info elided ... ] 
 A couple of things: there was just an update of plyr to 1.5.2; maybe 
 that fixes what you are seeing?  Also, your df consists of 
 only factors. 
   cbind-ing the data before turning it into a data.frame makes it a 
 character matrix which gets converted to factors.
 
   str(df)
 'data.frame':   7 obs. of  5 variables:
   $ ID1  : Factor w/ 4 levels 1,2,3,4: 1 2 2 3 3 4 4
   $ ID2  : Factor w/ 5 levels a,b,c,d,..: 1 2 2 3 4 5 5
   $ ID3  : Factor w/ 2 levels v1,v2: 1 1 1 1 2 1 1
   $ Date : Factor w/ 7 levels 1985-05-1,1985-05-2,..: 1 2 
 3 4 5 6 7
   $ Value: Factor w/ 7 levels 1,2,3,4,..: 1 2 3 4 5 6 7

The OP's data.frame contained a POSIXlt (not factor) object
in the Date column
   str(df)
  'data.frame':   7 obs. of  5 variables:
   $ ID1  : chr  1 2 2 3 ...
   $ ID2  : chr  a b b c ...
   $ ID3  : Factor w/ 2 levels v1,v2: 1 1 1 1 2 1 1
   $ Date : POSIXlt, format: 1985-05-01 1985-05-02 ...
   $ Value: Factor w/ 7 levels 1,2,3,4,..: 1 2 3 4 5 6 7
and apparently plyr's equivalent of rbind doesn't support that class.

If you want to continue using POSIXlt objects you can get your
immediate result without ddply; subscripting will do the job:
   nDups - with(df, ave(rep(0,nrow(df)), ID1, ID2, ID3, FUN=length))
   print(nDups)
  [1] 1 2 2 1 1 2 2
   df[nDups1, ]
ID1 ID2 ID3   Date Value
  2   2   b  v1 1985-05-02 2
  3   2   b  v1 1985-05-03 3
  6   4   e  v1 1985-05-06 6
  7   4   e  v1 1985-05-07 7
   str(.Last.value)
  'data.frame':   4 obs. of  5 variables:
   $ ID1  : chr  2 2 4 4
   $ ID2  : chr  b b e e
   $ ID3  : Factor w/ 2 levels v1,v2: 1 1 1 1
   $ Date : POSIXlt, format: 1985-05-02 1985-05-03 ...
   $ Value: Factor w/ 7 levels 1,2,3,4,..: 2 3 6 7

If you need plyr for other tasks you ought to use a different
class for your date data (or wait until plyr can deal with
POSIXlt objects).

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

 
 Maybe that has something to do with the odd dates since 
 they are not 
 really dates at all, just string representations of factor levels. 
 Compare with:
 
 DF - data.frame(ID1=c(1,2,2,3,3,4,4),
   ID2=c('a','b','b','c','d','e','e'),
   ID3=c(v1,v1,v1,v1,v2,v1,v1),
   Date=as.Date(c(1985-05-1,1985-05-2,1985-05-3,
   

Re: [R] extracting names from matrix according to a condition

2011-04-25 Thread ivan
thank you very much. worked great for me.

On Mon, Apr 25, 2011 at 8:22 PM, Peter Ehlers ehl...@ucalgary.ca wrote:
 On 2011-04-25 10:58, ivan wrote:

 Dear Community,

 I have a matrix with assigned colnames and rolnames as follows:

             A            B
 NR    0.15      0,05
 AL     0,05      0,05
 .           .            .
 .           .            .
 .           .            .

 I want to extract the names of the rows for which A0,1 and B0,1. In
 the above example this would be observation NR only. Hence the output
 should write for instance:

 names:
 NR

 Is this possible? Thank you very much for your help.

 Call the matrix m. Then

  rownames(m[ m[, A]  0.1  m[, B]  0.1, , drop=FALSE ])

 should do what you want.

 Peter Ehlers


__
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] Problem with ddply in the plyr-package: surprising output of a date-column

2011-04-25 Thread Brian Diggs

On 4/25/2011 11:55 AM, William Dunlap wrote:



Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


-Original Message-
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of Brian Diggs
Sent: Monday, April 25, 2011 11:05 AM
To: christoph.jaec...@wi.tum.de
Cc: r-help@r-project.org
Subject: Re: [R] Problem with ddply in the plyr-package:
surprising output of a date-column

On 4/25/2011 10:19 AM, Christoph Jäckel wrote:

Hi Together,

I have a problem with the plyr package - more precisely

with the ddply

function - and would be very grateful for any help. I hope

the example

here is precise enough for someone to identify the problem.

Basically,

in this step I want to identify observations that are identical in
terms of certain identifiers (ID1, ID2, ID3) and just want to save
those observations (in this step, without deleting any rows or
manipulating any data) in a separate data.frame. However, I get the
warning message below and the column with dates is messed up.
Interestingly, the value column (the type is factor here, but if you
change that with as.integer it doesn't make any difference)

is handled

correctly. Any idea what I do wrong?

df-

data.frame(cbind(ID1=c(1,2,2,3,3,4,4),ID2=c('a','b','b','c','d

','e','e'),ID3=c(v1,v1,v1,v1,v2,v1,v1),




Date=c(1985-05-1,1985-05-2,1985-05-3,1985-05-4,1985-0
5-5,1985-05-6,1985-05-7),

   Value=c(1,2,3,4,5,6,7)))
df[,1]- as.character(df[,1])
df[,2]- as.character(df[,2])
df$Date- strptime(df$Date,%Y-%m-%d)

#Apparently there are two observation that have the same

IDs: ID1=2 and ID1=4

ddply(df,.(ID1,ID2,ID3),nrow)
#I want to save those IDs in a separate data.frame, so the

desired output is:

df[c(2:3,6:7),]

#My idea: Write a custom function that only returns

observations with

multiple rows.
#Seems to work except that the Date column doesn't make any

sense anymore

#Warning message: In output[[var]][rng]- df[[var]]: number of items
to replace is not a multiple of replacement length
ddply(df,.(ID1,ID2,ID3),function(df) if(nrow(df)=1){NULL}else{df})

#Notice that it works perfectly if I only have one observation with
multiple rows
ddply(df[1:6,],.(ID1,ID2,ID3),function(df)

if(nrow(df)=1){NULL}else{df})

Works for me:

df[c(2:3,6:7),]
ID1 ID2 ID3  Date Value
2   2   b  v1 1985-05-2 2
3   2   b  v1 1985-05-3 3
6   4   e  v1 1985-05-6 6
7   4   e  v1 1985-05-7 7
ddply(df,.(ID1,ID2,ID3),function(df) if(nrow(df)=1){NULL}else{df})
ID1 ID2 ID3  Date Value
1   2   b  v1 1985-05-2 2
2   2   b  v1 1985-05-3 3
3   4   e  v1 1985-05-6 6
4   4   e  v1 1985-05-7 7
[ ... version info elided ... ]
A couple of things: there was just an update of plyr to 1.5.2; maybe
that fixes what you are seeing?  Also, your df consists of
only factors.
   cbind-ing the data before turning it into a data.frame makes it a
character matrix which gets converted to factors.

str(df)
'data.frame':   7 obs. of  5 variables:
   $ ID1  : Factor w/ 4 levels 1,2,3,4: 1 2 2 3 3 4 4
   $ ID2  : Factor w/ 5 levels a,b,c,d,..: 1 2 2 3 4 5 5
   $ ID3  : Factor w/ 2 levels v1,v2: 1 1 1 1 2 1 1
   $ Date : Factor w/ 7 levels 1985-05-1,1985-05-2,..: 1 2
3 4 5 6 7
   $ Value: Factor w/ 7 levels 1,2,3,4,..: 1 2 3 4 5 6 7


The OP's data.frame contained a POSIXlt (not factor) object
in the Date column
 str(df)
   'data.frame':   7 obs. of  5 variables:
$ ID1  : chr  1 2 2 3 ...
$ ID2  : chr  a b b c ...
$ ID3  : Factor w/ 2 levels v1,v2: 1 1 1 1 2 1 1
$ Date : POSIXlt, format: 1985-05-01 1985-05-02 ...
$ Value: Factor w/ 7 levels 1,2,3,4,..: 1 2 3 4 5 6 7


Thanks, Bill. Somehow I missed that, despite the OP having it in his 
code; I even copied it into my testing window.  It was my error for not 
running it and noting it.



and apparently plyr's equivalent of rbind doesn't support that class.


plyr uses rbind.fill primarily.  And it doesn't handle columns of 
POSIXlt based on testing that directly. (Although with only one 
argument, it just passes the data.frame back, which is why when there 
was just a single duplicate, it worked; that bypassed the code that 
couldn't handle POSIXlt's.)



If you want to continue using POSIXlt objects you can get your
immediate result without ddply; subscripting will do the job:
 nDups- with(df, ave(rep(0,nrow(df)), ID1, ID2, ID3, FUN=length))
 print(nDups)
   [1] 1 2 2 1 1 2 2
 df[nDups1, ]
 ID1 ID2 ID3   Date Value
   2   2   b  v1 1985-05-02 2
   3   2   b  v1 1985-05-03 3
   6   4   e  v1 1985-05-06 6
   7   4   e  v1 1985-05-07 7
 str(.Last.value)
   'data.frame':   4 obs. of  5 variables:
$ ID1  : chr  2 2 4 4
$ ID2  : chr  b b e e
$ ID3  : Factor w/ 2 levels v1,v2: 1 1 1 1
$ Date : POSIXlt, format: 1985-05-02 1985-05-03 ...
$ Value: Factor w/ 7 levels 1,2,3,4,..: 2 3 6 7

If you need plyr for other tasks you ought to use a different
class for your date data (or 

Re: [R] Problem with ddply in the plyr-package: surprising output of a date-column

2011-04-25 Thread Hadley Wickham
 If you need plyr for other tasks you ought to use a different
 class for your date data (or wait until plyr can deal with
 POSIXlt objects).

How do you get POSIXlt objects into a data frame?

 df - data.frame(x = as.POSIXlt(as.Date(c(2008-01-01
 str(df)
'data.frame':   1 obs. of  1 variable:
 $ x: POSIXct, format: 2008-01-01

 df - data.frame(x = I(as.POSIXlt(as.Date(c(2008-01-01)
 str(df)
'data.frame':   1 obs. of  1 variable:
 $ x: AsIs, format: 0

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

__
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] Generalized Linear Model

2011-04-25 Thread Megan
Hello,

I am trying to run a generalized linear model but do not know where to
begin. I have attached my data to R but do not know where to go from there.
I have two independent variables (each has two factors associated with them)
and two dependent variables, each with either a yes/no response which I've
valued either 0 or 1 in the data set. Any input would be greatly
appreciated. 

--
View this message in context: 
http://r.789695.n4.nabble.com/Generalized-Linear-Model-tp3473924p3473924.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.


Re: [R] Help needed!

2011-04-25 Thread shuangyan
Hello, i got this package from the paper: Nonparametric Covariance Function
estimation for Functional and Longitudinal data.
http://stat.wharton.upenn.edu/~tcai/paper/html/Covariance-Function.html.
Thanks lot!

--
View this message in context: 
http://r.789695.n4.nabble.com/Help-needed-tp3464470p3473745.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] About How to check if a html directory exists

2011-04-25 Thread Wendy Han
Dear all,



I want to let R automatically download available files from a website in
certain folders. Since the files I need, if exist, are in a certain
directory, I used download.file() function with a predesigned directory.
However, some of the folders do not have the file I want. When this occurs,
my program returns error and terminates. So I wonder if there is any way
that I can check if a directory exists before downloading that file. I
appreciate your help!



Thanks!

Wendy

[[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] Factor function

2011-04-25 Thread Lisa
Dear All,

I just want to remove “NA” from the levels of a factor.  For example:

d-data.frame(matrix(c(ww,ww,xx,yy,ww,yy,xx,yy,NA),
ncol=3, byrow=TRUE))

 factor(d[, 3], exclude=NA)
[1] xx yy NA
Levels: NA xx yy

But “NA” is still listed in the levels. How can I solve this problem? Thanks
in advance.

Lisa


--
View this message in context: 
http://r.789695.n4.nabble.com/Factor-function-tp3473984p3473984.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.


Re: [R] Problem with ddply in the plyr-package: surprising output of a date-column

2011-04-25 Thread Christoph Jäckel
Hi together,

thank you so much for your help! The problem was indeed the
strptime-function. Replacing that with as.Date solves the problem,
both in the example I provided and in my actual data set.

I think this is a lesson for me to not use types I'm not really
familiar with (POSIXlt in this case).

Thanks again!

Christoph

On Mon, Apr 25, 2011 at 10:07 PM, Hadley Wickham had...@rice.edu wrote:

  If you need plyr for other tasks you ought to use a different
  class for your date data (or wait until plyr can deal with
  POSIXlt objects).

 How do you get POSIXlt objects into a data frame?

  df - data.frame(x = as.POSIXlt(as.Date(c(2008-01-01
  str(df)
 'data.frame':   1 obs. of  1 variable:
  $ x: POSIXct, format: 2008-01-01

  df - data.frame(x = I(as.POSIXlt(as.Date(c(2008-01-01)
  str(df)
 'data.frame':   1 obs. of  1 variable:
  $ x: AsIs, format: 0

 Hadley

 --
 Assistant Professor / Dobelman Family Junior Chair
 Department of Statistics / Rice University
 http://had.co.nz/



--


Christoph Jäckel (Dipl.-Kfm.)



Research Assistant

Chair for Financial Management and Capital Markets | Lehrstuhl für
Finanzmanagement und Kapitalmärkte

TUM School of Management | Technische Universität München

Arcisstr. 21 | D-80333 München | Germany

Mailto: christoph.jaec...@wi.tum.de | Web: www.fm.wi.tum.de

Phone: +49 89 289 25482 | Fax: +49 89 289 25488



Head of Chair:

Univ.-Prof. Dr. Christoph Kaserer

--

E-Mail Disclaimer

Der Inhalt dieser E-Mail ist vertraulich und ausschliesslich
fuer den bezeichneten Adressaten bestimmt. Wenn Sie nicht
der vorgesehene Adressat dieser E-Mail oder dessen Vertreter
sein sollten, so beachten Sie bitte, dass jede Form der
Kenntnisnahme, Veroeffentlichung, Vervielfaeltigung oder
Weitergabe des Inhalts dieser E-Mail unzulaessig ist. Wir
bitten Sie, sich in diesem Fall mit dem Absender der E-Mail
in Verbindung zu setzen.

The information contained in this email is confidential{{dropped:11}}

__
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] Factor function

2011-04-25 Thread Ista Zahn
Hi Lisa,

NA != NA

The first represents a missing observation, the second represents a
character string.

HTH,
Ista


On Mon, Apr 25, 2011 at 3:53 PM, Lisa lisa...@gmail.com wrote:
 Dear All,

 I just want to remove “NA” from the levels of a factor.  For example:

 d-data.frame(matrix(c(ww,ww,xx,yy,ww,yy,xx,yy,NA),
 ncol=3, byrow=TRUE))

 factor(d[, 3], exclude=NA)
 [1] xx yy NA
 Levels: NA xx yy

 But “NA” is still listed in the levels. How can I solve this problem? Thanks
 in advance.

 Lisa


 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Factor-function-tp3473984p3473984.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.




-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

__
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] Generalized Linear Model

2011-04-25 Thread Alexander Engelhardt

Am 25.04.2011 21:28, schrieb Megan:

Hello,

I am trying to run a generalized linear model but do not know where to
begin. I have attached my data to R but do not know where to go from there.
I have two independent variables (each has two factors associated with them)


What do you mean by this? You have two input variables, who are binary, 
meaning yes/no (or male/female, high/low, ...) variables?



and two dependent variables, each with either a yes/no response which I've
valued either 0 or 1 in the data set. Any input would be greatly
appreciated.


If your dependent variable is binary, you might want to google for 
logistic regression (this belongs to generalized linear models). The 
R-function who handles this is glm(), with the parameter family=binomial().


Have fun,
 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] Generalized Linear Model

2011-04-25 Thread Kehl Dániel

Hi!

Try to read about the glm function, type:

?glm

in your R editor. It looks like you have contingency tables, maybe a 
loglin model would be good to start with.


D

2011-04-25 12:28 keltezéssel, Megan írta:

Hello,

I am trying to run a generalized linear model but do not know where to
begin. I have attached my data to R but do not know where to go from there.
I have two independent variables (each has two factors associated with them)
and two dependent variables, each with either a yes/no response which I've
valued either 0 or 1 in the data set. Any input would be greatly
appreciated.

--
View this message in context: 
http://r.789695.n4.nabble.com/Generalized-Linear-Model-tp3473924p3473924.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] My code is too loopy

2011-04-25 Thread Dimitri Liakhovitski
Hello!
I wrote a piece of code below that does the job but seems too loopy to me.
I was wondering if there is any way to make it more efficient/less loopy?
Thanks a lot for your hints!
Dimitri

### Creating example data set:

mygroups-c(rep(group1, 8),rep(group2, 8))
myweeks-seq(as.Date(2010-01-04), length = 8, by = week)
values.w-c(0,10,15,20,0,0,0,10,100,200,0,0,300,200,0,0)
mydata-data.frame(group=mygroups,mydates=myweeks,myvalue=values.w)
mydata$group-as.factor(mydata$group)
str(mydata)
(mydata)

### Doing the following within each level of the factor mydata$group:
### Create a new variable (new.value) that equals:
### myvalue in the same week * 0.5 +
### myvalue 1 week ago  * 0.35
### myvalue 2 weeks ago * 0.15

groups-levels(mydata$group)
(groups)

mydata[[new.value]]-mydata[[myvalue]]*0.5

for(i in groups){   # looping through groups
  temp.data-mydata[mydata$group %in% i,] # selecting values for one group
  
temp.data[2,new.value]-temp.data[[new.value]][2]+temp.data[1,myvalue]*0.35
# 2nd new value
  for(myrow in 3:nrow(temp.data)){  # Starting in row 3 and looping through rows

temp.data[myrow,new.value]-temp.data[[new.value]][myrow]+temp.data[(myrow-1),myvalue]*.35+temp.data[(myrow-2),myvalue]*.15
  }
  mydata[mydata$group %in% i,]-temp.data
}


-- 
Dimitri Liakhovitski
Ninah Consulting
www.ninah.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.


Re: [R] Factor function

2011-04-25 Thread Lisa
Did you see the data frame d? Thanks.

--
View this message in context: 
http://r.789695.n4.nabble.com/Factor-function-tp3473984p3474065.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.


Re: [R] Factor function

2011-04-25 Thread Ista Zahn
Yes... did you understand that NA is not equal to NA?

Best,
Ista

On Mon, Apr 25, 2011 at 4:31 PM, Lisa lisa...@gmail.com wrote:
 Did you see the data frame d? Thanks.

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Factor-function-tp3473984p3474065.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.




-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

__
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] Factor function

2011-04-25 Thread Lisa
Thank you for your reply again. I really know that NA is not NA. I just
want to figure out how to remove NA from the levels. Thanks again.

--
View this message in context: 
http://r.789695.n4.nabble.com/Factor-function-tp3473984p3474127.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.


Re: [R] Problem with ddply in the plyr-package: surprising output of a date-column

2011-04-25 Thread Brian Diggs

On 4/25/2011 1:07 PM, Hadley Wickham wrote:

If you need plyr for other tasks you ought to use a different
class for your date data (or wait until plyr can deal with
POSIXlt objects).


How do you get POSIXlt objects into a data frame?


df- data.frame(x = as.POSIXlt(as.Date(c(2008-01-01
str(df)

'data.frame':   1 obs. of  1 variable:
  $ x: POSIXct, format: 2008-01-01


df- data.frame(x = I(as.POSIXlt(as.Date(c(2008-01-01)
str(df)

'data.frame':   1 obs. of  1 variable:
  $ x: AsIs, format: 0

Hadley


Assigning to a column after the data.frame creation step

 df - data.frame(x = as.POSIXlt(as.Date(c(2008-01-01
 str(df)
'data.frame':   1 obs. of  1 variable:
 $ x: POSIXct, format: 2008-01-01
 dput(df)
structure(list(x = structure(1199145600, class = c(POSIXct,
POSIXt), tzone = UTC)), .Names = x, row.names = c(NA, -1L
), class = data.frame)
 df$x - as.POSIXlt(as.Date(c(2008-01-01)))
 str(df)
'data.frame':   1 obs. of  1 variable:
 $ x: POSIXlt, format: 2008-01-01
 dput(df)
structure(list(x = structure(list(sec = 0, min = 0L, hour = 0L,
mday = 1L, mon = 0L, year = 108L, wday = 2L, yday = 0L, isdst = 
0L), .Names = c(sec,

min, hour, mday, mon, year, wday, yday, isdst
), class = c(POSIXlt, POSIXt), tzone = UTC)), .Names = x, 
row.names = c(NA,

-1L), class = data.frame)

This is reminiscent of the 1d array problem; there are types that are 
coerced into other types when passed as part of a data.frame constructor 
(data.frame call), but are not coerced when assigned to a column.


Looking at help pages, calls to data.frame call as.data.frame on each 
argument; `[-.data.frame` has a section on coercion which starts The 
story over when replacement values are coerced is a complicated one, and 
one that has changed during R's development. This section is a guide 
only. which makes me think it is not all that well defined.


Digging more, there is a as.data.frame.POSIXlt, although the help page 
for it (DateTimeClasses in base) does not mention it or document it.  It 
is documented, though, in as.data.frame (which also has comments about 
coercing 1 dimensional arrays).


So, potentially, there could be differences with any class that has an 
as.data.frame method because it will be treated differently if passed to 
data.frame versus a column assignment with `[-.data.frame`


 methods(as.data.frame)
 [1] as.data.frame.aovproj*as.data.frame.array
 [3] as.data.frame.AsIsas.data.frame.character
 [5] as.data.frame.complex as.data.frame.data.frame
 [7] as.data.frame.Dateas.data.frame.default
 [9] as.data.frame.difftimeas.data.frame.factor
[11] as.data.frame.ftable* as.data.frame.function
[13] as.data.frame.idf*as.data.frame.integer
[15] as.data.frame.listas.data.frame.logical
[17] as.data.frame.logLik* as.data.frame.matrix
[19] as.data.frame.model.matrixas.data.frame.numeric
[21] as.data.frame.numeric_version as.data.frame.ordered
[23] as.data.frame.POSIXct as.data.frame.POSIXlt
[25] as.data.frame.raw as.data.frame.table
[27] as.data.frame.ts  as.data.frame.vector

So, I suppose it is working as documented.  Though I wonder how long ago 
it was that someone (who has been using R regularly for at least a year) 
actually read the entire help page for data.frame and/or as.data.frame. 
 It's one of those things you think you know and understand until you 
find out you don't.


--
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health  Science University

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


[R] [R-pkgs] Rook: software and specification for R web applications and servers

2011-04-25 Thread Jeffrey Horner
Dear  useRs,

Rook is a new package that does three things:

 - It provides a way to run R web applications on your desktop with the
 new internal R web server named Rhttpd. Please see the Rhttpd help page.

 - It provides a set of reference classes you can use to write you R
 web applications. The following help pages provide more information:
 Brewery, Builder, File, Middleware, Redirect, Request, Response, Static,
 URLMap, and Utils. Also see the example web applications located in
 'system(exampleApps,package=Rook)'.

 - It provides a specification for writing your R web applications to
 work on any web server that supports the Rook specification. Currently,
 only Rhttpd implements it, but rApache is close behind. See the Rook
 help page for more information.

You may not see the need for web applications written in R, but consider
using Rook to build a statistical engine that complements a front-end
web system, or consider creating elegant ggplot2 graphics on-demand from
a fresh data stream. Also, consider creating dynamic instructional content
for the classroom.

If you have other examples or ideas, please join in the discussion on
R-help or here:

http://groups.google.com/group/rrook

--
Jeffrey Horner  (author of rApache and brew)

___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages

__
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] Factor function

2011-04-25 Thread Petr Savicky
On Mon, Apr 25, 2011 at 12:53:40PM -0700, Lisa wrote:
 Dear All,
 
 I just want to remove “NA” from the levels of a factor.  For example:
 
 d-data.frame(matrix(c(ww,ww,xx,yy,ww,yy,xx,yy,NA),
 ncol=3, byrow=TRUE))
 
  factor(d[, 3], exclude=NA)
 [1] xx yy NA
 Levels: NA xx yy
 
 But “NA” is still listed in the levels. How can I solve this problem?

The column d[, 3] is already a factor. It is possible to avoid
this using

  d-data.frame(matrix(c(ww,ww,xx,yy,ww,yy,xx,yy,NA),
  ncol=3, byrow=TRUE), stringsAsFactors=FALSE)

Then, we get

  factor(d[, 3], exclude=NA)

  [1] xx   yy   NA
  Levels: xx yy

Hope this helps.

Petr Savicky.

__
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] split data frame by factor

2011-04-25 Thread ivan
Dear Community,

I have a dataframe like this one:

A   B
5   1
6   1
7   1
8   1
9   2
10  2
11  2
12  2

I have a problem splitting up the above data frame in respect to the
factor represented by B, whereas the resulting vector should contain
the numeric values only. I tried split() but it produces this:
A   B
[1]
5   1
6   1
7   1
8   1
[2]
9   2
10  2
11  2
12  2

I want to achieve this,though:

A   
[1]
5   
6   
7   
8
[2] 
9   
10  
11  
12  

How is this done? Thank you very much in advance.

Best Regards.

__
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] Problem with ddply in the plyr-package: surprising output of a date-column

2011-04-25 Thread Peter Ehlers

On 2011-04-25 13:07, Hadley Wickham wrote:

If you need plyr for other tasks you ought to use a different
class for your date data (or wait until plyr can deal with
POSIXlt objects).


How do you get POSIXlt objects into a data frame?


df- data.frame(x = as.POSIXlt(as.Date(c(2008-01-01
str(df)

'data.frame':   1 obs. of  1 variable:
  $ x: POSIXct, format: 2008-01-01


df- data.frame(x = I(as.POSIXlt(as.Date(c(2008-01-01)
str(df)

'data.frame':   1 obs. of  1 variable:
  $ x: AsIs, format: 0

Hadley



To mimic the OP's code

  df - data.frame(x = 2008-01-01)
  df$x - as.POSIXlt(df$x, %Y-%m-%d)
  str(df)
  #'data.frame':   1 obs. of  1 variable:
  # $ x: POSIXlt, format: 2008-01-01

Peter Ehlers

__
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 data frame by factor

2011-04-25 Thread ivan
sorry, the problem has been solved.

On Mon, Apr 25, 2011 at 11:28 PM, ivan i.pet...@gmail.com wrote:
 Dear Community,

 I have a dataframe like this one:

 A       B
 5       1
 6       1
 7       1
 8       1
 9       2
 10      2
 11      2
 12      2

 I have a problem splitting up the above data frame in respect to the
 factor represented by B, whereas the resulting vector should contain
 the numeric values only. I tried split() but it produces this:
 A       B
 [1]
 5       1
 6       1
 7       1
 8       1
 [2]
 9       2
 10      2
 11      2
 12      2

 I want to achieve this,though:

 A
 [1]
 5
 6
 7
 8
 [2]
 9
 10
 11
 12

 How is this done? Thank you very much in advance.

 Best Regards.


__
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] My code is too loopy

2011-04-25 Thread Dennis Murphy
Hi:

I think the embed() function is your friend here. From its help page example,

 x - 1:10
 embed (x, 3)
 [,1] [,2] [,3]
[1,]321
[2,]432
[3,]543
[4,]654
[5,]765
[6,]876
[7,]987
[8,]   1098


Applying it to your test data,

# h() creates a weighted average of the observations in each row
h - function(x) embed(x, 3) %*% c(0.5, 0.35, 0.15)
library(plyr)
ddply(mydata, group, summarise, ma = h(myvalue))
group ma
1  group1  11.00
2  group1  16.75
3  group1   9.25
4  group1   3.00
5  group1   0.00
6  group1   5.00
7  group2  85.00
8  group2  30.00
9  group2 150.00
10 group2 205.00
11 group2 115.00
12 group2  30.00

Does that work for you? The rollapply() function in the zoo package
may also be applicable with a similar input function that computes a
weighted average.

HTH,
Dennis


On Mon, Apr 25, 2011 at 1:50 PM, Dimitri Liakhovitski
dimitri.liakhovit...@gmail.com wrote:
 Hello!
 I wrote a piece of code below that does the job but seems too loopy to me.
 I was wondering if there is any way to make it more efficient/less loopy?
 Thanks a lot for your hints!
 Dimitri

 ### Creating example data set:

 mygroups-c(rep(group1, 8),rep(group2, 8))
 myweeks-seq(as.Date(2010-01-04), length = 8, by = week)
 values.w-c(0,10,15,20,0,0,0,10,100,200,0,0,300,200,0,0)
 mydata-data.frame(group=mygroups,mydates=myweeks,myvalue=values.w)
 mydata$group-as.factor(mydata$group)
 str(mydata)
 (mydata)

 ### Doing the following within each level of the factor mydata$group:
 ### Create a new variable (new.value) that equals:
 ### myvalue in the same week * 0.5 +
 ### myvalue 1 week ago  * 0.35
 ### myvalue 2 weeks ago * 0.15

 groups-levels(mydata$group)
 (groups)

 mydata[[new.value]]-mydata[[myvalue]]*0.5

 for(i in groups){   # looping through groups
  temp.data-mydata[mydata$group %in% i,] # selecting values for one group
  temp.data[2,new.value]-temp.data[[new.value]][2]+temp.data[1,myvalue]*0.35
 # 2nd new value
  for(myrow in 3:nrow(temp.data)){  # Starting in row 3 and looping through 
 rows
    
 temp.data[myrow,new.value]-temp.data[[new.value]][myrow]+temp.data[(myrow-1),myvalue]*.35+temp.data[(myrow-2),myvalue]*.15
  }
  mydata[mydata$group %in% i,]-temp.data
 }


 --
 Dimitri Liakhovitski
 Ninah Consulting
 www.ninah.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] Factor function

2011-04-25 Thread Lisa
Thank you for your help. Your R code works well.

Lisa

--
View this message in context: 
http://r.789695.n4.nabble.com/Factor-function-tp3473984p3474196.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] Problem installing XML in Ubuntu 10.10

2011-04-25 Thread Abraham Mathew
Hello folks,


Here's is info on what system I'm working on.
 sessionInfo()
R version 2.13.0 (2011-04-13)
Platform: i686-pc-linux-gnu (32-bit)


I'm trying to install the XML package. However, I end up with the following
error message.

 install.packages(XML)

checking for xml2-config... no
Cannot find xml2-config
ERROR: configuration failed for package ‘XML’
* removing ‘/home/abraham/R/i686-pc-linux-gnu-library/2.13/XML’

The downloaded packages are in
‘/tmp/RtmpUsckPl/downloaded_packages’
Warning message:
In install.packages() :
installation of package 'XML' had non-zero exit status


When I run library(XML), I get that there is no package named XML.

Can anyone help diagnose the problem.


Thank You,
Abraham

[[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] Problem installing XML in Ubuntu 10.10

2011-04-25 Thread Phil Spector

Abraham -

 sudo apt-get install libxml2-dev

is what you need to get the development libraries and 
xml2-config installed on your Ubuntu machine.


   - Phil



On Mon, 25 Apr 2011, Abraham Mathew wrote:


Hello folks,


Here's is info on what system I'm working on.

sessionInfo()

R version 2.13.0 (2011-04-13)
Platform: i686-pc-linux-gnu (32-bit)


I'm trying to install the XML package. However, I end up with the following
error message.


install.packages(XML)


checking for xml2-config... no
Cannot find xml2-config
ERROR: configuration failed for package ?XML?
* removing ?/home/abraham/R/i686-pc-linux-gnu-library/2.13/XML?

The downloaded packages are in
?/tmp/RtmpUsckPl/downloaded_packages?
Warning message:
In install.packages() :
installation of package 'XML' had non-zero exit status


When I run library(XML), I get that there is no package named XML.

Can anyone help diagnose the problem.


Thank You,
Abraham

[[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] About How to check if a html directory exists

2011-04-25 Thread Rolf Turner

On 26/04/11 05:52, Wendy Han wrote:

Dear all,



I want to let R automatically download available files from a website in
certain folders. Since the files I need, if exist, are in a certain
directory, I used download.file() function with a predesigned directory.
However, some of the folders do not have the file I want. When this occurs,
my program returns error and terminates. So I wonder if there is any way
that I can check if a directory exists before downloading that file. I
appreciate your help!


Not quite sure I understand your question,  but I think that the
file.info() function will provide what you need.  Check out ?file.info.
See also ?files and ?file.access.

cheers,

Rolf Turner

__
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 How to check if a html directory exists

2011-04-25 Thread Jerome Asselin
On Mon, 2011-04-25 at 12:52 -0500, Wendy Han wrote:
 I want to let R automatically download available files from a website in
 certain folders. Since the files I need, if exist, are in a certain
 directory, I used download.file() function with a predesigned directory.
 However, some of the folders do not have the file I want. When this occurs,
 my program returns error and terminates. So I wonder if there is any way
 that I can check if a directory exists before downloading that file. I
 appreciate your help!

You could use the try() command to catch the download.file() error and,
if there is one, handle it accordingly.

See help(try)

Regards,
Jerome

__
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 How to check if a html directory exists

2011-04-25 Thread William Dunlap
Use try() or tryCatch() to let your loop continue looking
for more files after download.file() throws an error.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com  

 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of Rolf Turner
 Sent: Monday, April 25, 2011 3:30 PM
 To: Wendy Han
 Cc: r-help@r-project.org
 Subject: Re: [R] About How to check if a html directory exists
 
 On 26/04/11 05:52, Wendy Han wrote:
  Dear all,
 
 
 
  I want to let R automatically download available files from 
 a website in
  certain folders. Since the files I need, if exist, are in a certain
  directory, I used download.file() function with a 
 predesigned directory.
  However, some of the folders do not have the file I want. 
 When this occurs,
  my program returns error and terminates. So I wonder if 
 there is any way
  that I can check if a directory exists before downloading 
 that file. I
  appreciate your help!
 
 Not quite sure I understand your question,  but I think that the
 file.info() function will provide what you need.  Check out 
 ?file.info.
 See also ?files and ?file.access.
 
  cheers,
 
  Rolf Turner
 
 __
 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] Problem installing XML in Ubuntu 10.10

2011-04-25 Thread Phil Spector

sudo apt-get install libcurl4-openssl-dev

- Phil Spector
 Statistical Computing Facility
 Department of Statistics
 UC Berkeley
 spec...@stat.berkeley.edu


On Mon, 25 Apr 2011, Abraham Mathew wrote:



This is kind of a second question (yeah, I know), but I also get a similar 
error when I try to install
the RCurl package

* installing *source* package ‘RCurl’ ...
checking for curl-config... no
Cannot find curl-config
ERROR: configuration failed for package ‘RCurl’
* removing ‘/home/abraham/R/i686-pc-linux-gnu-library/2.13/RCurl’

The downloaded packages are in
‘/tmp/RtmpNmbI03/downloaded_packages’
Warning message:
In install.packages() :
installation of package 'RCurl' had non-zero exit status



I never had any problems with installing packages. However, I recently removed 
my windows
partition and things all weird now.


Thanks again.



On Mon, Apr 25, 2011 at 6:19 PM, Phil Spector spec...@stat.berkeley.edu wrote:
  Abraham -

      sudo apt-get install libxml2-dev

  is what you need to get the development libraries and xml2-config 
installed on your Ubuntu
  machine.

                                        - Phil



  On Mon, 25 Apr 2011, Abraham Mathew wrote:

  Hello folks,


  Here's is info on what system I'm working on.
sessionInfo()

  R version 2.13.0 (2011-04-13)
  Platform: i686-pc-linux-gnu (32-bit)


  I'm trying to install the XML package. However, I end up with the 
following
  error message.

install.packages(XML)

  
  checking for xml2-config... no
  Cannot find xml2-config
  ERROR: configuration failed for package ?XML?
  * removing ?/home/abraham/R/i686-pc-linux-gnu-library/2.13/XML?

  The downloaded packages are in
  ?/tmp/RtmpUsckPl/downloaded_packages?
  Warning message:
  In install.packages() :
  installation of package 'XML' had non-zero exit status


  When I run library(XML), I get that there is no package named XML.

  Can anyone help diagnose the problem.


  Thank You,
  Abraham

       [[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] Problem installing XML in Ubuntu 10.10

2011-04-25 Thread Dirk Eddelbuettel

On 25 April 2011 at 17:39, Abraham Mathew wrote:
| Hello folks,
| 
| 
| Here's is info on what system I'm working on.
|  sessionInfo()
| R version 2.13.0 (2011-04-13)
| Platform: i686-pc-linux-gnu (32-bit)
| 
| 
| I'm trying to install the XML package. However, I end up with the following
| error message.

You can install the prebuilt package

r-cran-xml

directly from the Ubuntu repositories.  

Dirk

 
|  install.packages(XML)
| 
| checking for xml2-config... no
| Cannot find xml2-config
| ERROR: configuration failed for package �XML�
| * removing �/home/abraham/R/i686-pc-linux-gnu-library/2.13/XML�
| 
| The downloaded packages are in
| �/tmp/RtmpUsckPl/downloaded_packages�
| Warning message:
| In install.packages() :
| installation of package 'XML' had non-zero exit status
| 
| 
| When I run library(XML), I get that there is no package named XML.
| 
| Can anyone help diagnose the problem.
| 
| 
| Thank You,
| Abraham
| 
|   [[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.

-- 
Gauss once played himself in a zero-sum game and won $50.
  -- #11 at http://www.gaussfacts.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] Trouble Passing a for loop variable (iteration #) to a data frame

2011-04-25 Thread Galen Moore
Greetings - 

 

I am working on a piece of code to simulate vehicle times in and out in each
of a number of parking spaces.  At this stage, my code basically does what
it is supposed to do but for the sequential number of each new parking event
for a given space (i.e., the index of the loop variable).  Instead of
passing the index of the loop variable (iter) to the data frame, it passes
the value of the total number of iterations.  Eventually, the number of
iterations (parking events in a given space) will be determined by an
rnorm() fcn, so I am not looking for a process that locks-in the number of
iterations.  The total eventual data set size is small-ish, so I'm not
worried about speed.

 

I'm sure my problem lies somehow in my setup of the data frames and my
rbind() fcns, but a great many attempts and several hours of searching
online have not yet brought success.

 

Can you please suggest what I need to do to get the iteration # to appear in
the iter vector and therefore to the data frame?

 

Many thanks,

 

Galen 

 

 

 # fabdata3.r

 # fabricate sample data

 

 #declare the mean duration

 dur-.04

 

 #declare the stdDev of the rnorm() fcn (duration)

 varc-.01

 

 sp-numeric()

 iter-numeric()

 ti-numeric()

 to-numeric()

 actdur-numeric()

 #newline-data.frame(sp, iter, ti, to, actdur)

 ds-data.frame(sp, iter, ti, to, actdur)

 

 # BEGIN OUTER LOOP

 for (sp in c(1:3)) {

+ 

+ct-1

+# BEGIN INNER LOOP

+ 

+x - seq(1, 4, by=1)

+for (i in seq(along=x)) {

+ 

+ if (i == 1)   {

+  ti[1]-((.33+rnorm(1, dur, varc)))

+  to[1]-((ti[1]+rnorm(1, dur, varc)))

+  actdur[1]-(to[1]-ti[1])

+  iter-x[1]

+ 

+  }

+  

+ else {

+ # set subsequent time-ins to prev to + a rand#

+ ti[i]-((to[i-1]+rnorm(1, dur, varc)))

+ # calculate each event's time-out

+ to[i]-((ti[i]+rnorm(1, dur, varc)))

+ # calculate each event's actual duration

+ actdur[i]-(to[i]-ti[i])

+ iter-x[i]

+ 

+ }

+  spStep-paste(sp Value is , sp)

+  print(spStep)

+  iterStep-paste(iter Value is , iter)

+  print(iterStep)

+  

+ newrow-data.frame(sp, iter, ti, to, actdur)

+ ct=ct+1

+  }  #END INNER LOOP

+  ds-rbind(ds, newrow)

+ }

[1] sp Value is  1

[1] iter Value is  1

[1] sp Value is  1

[1] iter Value is  2

[1] sp Value is  1

[1] iter Value is  3

[1] sp Value is  1

[1] iter Value is  4

[1] sp Value is  2

[1] iter Value is  1

[1] sp Value is  2

[1] iter Value is  2

[1] sp Value is  2

[1] iter Value is  3

[1] sp Value is  2

[1] iter Value is  4

[1] sp Value is  3

[1] iter Value is  1

[1] sp Value is  3

[1] iter Value is  2

[1] sp Value is  3

[1] iter Value is  3

[1] sp Value is  3

[1] iter Value is  4

 print(ds)

   sp itertito actdur

1   14 0.3600055 0.4123550 0.05234955

2   14 0.4343887 0.4640804 0.02969170

3   14 0.5240268 0.5622272 0.03820032

4   14 0.5945877 0.6436489 0.04906118

5   24 0.3694827 0.4166405 0.04715775

6   24 0.4609841 0.4968517 0.03586767

7   24 0.5357721 0.5735439 0.03777185

8   24 0.6207077 0.6512799 0.03057217

9   34 0.3801887 0.4122605 0.03207179

10  34 0.4440002 0.4916171 0.04761685

11  34 0.5380228 0.5791549 0.04113214

12  34 0.6087923 0.6291451 0.02035284

 # END OUTER LOOP

   


[[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] Problem installing XML in Ubuntu 10.10

2011-04-25 Thread Abraham Mathew
This is kind of a second question (yeah, I know), but I also get a similar
error when I try to install the RCurl package

* installing *source* package ‘RCurl’ ...
checking for curl-config... no
Cannot find curl-config
ERROR: configuration failed for package ‘RCurl’
* removing ‘/home/abraham/R/i686-pc-linux-gnu-library/2.13/RCurl’

The downloaded packages are in
‘/tmp/RtmpNmbI03/downloaded_packages’
Warning message:
In install.packages() :
installation of package 'RCurl' had non-zero exit status



I never had any problems with installing packages. However, I recently
removed my windows
partition and things all weird now.


Thanks again.



On Mon, Apr 25, 2011 at 6:19 PM, Phil Spector spec...@stat.berkeley.eduwrote:

 Abraham -

 sudo apt-get install libxml2-dev

 is what you need to get the development libraries and xml2-config installed
 on your Ubuntu machine.

   - Phil




 On Mon, 25 Apr 2011, Abraham Mathew wrote:

  Hello folks,


 Here's is info on what system I'm working on.

 sessionInfo()

 R version 2.13.0 (2011-04-13)
 Platform: i686-pc-linux-gnu (32-bit)


 I'm trying to install the XML package. However, I end up with the
 following
 error message.

  install.packages(XML)

 
 checking for xml2-config... no
 Cannot find xml2-config
 ERROR: configuration failed for package ?XML?
 * removing ?/home/abraham/R/i686-pc-linux-gnu-library/2.13/XML?

 The downloaded packages are in
 ?/tmp/RtmpUsckPl/downloaded_packages?
 Warning message:
 In install.packages() :
 installation of package 'XML' had non-zero exit status


 When I run library(XML), I get that there is no package named XML.

 Can anyone help diagnose the problem.


 Thank You,
 Abraham

[[alternative HTML version deleted]]




[[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] Trouble Passing a for loop variable (iteration #) to a data frame

2011-04-25 Thread Peter Langfelder
You need to index the variable iter: instead of iter = x[i], say

iter[i] = x[i].

But a better solution is to simply say

iter = x

at the beginning and don't update it in the loop.

The way your code is written, iter just holds the last x[i], and the
last x[i] at the end of each loop is 4.

Peter

On Mon, Apr 25, 2011 at 3:29 PM, Galen Moore galen.a.mo...@gmail.com wrote:
 Greetings -



 I am working on a piece of code to simulate vehicle times in and out in each
 of a number of parking spaces.  At this stage, my code basically does what
 it is supposed to do but for the sequential number of each new parking event
 for a given space (i.e., the index of the loop variable).  Instead of
 passing the index of the loop variable (iter) to the data frame, it passes
 the value of the total number of iterations.  Eventually, the number of
 iterations (parking events in a given space) will be determined by an
 rnorm() fcn, so I am not looking for a process that locks-in the number of
 iterations.  The total eventual data set size is small-ish, so I'm not
 worried about speed.



 I'm sure my problem lies somehow in my setup of the data frames and my
 rbind() fcns, but a great many attempts and several hours of searching
 online have not yet brought success.



 Can you please suggest what I need to do to get the iteration # to appear in
 the iter vector and therefore to the data frame?



 Many thanks,



 Galen





 # fabdata3.r

 # fabricate sample data



 #declare the mean duration

 dur-.04



 #declare the stdDev of the rnorm() fcn (duration)

 varc-.01



 sp-numeric()

 iter-numeric()

 ti-numeric()

 to-numeric()

 actdur-numeric()

 #newline-data.frame(sp, iter, ti, to, actdur)

 ds-data.frame(sp, iter, ti, to, actdur)



 # BEGIN OUTER LOOP

 for (sp in c(1:3)) {

 +

 +            ct-1

 +            # BEGIN INNER LOOP

 +

 +            x - seq(1, 4, by=1)

 +            for (i in seq(along=x)) {

 +

 +                         if (i == 1)   {

 +                          ti[1]-((.33+rnorm(1, dur, varc)))

 +                          to[1]-((ti[1]+rnorm(1, dur, varc)))

 +                          actdur[1]-(to[1]-ti[1])

 +                          iter-x[1]

 +

 +                          }

 +

 +                         else {

 +                         # set subsequent time-ins to prev to + a rand#

 +                         ti[i]-((to[i-1]+rnorm(1, dur, varc)))

 +                         # calculate each event's time-out

 +                         to[i]-((ti[i]+rnorm(1, dur, varc)))

 +                         # calculate each event's actual duration

 +                         actdur[i]-(to[i]-ti[i])

 +                         iter-x[i]

 +

 +                         }

 +                          spStep-paste(sp Value is , sp)

 +                          print(spStep)

 +                          iterStep-paste(iter Value is , iter)

 +                          print(iterStep)

 +

 +                         newrow-data.frame(sp, iter, ti, to, actdur)

 +                         ct=ct+1

 +                  }  #END INNER LOOP

 +                  ds-rbind(ds, newrow)

 +             }

 [1] sp Value is  1

 [1] iter Value is  1

 [1] sp Value is  1

 [1] iter Value is  2

 [1] sp Value is  1

 [1] iter Value is  3

 [1] sp Value is  1

 [1] iter Value is  4

 [1] sp Value is  2

 [1] iter Value is  1

 [1] sp Value is  2

 [1] iter Value is  2

 [1] sp Value is  2

 [1] iter Value is  3

 [1] sp Value is  2

 [1] iter Value is  4

 [1] sp Value is  3

 [1] iter Value is  1

 [1] sp Value is  3

 [1] iter Value is  2

 [1] sp Value is  3

 [1] iter Value is  3

 [1] sp Value is  3

 [1] iter Value is  4

             print(ds)

   sp iter        ti        to     actdur

 1   1    4 0.3600055 0.4123550 0.05234955

 2   1    4 0.4343887 0.4640804 0.02969170

 3   1    4 0.5240268 0.5622272 0.03820032

 4   1    4 0.5945877 0.6436489 0.04906118

 5   2    4 0.3694827 0.4166405 0.04715775

 6   2    4 0.4609841 0.4968517 0.03586767

 7   2    4 0.5357721 0.5735439 0.03777185

 8   2    4 0.6207077 0.6512799 0.03057217

 9   3    4 0.3801887 0.4122605 0.03207179

 10  3    4 0.4440002 0.4916171 0.04761685

 11  3    4 0.5380228 0.5791549 0.04113214

 12  3    4 0.6087923 0.6291451 0.02035284

 # END OUTER LOOP




        [[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] Problem installing XML in Ubuntu 10.10

2011-04-25 Thread Rolf Turner

On 26/04/11 10:46, Dirk Eddelbuettel wrote:

On 25 April 2011 at 17:39, Abraham Mathew wrote:
| Hello folks,
|
|
| Here's is info on what system I'm working on.
|  sessionInfo()
| R version 2.13.0 (2011-04-13)
| Platform: i686-pc-linux-gnu (32-bit)
|
|
| I'm trying to install the XML package. However, I end up with the following
| error message.

You can install the prebuilt package

 r-cran-xml

directly from the Ubuntu repositories.


Just out of idle curiosity I tried this.  (Don't want/need XML, but since
I've fairly recently started using Ubuntu, I like to see whether I can drive
these sudo apt-get tools .)

So I did

sudo apt-get install r-cran-xml

and it seemed to run without error.  Then I started R and tried

library(XML)

and got the error

Error in library(XML) : there is no package called 'XML'

So I then said ``H.  Maybe I've misunderstood, and the sudo apt-get 
bizzo
has just provided the underlying xml2-config stuff, and I still need to 
do the install

of the R package XML.  So I tried that, and got the message:

checking for xml2-config... no
Cannot find xml2-config
ERROR: configuration failed for package ‘XML’
* removing ‘/home/rolf/Rlib/XML’

So either something's not working properly or I'm still not 
understanding what

I should be doing.  Enlightenment?

cheers,

Rolf Turner

P. S. I *believe* that I have the Ubuntu repositories referenced 
correctly in

my /etc/apt/sources.list file:

deb http://cran.stat.auckland.ac.nz/bin/linux/ubuntu lucid/

R. T.

__
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] Shouldn't this be fixed in the documentation? No.

2011-04-25 Thread David Winsemius

csmark wrote:
 
 I know I'm bringing up an old thread but I ran into this exact same
 problem.  It comes straight out of section 3.3 Getting  Setting
 Attributes from An Introduction to R documentation.
 
 
 http://cran.r-project.org/doc/manuals/R-intro.html#Getting-and-setting-attributes
 http://cran.r-project.org/doc/manuals/R-intro.html#Getting-and-setting-attributes
  
 
 Earlier in section 3.1 it has if z is a complex vector of length 100,
 then in an expression mode(z) is the character string complex and
 length(z) is 100.
 
 The very next assignment is z - 0:9.  
 
 If one makes a complex array of length 100 via z - c(1+0i:99+0i) the
 attr() function works perfectly.
 
 Not being fluent in complex numbers I don't quite know how the range
 (1+0i:100+0i) has 101 elements but maybe this could be added too.
 
 Who do we contact to clarify this?  Thanks!
 

First, hit your forehead ... hard, then repeat ten times: operator
precedence

Then go read the FAQ item about this or go to:
 ?Syntax

 . so you can see what efforts have already been made to clarify this.
-- 
Daid/

--
View this message in context: 
http://r.789695.n4.nabble.com/setting-attributes-tp3028152p3474356.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.


Re: [R] Problem installing XML in Ubuntu 10.10

2011-04-25 Thread Jim Lemon

On 04/26/2011 09:19 AM, Rolf Turner wrote:

...
So either something's not working properly or I'm still not
understanding what
I should be doing. Enlightenment?


When the sender and the receiver understand what is being said,
that is communication.
When the sender understands, but the receiver does not,
that is jargon.
When neither understands,
that is voodoo.

Jim

__
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 Relabelling

2011-04-25 Thread John Kane


--- On Mon, 4/25/11, kmatthews kevin-matth...@uiowa.edu wrote:

 From: kmatthews kevin-matth...@uiowa.edu
 Subject: Re: [R] Random Relabelling
 To: r-help@r-project.org
 Received: Monday, April 25, 2011, 10:53 AM
 Thanks to everyone... this helps a
 lot.  Just a quick question about
 etiquette in this forum (as it my first time
 questioning)... are notes of
 gratitude usually given in these forums?

Certainly and thanks
 
 On Wed, Apr 20, 2011 at 1:26 PM, jthetzel [via R] 
 ml-node+3463799-950416470-231...@n4.nabble.com
 wrote:
 
  Kevin,
 
  The following follows John's suggestion, but without
 the loop.  It's quick
  for me.
 
  Jeremy
 
 
  Jeremy T. Hetzel
  Boston University
 
 
 
  ## Generate sample data
  n - 4000
  rep - 1000
  rate - rnorm(n, mean = 15, sd = 2) / 10 #
 Mortality rates around
  15/100k
 
  ## Create an empty matrix with appropriate dimensions
  permutations - matrix(ncol = n, nrow = rep)
 
  ## Use apply() to resample
  permutations - apply(permutations, 1, function(x)
  {
  sample(rate, size = n, replace = F)
  })
 
  ## Look at the matrix
  dim(permutations)
  head(permutations)
 
  ## Find the column means
  means - apply(permutations, 1, mean)
  means
 
 
 
 
 
  On Wednesday, April 20, 2011 1:56:35 PM UTC-4, John
 Kane wrote:
 
  
   There is probably a better way to do this but a
 for loop like this should
 
   work. You would just need to change the numbers
 to yours and then add on
  the
   locations
  
 =
  
   scores  - 1:5
   mydata - matrix(data=NA, nrow=5, ncol=10)
  
   for(i in 1:10) {
   mydata[,i] - sample(scores, 5,
 replace=FALSE)
   }
  
  
 =
   --- On Wed, 4/20/11, Kevin Matthews [hidden
 email]http://user/SendEmail.jtp?type=nodenode=3463799i=0by-user=t
  wrote:
  
   From: Kevin Matthews [hidden 
   email]http://user/SendEmail.jtp?type=nodenode=3463799i=1by-user=t
 
   Subject: Re: [R] Random Relabelling
   To: John Kane [hidden 
   email]http://user/SendEmail.jtp?type=nodenode=3463799i=2by-user=t
 
   Cc: [hidden 
   email]http://user/SendEmail.jtp?type=nodenode=3463799i=3by-user=t
   Received: Wednesday, April 20, 2011, 1:22 PM
  
   I have a map of Iowa of with 4000
 locations.  At each location, I have a
   cancer mortality rate.  I need to test my
 null hypothesis; that the
  spatial
   distribution of the mortality rates is 
 random.  For this test, I need to
 
   establish a spatial reference distribution.
  
  
   My reference distribution will be created by some
 random relabelling
   algorithm.  The 4000 locations would remain
 fixed, but the observed
   mortality rates would be randomly
 redistributed.  Then, I want 1000
   permutations of the same algorithm.  For
 each of those 1000 times, I
  would
   record the redistributed mortality rate at each
 location.  Then,  I would
 
   calculate the mean of the 1000 points.  The
 result would be a spatial
   reference distribution with a mean value of the
 random permutations at
  each
   of the 4000 locations.
  
   Thanks for the response,Kevin
  
   On Wed, Apr 20, 2011 at 11:08 AM, John Kane
 [hidden 
 email]http://user/SendEmail.jtp?type=nodenode=3463799i=4by-user=t
  wrote:
  
  
   Can you explain this a bit more. At the moment I
 don't see what you are
   trying to achieve.   calculate
 the mean of the 1000 values at each of
  the
   4000 points does not seem to make sense.
  
   --- On Wed, 4/20/11, kmatthews [hidden
 email]http://user/SendEmail.jtp?type=nodenode=3463799i=5by-user=t
  wrote:
  
From: kmatthews [hidden 
email]http://user/SendEmail.jtp?type=nodenode=3463799i=6by-user=t
 
  
Subject: [R] Random Relabelling
  
To: [hidden 
email]http://user/SendEmail.jtp?type=nodenode=3463799i=7by-user=t
  
Received: Wednesday, April 20, 2011, 10:04
 AM
  
I have 4000 observations that I need
  
to randomly relabel 1000 times and then
  
calculate the mean of the 1000 values at
 each of the 4000
  
points.  Any ideas
  
for where to begin?
  
   
  
Thanks
  
Kevin
  
   
  
  
   [[alternative HTML version deleted]]
  
   __
   [hidden 
   email]http://user/SendEmail.jtp?type=nodenode=3463799i=8by-user=tmailing
 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.
  
  
  __
  [hidden 
  email]http://user/SendEmail.jtp?type=nodenode=3463799i=9by-user=tmailing
 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.
  Jeremy T. Hetzel
  Boston University
 
 
  --
   If you reply to this email, your message will be
 

Re: [R] Problem installing XML in Ubuntu 10.10

2011-04-25 Thread Ben Tupper

Hi,

On Apr 25, 2011, at 6:38 PM, Abraham Mathew wrote:

This is kind of a second question (yeah, I know), but I also get a  
similar

error when I try to install the RCurl package

* installing *source* package ‘RCurl’ ...
checking for curl-config... no
Cannot find curl-config
ERROR: configuration failed for package ‘RCurl’
* removing ‘/home/abraham/R/i686-pc-linux-gnu-library/2.13/RCurl’

The downloaded packages are in
‘/tmp/RtmpNmbI03/downloaded_packages’
Warning message:
In install.packages() :
installation of package 'RCurl' had non-zero exit status




I just went through a similar experience on CentOS.  My Linux skills  
are a bit wobbly, but I learned watching my local IT whiz get me  
straightened out.  Have you tried testing the curl companion command,  
curl-config, to see what you have installed?  For example...


$ curl-config --version
libcurl 7.19.7

If that doesn't work then it seems to me that you either don't have  
curl installed or if you do it isn't on your search path.


Cheers,
Ben







I never had any problems with installing packages. However, I recently
removed my windows
partition and things all weird now.


Thanks again.



On Mon, Apr 25, 2011 at 6:19 PM, Phil Spector spec...@stat.berkeley.edu 
wrote:



Abraham -

   sudo apt-get install libxml2-dev

is what you need to get the development libraries and xml2-config  
installed

on your Ubuntu machine.

 - Phil




On Mon, 25 Apr 2011, Abraham Mathew wrote:

Hello folks,



Here's is info on what system I'm working on.


sessionInfo()


R version 2.13.0 (2011-04-13)
Platform: i686-pc-linux-gnu (32-bit)


I'm trying to install the XML package. However, I end up with the
following
error message.

install.packages(XML)




checking for xml2-config... no
Cannot find xml2-config
ERROR: configuration failed for package ?XML?
* removing ?/home/abraham/R/i686-pc-linux-gnu-library/2.13/XML?

The downloaded packages are in
?/tmp/RtmpUsckPl/downloaded_packages?
Warning message:
In install.packages() :
installation of package 'XML' had non-zero exit status


When I run library(XML), I get that there is no package named XML.

Can anyone help diagnose the problem.


Thank You,
Abraham

  [[alternative HTML version deleted]]





[[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.


Ben Tupper
Bigelow Laboratory for Ocean Sciences
180 McKown Point Rd. P.O. Box 475
West Boothbay Harbor, Maine   04575-0475
http://www.bigelow.org/

__
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] Trouble Passing a for loop variable (iteration #) to a data frame

2011-04-25 Thread Galen Moore
Thank you very much, Peter.  The  iter[i] = x[i] solution worked
perfectly.

Galen

-Original Message-
From: Peter Langfelder [mailto:peter.langfel...@gmail.com] 
Sent: Monday, April 25, 2011 17:07
To: galen.a.mo...@gmail.com
Cc: r-help@r-project.org
Subject: Re: [R] Trouble Passing a for loop variable (iteration #) to a data
frame

You need to index the variable iter: instead of iter = x[i], say

iter[i] = x[i].

But a better solution is to simply say

iter = x

at the beginning and don't update it in the loop.

The way your code is written, iter just holds the last x[i], and the last
x[i] at the end of each loop is 4.

Peter

On Mon, Apr 25, 2011 at 3:29 PM, Galen Moore galen.a.mo...@gmail.com
wrote:
 Greetings -



 I am working on a piece of code to simulate vehicle times in and out 
 in each of a number of parking spaces.  At this stage, my code 
 basically does what it is supposed to do but for the sequential number 
 of each new parking event for a given space (i.e., the index of the 
 loop variable).  Instead of passing the index of the loop variable 
 (iter) to the data frame, it passes the value of the total number of 
 iterations.  Eventually, the number of iterations (parking events in a 
 given space) will be determined by an
 rnorm() fcn, so I am not looking for a process that locks-in the 
 number of iterations.  The total eventual data set size is small-ish, 
 so I'm not worried about speed.



 I'm sure my problem lies somehow in my setup of the data frames and my
 rbind() fcns, but a great many attempts and several hours of searching 
 online have not yet brought success.



 Can you please suggest what I need to do to get the iteration # to 
 appear in the iter vector and therefore to the data frame?



 Many thanks,



 Galen





 # fabdata3.r

 # fabricate sample data



 #declare the mean duration

 dur-.04



 #declare the stdDev of the rnorm() fcn (duration)

 varc-.01



 sp-numeric()

 iter-numeric()

 ti-numeric()

 to-numeric()

 actdur-numeric()

 #newline-data.frame(sp, iter, ti, to, actdur)

 ds-data.frame(sp, iter, ti, to, actdur)



 # BEGIN OUTER LOOP

 for (sp in c(1:3)) {

 +

 +            ct-1

 +            # BEGIN INNER LOOP

 +

 +            x - seq(1, 4, by=1)

 +            for (i in seq(along=x)) {

 +

 +                         if (i == 1)   {

 +                          ti[1]-((.33+rnorm(1, dur, varc)))

 +                          to[1]-((ti[1]+rnorm(1, dur, varc)))

 +                          actdur[1]-(to[1]-ti[1])

 +                          iter-x[1]

 +

 +                          }

 +

 +                         else {

 +                         # set subsequent time-ins to prev to + a 
 + rand#

 +                         ti[i]-((to[i-1]+rnorm(1, dur, varc)))

 +                         # calculate each event's time-out

 +                         to[i]-((ti[i]+rnorm(1, dur, varc)))

 +                         # calculate each event's actual duration

 +                         actdur[i]-(to[i]-ti[i])

 +                         iter-x[i]

 +

 +                         }

 +                          spStep-paste(sp Value is , sp)

 +                          print(spStep)

 +                          iterStep-paste(iter Value is , iter)

 +                          print(iterStep)

 +

 +                         newrow-data.frame(sp, iter, ti, to, actdur)

 +                         ct=ct+1

 +                  }  #END INNER LOOP

 +                  ds-rbind(ds, newrow)

 +             }

 [1] sp Value is  1

 [1] iter Value is  1

 [1] sp Value is  1

 [1] iter Value is  2

 [1] sp Value is  1

 [1] iter Value is  3

 [1] sp Value is  1

 [1] iter Value is  4

 [1] sp Value is  2

 [1] iter Value is  1

 [1] sp Value is  2

 [1] iter Value is  2

 [1] sp Value is  2

 [1] iter Value is  3

 [1] sp Value is  2

 [1] iter Value is  4

 [1] sp Value is  3

 [1] iter Value is  1

 [1] sp Value is  3

 [1] iter Value is  2

 [1] sp Value is  3

 [1] iter Value is  3

 [1] sp Value is  3

 [1] iter Value is  4

             print(ds)

   sp iter        ti        to     actdur

 1   1    4 0.3600055 0.4123550 0.05234955

 2   1    4 0.4343887 0.4640804 0.02969170

 3   1    4 0.5240268 0.5622272 0.03820032

 4   1    4 0.5945877 0.6436489 0.04906118

 5   2    4 0.3694827 0.4166405 0.04715775

 6   2    4 0.4609841 0.4968517 0.03586767

 7   2    4 0.5357721 0.5735439 0.03777185

 8   2    4 0.6207077 0.6512799 0.03057217

 9   3    4 0.3801887 0.4122605 0.03207179

 10  3    4 0.4440002 0.4916171 0.04761685

 11  3    4 0.5380228 0.5791549 0.04113214

 12  3    4 0.6087923 0.6291451 0.02035284

 # END OUTER LOOP




        [[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.



  1   2   >