[R] Replacing part of delimited string with R's regex

2013-07-10 Thread Gundala Viswanath
I have the following list of strings:

name <- c("hsa-miR-555p","hsa-miR-519b-3p","hsa-let-7a")

What I want to do is for each of the above strings
replace the text after second delimiter with "zzz".
Yielding:

hsa-miR-zzz
hsa-miR-zzz
hsa-let-zzz

What's the way to do it?

[[alternative HTML version deleted]]

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


Re: [R] Replacing part of delimited string with R's regex

2013-07-10 Thread David Winsemius

On Jul 10, 2013, at 12:02 AM, Gundala Viswanath wrote:

> I have the following list of strings:
> 
> name <- c("hsa-miR-555p","hsa-miR-519b-3p","hsa-let-7a")
> 
> What I want to do is for each of the above strings
> replace the text after second delimiter with "zzz".
> Yielding:
> 
> hsa-miR-zzz
> hsa-miR-zzz
> hsa-let-zzz

?regex

Look at sections on character classe, repetition quantifiers, and back 
references.

> sub("(^[^-]*-[^-]*-)(.*$)", "\\1zzz", name)
[1] "hsa-miR-zzz" "hsa-miR-zzz" "hsa-let-zzz"

-- 
David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Filter Dataframe for Alarm for particular column(s).

2013-07-10 Thread R_Antony
Hi Arun,

 

Thanks for the solution it  really works !. But how can we avoid even lappy() 
and  sappy().

Actually any way to do with ts() ?

 

Thanks,

Antony.

 

From: arun kirshna [via R] [mailto:ml-node+s789695n467097...@n4.nabble.com] 
Sent: Saturday, July 06, 2013 12:54 AM
To: Akkara, Antony (GE Power & Water, Non-GE)
Subject: Re: Filter Dataframe for Alarm for particular column(s).

 

Hi, 
May be this helps: 
If you had showed your solution, it would be easier to compare. 

res<-data.frame(lapply(sapply(MyDF[,c(2,4)],function(x) 
{x1<-which(c(0,diff(x))<0);x1[length(x1)==0]<-0;x1}),`[`,1)) 
 res 
#  TNH BIX 
#1   3   9 


#Speed 

 set.seed(24) 
 MyDFNew<- 
data.frame(TNH=sample(0:1,1e6,replace=TRUE),BIX=sample(0:1,1e6,replace=TRUE)) 
system.time(res1<-data.frame(lapply(sapply(MyDFNew,function(x) 
{x1<-which(c(0,diff(x))<0);x1[length(x1)==0]<-0;x1}),`[`,1))) 
#   user  system elapsed 
#  0.364   0.000   0.363 

 res1 
#  TNH BIX 
#1   7   2 
 MyDFNew[1:10,] 
#   TNH BIX 
#10   1 
#20   0 
#31   1 
#41   1 
#51   0 
#61   0 
#70   1 
#81   1 
#91   1 
#10   0   0 


A.K. 


Hi, 


Hi here i have a dataframe called MyDF. 

a<-c(1,1,1,1,1,0,0,0,1,1) 
b<-c(1,1,0,1,1,0,0,0,1,1) 
c<-c(1,1,1,1,1,1,1,0,1,1) 
d<-c(1,1,1,1,1,1,1,1,0,1) 
MyDF<-data.frame(DWATT=a,TNH=b,CSGV=c,BIX=d) 

My requirement is, here i need a function - to get for a 
particular row number(s), when particular column(s) value change from 
one-to-zero  (for the first change). Suppose there is no change is 
happening then it should return "Zero" 

For example,  Using MyDF, 

DWATT TNH CSGV BIX 
1   11   1 
1   11   1 
1   01   1 
1   11   1 
1   11   1 
0   01   1 
0   01   1 
0   00   1 
1   11   0 
1   11   1 

Here i want to know, the row number where TNH-column and BIX-column values 
change happening from one-to-zero for the first time. 

Note:- Suppose there is no change is happening then it should return "Zero" 

Answer should be  a dataframe with single row. 
So here answer should return a dataframe like this. 

TNH  BIX 
-- 
3  9 


i used some ways to get a solution using loops. But there is a bulk files with 
bulk rows to process. 
So performace is most important. Could someone please suggest better ideas ? 

Thanks, 
Antony. 

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





If you reply to this email, your message will be added to the discussion below:

http://r.789695.n4.nabble.com/Filter-Dataframe-for-Alarm-for-particular-column-s-tp4670950p4670970.html
 

To unsubscribe from Filter Dataframe for Alarm for particular column(s)., click 
here 

 .
NAML 

  





--
View this message in context: 
http://r.789695.n4.nabble.com/Filter-Dataframe-for-Alarm-for-particular-column-s-tp4670950p4671203.html
Sent from the R help mailing list archive at Nabble.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.


[R] Announcing TIBCO Enterprise Runtime for R

2013-07-10 Thread Louis Bajuk-Yorgan
In honor of the kickoff of useR 2013 today, I'm proud to announce the 
availability of TIBCO Enterprise Runtime for R (or TERR for short), our new 
enterprise-grade, high-performance statistical engine, fully compatible with 
the R language.

For more information on TERR, and a link to download the free Developer's 
Edition via the TERR Community site, check out 
http://spotfire.tibco.com/terr--or come to my talk at useR on Thursday morning.

As part of our development of TERR, we have also contributed new packages to 
CRAN: sjdbc (a JDBC driver interface, previously developed for S-PLUS) and 
tibbrConnector (an R interface to tibbr, TIBCO's Social Network for the 
Enterprise).

--
Lou Bajuk-Yorgan
@loubajuk
TIBCO Spotfire

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Kriging Package Cryptic Error Message

2013-07-10 Thread S Ellison
Try initial fitting with fewer lags; I get a fit to your data with lags=3.

S Ellison
 

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Diego Ubuntu
> Sent: 06 July 2013 16:09
> To: r-help@r-project.org
> Subject: [R] Kriging Package Cryptic Error Message
> 
> I'm trying to get a kriging surface using these data, but I 
> only get this error message. Any ideas on why or how to solve it.
> >d
>   x   y  e
> 1  551595.2 18040622.0
> 2  599591.7 18208232.0
> 3  615604.7 18209032.0
> 4  612337.6 17709892.1
> 5  614203.6 17618163.0
> 6  514248.6 1739406   26.0
> 7  448250.4 17376913.0
> 8  399904.6 1708316   31.0
> 9  487431.4 1676800  670.0
> 10 614769.4 1647540  442.0
> 11 485710.4 16730410.0
> 12 308095.1 1635087 1079.0
> 13 374141.7 1583102 1674.0
> 14 483754.7 1472197   48.0
> 15 433475.7 1588404  628.0
> 16 476571.0 1553267 1007.0
> 17 433480.4 1590174  628.0
> 18 264654.0 1596733  626.0
> 19 431438.7 14703995.0
> 20 429587.9 14667545.0
> 
> >kriging(d$x,d$y,d$e)
> Error in krig.fit(D, nugget, range, sill, model, n) :
>   NA/NaN/Inf in foreign function call (arg 3)
> 
> Thanks
> 
>   [[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.
> 

***
This email and any attachments are confidential. Any use...{{dropped:8}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] find 2D corelation coefficient

2013-07-10 Thread smriti Sebastian
Plz c this link
http://www.mathworks.in/help/images/ref/corr2.html


On Tue, Jul 9, 2013 at 3:43 PM, smriti Sebastian  wrote:

> Two dimensional corelation coefficient-2D corelation between (x,y) and
> (x1,y1) where x and x1 are same.
>
>
> On Tue, Jul 9, 2013 at 2:27 PM, peter dalgaard  wrote:
>
>>
>> On Jul 9, 2013, at 07:30 , smriti Sebastian wrote:
>>
>> > I need to find the 2d corelation betwee two datasets which are having
>> > common x-values.Is there any way to find 2D corelation in R?
>>
>>
>> If you can tell us what the definition is
>>
>> --
>> Peter Dalgaard, Professor
>> Center for Statistics, Copenhagen Business School
>> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
>> Phone: (+45)38153501
>> Email: pd@cbs.dk  Priv: pda...@gmail.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.


[R] Handling large R objects and limitation by RAM

2013-07-10 Thread siddharth arun
I’m doing some text analytic in R and facing some issue on which I need
help.
As a part of the algorithm I’ve to generate the *svd matrix* (dimension
reduction) for a large binary matrix (parent). I’m using the svd function
for that. The size (memory occupied) of the svd tends to get very large and
if the amount of data (no. of rows / cols ) of the parent matrix is very
large then the size of svd gets tremendously unhandlable. It looks like R
runs the processes on system RAM and if the size of the svd matrix gets
larger than the available RAM then it (and the system) hangs!! *Is there a
way to handle internal objects in R with very large sizes (specially more
than the available RAM)??* Any suggestion for the problem I’m facing?

-- 
Regards,

Siddharth Arun,
Contact No. - +91 8880065278

[[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] Replacing part of delimited string with R's regex

2013-07-10 Thread arun
Hi
You could use:
 gsub("([[:alnum:]]+-)([[:alnum:]]+-)(.*)","\\1\\2zzz",name)
#[1] "hsa-miR-zzz" "hsa-miR-zzz" "hsa-let-zzz"
A.K.




- Original Message -
From: Gundala Viswanath 
To: "r-h...@stat.math.ethz.ch" 
Cc: 
Sent: Wednesday, July 10, 2013 3:02 AM
Subject: [R] Replacing part of delimited string with R's regex

I have the following list of strings:

name <- c("hsa-miR-555p","hsa-miR-519b-3p","hsa-let-7a")

What I want to do is for each of the above strings
replace the text after second delimiter with "zzz".
Yielding:

hsa-miR-zzz
hsa-miR-zzz
hsa-let-zzz

What's the way to do it?

    [[alternative HTML version deleted]]

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


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] find 2D corelation coefficient

2013-07-10 Thread peter dalgaard

On Jul 10, 2013, at 13:13 , smriti Sebastian wrote:

> Plz c this link
> http://www.mathworks.in/help/images/ref/corr2.html
> 

That's for comparing images. Are your data images?


> 
> On Tue, Jul 9, 2013 at 3:43 PM, smriti Sebastian > wrote:
> 
>> Two dimensional corelation coefficient-2D corelation between (x,y) and
>> (x1,y1) where x and x1 are same.
>> 
>> 
>> On Tue, Jul 9, 2013 at 2:27 PM, peter dalgaard  wrote:
>> 
>>> 
>>> On Jul 9, 2013, at 07:30 , smriti Sebastian wrote:
>>> 
 I need to find the 2d corelation betwee two datasets which are having
 common x-values.Is there any way to find 2D corelation in R?
>>> 
>>> 
>>> If you can tell us what the definition is
>>> 
>>> --
>>> Peter Dalgaard, Professor
>>> Center for Statistics, Copenhagen Business School
>>> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
>>> Phone: (+45)38153501
>>> Email: pd@cbs.dk  Priv: pda...@gmail.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.

-- 
Peter Dalgaard, Professor
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] Kruskal.test

2013-07-10 Thread arun
Hi,
Please dput() your example dataset.

dat1<- read.table(text="a   a   a   a    a    b   b    b    c    c   c    c
2  4    5   2    7    2   2    6    3    7   9    3
3  3   4   1 6    8   1    3    5    2    6    
3",sep="",header=FALSE,stringsAsFactors=FALSE)
library(reshape)
 dat2<-melt(as.data.frame(t(dat1)),id.var="V1")[,-2]
kruskal.test(value~V1,data=dat2)
#
#    Kruskal-Wallis rank sum test
#
#data:  value by V1
#Kruskal-Wallis chi-squared = 1.2888, df = 2, p-value = 0.525

#I guess you wanted for each row:
lapply(split(dat2,(seq_len(nrow(dat2))-1)%/%ncol(dat1)+1),function(x) 
kruskal.test(value~V1,data=x))
#$`1`
#
#    Kruskal-Wallis rank sum test
#
#data:  value by V1
#Kruskal-Wallis chi-squared = 2.003, df = 2, p-value = 0.3673
#

#$`2`

#    Kruskal-Wallis rank sum test

#data:  value by V1
#Kruskal-Wallis chi-squared = 0.1231, df = 2, p-value = 0.9403



A.K.


From: Vera Costa 
To: arun  
Sent: Wednesday, July 10, 2013 6:38 AM
Subject: Re: Kruskal.test



Thank you. 
And if I have 

a   a   a   a    a    b   b    b    c    c   c    c
2  4    5   2    7    2   2    6    3    7   9    3
3  3   4   1 6    8   1    3    5    2    6    3   ?

How can I apply the test by row?

Thank you

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] find a function for a random curve

2013-07-10 Thread Xiaoyu Lu
Hi,

I want to find a functional form for my data. I have tried smoothing and
obtained a kinda perfect fit.
However, I can only draw it but cannot call it.

I am wondering that is there a way that I can store the fit as a function
and apply it when needed. e.g. tranformation etc.

Many thanks!


Yours sincerely,
Xiaoyu

[[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] Canonical Correlation Analysis for three fields

2013-07-10 Thread fsantos
Dear R community,

I was wondering if it is possible to adapt the CCA methodology for three
set of variables. Could you give me some suggestions?

Regards,

Francisco

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] find a function for a random curve

2013-07-10 Thread S Ellison
> I want to find a functional form for my data. I have tried 
> smoothing and obtained a kinda perfect fit.
> However, I can only draw it but cannot call it.
You'll need to apply the smoothing function to the data separately, store that 
and plot the curve (?) fom that.

You can plot a line for many model fits using the associated predict() method 
and if necessary specifying a newdata data frame containing neatly-spaced 
predictors; look up the generic ?predict and predict.lm for a typical case. 
predict.nlm and predict.loess also exist and work much the same way. 

S Ellison 


***
This email and any attachments are confidential. Any use...{{dropped:8}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Bivariate Tolerance Region

2013-07-10 Thread Anamika Chaudhuri
Hi:

I apologize for posting in the R listserv. But I am trying to do the
following in R.
I am trying to construct Bivariate 95% Approximate Confidence interval for
the mean vector p=(p1,p2) similar to what we have in the univariate case.

[image: \hat p \pm z_{1 - \frac{1}{2}\alpha} \sqrt{\frac{1}{n}\hat p
\left(1 - \hat p \right)}]



Should I be using bivariate tolerance region instead? Any thoughts?

Thanks
Anamika

[[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] PCA and gglot2

2013-07-10 Thread ashz
Hi,

I was trying as well as looking for an answer without success (a bit strange
since it should be an easy problem) and therefore I will appreciate you
help:

My simple script is:
# Loadings data of 5 columns and 100 rows of data
data1<-read.csv("C:/…/MyPCA.csv")
pairs(data1[,1:4])
pca1 <- princomp(data1[,1:4], score=TRUE, cor=TRUE)
biplot(pca1)

The biplot present the data points as numbers. How can I present the data
point in color (depends on their group-column 5). I was thinking about doing
it using ggplot2 but I can not succeed. Any idea how to do it?

Thanks 



--
View this message in context: 
http://r.789695.n4.nabble.com/PCA-and-gglot2-tp4671225.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] Error message

2013-07-10 Thread Emanuele Belli
Hello,
I'm an italian student, I've got some problems using R:
After calculating a dbinom() function, my  "help.start()" started not to work.
If I type on the console "Help.start", it says me "starting httpd help server 
...Errore in stats::runif(10) : 
  .Random.seed is not an integer vector but of type 'double'" 
 
I tried to upgrade, unistall, but anything, it was impossible to solve this 
problem.
Can you help me?
Thank you in advance,
 
Emanuele
[[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] Error message

2013-07-10 Thread Prof Brian Ripley

On 10/07/2013 15:04, Emanuele Belli wrote:

Hello,
I'm an italian student, I've got some problems using R:
After calculating a dbinom() function, my  "help.start()" started not to work.
If I type on the console "Help.start", it says me "starting httpd help server 
...Errore in stats::runif(10) :
   .Random.seed is not an integer vector but of type 'double'"

I tried to upgrade, unistall, but anything, it was impossible to solve this 
problem.
Can you help me?


Try

rm(.Random.seed)

Looks like you saved an object of the wrong type under than name.


Thank you in advance,

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




--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] fitting log function: errors using nls and nlxb

2013-07-10 Thread Prof J C Nash (U30A)
This reply only addresses the NaN in Jacobian matter. I believe it is a 
result of getting a perfect fit (0 sum of squares). I have amended the 
r-forge version of nlmrt package in routines nlfb and nlxb and did not 
get the error running Elizabeth's example. This only answers the 
software issue, of course, not the statistical one.


Use the version of nlmrt from the SCM repository on
https://r-forge.r-project.org/R/?group_id=395

or email me for a tarball of this.

JN


On 13-07-10 06:00 AM, r-help-requ...@r-project.org wrote:

On Mon, Jul 8, 2013 at 9:27 PM, Elizabeth Webb
wrote:

>Hi-
>I am trying to fit a log function to my data, with the ultimate goal of
>finding the second derivative of the function.  However, I am stalled on
>the first step of fitting a curve.
>
>When I use the following code:
>FG2.model<-(nls((CO2~log(a*Time)+b), start=setNames(coef(lm(CO2 ~
>log(Time), data=FG2)), c("a", "b")),data=FG2))
>I get the following error:
>Error in numericDeriv(form[[3L]], names(ind), env) :
>   Missing value or an infinity produced when evaluating the model
>In addition: Warning messages:
>1: In min(x) : no non-missing arguments to min; returning Inf
>2: In max(x) : no non-missing arguments to max; returning -Inf
>3: In log(a * Time) : NaNs produced
>4: In log(a * Time) : NaNs produced
>
>When I fit the curve in Plot and use the coefficients as starting values:
>start=c(a=68,b=400)
>FG2.model<-(nls((CO2~log(a*Time)+b), start=start,data=FG2))
>I get the following error:
>Error in nls((CO2 ~ log(a * Time) + b), start = start, data = FG2) :
>   singular gradient
>In addition: Warning messages:
>1: In min(x) : no non-missing arguments to min; returning Inf
>2: In max(x) : no non-missing arguments to max; returning -Inf
>
>So then when I substituded nlxb for nls in the above two models, I got this
>error:
>Error in nlxb((CO2 ~ log(a * Time) + b), start = start, data = FG2) :
>   NaN in Jacobian
>


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] PCA and gglot2

2013-07-10 Thread John Kane
It looks like you can if I understand properly. Try this
dat1  <-  data.frame(dat1$scores)
dat1$items  <-  rownames(data1)
ggplot(dat1, aes(Comp.1, Comp.2, colour = items)) + geom_point() +
   theme(legend.position="none")


John Kane
Kingston ON Canada


> -Original Message-
> From: a...@walla.co.il
> Sent: Wed, 10 Jul 2013 06:09:00 -0700 (PDT)
> To: r-help@r-project.org
> Subject: [R] PCA and gglot2
> 
> Hi,
> 
> I was trying as well as looking for an answer without success (a bit
> strange
> since it should be an easy problem) and therefore I will appreciate you
> help:
> 
> My simple script is:
> # Loadings data of 5 columns and 100 rows of data
> data1<-read.csv("C:/…/MyPCA.csv")
> pairs(data1[,1:4])
> pca1 <- princomp(data1[,1:4], score=TRUE, cor=TRUE)
> biplot(pca1)
> 
> The biplot present the data points as numbers. How can I present the data
> point in color (depends on their group-column 5). I was thinking about
> doing
> it using ggplot2 but I can not succeed. Any idea how to do it?
> 
> Thanks
> 
> 
> 
> --
> View this message in context:
> http://r.789695.n4.nabble.com/PCA-and-gglot2-tp4671225.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.


FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Sparse matrix no longer sparse (Matrix Package)

2013-07-10 Thread Doran, Harold
I have a large function computing an iterative algorithm for fitting mixed 
linear models. Almost all code relies on functions from the Matrix package. 
I've come across an issue that I do not believe previously occurred in earlier 
versions of R or Matrix.

I have a large, sparse matrix, A as

> class(A);dim(A)
[1] "dgCMatrix"
attr(,"package")
[1] "Matrix"
[1] 12312 12312

I am in a position where I must find its inverse.  I realize this is less than 
ideal, and I have two ways of doing this

A.Inv <- solve(A, Ir) or just solve(A)

Where Ir is an identity matrix with the same dimensions as A and it is also 
sparse

> class(Ir)
[1] "ddiMatrix"
attr(,"package")
[1] "Matrix"

The issue, however, is that the inverse of A is converted into a dense matrix 
and this becomes a huge memory hog, causing the rest of the algorithm to fail. 
In prior versions this remained as a sparse matrix.

> A.Inv[1:5, 1:5]
5 x 5 Matrix of class "dgeMatrix"
  [,1]  [,2]  [,3]  [,4]  [,5]
[1,] 0.6878713 0.000 0.000 0.000 0.000
[2,] 0.000 0.6718767 0.000 0.000 0.000
[3,] 0.000 0.000 0.5076945 0.000 0.000
[4,] 0.000 0.000 0.000 0.2324122 0.000
[5,] 0.000 0.000 0.000 0.000 0.2139975

I could coerce this matrix to become sparse such as

> AA <- as(A.Inv, 'sparseMatrix')
> class(AA)
[1] "dgCMatrix"
attr(,"package")
[1] "Matrix"

> AA[1:5, 1:5]
5 x 5 sparse Matrix of class "dgCMatrix"

[1,] 0.6878713 . . . .
[2,] . 0.6718767 . . .
[3,] . . 0.5076945 . .
[4,] . . . 0.2324122 .
[5,] . . . . 0.2139975

But I don't think this is best.

So, my question is why is a matrix that is sparse turning into a dense matrix? 
Can I avoid that and keep it sparse without having to coerce it to be sparse 
after it is created?

Thank you very much
Harold


> sessionInfo()
R version 3.0.1 (2013-05-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 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] lme4_0.99-2 Matrix_1.0-12   lattice_0.20-15

loaded via a namespace (and not attached):
[1] grid_3.0.1   nlme_3.1-109 stats4_3.0.1 tools_3.0.1

[[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] PCA and gglot2

2013-07-10 Thread S Ellison
> > The biplot present the data points as numbers. How can I 
> present the 
> > data point in color (depends on their group-column 5). I 
> was thinking 
> > about doing it using ggplot2 but I can not succeed. Any 
> idea how to do 
> > it?

Perhaps the post at
http://www.codesofmylife.com/2012/06/07/plotting-pca-results-with-ggplot2/

would help?
 
(as would googling "biplot in ggplot2", which is how I found it...)

Incidentally, if you want base graphics biplots with points and colour coding, 
you'd need to modify the biplot code a bit or roll your own. 

S Ellison


***
This email and any attachments are confidential. Any use...{{dropped:8}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Recherche de fonction

2013-07-10 Thread Raphaëlle Carraud
Bonjour,

Je souhaite  résoudre le couple d'équation différentielles suivant :

0 = -dA + dB + 2*dC - 2*r1 - 2*r5
0 = dA + dD + r1 + r4
0 = K2 - C/B^2
0 = K3 - D/(A*B)

0 = r5 + 2*r4 - dE
0 = r5 -dI
0 = -r5 - r4 - dG
0 = -r1/2 - dH

en ayant connaissance des valeurs initiales de dA, dB, dC, dE, dI, dG, dH, r1, 
r2, r4, r5, K2, K3, A, B, C et D.

J'ai essayé plusieurs fonctions mais comme je ne peux pas lui faire calculer 
une des dérivée de laquelle découlerait les autre, il n'arrive pas à me fournir 
la solution.
Je n'ai pas vu d'exemple qui pourrai s'assimiler à celui-ci dans la 
documentation.

Est-il possible de résoudre ce problème sur R ?

Merci

Cordialement,
Raphaëlle Carraud

[[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] output ggplot2 graph from asp.net?

2013-07-10 Thread yu ge
Hello there,

I want to output ggplot2 graphs(b/c they are pretty) in ASP.NET(C#). Any
one has success or is it feasible to do? Online said R.net is a choice but
said it's not available for R graph. Any suggestions?

[[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] Appropriate forum for announcing R package updates

2013-07-10 Thread Frank Harrell
I have been confused about the appropriate e-mail address to use to make 
announcements to r-help for major package update.  In the past I've 
submitted to r-packa...@lists.r-project.org without seeing the 
announcement appear on r-help.


Thanks for any guidance.
Frank

--
Frank E Harrell Jr Professor and Chairman  School of Medicine
   Department of Biostatistics Vanderbilt 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.


Re: [R] Sparse matrix no longer sparse (Matrix Package)

2013-07-10 Thread Doran, Harold
I have zero'd in on what appears to be the issue. This seems to be a bug in 
Matrix, but I am not sure yet. I am attaching files that would allow others to 
replicate this with my toy data.

Notice the elements of D1 in the attached data are all integers. It is a 
sparse, diagonal matrix.

> library(Matrix)
> class(D1)
[1] "ddiMatrix"
attr(,"package")
[1] "Matrix"

Now, I find the inverse of the matrix A as follows:
> A <- Ir + ZtZ %*% D1
> A.Inv <- solve(A, Ir)

Notice now the inverse of A remains a dgCMatrix and it is relatively small in 
size, only 33424 bytes.
> class(A.Inv)
[1] "dgCMatrix"
attr(,"package")
[1] "Matrix"

> object.size(A.Inv)
33424 bytes

Now, if I change an element of the matrix D1 to be non-integer, D1 still has 
the same class as it did before

> D1[1] <- 1.2

> class(D1)
[1] "ddiMatrix"
attr(,"package")
[1] "Matrix"

Now, if I use this new version of D1 in the same calculations as above, notice 
that A.Inv is no longer a dgCMatrix but instead becomes a dgeMatrix. It then 
increases from an object of size 33424 bytes to an object of size 2001112 bytes!

> A <- Ir + ZtZ %*% D1
> A.Inv <- solve(A, Ir)
> class(A.Inv)
[1] "dgeMatrix"
attr(,"package")
[1] "Matrix"
> object.size(A.Inv)
2001112 bytes

What I desire is that the object A.Inv remain sparse at all times and not 
become dense. But, perhaps there is a reason this change occurs that I don't 
fully understand.

I can of course coerce it back to a sparse matrix and it reduces back in size.
>  object.size(as(A.Inv, 'sparseMatrix'))
33424 bytes

I of course recognize it requires more memory to store floating points than 
integers, but is this large increase on the order of magnitude that seems about 
right? 

Is there a reason the floating point in D1 causes for A.Inv to no longer remain 
sparse?

Thank you for your help,
Harold





-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Doran, Harold
Sent: Wednesday, July 10, 2013 11:42 AM
To: r-help@r-project.org
Cc: dmba...@gmail.com; 'maech...@stat.math.ethz.ch'
Subject: [R] Sparse matrix no longer sparse (Matrix Package)

I have a large function computing an iterative algorithm for fitting mixed 
linear models. Almost all code relies on functions from the Matrix package. 
I've come across an issue that I do not believe previously occurred in earlier 
versions of R or Matrix.

I have a large, sparse matrix, A as

> class(A);dim(A)
[1] "dgCMatrix"
attr(,"package")
[1] "Matrix"
[1] 12312 12312

I am in a position where I must find its inverse.  I realize this is less than 
ideal, and I have two ways of doing this

A.Inv <- solve(A, Ir) or just solve(A)

Where Ir is an identity matrix with the same dimensions as A and it is also 
sparse

> class(Ir)
[1] "ddiMatrix"
attr(,"package")
[1] "Matrix"

The issue, however, is that the inverse of A is converted into a dense matrix 
and this becomes a huge memory hog, causing the rest of the algorithm to fail. 
In prior versions this remained as a sparse matrix.

> A.Inv[1:5, 1:5]
5 x 5 Matrix of class "dgeMatrix"
  [,1]  [,2]  [,3]  [,4]  [,5]
[1,] 0.6878713 0.000 0.000 0.000 0.000 [2,] 0.000 0.6718767 
0.000 0.000 0.000 [3,] 0.000 0.000 0.5076945 0.000 
0.000 [4,] 0.000 0.000 0.000 0.2324122 0.000 [5,] 0.000 
0.000 0.000 0.000 0.2139975

I could coerce this matrix to become sparse such as

> AA <- as(A.Inv, 'sparseMatrix')
> class(AA)
[1] "dgCMatrix"
attr(,"package")
[1] "Matrix"

> AA[1:5, 1:5]
5 x 5 sparse Matrix of class "dgCMatrix"

[1,] 0.6878713 . . . .
[2,] . 0.6718767 . . .
[3,] . . 0.5076945 . .
[4,] . . . 0.2324122 .
[5,] . . . . 0.2139975

But I don't think this is best.

So, my question is why is a matrix that is sparse turning into a dense matrix? 
Can I avoid that and keep it sparse without having to coerce it to be sparse 
after it is created?

Thank you very much
Harold


> sessionInfo()
R version 3.0.1 (2013-05-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252 
[3] LC_MONETARY=English_United States.1252 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] lme4_0.99-2 Matrix_1.0-12   lattice_0.20-15

loaded via a namespace (and not attached):
[1] grid_3.0.1   nlme_3.1-109 stats4_3.0.1 tools_3.0.1

[[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] Recherche de fonction

2013-07-10 Thread Berend Hasselman

On 10-07-2013, at 16:21, Raphaëlle Carraud  
wrote:

> Bonjour,
> 
> Je souhaite  résoudre le couple d'équation différentielles suivant :
> 
>0 = -dA + dB + 2*dC - 2*r1 - 2*r5
>0 = dA + dD + r1 + r4
>0 = K2 - C/B^2
>0 = K3 - D/(A*B)
> 
>0 = r5 + 2*r4 - dE
>0 = r5 -dI
>0 = -r5 - r4 - dG
>0 = -r1/2 - dH
> 
> en ayant connaissance des valeurs initiales de dA, dB, dC, dE, dI, dG, dH, 
> r1, r2, r4, r5, K2, K3, A, B, C et D.
> 

If all initial values are known then plugging the values in the system will 
give 0 or not 0. There is nothing to "solve".

> J'ai essayé plusieurs fonctions mais comme je ne peux pas lui faire calculer 
> une des dérivée de laquelle découlerait les autre, il n'arrive pas à me 
> fournir la solution.
> Je n'ai pas vu d'exemple qui pourrai s'assimiler à celui-ci dans la 
> documentation.
> 

You will have to redo your query in English. Questions in French won't receive 
many replies.
My French is rudimentary but I'll try.

You have 8 equations and 17 variables.
So how do you propose to "solve" the system?

Assuming that the d? variables are differentials and that you want to solve for 
those:
you have 7 of these and 8 equations. So how to solve?

But the third and fourth equations have no d? variables, so the may even be 
inconsistent given the values of K2, K3, C, B, A, D.
So you have 6 equations for 7 d? variables. So how do you propose to solve for 
the d? variables?

Finally your system seems to be linear in the d? variables. You would be able 
to use R's solve()  if you can get your system to be a square system.

If your system is not square and underdetermined then you can use a Moore 
Penrose inverse to get a minimum norm solution 
(http://en.wikipedia.org/wiki/Moore–Penrose_pseudoinverse#Minimum-norm_solution_to_a_linear_system).
package MASS provides a function ginv().

Berend

> Est-il possible de résoudre ce problème sur R ?
> 
> Merci
> 
> Cordialement,
> Raphaëlle Carraud
> 
>   [[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] Appropriate forum for announcing R package updates

2013-07-10 Thread Frank Harrell
Thank you Marc
Frank

Marc Schwartz-3 wrote
> On Jul 10, 2013, at 1:29 PM, Frank Harrell <

> f.harrell@

> > wrote:
> 
>> I have been confused about the appropriate e-mail address to use to make
>> announcements to r-help for major package update.  In the past I've
>> submitted to 

> R-packages@.r-project

>  without seeing the announcement appear on r-help.
>> 
>> Thanks for any guidance.
>> Frank
> 
> 
> 
> Hi Frank,
> 
> R-packages (https://stat.ethz.ch/mailman/listinfo/r-packages) should be
> the correct list for those announcements.
> 
> A quick check of a few recent posts shows that they are being forwarded to
> R-Help as well.
> 
> It is however a low volume list. 116 posts in 2010, 77 in 2011, 72 in 2012
> and 25 so far in 2013. The trend would seem to be downward.
> 
> Regards,
> 
> Marc Schwartz
> 
> __

> R-help@

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





-
Frank Harrell
Department of Biostatistics, Vanderbilt University
--
View this message in context: 
http://r.789695.n4.nabble.com/Appropriate-forum-for-announcing-R-package-updates-tp4671238p4671242.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] replacement functions for subsets

2013-07-10 Thread Harry Mamaysky
I know how to define replacement functions in R (i.e. ‘foo<-‘ <- 
function(x,value) x<-value, etc.), but how do you define replacement functions 
that operate on subsets of arrays (i.e. how do you pass an index into foo)?
For example, why does the following use of “rownames” work?

> aa <- data.frame( a=1:10,b=101:110 )

> aa

a   b

1   1 101

2   2 102

3   3 103

4   4 104

5   5 105

6   6 106

7   7 107

8   8 108

9   9 109

10 10 110

> rownames(aa)[2:4] <- c('row2','row3','row4')

> aa

  a   b

1 1 101

row2  2 102

row3  3 103

row4  4 104

5 5 105

6 6 106

7 7 107

8 8 108

9 9 109

10   10 110

> 

 

Thanks,

Harry

 
[[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] Appropriate forum for announcing R package updates

2013-07-10 Thread Marc Schwartz
On Jul 10, 2013, at 1:29 PM, Frank Harrell  wrote:

> I have been confused about the appropriate e-mail address to use to make 
> announcements to r-help for major package update.  In the past I've submitted 
> to r-packa...@lists.r-project.org without seeing the announcement appear on 
> r-help.
> 
> Thanks for any guidance.
> Frank



Hi Frank,

R-packages (https://stat.ethz.ch/mailman/listinfo/r-packages) should be the 
correct list for those announcements.

A quick check of a few recent posts shows that they are being forwarded to 
R-Help as well.

It is however a low volume list. 116 posts in 2010, 77 in 2011, 72 in 2012 and 
25 so far in 2013. The trend would seem to be downward.

Regards,

Marc Schwartz

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] PCA and gglot2

2013-07-10 Thread ashz
Hi,

Thanks. Fig 4 in the link you provided is what I am looking for.

I still do not know how to implement my data1 and pca1 in the script you
provided as I think it is only a part of a full script.
"
data1<-read.csv("C:/…/MyPCA.csv")
pca1 <- princomp(data1[,1:4], score=TRUE, cor=TRUE) 
"

Am I right, how can I implement my data.frames?

Thanks again



--
View this message in context: 
http://r.789695.n4.nabble.com/PCA-and-gglot2-tp4671225p4671237.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] Recherche de fonction

2013-07-10 Thread Berend Hasselman

On 10-07-2013, at 20:42, Berend Hasselman  wrote:

> 
> On 10-07-2013, at 16:21, Raphaëlle Carraud 
>  wrote:
> 
>> Bonjour,
>> 
>> Je souhaite  résoudre le couple d'équation différentielles suivant :
>> 
>>   0 = -dA + dB + 2*dC - 2*r1 - 2*r5
>>   0 = dA + dD + r1 + r4
>>   0 = K2 - C/B^2
>>   0 = K3 - D/(A*B)
>> 
>>   0 = r5 + 2*r4 - dE
>>   0 = r5 -dI
>>   0 = -r5 - r4 - dG
>>   0 = -r1/2 - dH
>> 
>> en ayant connaissance des valeurs initiales de dA, dB, dC, dE, dI, dG, dH, 
>> r1, r2, r4, r5, K2, K3, A, B, C et D.
>> 
> 
> If all initial values are known then plugging the values in the system will 
> give 0 or not 0. There is nothing to "solve".
> 
>> J'ai essayé plusieurs fonctions mais comme je ne peux pas lui faire calculer 
>> une des dérivée de laquelle découlerait les autre, il n'arrive pas à me 
>> fournir la solution.
>> Je n'ai pas vu d'exemple qui pourrai s'assimiler à celui-ci dans la 
>> documentation.
>> 
> 
> You will have to redo your query in English. Questions in French won't 
> receive many replies.
> My French is rudimentary but I'll try.
> 
> You have 8 equations and 17 variables.
> So how do you propose to "solve" the system?
> 
> Assuming that the d? variables are differentials and that you want to solve 
> for those:
> you have 7 of these and 8 equations. So how to solve?
> 
> But the third and fourth equations have no d? variables, so the may even be 
> inconsistent given the values of K2, K3, C, B, A, D.
> So you have 6 equations for 7 d? variables. So how do you propose to solve 
> for the d? variables?
> 
> Finally your system seems to be linear in the d? variables. You would be able 
> to use R's solve()  if you can get your system to be a square system.
> 
> If your system is not square and underdetermined then you can use a Moore 
> Penrose inverse to get a minimum norm solution 
> (http://en.wikipedia.org/wiki/Moore–Penrose_pseudoinverse#Minimum-norm_solution_to_a_linear_system).
> package MASS provides a function ginv().


And to make matters simple: since your lefthand sides are 0 the minimum norm 
solution of your system is 0.

Berend

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] replacement functions for subsets

2013-07-10 Thread David Winsemius

On Jul 10, 2013, at 11:47 AM, Harry Mamaysky wrote:

> I know how to define replacement functions in R (i.e. ‘foo<-‘ <- 
> function(x,value) x<-value, etc.), but how do you define replacement 
> functions that operate on subsets of arrays (i.e. how do you pass an index 
> into foo)?
> For example, why does the following use of “rownames” work?

`rownames` of a dataframe is a vector, so indexing with "[" and a single vector 
of indices is adequate. I cannot really tell what your conceptual 
"why"-difficulty might be. This is just assignment within a vector. That is not 
really a "replacement function operating on a subset of an array" since 
rownames are not values of the dataframe  and it's not an "array". (Careful 
use of terms is needed here.)


> 
>> aa <- data.frame( a=1:10,b=101:110 )
> 
>> aa
> 
>a   b
> 
> 1   1 101
> 
> 2   2 102
> 
> 3   3 103
> 
> 4   4 104
> 
> 5   5 105
> 
> 6   6 106
> 
> 7   7 107
> 
> 8   8 108
> 
> 9   9 109
> 
> 10 10 110
> 
>> rownames(aa)[2:4] <- c('row2','row3','row4')
> 
>> aa
> 
>  a   b
> 
> 1 1 101
> 
> row2  2 102
> 
> row3  3 103
> 
> row4  4 104
> 
> 5 5 105
> 
> 6 6 106
> 
> 7 7 107
> 
> 8 8 108
> 
> 9 9 109
> 
> 10   10 110
> 
>> 
> 
> 
> 
> Thanks,
> 
> Harry
> 
> 
>   [[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.

David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] how to adjust the x axis range based on y axis data

2013-07-10 Thread Kara Przeczek
I am using R studio version 0.97.336.



I am trying to produce multiple figures based on a large data set (98010 rows). 
I am creating a plot for each TITLE (related to a variable/station combination).



#Create a plot for each Title. Save all plots as jpegs in folder named 
"SkeenaQfigs"
for(i in 1:nlevels(dt$TITLE)){
  tmp.title <- subset(dt, TITLE == levels(dt$TITLE)[i])
  #save plot to file
  setwd("H:/R stuff/SJackson/SkeenaQfigs")
  options(show.error.messages = FALSE)
  result <- try(plot(tmp.title$YEAR, tmp.title$VALUE, xlab = "Year", ylab="", 
main = tmp.title$TITLE[1]))
  if(class(result) == 'try-error')
{
print(paste("error", tmp.title$TITLE[1], sep=" "))
}
else {
jpeg(file = paste(tmp.title$TITLE[1],".jpg",sep=""))
plot(tmp.title$YEAR, tmp.title$VALUE, xlab = "Year", ylab="", main = 
tmp.title$TITLE[1])
dev.off()
 }
}

The range of YEAR is the same for every station, but there is not always data 
for every year (and some stations have no data). I would like each plot to 
adjust the x-axis to start at the first occurrence of a y value.

I used



tmp.title <- tmp.title[!is.na(tmp.title$VALUE),]



to remove all the rows where VALUE = NA. However, there are some years later on 
in the data set that are missing data, but I want those to be included. I only 
want to remove the first empty rows.



I then tried,



xmin <- min(tmp.title$YEAR[tmp.title$VALUE>0], na.rm=T)
xmax <- max(tmp.title$YEAR, na.rm=T)

plot(tmp.title$YEAR, tmp.title$VALUE, xlab = "Year", ylab="", 
xlim=c(xmin,xmax), main = tmp.title$TITLE[1])



This works, but is there a simpler way to do this within the plot command?



Thank you very much for your help!

Kara

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Filter Dataframe for Alarm for particular column(s).

2013-07-10 Thread arun
Hi,
You could try ?data.table() to further increase the speed:



#Same example:
dt2<- data.table(MyDFNew)
system.time(resNew<- dt2[,lapply(.SD,function(x) 
{x1<-which(c(0,diff(x))<0);x1[length(x1)==0]<-0;x1})][1] )
 # user  system elapsed 
 # 0.144   0.004   0.148 
resNew
#   TNH BIX
#1:   7   2


According to this link 
(http://stackoverflow.com/questions/9236438/how-do-i-run-apply-on-a-data-table),
 using for loop should improve the speed

Regarding the use of ts() in this case, I am not very sure.

A.K.



- Original Message -
From: R_Antony 
To: r-help@r-project.org
Cc: 
Sent: Wednesday, July 10, 2013 1:48 AM
Subject: Re: [R] Filter Dataframe for Alarm for particular column(s).

Hi Arun,



Thanks for the solution it  really works !. But how can we avoid even lappy() 
and  sappy().

Actually any way to do with ts() ?

Thanks,

Antony.



From: arun kirshna [via R] [mailto:ml-node+s789695n467097...@n4.nabble.com] 
Sent: Saturday, July 06, 2013 12:54 AM
To: Akkara, Antony (GE Power & Water, Non-GE)
Subject: Re: Filter Dataframe for Alarm for particular column(s).



Hi, 
May be this helps: 
If you had showed your solution, it would be easier to compare. 

res<-data.frame(lapply(sapply(MyDF[,c(2,4)],function(x) 
{x1<-which(c(0,diff(x))<0);x1[length(x1)==0]<-0;x1}),`[`,1)) 
res 
#  TNH BIX 
#1   3   9 


#Speed 

set.seed(24) 
MyDFNew<- 
data.frame(TNH=sample(0:1,1e6,replace=TRUE),BIX=sample(0:1,1e6,replace=TRUE)) 
system.time(res1<-data.frame(lapply(sapply(MyDFNew,function(x) 
{x1<-which(c(0,diff(x))<0);x1[length(x1)==0]<-0;x1}),`[`,1))) 
#   user  system elapsed 
#  0.364   0.000   0.363 

res1 
#  TNH BIX 
#1   7   2 
MyDFNew[1:10,] 
#   TNH BIX 
#1    0   1 
#2    0   0 
#3    1   1 
#4    1   1 
#5    1   0 
#6    1   0 
#7    0   1 
#8    1   1 
#9    1   1 
#10   0   0 


A.K. 


Hi, 


Hi here i have a dataframe called MyDF. 

a<-c(1,1,1,1,1,0,0,0,1,1) 
b<-c(1,1,0,1,1,0,0,0,1,1) 
c<-c(1,1,1,1,1,1,1,0,1,1) 
d<-c(1,1,1,1,1,1,1,1,0,1) 
MyDF<-data.frame(DWATT=a,TNH=b,CSGV=c,BIX=d) 

My requirement is, here i need a function - to get for a 
particular row number(s), when particular column(s) value change from 
one-to-zero  (for the first change). Suppose there is no change is 
happening then it should return "Zero" 

For example,  Using MyDF, 

DWATT TNH CSGV BIX 
1   1    1   1 
1   1    1   1 
1   0    1   1 
1   1    1   1 
1   1    1   1 
0   0    1   1 
0   0    1   1 
0   0    0   1 
1   1    1   0 
1   1    1   1 

Here i want to know, the row number where TNH-column and BIX-column values 
change happening from one-to-zero for the first time. 

Note:- Suppose there is no change is happening then it should return "Zero" 

Answer should be  a dataframe with single row. 
So here answer should return a dataframe like this. 

TNH  BIX 
    -- 
3      9 


i used some ways to get a solution using loops. But there is a bulk files with 
bulk rows to process. 
So performace is most important. Could someone please suggest better ideas ? 

Thanks, 
Antony. 

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





If you reply to this email, your message will be added to the discussion below:

http://r.789695.n4.nabble.com/Filter-Dataframe-for-Alarm-for-particular-column-s-tp4670950p4670970.html
 

To unsubscribe from Filter Dataframe for Alarm for particular column(s)., click 
here 

 .
NAML 

  





--
View this message in context: 
http://r.789695.n4.nabble.com/Filter-Dataframe-for-Alarm-for-particular-column-s-tp4670950p4671203.html
Sent from the R help mailing list archive at Nabble.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.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] PCA and gglot2

2013-07-10 Thread John Kane
'Sorry I made a mistake .  I was using some data of my own and didn't make some 
key changes to the script to match your variables.


dat1  <-  data.frame(pca1 $scores)  # creates the data.frame
dat1$items  <-  rownames(data1pca1 ) # adds item names
ggplot(dat1, aes(Comp.1, Comp.2, colour = items)) + geom_point() +
   theme(legend.position="none")

A quick look suggests that this is roughly the same plot as in the example Fig 
4 but there the author is using geom_segment to add the lines but I have not 
looked at it all that carefully.





John Kane
Kingston ON Canada


> -Original Message-
> From: a...@walla.co.il
> Sent: Wed, 10 Jul 2013 11:02:11 -0700 (PDT)
> To: r-help@r-project.org
> Subject: Re: [R] PCA and gglot2
> 
> Hi,
> 
> Thanks. Fig 4 in the link you provided is what I am looking for.
> 
> I still do not know how to implement my data1 and pca1 in the script you
> provided as I think it is only a part of a full script.
> "
> data1<-read.csv("C:/…/MyPCA.csv")
> pca1 <- princomp(data1[,1:4], score=TRUE, cor=TRUE)
> "
> 
> Am I right, how can I implement my data.frames?
> 
> Thanks again
> 
> 
> 
> --
> View this message in context:
> http://r.789695.n4.nabble.com/PCA-and-gglot2-tp4671225p4671237.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.


FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your 
desktop!

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] replacement functions for subsets

2013-07-10 Thread Harry Mamaysky
As I understand it rownames(aa) returns a copy of an attribute of aa. So 
changing the value of this vector should make the change to the copy of the 
row.names attribute. I would then have to set the original row.names equal to 
this copy to effect the change.

So my question is why "rownames(aa)[2:4] <-" changes the original attribute 
rather than its copy?

And the follow on question is whether it's possible to have "f(x)[2:4] <-" 
operate in the same way for some user defined replacement function f. 

Sent from my iPhone

On Jul 10, 2013, at 3:05 PM, David Winsemius  wrote:


On Jul 10, 2013, at 11:47 AM, Harry Mamaysky wrote:

> I know how to define replacement functions in R (i.e. ‘foo<-‘ <- 
> function(x,value) x<-value, etc.), but how do you define replacement 
> functions that operate on subsets of arrays (i.e. how do you pass an index 
> into foo)?
> For example, why does the following use of “rownames” work?

`rownames` of a dataframe is a vector, so indexing with "[" and a single vector 
of indices is adequate. I cannot really tell what your conceptual 
"why"-difficulty might be. This is just assignment within a vector. That is not 
really a "replacement function operating on a subset of an array" since 
rownames are not values of the dataframe  and it's not an "array". (Careful 
use of terms is needed here.)


> 
>> aa <- data.frame( a=1:10,b=101:110 )
> 
>> aa
> 
>   a   b
> 
> 1   1 101
> 
> 2   2 102
> 
> 3   3 103
> 
> 4   4 104
> 
> 5   5 105
> 
> 6   6 106
> 
> 7   7 107
> 
> 8   8 108
> 
> 9   9 109
> 
> 10 10 110
> 
>> rownames(aa)[2:4] <- c('row2','row3','row4')
> 
>> aa
> 
> a   b
> 
> 1 1 101
> 
> row2  2 102
> 
> row3  3 103
> 
> row4  4 104
> 
> 5 5 105
> 
> 6 6 106
> 
> 7 7 107
> 
> 8 8 108
> 
> 9 9 109
> 
> 10   10 110
> 
> 
> 
> 
> Thanks,
> 
> Harry
> 
> 
>[[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.

David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] PCA and gglot2

2013-07-10 Thread stephen sefick
how about ggbiplot package on github?


On Wed, Jul 10, 2013 at 2:13 PM, John Kane  wrote:

> 'Sorry I made a mistake .  I was using some data of my own and didn't make
> some key changes to the script to match your variables.
>
>
> dat1  <-  data.frame(pca1 $scores)  # creates the data.frame
> dat1$items  <-  rownames(data1pca1 ) # adds item names
> ggplot(dat1, aes(Comp.1, Comp.2, colour = items)) + geom_point() +
>theme(legend.position="none")
>
> A quick look suggests that this is roughly the same plot as in the example
> Fig 4 but there the author is using geom_segment to add the lines but I
> have not looked at it all that carefully.
>
>
>
>
>
> John Kane
> Kingston ON Canada
>
>
> > -Original Message-
> > From: a...@walla.co.il
> > Sent: Wed, 10 Jul 2013 11:02:11 -0700 (PDT)
> > To: r-help@r-project.org
> > Subject: Re: [R] PCA and gglot2
> >
> > Hi,
> >
> > Thanks. Fig 4 in the link you provided is what I am looking for.
> >
> > I still do not know how to implement my data1 and pca1 in the script you
> > provided as I think it is only a part of a full script.
> > "
> > data1<-read.csv("C:/…/MyPCA.csv")
> > pca1 <- princomp(data1[,1:4], score=TRUE, cor=TRUE)
> > "
> >
> > Am I right, how can I implement my data.frames?
> >
> > Thanks again
> >
> >
> >
> > --
> > View this message in context:
> > http://r.789695.n4.nabble.com/PCA-and-gglot2-tp4671225p4671237.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.
>
> 
> FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on
> your desktop!
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Stephen Sefick
**
Auburn University
Biological Sciences
331 Funchess Hall
Auburn, Alabama
36849
**
sas0...@auburn.edu
http://www.auburn.edu/~sas0025
**

Let's not spend our time and resources thinking about things that are so
little or so large that all they really do for us is puff us up and make us
feel like gods.  We are mammals, and have not exhausted the annoying little
problems of being mammals.

-K. Mullis

"A big computer, a complex algorithm and a long time does not equal
science."

  -Robert Gentleman

[[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] PCA and gglot2

2013-07-10 Thread stephen sefick
how about ggbiplot package on github?


On Wed, Jul 10, 2013 at 2:13 PM, John Kane  wrote:

> 'Sorry I made a mistake .  I was using some data of my own and didn't make
> some key changes to the script to match your variables.
>
>
> dat1  <-  data.frame(pca1 $scores)  # creates the data.frame
> dat1$items  <-  rownames(data1pca1 ) # adds item names
> ggplot(dat1, aes(Comp.1, Comp.2, colour = items)) + geom_point() +
>theme(legend.position="none")
>
> A quick look suggests that this is roughly the same plot as in the example
> Fig 4 but there the author is using geom_segment to add the lines but I
> have not looked at it all that carefully.
>
>
>
>
>
> John Kane
> Kingston ON Canada
>
>
> > -Original Message-
> > From: a...@walla.co.il
> > Sent: Wed, 10 Jul 2013 11:02:11 -0700 (PDT)
> > To: r-help@r-project.org
> > Subject: Re: [R] PCA and gglot2
> >
> > Hi,
> >
> > Thanks. Fig 4 in the link you provided is what I am looking for.
> >
> > I still do not know how to implement my data1 and pca1 in the script you
> > provided as I think it is only a part of a full script.
> > "
> > data1<-read.csv("C:/…/MyPCA.csv")
> > pca1 <- princomp(data1[,1:4], score=TRUE, cor=TRUE)
> > "
> >
> > Am I right, how can I implement my data.frames?
> >
> > Thanks again
> >
> >
> >
> > --
> > View this message in context:
> > http://r.789695.n4.nabble.com/PCA-and-gglot2-tp4671225p4671237.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.
>
> 
> FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on
> your desktop!
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Stephen Sefick
**
Auburn University
Biological Sciences
331 Funchess Hall
Auburn, Alabama
36849
**
sas0...@auburn.edu
http://www.auburn.edu/~sas0025
**

Let's not spend our time and resources thinking about things that are so
little or so large that all they really do for us is puff us up and make us
feel like gods.  We are mammals, and have not exhausted the annoying little
problems of being mammals.

-K. Mullis

"A big computer, a complex algorithm and a long time does not equal
science."

  -Robert Gentleman

[[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] replacement functions for subsets

2013-07-10 Thread David Winsemius

On Jul 10, 2013, at 12:17 PM, Harry Mamaysky wrote:

> As I understand it rownames(aa) returns a copy of an attribute of aa. So 
> changing the value of this vector should make the change to the copy of the 
> row.names attribute. I would then have to set the original row.names equal to 
> this copy to effect the change.
> 
> So my question is why "rownames(aa)[2:4] <-" changes the original attribute 
> rather than its copy?

I'm not sure how you decide that was happening. Your first paragraph seemed 
correct:

aa <- data.frame( a=1:10,b=101:110 )
str(aa)
attributes(aa)
dput(aa)
`rownames<-`

> trace(`rownames<-`)
> rownames(aa)[2:4] <- c('row2','row3','row4')
trace: `rownames<-`(`*tmp*`, value = c("1", "row2", "row3", "row4", 
"5", "6", "7", "8", "9", "10"))

You can see that R first builds a full length vector with the second argumens 
to `rownames<-` fully expanded before doing the assignment to the 'row.names' 
attribute.

> 
> And the follow on question is whether it's possible to have "f(x)[2:4] <-" 
> operate in the same way for some user defined replacement function f. 

Take a look at the code:

`row.names<-.data.frame`

-- 
David.
> 
> Sent from my iPhone
> 
> On Jul 10, 2013, at 3:05 PM, David Winsemius  wrote:
> 
> 
> On Jul 10, 2013, at 11:47 AM, Harry Mamaysky wrote:
> 
>> I know how to define replacement functions in R (i.e. ‘foo<-‘ <- 
>> function(x,value) x<-value, etc.), but how do you define replacement 
>> functions that operate on subsets of arrays (i.e. how do you pass an index 
>> into foo)?
>> For example, why does the following use of “rownames” work?
> 
> `rownames` of a dataframe is a vector, so indexing with "[" and a single 
> vector of indices is adequate. I cannot really tell what your conceptual 
> "why"-difficulty might be. This is just assignment within a vector. That is 
> not really a "replacement function operating on a subset of an array" since 
> rownames are not values of the dataframe  and it's not an "array". 
> (Careful use of terms is needed here.)
> 
> 
>> 
>>> aa <- data.frame( a=1:10,b=101:110 )
>> 
>>> aa
>> 
>>  a   b
>> 
>> 1   1 101
>> 
>> 2   2 102
>> 
>> 3   3 103
>> 
>> 4   4 104
>> 
>> 5   5 105
>> 
>> 6   6 106
>> 
>> 7   7 107
>> 
>> 8   8 108
>> 
>> 9   9 109
>> 
>> 10 10 110
>> 
>>> rownames(aa)[2:4] <- c('row2','row3','row4')
>> 
>>> aa
>> 
>>a   b
>> 
>> 1 1 101
>> 
>> row2  2 102
>> 
>> row3  3 103
>> 
>> row4  4 104
>> 
>> 5 5 105
>> 
>> 6 6 106
>> 
>> 7 7 107
>> 
>> 8 8 108
>> 
>> 9 9 109
>> 
>> 10   10 110
>> 
>> 
>> 
>> 
>> Thanks,
>> 
>> Harry
>> 
>> 
>>   [[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.
> 
> David Winsemius
> Alameda, CA, USA
> 

David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] FOAS and Use R! 2014

2013-07-10 Thread Jan de Leeuw
FOAS promotes open access publishing (without costs to the reader and author), 
open source software (GPL licensed), and reproducibility of published results. 
Currently the only project we financially support is the 

-- Journal of Statistical Software http://www.jstatsoft.org, 

but we have a number of affliated projects that we promote.

-- UseR! 2014 http://user2014.stat.ucla.edu
-- Journal of Environmental Statistics http://www.jenvstat.org
-- OpenIntro http://www.openintro.org 
-- Spatial Demography http://spatialdemography.org
-- RKWard http://rkward.sourceforge.net
-- Project MOSAIC http://mosaic-web.org

Individuals can help spread the mission of FOAS by becoming a member, 
subscribing to our mailing list, adding yourself to our Facebook group, and, of 
course, send us your tax-deductible donation to support our projects. It will 
also help if you announce your membership on your personal webpage and on your 
professional C.V. Feel free to use our logos and banners. Open Access, Open 
Source, and Reproducbility Projects that are of interest to statisticians can 
request by email to become FOAS-affiliated projects.

website:

http://www.foastat.org/membership.html

donations:

http://www.foastat.org/donate.html

affilliated projects:

http://www.foastat.org/projects.html

email:

i...@foastat.org

mailing list:

http://c.okpublic.com/mailman/listinfo/foas-members_foastat.org

Facebook group:

https://www.facebook.com/groups/foastat/

===
Jan de Leeuw 
Distinguished Professor and Founding Chair, UCLA Department of Statistics
Editor: Journal of Multivariate Analysis, Journal of Statistical Software
US mail: 8125 Math Sciences Bldg, Box 951554, Los Angeles, CA 90095-1554
phone (310)-825-9550;  fax (310)-206-5658;  email: dele...@stat.ucla.edu
homepages: http://gifi.stat.ucla.edu 
 -
  No matter where you go, there you are. --- Buckaroo Banzai
http://gifi.stat.ucla.edu/sounds/nomatter.wav   
  
 -  
 








[[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] replacement functions for subsets

2013-07-10 Thread Bert Gunter
I think the OP may perhaps want to define a method for "[<-" .

e.g. try:

methods("[<-")

If this is not it ... ??

Cheers,
Bert

On Wed, Jul 10, 2013 at 12:51 PM, David Winsemius
 wrote:
>
> On Jul 10, 2013, at 12:17 PM, Harry Mamaysky wrote:
>
>> As I understand it rownames(aa) returns a copy of an attribute of aa. So 
>> changing the value of this vector should make the change to the copy of the 
>> row.names attribute. I would then have to set the original row.names equal 
>> to this copy to effect the change.
>>
>> So my question is why "rownames(aa)[2:4] <-" changes the original attribute 
>> rather than its copy?
>
> I'm not sure how you decide that was happening. Your first paragraph seemed 
> correct:
>
> aa <- data.frame( a=1:10,b=101:110 )
> str(aa)
> attributes(aa)
> dput(aa)
> `rownames<-`
>
>> trace(`rownames<-`)
>> rownames(aa)[2:4] <- c('row2','row3','row4')
> trace: `rownames<-`(`*tmp*`, value = c("1", "row2", "row3", "row4",
> "5", "6", "7", "8", "9", "10"))
>
> You can see that R first builds a full length vector with the second argumens 
> to `rownames<-` fully expanded before doing the assignment to the 'row.names' 
> attribute.
>
>>
>> And the follow on question is whether it's possible to have "f(x)[2:4] <-" 
>> operate in the same way for some user defined replacement function f.
>
> Take a look at the code:
>
> `row.names<-.data.frame`
>
> --
> David.
>>
>> Sent from my iPhone
>>
>> On Jul 10, 2013, at 3:05 PM, David Winsemius  wrote:
>>
>>
>> On Jul 10, 2013, at 11:47 AM, Harry Mamaysky wrote:
>>
>>> I know how to define replacement functions in R (i.e. ‘foo<-‘ <- 
>>> function(x,value) x<-value, etc.), but how do you define replacement 
>>> functions that operate on subsets of arrays (i.e. how do you pass an index 
>>> into foo)?
>>> For example, why does the following use of “rownames” work?
>>
>> `rownames` of a dataframe is a vector, so indexing with "[" and a single 
>> vector of indices is adequate. I cannot really tell what your conceptual 
>> "why"-difficulty might be. This is just assignment within a vector. That is 
>> not really a "replacement function operating on a subset of an array" since 
>> rownames are not values of the dataframe  and it's not an "array". 
>> (Careful use of terms is needed here.)
>>
>>
>>>
 aa <- data.frame( a=1:10,b=101:110 )
>>>
 aa
>>>
>>>  a   b
>>>
>>> 1   1 101
>>>
>>> 2   2 102
>>>
>>> 3   3 103
>>>
>>> 4   4 104
>>>
>>> 5   5 105
>>>
>>> 6   6 106
>>>
>>> 7   7 107
>>>
>>> 8   8 108
>>>
>>> 9   9 109
>>>
>>> 10 10 110
>>>
 rownames(aa)[2:4] <- c('row2','row3','row4')
>>>
 aa
>>>
>>>a   b
>>>
>>> 1 1 101
>>>
>>> row2  2 102
>>>
>>> row3  3 103
>>>
>>> row4  4 104
>>>
>>> 5 5 105
>>>
>>> 6 6 106
>>>
>>> 7 7 107
>>>
>>> 8 8 108
>>>
>>> 9 9 109
>>>
>>> 10   10 110
>>>
>>>
>>>
>>>
>>> Thanks,
>>>
>>> Harry
>>>
>>>
>>>   [[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.
>>
>> David Winsemius
>> Alameda, CA, USA
>>
>
> David Winsemius
> Alameda, CA, USA
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] replacement functions for subsets

2013-07-10 Thread Harry Mamaysky
So how would I get the following to work?

> aa<-1
> aa
[1] 1
> 'foo<-' <- function(x,value) x<-value
> foo(aa)<-1:10
> aa
[1]  1  2  3  4  5  6  7  8  9 10
> # This doesn't work:
> foo(aa)[4:5] <- c(101,102)
Error in foo(aa)[4:5] <- c(101, 102) : could not find function "foo"
> # What I would like to see is: aa becomes 1 2 3 101 102 6 7 8 9 10
> # Is it possible to define such a function 'foo'?
 

Sent from my iPhone

On Jul 10, 2013, at 4:10 PM, Bert Gunter  wrote:

I think the OP may perhaps want to define a method for "[<-" .

e.g. try:

methods("[<-")

If this is not it ... ??

Cheers,
Bert

On Wed, Jul 10, 2013 at 12:51 PM, David Winsemius
 wrote:
> 
> On Jul 10, 2013, at 12:17 PM, Harry Mamaysky wrote:
> 
>> As I understand it rownames(aa) returns a copy of an attribute of aa. So 
>> changing the value of this vector should make the change to the copy of the 
>> row.names attribute. I would then have to set the original row.names equal 
>> to this copy to effect the change.
>> 
>> So my question is why "rownames(aa)[2:4] <-" changes the original attribute 
>> rather than its copy?
> 
> I'm not sure how you decide that was happening. Your first paragraph seemed 
> correct:
> 
> aa <- data.frame( a=1:10,b=101:110 )
> str(aa)
> attributes(aa)
> dput(aa)
> `rownames<-`
> 
>> trace(`rownames<-`)
>> rownames(aa)[2:4] <- c('row2','row3','row4')
> trace: `rownames<-`(`*tmp*`, value = c("1", "row2", "row3", "row4",
> "5", "6", "7", "8", "9", "10"))
> 
> You can see that R first builds a full length vector with the second argumens 
> to `rownames<-` fully expanded before doing the assignment to the 'row.names' 
> attribute.
> 
>> 
>> And the follow on question is whether it's possible to have "f(x)[2:4] <-" 
>> operate in the same way for some user defined replacement function f.
> 
> Take a look at the code:
> 
> `row.names<-.data.frame`
> 
> --
> David.
>> 
>> Sent from my iPhone
>> 
>> On Jul 10, 2013, at 3:05 PM, David Winsemius  wrote:
>> 
>> 
>> On Jul 10, 2013, at 11:47 AM, Harry Mamaysky wrote:
>> 
>>> I know how to define replacement functions in R (i.e. ‘foo<-‘ <- 
>>> function(x,value) x<-value, etc.), but how do you define replacement 
>>> functions that operate on subsets of arrays (i.e. how do you pass an index 
>>> into foo)?
>>> For example, why does the following use of “rownames” work?
>> 
>> `rownames` of a dataframe is a vector, so indexing with "[" and a single 
>> vector of indices is adequate. I cannot really tell what your conceptual 
>> "why"-difficulty might be. This is just assignment within a vector. That is 
>> not really a "replacement function operating on a subset of an array" since 
>> rownames are not values of the dataframe  and it's not an "array". 
>> (Careful use of terms is needed here.)
>> 
>> 
>>> 
 aa <- data.frame( a=1:10,b=101:110 )
>>> 
 aa
>>> 
>>> a   b
>>> 
>>> 1   1 101
>>> 
>>> 2   2 102
>>> 
>>> 3   3 103
>>> 
>>> 4   4 104
>>> 
>>> 5   5 105
>>> 
>>> 6   6 106
>>> 
>>> 7   7 107
>>> 
>>> 8   8 108
>>> 
>>> 9   9 109
>>> 
>>> 10 10 110
>>> 
 rownames(aa)[2:4] <- c('row2','row3','row4')
>>> 
 aa
>>> 
>>>   a   b
>>> 
>>> 1 1 101
>>> 
>>> row2  2 102
>>> 
>>> row3  3 103
>>> 
>>> row4  4 104
>>> 
>>> 5 5 105
>>> 
>>> 6 6 106
>>> 
>>> 7 7 107
>>> 
>>> 8 8 108
>>> 
>>> 9 9 109
>>> 
>>> 10   10 110
>>> 
>>> 
>>> 
>>> 
>>> Thanks,
>>> 
>>> Harry
>>> 
>>> 
>>>  [[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.
>> 
>> David Winsemius
>> Alameda, CA, USA
> 
> David Winsemius
> Alameda, CA, USA
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

[[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] alternative of package parallel for R 3.0

2013-07-10 Thread Jie
Dear All,

I would like to use parApply in "parallel" to do parallel computing.
But after I updated to the new version of R, I got the message like
"Warning message: package ‘parallel’ is not available (for R version 3.0.0) "
Any people has the same issue? I know there are some other packages
but which has a similar way to implement it? Thank you.

Best wishes,
Jie

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] alternative of package parallel for R 3.0

2013-07-10 Thread Marc Schwartz
On Jul 10, 2013, at 3:29 PM, Jie  wrote:

> Dear All,
> 
> I would like to use parApply in "parallel" to do parallel computing.
> But after I updated to the new version of R, I got the message like
> "Warning message: package ‘parallel’ is not available (for R version 3.0.0) "
> Any people has the same issue? I know there are some other packages
> but which has a similar way to implement it? Thank you.
> 
> Best wishes,
> Jie
> 


parallel is part of the standard R distribution and has been since R version 
2.14.0, almost two years ago. You just need:

> require(parallel)
Loading required package: parallel


Regards,

Marc Schwartz

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] replacement functions for subsets

2013-07-10 Thread William Dunlap
If you define a function 'foo<-'  to replace a part of an object you need
to have a corresponding function 'foo' that extracts that same part.
If 'foo' does not exist or if 'foo' extracts something other than what 'foo<-'
alters, then nested replacements will not work.

The expression
   bar(foo(x)) <- newValue
is evaluated as
   tmp <- foo(x) # extract the part of x you want to alter
   bar(tmp) <- newValue # alter the extracted stuff
   foo(x) <- tmp # put the altered extracted stuff back where it came from
   # tmp is then discarded
('tmp' is chosen to be a name like '*tmp*'; you will see that in the traceback
after an error.)

Sometimes the 'extracted part' is not really a part of an object but something
more abstract, but the it is still true that foo<- and foo need to be paired.  
E.g.,
  > twoTimes <- function(x) {
  + cat("Calling twoTimes: x=", deparse(x), "\n")
  + x * 2
  + }
  > `twoTimes<-` <- function(x, value) {
  + cat("Calling twoTimes<-: x=", deparse(x), "\n")
  + x[] <- value/2
  + x
  + }
  > p <- 1:5
  > twoTimes(p)
  Calling twoTimes: x= 1:5 
  [1]  2  4  6  8 10
  > twoTimes(p)[1:2] <- c(100,102)
  Calling twoTimes: x= 1:5 
  Calling twoTimes<-: x= 1:5 
  > p
  [1] 50 51  3  4  5
  > 
  > p <- 1:5
  > twoTimes(p[1:2]) <- c(100,102)
  Calling twoTimes<-: x= 1:2 
  > p
  [1] 50 51  3  4  5
 
 
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 Harry Mamaysky
> Sent: Wednesday, July 10, 2013 1:23 PM
> To: Bert Gunter
> Cc: r-help@r-project.org
> Subject: Re: [R] replacement functions for subsets
> 
> So how would I get the following to work?
> 
> > aa<-1
> > aa
> [1] 1
> > 'foo<-' <- function(x,value) x<-value
> > foo(aa)<-1:10
> > aa
> [1]  1  2  3  4  5  6  7  8  9 10
> > # This doesn't work:
> > foo(aa)[4:5] <- c(101,102)
> Error in foo(aa)[4:5] <- c(101, 102) : could not find function "foo"
> > # What I would like to see is: aa becomes 1 2 3 101 102 6 7 8 9 10
> > # Is it possible to define such a function 'foo'?
> 
> 
> Sent from my iPhone
> 
> On Jul 10, 2013, at 4:10 PM, Bert Gunter  wrote:
> 
> I think the OP may perhaps want to define a method for "[<-" .
> 
> e.g. try:
> 
> methods("[<-")
> 
> If this is not it ... ??
> 
> Cheers,
> Bert
> 
> On Wed, Jul 10, 2013 at 12:51 PM, David Winsemius
>  wrote:
> >
> > On Jul 10, 2013, at 12:17 PM, Harry Mamaysky wrote:
> >
> >> As I understand it rownames(aa) returns a copy of an attribute of aa. So 
> >> changing the
> value of this vector should make the change to the copy of the row.names 
> attribute. I
> would then have to set the original row.names equal to this copy to effect 
> the change.
> >>
> >> So my question is why "rownames(aa)[2:4] <-" changes the original 
> >> attribute rather
> than its copy?
> >
> > I'm not sure how you decide that was happening. Your first paragraph seemed 
> > correct:
> >
> > aa <- data.frame( a=1:10,b=101:110 )
> > str(aa)
> > attributes(aa)
> > dput(aa)
> > `rownames<-`
> >
> >> trace(`rownames<-`)
> >> rownames(aa)[2:4] <- c('row2','row3','row4')
> > trace: `rownames<-`(`*tmp*`, value = c("1", "row2", "row3", "row4",
> > "5", "6", "7", "8", "9", "10"))
> >
> > You can see that R first builds a full length vector with the second 
> > argumens to
> `rownames<-` fully expanded before doing the assignment to the 'row.names' 
> attribute.
> >
> >>
> >> And the follow on question is whether it's possible to have "f(x)[2:4] <-" 
> >> operate in the
> same way for some user defined replacement function f.
> >
> > Take a look at the code:
> >
> > `row.names<-.data.frame`
> >
> > --
> > David.
> >>
> >> Sent from my iPhone
> >>
> >> On Jul 10, 2013, at 3:05 PM, David Winsemius  
> >> wrote:
> >>
> >>
> >> On Jul 10, 2013, at 11:47 AM, Harry Mamaysky wrote:
> >>
> >>> I know how to define replacement functions in R (i.e. ‘foo<-‘ <- 
> >>> function(x,value) x<-
> value, etc.), but how do you define replacement functions that operate on 
> subsets of
> arrays (i.e. how do you pass an index into foo)?
> >>> For example, why does the following use of “rownames” work?
> >>
> >> `rownames` of a dataframe is a vector, so indexing with "[" and a single 
> >> vector of
> indices is adequate. I cannot really tell what your conceptual 
> "why"-difficulty might be.
> This is just assignment within a vector. That is not really a "replacement 
> function
> operating on a subset of an array" since rownames are not values of the 
> dataframe 
> and it's not an "array". (Careful use of terms is needed here.)
> >>
> >>
> >>>
>  aa <- data.frame( a=1:10,b=101:110 )
> >>>
>  aa
> >>>
> >>> a   b
> >>>
> >>> 1   1 101
> >>>
> >>> 2   2 102
> >>>
> >>> 3   3 103
> >>>
> >>> 4   4 104
> >>>
> >>> 5   5 105
> >>>
> >>> 6   6 106
> >>>
> >>> 7   7 107
> >>>
> >>> 8   8 108
> >>>
> >>> 9   9 109
> >>>
> >>> 10 10 110
> >>>
>  rownames(aa)[2:4] <- c('row2','row3','row4'

Re: [R] create new matrix from user-defined function

2013-07-10 Thread arun
Hi,
You could try:
 
mat1<-matrix(dat3[rowSums(dat3[,2:3])!=dat3[,4],1],ncol=1,dimnames=list(NULL,"MW_EEsDue_ERRORS"))
 mat1
# MW_EEsDue_ERRORS
#[1,] 1882
#[2,] 1884
#[3,] 1885
A.K.


#Let's say I have the following data set: 

dat3 = data.frame(A_CaseID = c(1881, 1882, 1883, 1884, 1885), 
                  B_MW_EEsDue1 = c(2, 2, 1, 4, 6), 
                  C_MW_EEsDue2 = c(5, 5, 4, 1, 6), 
                  D_MW_EEsDueTotal = c(7, 9, 5, 6, 112)) 
dat3 
# A_CaseID B_MW_EEsDue1 C_MW_EEsDue2 D_MW_EEsDueTotal 
# 1     1881            2            5                7 
# 2     1882            2            5                9 
# 3     1883            1            4                5 
# 4     1884            4            1                6 
# 5     1885            6            6              112 

# I want to: 
#CREATE A NEW 1-COLUMN MATRIX (of unknown #rows) LISTING ONLY "A"'s WHERE "D != 
B + C" 
#THIS COLUMN CAN BE LABELED "MW_EEsDue_ERRORS", and output for this example 
should be: 

# MW_EEsDue_ERRORS 
# 1 1882 
# 2 1884 
# 3 1885 

#What is the best way to do this?  Thanks for your time.  BNC

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] PCA and gglot2

2013-07-10 Thread ashz
Dear John,

Thanks for the help.

I did some minor modifications to your script as I had some problems:
... 
pca = PCA(data[,1:4], scale.unit=T, graph=F)
dat1  <-  data.frame(pca$scores)  # creates the data.frame
dat1$items  <-  rownames(data$group) # adds item names
ggplot(dat1, aes(pca$ind$coord[,1], pca$ind$coord[,2], colour = dat1$item))
+ geom_point() + theme(legend.position="none")

I still do not get separation by color by group (column 5 of csv file) as
the  dat1 is empty (data frame with 0 columns and 0 rows).

Any reason why?

Thanks again.



--
View this message in context: 
http://r.789695.n4.nabble.com/PCA-and-gglot2-tp4671225p4671253.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] PCA and gglot2

2013-07-10 Thread ashz
Hi,

Thanks to ssefick for the ggbiplot tip.

It works fine so I submit a general script thats works for future users.

library(ggbiplot)
data<-read.csv("C:/…/MyPCA.csv") 
data1<-data[,1:4] 
my.pca <- prcomp(data1, scale. = TRUE)
my.class<- data$Group  
g <- ggbiplot(my.pca, obs.scale = 1, var.scale = 1,groups = my.class,
ellipse = TRUE, circle = TRUE)
g <- g + scale_color_discrete(name = '')
g <- g + theme(legend.direction = 'horizontal', 
   legend.position = 'top')
print(g)

BTW
Installation:
library(devtools)
install_github("ggbiplot", "vqv")

you will need to instal before Rtools
(http://cran.r-project.org/bin/windows/Rtools/)

Thanks a lot for the help.




--
View this message in context: 
http://r.789695.n4.nabble.com/PCA-and-gglot2-tp4671225p4671258.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] create new matrix from user-defined function

2013-07-10 Thread bcrombie
#Let's say I have the following data set:

dat3 = data.frame(A_CaseID = c(1881, 1882, 1883, 1884, 1885),
  B_MW_EEsDue1 = c(2, 2, 1, 4, 6),
  C_MW_EEsDue2 = c(5, 5, 4, 1, 6),
  D_MW_EEsDueTotal = c(7, 9, 5, 6, 112))
dat3
# A_CaseID B_MW_EEsDue1 C_MW_EEsDue2 D_MW_EEsDueTotal
# 1 1881257
# 2 1882259
# 3 1883145
# 4 1884416
# 5 188566  112

# I want to:
#CREATE A NEW 1-COLUMN MATRIX (of unknown #rows) LISTING ONLY "A"'s WHERE "D
!= B + C"
#THIS COLUMN CAN BE LABELED "MW_EEsDue_ERRORS", and output for this example
should be:

# MW_EEsDue_ERRORS 
# 1 1882
# 2 1884
# 3 1885

#What is the best way to do this?  Thanks for your time.  BNC



--
View this message in context: 
http://r.789695.n4.nabble.com/create-new-matrix-from-user-defined-function-tp4671250.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] permanova for multivariate repeat measures toxicology data set

2013-07-10 Thread Elizabeth Beck
Hello,

I would like to use a permanova to analyze my repeated measures,
multivariate data set using the package vegan (adonis function). I
have several explanatory variables and many clinical
biochemistry/hematological response variables (all continuous,
non-normally distributed).


My explanatory variables are:

ID - 29 levels - individual subjects

Treatment - 2 levels

Sex - 2 levels

Time - 11 levels - subjects were treated 11 times


I am interested in (1) whether the response variable changes over time
with repeated exposure and (2) whether the 2 treatment groups are
significantly different from each other and whether this effect varies
with time.


I can run the adonis function from package vegan but am unsure how to
incorporate the repeated measures on the same subjects into the
analysis.


adonis(hemvar~ hemat$Treatment * hemat$Exposure * hemat$SEX *
hemat$ID, permutations=999, method="euclidean")


Any help would be greatly appreciated!

An example of one of my data sets

> str(hemat)
'data.frame':   87 obs. of  14 variables:
 $ ID   : Factor w/ 29 levels "G-BB","G-BW",..: 1 1 1 2 2 2 3 3 3 4 ...
 $ Time : Factor w/ 3 levels "Tx4","Tx5","Tx6": 1 2 3 1 2 3 1 2 3 1 ...
 $ Treatment: Factor w/ 2 levels "Control","Experimental": 1 1 1 2 2 2
1 1 1 1 ...
 $ SEX  : Factor w/ 2 levels "Female","Male": 2 2 2 2 2 2 1 1 1 2 ...
 $ PCV  : int  45 33 38 50 49 53 45 37 39 36 ...
 $ WBC  : num  10.3 6.8 11.6 19.1 9.7 9.8 20 34.3 33.4 20.7 ...
 $ BASO : num  0.206 0.068 0.464 0.382 0.388 ...

[[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] create new matrix from user-defined function

2013-07-10 Thread Nordlund, Dan (DSHS/RDA)
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of bcrombie
> Sent: Wednesday, July 10, 2013 12:19 PM
> To: r-help@r-project.org
> Subject: [R] create new matrix from user-defined function
> 
> #Let's say I have the following data set:
> 
> dat3 = data.frame(A_CaseID = c(1881, 1882, 1883, 1884, 1885),
>   B_MW_EEsDue1 = c(2, 2, 1, 4, 6),
>   C_MW_EEsDue2 = c(5, 5, 4, 1, 6),
>   D_MW_EEsDueTotal = c(7, 9, 5, 6, 112))
> dat3
> # A_CaseID B_MW_EEsDue1 C_MW_EEsDue2 D_MW_EEsDueTotal
> # 1 1881257
> # 2 1882259
> # 3 1883145
> # 4 1884416
> # 5 188566  112
> 
> # I want to:
> #CREATE A NEW 1-COLUMN MATRIX (of unknown #rows) LISTING ONLY "A"'s
> WHERE "D
> != B + C"
> #THIS COLUMN CAN BE LABELED "MW_EEsDue_ERRORS", and output for this
> example
> should be:
> 
> # MW_EEsDue_ERRORS
> # 1 1882
> # 2 1884
> # 3 1885
> 
> #What is the best way to do this?  Thanks for your time.  BNC
> 
> 

Here is one option, there are many others.  Only you can decide what is "best".

data.frame(MW_EEsDue_ERRORS=dat3[dat3[[4]] != dat3[[2]]+dat3[[3]],][[1]])


Hope this is helpful,

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] find a function for a random curve

2013-07-10 Thread Rolf Turner


Your question is very vague, so it's hard to know what to suggest.
Please note the exhortation that appears at the bottom of every
r-help message:

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


It is possible that splinefun() is what you are looking for.

cheers,

Rolf Turner

On 10/07/13 22:29, Xiaoyu Lu wrote:

Hi,

I want to find a functional form for my data. I have tried smoothing and
obtained a kinda perfect fit.
However, I can only draw it but cannot call it.

I am wondering that is there a way that I can store the fit as a function
and apply it when needed. e.g. tranformation etc.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 installing a .tar.gz package on windows

2013-07-10 Thread Lucy Leigh
Hi,
I have had a look at the manual but it makes no sense to me. I have
downloaded RTools, and the InnoSetup,
but I don't understand how to use these to install my package? Am I
meant to be writing commands
in R itself, or in these other things I've downloaded?
Lucy

>>> Erin Hodgess  9/07/2013 5:30 pm >>>
Hi Lucy:

Did you look at the R Installation and Administration manuals?  There's
a
good section about installing on Windows via Rtools.



On Mon, Jul 8, 2013 at 10:18 PM, Lucy Leigh
wrote:

> Great thank you - are there any resources that step through how to
use
> RTools to compile the
> source package and install it in R on (64-bit windows) ?
>
> >>> Berend Hasselman  8/07/2013 6:38 pm >>>
>
> On 08-07-2013, at 02:15, "Lucy Leigh" 
> wrote:
>
> > Hi,
> > I have a source package that isn't available as a windows zip
file.
> Can
> > anyone explain to me how I can install this on my windows R
> platform?
> > When I use the following code:
> > install.packages("PReMiuM_3.0.21.tar.gz", type = "source")
> >
> >
>
> Where did you get that version from?
> CRAN has version 3.0.20 and that is available as a binary Windows
> package (.zip).
>
> As for the error message: you have to have Rtools installed to
compile
> source packages.
>
> Berend
>
> > I get this error message:
> >
> >
> >
> > * installing *source* package 'PReMiuM' ...
> > ** libs
> >
> > *** arch - i386
> > ERROR: compilation failed for package 'PReMiuM'
> > * removing 'C:/Program Files/R/R-3.0.1/library/PReMiuM'
> > Warning messages:
> > 1: running command '"C:/PROGRA~1/R/R-30~1.1/bin/x64/R" CMD INSTALL
> -l
> > "C:\Program Files\R\R-3.0.1\library" "PReMiuM_3.0.21.tar.gz"' had
> status
> > 1
> > 2: In install.packages("PReMiuM_3.0.21.tar.gz", type = "source") :
> >  installation of package ‘PReMiuM_3.0.21.tar.gz’ had non-zero
> exit
> > status
> >>
> >
> > Thanks for any help anyone can give me,
> > Lucy
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/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.
>



-- 
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: erinm.hodg...@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] Help with installing a .tar.gz package on windows

2013-07-10 Thread Jeff Newmiller
Lucy, you have stepped into something of a mess. Although you just want to 
install the package to use it, installing from source often (but not always) 
requires the ability to compile C, C++, or Fortran, and discussions about 
development really belong on the R-devel mailing list. The steps needed may be 
extremely simple, or quite complex depending on how that package is 
constructed. They are automatic on most operating systems, but on Windows you 
have to learn a bit more than you appear comfortable with to make the 
conversion to binary.

In short, if you cannot utilize the documentation to build it yourself, you 
should wait for it to get through the review process at CRAN so you can install 
a binary version from a repository, or ask the library developer to create a 
"preview" binary version for you. If you want to pursue the compile it yourself 
approach further you are going to have to take your questions to R-devel and be 
prepared to read the documentation more carefully so you can ask specific 
questions rather than open-ended ones.

Your question about writing commands in R is an example of an open-ended 
question, since you did not say which commands you are thinking of. You do have 
to use the operating system command line ("cmd") in several cases, and you have 
to get the environment variables setup properly before those commands will work 
(which is operating-system specific and not about R) but the R team cannot 
reproduce documentation for every operating system so you need to learn that 
with Google.
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

Lucy Leigh  wrote:

>Hi,
>I have had a look at the manual but it makes no sense to me. I have
>downloaded RTools, and the InnoSetup,
>but I don't understand how to use these to install my package? Am I
>meant to be writing commands
>in R itself, or in these other things I've downloaded?
>Lucy
>
 Erin Hodgess  9/07/2013 5:30 pm >>>
>Hi Lucy:
>
>Did you look at the R Installation and Administration manuals?  There's
>a
>good section about installing on Windows via Rtools.
>
>
>
>On Mon, Jul 8, 2013 at 10:18 PM, Lucy Leigh
>wrote:
>
>> Great thank you - are there any resources that step through how to
>use
>> RTools to compile the
>> source package and install it in R on (64-bit windows) ?
>>
>> >>> Berend Hasselman  8/07/2013 6:38 pm >>>
>>
>> On 08-07-2013, at 02:15, "Lucy Leigh" 
>> wrote:
>>
>> > Hi,
>> > I have a source package that isn't available as a windows zip
>file.
>> Can
>> > anyone explain to me how I can install this on my windows R
>> platform?
>> > When I use the following code:
>> > install.packages("PReMiuM_3.0.21.tar.gz", type = "source")
>> >
>> >
>>
>> Where did you get that version from?
>> CRAN has version 3.0.20 and that is available as a binary Windows
>> package (.zip).
>>
>> As for the error message: you have to have Rtools installed to
>compile
>> source packages.
>>
>> Berend
>>
>> > I get this error message:
>> >
>> >
>> >
>> > * installing *source* package 'PReMiuM' ...
>> > ** libs
>> >
>> > *** arch - i386
>> > ERROR: compilation failed for package 'PReMiuM'
>> > * removing 'C:/Program Files/R/R-3.0.1/library/PReMiuM'
>> > Warning messages:
>> > 1: running command '"C:/PROGRA~1/R/R-30~1.1/bin/x64/R" CMD INSTALL
>> -l
>> > "C:\Program Files\R\R-3.0.1\library" "PReMiuM_3.0.21.tar.gz"' had
>> status
>> > 1
>> > 2: In install.packages("PReMiuM_3.0.21.tar.gz", type = "source") :
>> >  installation of package ‘PReMiuM_3.0.21.tar.gz’ had non-zero
>> exit
>> > status
>> >>
>> >
>> > Thanks for any help anyone can give me,
>> > Lucy
>> >
>> > __
>> > R-help@r-project.org mailing list
>> > https://stat.ethz.ch/mailman/listinfo/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.
>>
>
>
>
>-- 
>Erin Hodgess
>Associate Professor
>Department of Computer and Mathematical Sciences
>University of Houston - Downtown
>mailto: erinm.hodg...@gmail.com
>
>__
>R-help@r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read th

Re: [R] Help with installing a .tar.gz package on windows

2013-07-10 Thread David Winsemius

On Jul 10, 2013, at 4:37 PM, Lucy Leigh wrote:

> Hi,
> I have had a look at the manual but it makes no sense to me. I have
> downloaded RTools, and the InnoSetup,
> but I don't understand how to use these to install my package? Am I
> meant to be writing commands
> in R itself, or in these other things I've downloaded?

Since you are clearly out of your league with respect to compiling from source, 
now is the time to ask (again), why are you not installing the binary package?

At the R command line just type:

install.packages("PReMiuM")  # should default to type="win.binary" and use a 
CRAN mirror

-- 
David


> Lucy
> 
 Erin Hodgess  9/07/2013 5:30 pm >>>
> Hi Lucy:
> 
> Did you look at the R Installation and Administration manuals?  There's
> a
> good section about installing on Windows via Rtools.
> 
> 
> 
> On Mon, Jul 8, 2013 at 10:18 PM, Lucy Leigh
> wrote:
> 
>> Great thank you - are there any resources that step through how to
> use
>> RTools to compile the
>> source package and install it in R on (64-bit windows) ?
>> 
> Berend Hasselman  8/07/2013 6:38 pm >>>
>> 
>> On 08-07-2013, at 02:15, "Lucy Leigh" 
>> wrote:
>> 
>>> Hi,
>>> I have a source package that isn't available as a windows zip
> file.
>> Can
>>> anyone explain to me how I can install this on my windows R
>> platform?
>>> When I use the following code:
>>> install.packages("PReMiuM_3.0.21.tar.gz", type = "source")
>>> 
>>> 
>> 
>> Where did you get that version from?
>> CRAN has version 3.0.20 and that is available as a binary Windows
>> package (.zip).
>> 
>> As for the error message: you have to have Rtools installed to
> compile
>> source packages.
>> 
>> Berend
>> 
>>> I get this error message:
>>> 
>>> 
>>> 
>>> * installing *source* package 'PReMiuM' ...
>>> ** libs
>>> 
>>> *** arch - i386
>>> ERROR: compilation failed for package 'PReMiuM'
>>> * removing 'C:/Program Files/R/R-3.0.1/library/PReMiuM'
>>> Warning messages:
>>> 1: running command '"C:/PROGRA~1/R/R-30~1.1/bin/x64/R" CMD INSTALL
>> -l
>>> "C:\Program Files\R\R-3.0.1\library" "PReMiuM_3.0.21.tar.gz"' had
>> status
>>> 1
>>> 2: In install.packages("PReMiuM_3.0.21.tar.gz", type = "source") :
>>> installation of package ‘PReMiuM_3.0.21.tar.gz’ had non-zero
>> exit
>>> status
 
>>> 
>>> Thanks for any help anyone can give me,
>>> Lucy
>>> 
>>> __

David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 building R-2.15.3 from source

2013-07-10 Thread Mark Dalphin

Hi,

I have for many years build R from source for Linux. I have just run 
into my first problem with this in ... I don't know how long.


uname -a
Linux douglas 3.2.0-4-686-pae #1 SMP Debian 3.2.46-1 i686 GNU/Linux

cat /etc/issue
Debian GNU/Linux 7 \n \l


The version of R is 2.15.3. I know it is old, but we are in a regulated 
environment and changes to R versions are painful. I have built R 2.15.3 
elsewhere and have it running on multiple Linux boxes around here, both 
32-bit and 64-bit; Ubuntu distributions, however, not Debian.


This build is on a virtual machine under OpenBox. The host is a 64-bit 
Debian; the guest is a 32-bit Debian installation.


The symptoms are strange (to me). I get segfaults during the 
byte-compiling phase of libraries. If I re-run 'make', the make proceeds 
as if it finished the previous seg-faulted step, and then segfaults on 
the next byte-compile. The "permissions" makes me wonder about file 
permissions, but the whole 'make' is under my HOME. Furthermore, I have 
scanned the unpacked tar-gz package for something I don't "own" and it 
isn't there. I also think segfaults are usually in memory, though I 
don't know what "permission" I have there (don't I own the RAM I request?).


I have attached a section of the 'make' output  below, followed by a the 
next "make" output:

--
make[4]: Leaving directory `/home/mdalphin/src/R-2.15.3/src/library/splines'
make[4]: Entering directory 
`/home/mdalphin/src/R-2.15.3/src/library/splines'

byte-compiling package 'splines'

*** caught segfault ***
address 0x403ac3dc, cause 'invalid permissions'

Traceback:
1: fun(libname, pkgname)
2: doTryCatch(return(expr), name, parentenv, handler)
3: tryCatchOne(expr, names, parentenv, handlers[[1L]])
4: tryCatchList(expr, classes, parentenv, handlers)
5: tryCatch(fun(libname, pkgname), error = identity)
6: runHook(".onLoad", env, package.lib, package)
7: loadNamespace(name)
8: doTryCatch(return(expr), name, parentenv, handler)
9: tryCatchOne(expr, names, parentenv, handlers[[1L]])
10: tryCatchList(expr, classes, parentenv, handlers)
11: tryCatch(loadNamespace(name), error = function(e) stop(e))
12: getNamespace(ns)
13: asNamespace(pkg)
14: get(name, envir = asNamespace(pkg), inherits = FALSE)
15: compiler:::tryCmpfun
16: .Call("R_lazyLoadDBinsertValue", x[[1L]], file, ascii, compress, 
hook, PACKAGE = "base")
17: lazyLoadDBinsertVariable(vars[i], from, datafile, ascii, 
compress, envhook)

18: makeLazyLoadDB(ns, dbbase, compress = compress)
19: code2LazyLoadDB(package, lib.loc = lib.loc, keep.source = 
keep.source, compress = compress)

20: tools:::makeLazyLoading("splines")
aborting ...
/bin/bash: line 8: 18709 Doneecho 
"tools:::makeLazyLoading(\"splines\")"
18710 Segmentation fault  | R_COMPILE_PKGS=1 
R_COMPILER_SUPPRESS_ALL=1 R_DEFAULT_PACKAGES=NULL LC_ALL=C 
../../../bin/R --vanilla --slave > /dev/null

make[4]: *** [../../../library/splines/R/splines.rdb] Error 139
make[4]: Leaving directory `/home/mdalphin/src/R-2.15.3/src/library/splines'
make[3]: *** [all] Error 2
make[3]: Leaving directory `/home/mdalphin/src/R-2.15.3/src/library/splines'
make[2]: *** [R] Error 1
make[2]: Leaving directory `/home/mdalphin/src/R-2.15.3/src/library'
make[1]: *** [R] Error 1
make[1]: Leaving directory `/home/mdalphin/src/R-2.15.3/src'
make: *** [R] Error 1
---
make[4]: Entering directory 
`/home/mdalphin/src/R-2.15.3/src/library/splines'

make[4]: Nothing to be done for `mklazycomp'.
make[4]: Leaving directory `/home/mdalphin/src/R-2.15.3/src/library/splines'
make[3]: Leaving directory `/home/mdalphin/src/R-2.15.3/src/library/splines'
make[3]: Entering directory `/home/mdalphin/src/R-2.15.3/src/library/stats4'
building package 'stats4'
mkdir -p -- ../../../library/stats4
make[4]: Entering directory `/home/mdalphin/src/R-2.15.3/src/library/stats4'
mkdir -p -- ../../../library/stats4/R
mkdir -p -- ../../../library/stats4/po
make[4]: Leaving directory `/home/mdalphin/src/R-2.15.3/src/library/stats4'
make[4]: Entering directory `/home/mdalphin/src/R-2.15.3/src/library/stats4'
byte-compiling package 'stats4'

*** caught segfault ***
address 0x403ac3dc, cause 'invalid permissions'

Traceback:
1: fun(libname, pkgname)
2: doTryCatch(return(expr), name, parentenv, handler)
3: tryCatchOne(expr, names, parentenv, handlers[[1L]])
4: tryCatchList(expr, classes, parentenv, handlers)
5: tryCatch(fun(libname, pkgname), error = identity)
6: runHook(".onLoad", env, package.lib, package)
7: loadNamespace(name)
8: doTryCatch(return(expr), name, parentenv, handler)
9: tryCatchOne(expr, names, parentenv, handlers[[1L]])
10: tryCatchList(expr, classes, parentenv, handlers)
11: tryCatch(loadNamespace(name), error = function(e) stop(e))
12: getNamespace(ns)
13: asNamespace(pkg)
14: get(name, envir

Re: [R] Need hep for converting date data in POSIXct

2013-07-10 Thread arun


Hi,
I guess the error message:
> vmask(lat,lon,time,vmax=25)
Error en vmask(lat, lon,
time, vmax = 25) : objeto 'lat' no encontrado

says that you have not defined the object 'lat'.

time<-subset(Geo, select =date)
time[,1]<-  as.POSIXct(time[,1],format="%d/%m/%Y %H:%M")
location<- subset(Geo,select=c(lat.comp,long))
 time1<- time[,1]
 lat<- location[,1]
 long<- location[,2]
library(argosfilter)
 vmask(lat,long,time1,25)
#[1] "end_location" "end_location" "not"  "not"  "end_location"
#[6] "end_location"

A.K.

From: laila Aranda Romero 
To: arun  
Sent: Wednesday, July 10, 2013 6:21 PM
Subject: RE: [R] Need hep for converting date data in POSIXct





Hi,

The code: 

library(argosfilter)
setwd("C:/Users/Usuario/Dropbox/Laila Aranda/PUFGRA")
Geo = 
read.table("2370001_PUFGRA_2009_Gough_000_retarded10_both.trj",header=FALSE,sep
= ",", col.names= c("type", "date",
"secs", "Trans1",  "Trans2",
"lat.sta",  "lat.comp", "long", 
"dist", "rumbo", "velocidad", 
"confianza"))
View(Geo)
location=subset(Geo, select= c(lat.comp,long))
time=subset(Geo, select =c(date))
time[,1]<-as.POSIXct(time[,1],format="%d/%m/%Y
%H:%M")   
vmask(lat,lon,time,vmax=25)




The example: library(argosfilter)
> setwd("C:/Users/Usuario/Dropbox/LailaAranda/PUFGRA")
> Geo = 
> read.table("2370001_PUFGRA_2009_Gough_000_retarded10_both.trj",header=FALSE,sep
= ",", col.names= c("type", "date","secs", "Trans1", "Trans2", "lat.sta", 
"lat.comp", "long", "dist", "rumbo", "velocidad",  "confianza"))
> str(Geo)

'data.frame':  582
obs. of  12 variables: $
type : Factor w/ 2 levels
"midnight","noon": 2 1 2 1 2 1 2 1 2 1 ...
 $
date : Factor w/ 582 levels
"01/01/2009 01:58",..: 370 389 390 409 410 429 430 450 451 471 ...

 $
secs : num  39773 39773 39774 39774 39775 ... $
Trans1   : Factor w/ 186 levels
"04:06","04:08",..: 14 17 17 16 16 28 28 19 19 15 ...
 $
Trans2   : Factor w/ 159 levels
"00:01","00:03",..: 30 30 28 28 34 34 35 35 36 36 ...
 $
lat.sta  : num  -42.7 -39.1 -37.8 -37.9 -41.2 ...
 $
lat.comp : num  -42.7 -40.6 -38.6 -37.9
-39 ...

 $
long : num  9.31 11.66 10.88 10.72 13.06 ...
 $ dist : num 
0 0 127 45 131 ...
 $ rumbo   
: num  0 0 -16.49 -9.64 -57.22 ...
 $ velocidad: num  0 0 10.64 3.75 10.75 ... $ confianza: int  3 9 9 9 9 6 6 9 9 
9
...
> head(Geo)
type date secs Trans1 Trans2 lat.sta lat.comp  long  
dist
1 noon 20/11/2008 12:23 39772.52 
04:59  19:47  -42.72  
-42.72  9.31   0.00
2 midnight 21/11/2008 00:33 39773.02  05:18 
19:47  -39.14   -40.63 11.66   0.00
3 noon 21/11/2008 12:29 39773.52 
05:18  19:41  -37.82  
-38.60 10.88 127.02
4 midnight 22/11/2008 00:29 39774.02  05:17 
19:41  -37.86   -37.86 10.72 
45.04
5 noon 22/11/2008 12:39 39774.53 
05:17  20:00  -41.21  
-39.04 13.06 130.78
6 midnight 23/11/2008 00:50 39775.03  05:41 
20:00  -36.56   -38.51 16.02 142.06
   rumbo
velocidad confianza
1  
0.00  0.00 3
2  
0.00  0.00 9
3 -16.49
10.64 9
4 
-9.64  3.75     9
5 -57.22
10.75 9
6 
77.07 11.66 6
> location=subset(Geo, select=
c(lat.comp,long))

> str(location)
'data.frame':  582
obs. of  2 variables:
 $lat.comp: num  -42.7 -40.6 -38.6 -37.9 -39 ...
 $long    : num  9.31 11.66 10.88 10.72 13.06 ...
> head(location)

lat.comp  long
1  
-42.72  9.31
2  
-40.63 11.66
3  
-38.60 10.88
4  
-37.86 10.72
5  
-39.04 13.06
6  
-38.51 16.02

> time=subset(Geo, select =c(date))
> time[,1]<-as.POSIXct(time[,1],format="%d/%m/%Y
%H:%M")
> str(time)
'data.frame':  582
obs. of  1 variable:
 $ date:
POSIXct, format: "2008-11-20 12:23:00" "2008-11-21
00:33:00" ...
> head(time)
 date
1 2008-11-20 12:23:00
2 2008-11-21 00:33:00
3 2008-11-21 12:29:00
4 2008-11-22 00:29:00
5 2008-11-22 12:39:00
6 2008-11-23 00:50:00
> vmask(lat,lon,time,vmax=25)
Error en vmask(lat, lon,
time, vmax = 25) : objeto 'lat' no encontrado

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] replacement functions for subsets

2013-07-10 Thread Harry Mamaysky
Got it.  Thank you for the explanation.  And thanks to everyone for their
help.

On Wed, Jul 10, 2013 at 5:09 PM, William Dunlap  wrote:

> If you define a function 'foo<-'  to replace a part of an object you need
> to have a corresponding function 'foo' that extracts that same part.
> If 'foo' does not exist or if 'foo' extracts something other than what
> 'foo<-'
> alters, then nested replacements will not work.
>
> The expression
>bar(foo(x)) <- newValue
> is evaluated as
>tmp <- foo(x) # extract the part of x you want to alter
>bar(tmp) <- newValue # alter the extracted stuff
>foo(x) <- tmp # put the altered extracted stuff back where it came from
># tmp is then discarded
> ('tmp' is chosen to be a name like '*tmp*'; you will see that in the
> traceback
> after an error.)
>
> Sometimes the 'extracted part' is not really a part of an object but
> something
> more abstract, but the it is still true that foo<- and foo need to be
> paired.  E.g.,
>   > twoTimes <- function(x) {
>   + cat("Calling twoTimes: x=", deparse(x), "\n")
>   + x * 2
>   + }
>   > `twoTimes<-` <- function(x, value) {
>   + cat("Calling twoTimes<-: x=", deparse(x), "\n")
>   + x[] <- value/2
>   + x
>   + }
>   > p <- 1:5
>   > twoTimes(p)
>   Calling twoTimes: x= 1:5
>   [1]  2  4  6  8 10
>   > twoTimes(p)[1:2] <- c(100,102)
>   Calling twoTimes: x= 1:5
>   Calling twoTimes<-: x= 1:5
>   > p
>   [1] 50 51  3  4  5
>   >
>   > p <- 1:5
>   > twoTimes(p[1:2]) <- c(100,102)
>   Calling twoTimes<-: x= 1:2
>   > p
>   [1] 50 51  3  4  5
>
>
> 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 Harry Mamaysky
> > Sent: Wednesday, July 10, 2013 1:23 PM
> > To: Bert Gunter
> > Cc: r-help@r-project.org
> > Subject: Re: [R] replacement functions for subsets
> >
> > So how would I get the following to work?
> >
> > > aa<-1
> > > aa
> > [1] 1
> > > 'foo<-' <- function(x,value) x<-value
> > > foo(aa)<-1:10
> > > aa
> > [1] 1 2 3 4 5 6 7 8 9 10
> > > # This doesn't work:
> > > foo(aa)[4:5] <- c(101,102)
> > Error in foo(aa)[4:5] <- c(101, 102) : could not find function "foo"
> > > # What I would like to see is: aa becomes 1 2 3 101 102 6 7 8 9 10
> > > # Is it possible to define such a function 'foo'?
> >
> >
> > Sent from my iPhone
> >
> > On Jul 10, 2013, at 4:10 PM, Bert Gunter  wrote:
> >
> > I think the OP may perhaps want to define a method for "[<-" .
> >
> > e.g. try:
> >
> > methods("[<-")
> >
> > If this is not it ... ??
> >
> > Cheers,
> > Bert
> >
> > On Wed, Jul 10, 2013 at 12:51 PM, David Winsemius
> >  wrote:
> > >
> > > On Jul 10, 2013, at 12:17 PM, Harry Mamaysky wrote:
> > >
> > >> As I understand it rownames(aa) returns a copy of an attribute of aa.
> So changing the
> > value of this vector should make the change to the copy of the row.names
> attribute. I
> > would then have to set the original row.names equal to this copy to
> effect the change.
> > >>
> > >> So my question is why "rownames(aa)[2:4] <-" changes the original
> attribute rather
> > than its copy?
> > >
> > > I'm not sure how you decide that was happening. Your first paragraph
> seemed correct:
> > >
> > > aa <- data.frame( a=1:10,b=101:110 )
> > > str(aa)
> > > attributes(aa)
> > > dput(aa)
> > > `rownames<-`
> > >
> > >> trace(`rownames<-`)
> > >> rownames(aa)[2:4] <- c('row2','row3','row4')
> > > trace: `rownames<-`(`*tmp*`, value = c("1", "row2", "row3", "row4",
> > > "5", "6", "7", "8", "9", "10"))
> > >
> > > You can see that R first builds a full length vector with the second
> argumens to
> > `rownames<-` fully expanded before doing the assignment to the
> 'row.names' attribute.
> > >
> > >>
> > >> And the follow on question is whether it's possible to have
> "f(x)[2:4] <-" operate in the
> > same way for some user defined replacement function f.
> > >
> > > Take a look at the code:
> > >
> > > `row.names<-.data.frame`
> > >
> > > --
> > > David.
> > >>
> > >> Sent from my iPhone
> > >>
> > >> On Jul 10, 2013, at 3:05 PM, David Winsemius 
> wrote:
> > >>
> > >>
> > >> On Jul 10, 2013, at 11:47 AM, Harry Mamaysky wrote:
> > >>
> > >>> I know how to define replacement functions in R (i.e. ‘foo<-‘ <-
> function(x,value) x<-
> > value, etc.), but how do you define replacement functions that operate
> on subsets of
> > arrays (i.e. how do you pass an index into foo)?
> > >>> For example, why does the following use of “rownames” work?
> > >>
> > >> `rownames` of a dataframe is a vector, so indexing with "[" and a
> single vector of
> > indices is adequate. I cannot really tell what your conceptual
> "why"-difficulty might be.
> > This is just assignment within a vector. That is not really a
> "replacement function
> > operating on a subset of an array" since rownames are not values of the
> dataframe 
> > and it's not an "array". (Careful use of terms is needed here.)
> > >>
> > 

[R] Reserve word "in" could not be used it as a "dimname"?

2013-07-10 Thread jpm miao
Hi,

   I have a matrix whose columns are named as "in" and "out". Then I coerce
it to be a data.frame. However the system seems to forbid me from using the
name "in", but I am not aware of it until I call it by the dollar sign $.
Is there something R should remind me but it does not?
Is there any remedy to work on it?

> head(dat1$in)
Error: unexpected 'in' in "head(dat1$in"
> View(dat1)
> head(dat1["in"])
in
1 3.28
2  9.6
3 7.24
4 4.45
5 2.33
6 2.83
> head(dat1["out"])
   out
10
20
3 0.04
4 0.03
5 0.04
6 0.01
> head(dat1$out)
[1] 000.04 0.03 0.04 0.01

[[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] Reserve word "in" could not be used it as a "dimname"?

2013-07-10 Thread Pascal Oettli
Hello,

"in" is a reserved word.

?Reserved

Hope this clarifies,
Pascal



2013/7/11 jpm miao 

> Hi,
>
>I have a matrix whose columns are named as "in" and "out". Then I coerce
> it to be a data.frame. However the system seems to forbid me from using the
> name "in", but I am not aware of it until I call it by the dollar sign $.
> Is there something R should remind me but it does not?
> Is there any remedy to work on it?
>
> > head(dat1$in)
> Error: unexpected 'in' in "head(dat1$in"
> > View(dat1)
> > head(dat1["in"])
> in
> 1 3.28
> 2  9.6
> 3 7.24
> 4 4.45
> 5 2.33
> 6 2.83
> > head(dat1["out"])
>out
> 10
> 20
> 3 0.04
> 4 0.03
> 5 0.04
> 6 0.01
> > head(dat1$out)
> [1] 000.04 0.03 0.04 0.01
>
> [[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.
>

[[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] Reserve word "in" could not be used it as a "dimname"?

2013-07-10 Thread jpm miao
Just wonder why R does not remind me so when I use it as a dimname...


2013/7/11 Pascal Oettli 

> Hello,
>
> "in" is a reserved word.
>
> ?Reserved
>
> Hope this clarifies,
> Pascal
>
>
>
> 2013/7/11 jpm miao 
>
>> Hi,
>>
>>I have a matrix whose columns are named as "in" and "out". Then I
>> coerce
>> it to be a data.frame. However the system seems to forbid me from using
>> the
>> name "in", but I am not aware of it until I call it by the dollar sign $.
>> Is there something R should remind me but it does not?
>> Is there any remedy to work on it?
>>
>> > head(dat1$in)
>> Error: unexpected 'in' in "head(dat1$in"
>> > View(dat1)
>> > head(dat1["in"])
>> in
>> 1 3.28
>> 2  9.6
>> 3 7.24
>> 4 4.45
>> 5 2.33
>> 6 2.83
>> > head(dat1["out"])
>>out
>> 10
>> 20
>> 3 0.04
>> 4 0.03
>> 5 0.04
>> 6 0.01
>> > head(dat1$out)
>> [1] 000.04 0.03 0.04 0.01
>>
>> [[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.
>>
>
>

[[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] Reserve word "in" could not be used it as a "dimname"?

2013-07-10 Thread Pascal Oettli
Hello,

You can offer your help to develop a built-in function designed to
internally check the use of reserved words.

Or, citing the help page:
"Reserved words outside quotes are always parsed to be references to the
objects linked to in the ‘Description’, and hence they are not allowed as
syntactic names (see make.names). They are allowed as non-syntactic names,
e.g. inside backtick quotes."

You should prefer the use of "[" rather than "$".

Regards,
Pascal



2013/7/11 jpm miao 

> Just wonder why R does not remind me so when I use it as a dimname...
>
>
> 2013/7/11 Pascal Oettli 
>
>> Hello,
>>
>> "in" is a reserved word.
>>
>> ?Reserved
>>
>> Hope this clarifies,
>> Pascal
>>
>>
>>
>> 2013/7/11 jpm miao 
>>
>>>  Hi,
>>>
>>>I have a matrix whose columns are named as "in" and "out". Then I
>>> coerce
>>> it to be a data.frame. However the system seems to forbid me from using
>>> the
>>> name "in", but I am not aware of it until I call it by the dollar sign $.
>>> Is there something R should remind me but it does not?
>>> Is there any remedy to work on it?
>>>
>>> > head(dat1$in)
>>> Error: unexpected 'in' in "head(dat1$in"
>>> > View(dat1)
>>> > head(dat1["in"])
>>> in
>>> 1 3.28
>>> 2  9.6
>>> 3 7.24
>>> 4 4.45
>>> 5 2.33
>>> 6 2.83
>>> > head(dat1["out"])
>>>out
>>> 10
>>> 20
>>> 3 0.04
>>> 4 0.03
>>> 5 0.04
>>> 6 0.01
>>> > head(dat1$out)
>>> [1] 000.04 0.03 0.04 0.01
>>>
>>> [[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.
>>>
>>
>>
>

[[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] [SOLVED] Problem building R-2.15.3 from source

2013-07-10 Thread Mark Dalphin

I have found a solution to the repeated seg-faults below.

If I set environment variables:
   setenv CFLAGS -O2
   setenv FFLAGS -O2
rather than the default -O3, then R builds and "checks" successfully.

A few more details about the Debian system on which I have been building:
gcc (Debian 4.7.2-5) 4.7.2

My "configure" command is:
./configure \
   --prefix=$my_R_path \
   --with-readline \
   --without-x \
   --enable-R-shlib\
   --enable-BLAS-shlib \
   --with-system-zlib  \
   --with-system-bzlib \
--with-system-pcre

So, I'm good for the time being and hope this helps others who have 
trouble building from source.


Cheers,
Mark

Mark Dalphin wrote:

Hi,

I have for many years build R from source for Linux. I have just run 
into my first problem with this in ... I don't know how long.


uname -a
Linux douglas 3.2.0-4-686-pae #1 SMP Debian 3.2.46-1 i686 GNU/Linux

cat /etc/issue
Debian GNU/Linux 7 \n \l


The version of R is 2.15.3. I know it is old, but we are in a 
regulated environment and changes to R versions are painful. I have 
built R 2.15.3 elsewhere and have it running on multiple Linux boxes 
around here, both 32-bit and 64-bit; Ubuntu distributions, however, 
not Debian.


This build is on a virtual machine under OpenBox. The host is a 64-bit 
Debian; the guest is a 32-bit Debian installation.


The symptoms are strange (to me). I get segfaults during the 
byte-compiling phase of libraries. If I re-run 'make', the make 
proceeds as if it finished the previous seg-faulted step, and then 
segfaults on the next byte-compile. The "permissions" makes me wonder 
about file permissions, but the whole 'make' is under my HOME. 
Furthermore, I have scanned the unpacked tar-gz package for something 
I don't "own" and it isn't there. I also think segfaults are usually 
in memory, though I don't know what "permission" I have there (don't I 
own the RAM I request?).


I have attached a section of the 'make' output  below, followed by a 
the next "make" output:
-- 

make[4]: Leaving directory 
`/home/mdalphin/src/R-2.15.3/src/library/splines'
make[4]: Entering directory 
`/home/mdalphin/src/R-2.15.3/src/library/splines'

byte-compiling package 'splines'

*** caught segfault ***
address 0x403ac3dc, cause 'invalid permissions'

Traceback:
1: fun(libname, pkgname)
2: doTryCatch(return(expr), name, parentenv, handler)
3: tryCatchOne(expr, names, parentenv, handlers[[1L]])
4: tryCatchList(expr, classes, parentenv, handlers)
5: tryCatch(fun(libname, pkgname), error = identity)
6: runHook(".onLoad", env, package.lib, package)
7: loadNamespace(name)
8: doTryCatch(return(expr), name, parentenv, handler)
9: tryCatchOne(expr, names, parentenv, handlers[[1L]])
10: tryCatchList(expr, classes, parentenv, handlers)
11: tryCatch(loadNamespace(name), error = function(e) stop(e))
12: getNamespace(ns)
13: asNamespace(pkg)
14: get(name, envir = asNamespace(pkg), inherits = FALSE)
15: compiler:::tryCmpfun
16: .Call("R_lazyLoadDBinsertValue", x[[1L]], file, ascii, 
compress, hook, PACKAGE = "base")
17: lazyLoadDBinsertVariable(vars[i], from, datafile, ascii, 
compress, envhook)

18: makeLazyLoadDB(ns, dbbase, compress = compress)
19: code2LazyLoadDB(package, lib.loc = lib.loc, keep.source = 
keep.source, compress = compress)

20: tools:::makeLazyLoading("splines")
aborting ...
/bin/bash: line 8: 18709 Doneecho 
"tools:::makeLazyLoading(\"splines\")"
18710 Segmentation fault  | R_COMPILE_PKGS=1 
R_COMPILER_SUPPRESS_ALL=1 R_DEFAULT_PACKAGES=NULL LC_ALL=C 
../../../bin/R --vanilla --slave > /dev/null

make[4]: *** [../../../library/splines/R/splines.rdb] Error 139
make[4]: Leaving directory 
`/home/mdalphin/src/R-2.15.3/src/library/splines'

make[3]: *** [all] Error 2
make[3]: Leaving directory 
`/home/mdalphin/src/R-2.15.3/src/library/splines'

make[2]: *** [R] Error 1
make[2]: Leaving directory `/home/mdalphin/src/R-2.15.3/src/library'
make[1]: *** [R] Error 1
make[1]: Leaving directory `/home/mdalphin/src/R-2.15.3/src'
make: *** [R] Error 1
--- 

make[4]: Entering directory 
`/home/mdalphin/src/R-2.15.3/src/library/splines'

make[4]: Nothing to be done for `mklazycomp'.
make[4]: Leaving directory 
`/home/mdalphin/src/R-2.15.3/src/library/splines'
make[3]: Leaving directory 
`/home/mdalphin/src/R-2.15.3/src/library/splines'
make[3]: Entering directory 
`/home/mdalphin/src/R-2.15.3/src/library/stats4'

building package 'stats4'
mkdir -p -- ../../../library/stats4
make[4]: Entering directory 
`/home/mdalphin/src/R-2.15.3/src/library/stats4'

mkdir -p -- ../../../library/stats4/R
mkdir -p -- ../../../library/stats4/po
make[4]: Leaving directory 
`/home/mdalphin/src/R-2.15.3/src/library/stats4'
make[4]: Entering directory 
`/home/mdalphin/src/R-2.15.3/src/library/st

Re: [R] [SOLVED] Problem building R-2.15.3 from source

2013-07-10 Thread Pascal Oettli
Hello,

Maybe the reason why:

http://www.cran.r-project.org/doc/manuals/R-admin.html#Compilation-flags

Regards,
Pascal



2013/7/11 Mark Dalphin 

> I have found a solution to the repeated seg-faults below.
>
> If I set environment variables:
>setenv CFLAGS -O2
>setenv FFLAGS -O2
> rather than the default -O3, then R builds and "checks" successfully.
>
> A few more details about the Debian system on which I have been building:
> gcc (Debian 4.7.2-5) 4.7.2
>
> My "configure" command is:
> ./configure \
>--prefix=$my_R_path \
>--with-readline \
>--without-x \
>--enable-R-shlib\
>--enable-BLAS-shlib \
>--with-system-zlib  \
>--with-system-bzlib \
> --with-system-pcre
>
> So, I'm good for the time being and hope this helps others who have
> trouble building from source.
>
> Cheers,
> Mark
>
> Mark Dalphin wrote:
>
>> Hi,
>>
>> I have for many years build R from source for Linux. I have just run into
>> my first problem with this in ... I don't know how long.
>>
>> uname -a
>> Linux douglas 3.2.0-4-686-pae #1 SMP Debian 3.2.46-1 i686 GNU/Linux
>>
>> cat /etc/issue
>> Debian GNU/Linux 7 \n \l
>>
>>
>> The version of R is 2.15.3. I know it is old, but we are in a regulated
>> environment and changes to R versions are painful. I have built R 2.15.3
>> elsewhere and have it running on multiple Linux boxes around here, both
>> 32-bit and 64-bit; Ubuntu distributions, however, not Debian.
>>
>> This build is on a virtual machine under OpenBox. The host is a 64-bit
>> Debian; the guest is a 32-bit Debian installation.
>>
>> The symptoms are strange (to me). I get segfaults during the
>> byte-compiling phase of libraries. If I re-run 'make', the make proceeds as
>> if it finished the previous seg-faulted step, and then segfaults on the
>> next byte-compile. The "permissions" makes me wonder about file
>> permissions, but the whole 'make' is under my HOME. Furthermore, I have
>> scanned the unpacked tar-gz package for something I don't "own" and it
>> isn't there. I also think segfaults are usually in memory, though I don't
>> know what "permission" I have there (don't I own the RAM I request?).
>>
>> I have attached a section of the 'make' output  below, followed by a the
>> next "make" output:
>> --**--**
>> --**
>> make[4]: Leaving directory `/home/mdalphin/src/R-2.15.3/**
>> src/library/splines'
>> make[4]: Entering directory `/home/mdalphin/src/R-2.15.3/**
>> src/library/splines'
>> byte-compiling package 'splines'
>>
>> *** caught segfault ***
>> address 0x403ac3dc, cause 'invalid permissions'
>>
>> Traceback:
>> 1: fun(libname, pkgname)
>> 2: doTryCatch(return(expr), name, parentenv, handler)
>> 3: tryCatchOne(expr, names, parentenv, handlers[[1L]])
>> 4: tryCatchList(expr, classes, parentenv, handlers)
>> 5: tryCatch(fun(libname, pkgname), error = identity)
>> 6: runHook(".onLoad", env, package.lib, package)
>> 7: loadNamespace(name)
>> 8: doTryCatch(return(expr), name, parentenv, handler)
>> 9: tryCatchOne(expr, names, parentenv, handlers[[1L]])
>> 10: tryCatchList(expr, classes, parentenv, handlers)
>> 11: tryCatch(loadNamespace(name), error = function(e) stop(e))
>> 12: getNamespace(ns)
>> 13: asNamespace(pkg)
>> 14: get(name, envir = asNamespace(pkg), inherits = FALSE)
>> 15: compiler:::tryCmpfun
>> 16: .Call("R_**lazyLoadDBinsertValue", x[[1L]], file, ascii, compress,
>>   hook, PACKAGE = "base")
>> 17: lazyLoadDBinsertVariable(vars[**i], from, datafile, ascii, compress,
>> envhook)
>> 18: makeLazyLoadDB(ns, dbbase, compress = compress)
>> 19: code2LazyLoadDB(package, lib.loc = lib.loc, keep.source =
>> keep.source, compress = compress)
>> 20: tools:::makeLazyLoading("**splines")
>> aborting ...
>> /bin/bash: line 8: 18709 Doneecho
>> "tools:::makeLazyLoading(\"**splines\")"
>> 18710 Segmentation fault  | R_COMPILE_PKGS=1
>> R_COMPILER_SUPPRESS_ALL=1 R_DEFAULT_PACKAGES=NULL LC_ALL=C ../../../bin/R
>> --vanilla --slave > /dev/null
>> make[4]: *** [../../../library/splines/R/**splines.rdb] Error 139
>> make[4]: Leaving directory `/home/mdalphin/src/R-2.15.3/**
>> src/library/splines'
>> make[3]: *** [all] Error 2
>> make[3]: Leaving directory `/home/mdalphin/src/R-2.15.3/**
>> src/library/splines'
>> make[2]: *** [R] Error 1
>> make[2]: Leaving directory `/home/mdalphin/src/R-2.15.3/**src/library'
>> make[1]: *** [R] Error 1
>> make[1]: Leaving directory `/home/mdalphin/src/R-2.15.3/**src'
>> make: *** [R] Error 1
>> --**--**
>> --**-
>> make[4]: Entering directory `/home/mdalphin/src/R-2.15.3/**
>> src/library/splines'
>> make[4]: Nothing to be done for `mklazycomp'.
>> make[4]: Leaving directory `/home/mdalphin/src/R-2.15.3/**
>> src/library/splines'
>> make[3]: Leaving directory `/home/mdalphin/src/R-2.15.3/**
>> 

[R] Word occurrence rate in a tweet

2013-07-10 Thread Bembi Prima
Hi all,

Currently I am working on a code that will calculate word occurrence rate
in a tweet.
First, I have 'tweets' that contains all the tweet I grabbed and I make
'words' that contains all unique word in 'tweets'.
After that I use sapply to calculate probability of a word appearing in
'tweets'.
The main problems is speed, before using sapply, I use simple for loop that
takes a really long time to finish but I can make simple ETA in the loop.
After I learn to use sapply and implement it on the code, speed is
improving greatly but I don't know the ETA so I just waiting for the result
to appear.
Using just 5% of the data I have waited for hours and R is still busy with
no output.
Is there a faster solution or useful package to help on my problem?

Here is my code :

sample.num<-10

tweets<-read.csv('data_conv.csv', sep=',', header=TRUE, stringsAsFactors =
FALSE)
tweets.num<-dim(tweets)[1]
tweets<-tweets[sample(1:tweets.num,sample.num,replace=FALSE)]
tweets.num<-length(tweets)

words<-paste(tweets,collapse=' ')
words<-gsub("\\\r\\\n", " ", words,ignore.case=TRUE,perl=TRUE) # remove
newlines
words<-gsub(" *\\d+ *", " ", words,ignore.case=TRUE,perl=TRUE) # remove
digits
words<-gsub("[^\\w@]+", " ", words,ignore.case=TRUE,perl=TRUE) # remove
nonwords
words<-unique(as.data.frame(strsplit(tolower(words),split=' '))) # unique
words
words<-words[order(words),] # sort it
words<-as.character(words)
words.num<-length(words)

result<-as.data.frame(words)
result$prob<-0
result$prob<-sapply(1:words.num,function(i)sum(grepl(sprintf('\\b%s\\b',words[i]),
tweets, ignore.case = TRUE, perl = TRUE))/tweets.num) # Lng time here

Thank you,
Bembi

[[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] Help with installing a .tar.gz package on windows

2013-07-10 Thread Prof Brian Ripley

On 11/07/2013 01:22, David Winsemius wrote:


On Jul 10, 2013, at 4:37 PM, Lucy Leigh wrote:


Hi,
I have had a look at the manual but it makes no sense to me. I have
downloaded RTools, and the InnoSetup,
but I don't understand how to use these to install my package? Am I
meant to be writing commands
in R itself, or in these other things I've downloaded?


Since you are clearly out of your league with respect to compiling from source, 
now is the time to ask (again), why are you not installing the binary package?

At the R command line just type:

install.packages("PReMiuM")  # should default to type="win.binary" and use a 
CRAN mirror



Or as she seems to want to use a later version than on CRAN, to ask 
again why she does not use winbuilder.



--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] [SOLVED] Problem building R-2.15.3 from source

2013-07-10 Thread Prof Brian Ripley

On 11/07/2013 06:44, Pascal Oettli wrote:

Hello,

Maybe the reason why:

http://www.cran.r-project.org/doc/manuals/R-admin.html#Compilation-flags


And since this is a ix86 system, you really should be using -mtune=native.

I do not believe the default in 2.15.3 was -O3: it is not in current R, 
and it certainly included -g .





Regards,
Pascal



2013/7/11 Mark Dalphin 


I have found a solution to the repeated seg-faults below.

If I set environment variables:
setenv CFLAGS -O2
setenv FFLAGS -O2
rather than the default -O3, then R builds and "checks" successfully.

A few more details about the Debian system on which I have been building:
 gcc (Debian 4.7.2-5) 4.7.2

My "configure" command is:
./configure \
--prefix=$my_R_path \
--with-readline \
--without-x \
--enable-R-shlib\
--enable-BLAS-shlib \
--with-system-zlib  \
--with-system-bzlib \
 --with-system-pcre

So, I'm good for the time being and hope this helps others who have
trouble building from source.


Others who do not follow the instructions?  As the manual says at the end

'Beware of using high levels of optimization, at least initially. On 
many compilers these reduce the degree of compliance to the IEEE model.'






Cheers,
Mark

Mark Dalphin wrote:


Hi,

I have for many years build R from source for Linux. I have just run into
my first problem with this in ... I don't know how long.

uname -a
Linux douglas 3.2.0-4-686-pae #1 SMP Debian 3.2.46-1 i686 GNU/Linux

cat /etc/issue
Debian GNU/Linux 7 \n \l


The version of R is 2.15.3. I know it is old, but we are in a regulated
environment and changes to R versions are painful. I have built R 2.15.3
elsewhere and have it running on multiple Linux boxes around here, both
32-bit and 64-bit; Ubuntu distributions, however, not Debian.

This build is on a virtual machine under OpenBox. The host is a 64-bit
Debian; the guest is a 32-bit Debian installation.

The symptoms are strange (to me). I get segfaults during the
byte-compiling phase of libraries. If I re-run 'make', the make proceeds as
if it finished the previous seg-faulted step, and then segfaults on the
next byte-compile. The "permissions" makes me wonder about file
permissions, but the whole 'make' is under my HOME. Furthermore, I have
scanned the unpacked tar-gz package for something I don't "own" and it
isn't there. I also think segfaults are usually in memory, though I don't
know what "permission" I have there (don't I own the RAM I request?).

I have attached a section of the 'make' output  below, followed by a the
next "make" output:
--**--**
--**
make[4]: Leaving directory `/home/mdalphin/src/R-2.15.3/**
src/library/splines'
make[4]: Entering directory `/home/mdalphin/src/R-2.15.3/**
src/library/splines'
byte-compiling package 'splines'

*** caught segfault ***
address 0x403ac3dc, cause 'invalid permissions'

Traceback:
1: fun(libname, pkgname)
2: doTryCatch(return(expr), name, parentenv, handler)
3: tryCatchOne(expr, names, parentenv, handlers[[1L]])
4: tryCatchList(expr, classes, parentenv, handlers)
5: tryCatch(fun(libname, pkgname), error = identity)
6: runHook(".onLoad", env, package.lib, package)
7: loadNamespace(name)
8: doTryCatch(return(expr), name, parentenv, handler)
9: tryCatchOne(expr, names, parentenv, handlers[[1L]])
10: tryCatchList(expr, classes, parentenv, handlers)
11: tryCatch(loadNamespace(name), error = function(e) stop(e))
12: getNamespace(ns)
13: asNamespace(pkg)
14: get(name, envir = asNamespace(pkg), inherits = FALSE)
15: compiler:::tryCmpfun
16: .Call("R_**lazyLoadDBinsertValue", x[[1L]], file, ascii, compress,
   hook, PACKAGE = "base")
17: lazyLoadDBinsertVariable(vars[**i], from, datafile, ascii, compress,
 envhook)
18: makeLazyLoadDB(ns, dbbase, compress = compress)
19: code2LazyLoadDB(package, lib.loc = lib.loc, keep.source =
keep.source, compress = compress)
20: tools:::makeLazyLoading("**splines")
aborting ...
/bin/bash: line 8: 18709 Doneecho
"tools:::makeLazyLoading(\"**splines\")"
 18710 Segmentation fault  | R_COMPILE_PKGS=1
R_COMPILER_SUPPRESS_ALL=1 R_DEFAULT_PACKAGES=NULL LC_ALL=C ../../../bin/R
--vanilla --slave > /dev/null
make[4]: *** [../../../library/splines/R/**splines.rdb] Error 139
make[4]: Leaving directory `/home/mdalphin/src/R-2.15.3/**
src/library/splines'
make[3]: *** [all] Error 2
make[3]: Leaving directory `/home/mdalphin/src/R-2.15.3/**
src/library/splines'
make[2]: *** [R] Error 1
make[2]: Leaving directory `/home/mdalphin/src/R-2.15.3/**src/library'
make[1]: *** [R] Error 1
make[1]: Leaving directory `/home/mdalphin/src/R-2.15.3/**src'
make: *** [R] Error 1
--**--**
--**-
make[4]: Entering directory `/home/mdalphin/src/R-2.15.3/**
src/library/splines'
make[4]: Nothing to be done for

[R] Installing OpenBLAS in R

2013-07-10 Thread Christofer Bogaso
Hello again,

I was wondering if it is possible to install OpenBLAS linear algebra
library in R running under windows.

I found some study saying working with OpenBLAS would significantly
speed-up the calculations in R.

Thanks for your pointer.

Thanks and regards,

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