[R] plot discrete time series against time

2013-07-20 Thread shanxiao
Dear all, 

 

I try to plot some discrete time series data through time, of course I can
achieve it by using the combination of some basic R functions, but it is not
that convenient, does anyone know any R-inbuilt function to do it? Best. 

 

Shan Xiao

Ph.D. student of Biostatistics, 

Department of Biostatistics, IUPUI.

 


[[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] Linear regression repeat for each column

2013-07-20 Thread arun


Hi,
set.seed(28)
dat1<- as.data.frame(matrix(sample(1:20,100,replace=TRUE),ncol=10))
set.seed(49)
dat2<- as.data.frame(matrix(sample(40:80,100,replace=TRUE),ncol=10))
 lapply(seq_len(ncol(dat1)),function(i) {lm(dat2[,i]~dat1[,i])})
A.K.

- Original Message -
From: iza.ch1 
To: r-help@r-project.org
Cc: 
Sent: Saturday, July 20, 2013 7:55 PM
Subject: [R] Linear regression repeat for each column

Hi everyone

I need to calculate abnormal returns for different events applying event study 
methodology. I must create a market model in order to perform the analysis. I 
apply regression analysis to get OLS estimators.

I have a problem to create a linear regression which I could repeat for each 
column in two different data frames (one with explainatory and one with 
explaning variables). It means that I want to regress column 1 from first data 
frame with column 1 from second data frame,, clumn two with column two etc. I 
tried to use the following code:#x  is matrix containing stock returns
y is matrix containing market index                          
i<-1:length(x)
t[i] <- lapply(t[i], lm(x[,1]~y[,i]))

but it is not working.

Could anybody help me?

Thanks a lot

Iza

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] BH correction with p.adjust

2013-07-20 Thread David Winsemius

On Jul 20, 2013, at 10:37 AM, Scott Robinson wrote:

> Dear List,
> 
> I have been trying to use p.adjust() to do BH multiple test correction and 
> have gotten some unexpected results. I thought that the equation for this was:
> 
> pBH = p*n/i

Looking at the code for `p.adjust`, you see that the method is picked from a 
switch function

lp <- length(p)
BH = {
i <- lp:1L
o <- order(p, decreasing = TRUE)
ro <- order(o)
pmin(1, cummin(n/i * p[o]))[ro]
}

You may not have sorted the p-values in pList.


> 
> where p is the original p value, n is the number of tests and i is the rank 
> of the p value. However when I try and recreate the corrected p from my most 
> significant value it does not match up to the one computed by the method 
> p.adjust:
> 
>> setwd("C:/work/Methylation/IMA/GM/siteLists")
>> 
>> hypTable <- read.delim("hypernormal vs others.txt")
>> pList <- hypTable$p
>> names(pList) <- hypTable$site
>> 
>> adjusted <- p.adjust(pList, method="BH")
>> adjusted[1]
> cg27433479 
> 0.05030589 
>> 
>> pList[1]*nrow(hypTable)/1
> cg27433479 
> 0.09269194 
> 

No data provided, so unable to pursue this further.

> I tried to recreate this is a small example of a vector of 5 p values but 
> everything worked as expected there. I was wondering if there is some subtle 
> difference about how p.adjust operates? Is there something more complicated 
> about how to calculate 'n' or 'i' - perhaps due to identical p values being 
> assigned the same rank or something? Does anyone have an idea what might be 
> going on here?


-- 

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] Extract specific rows from a data frame

2013-07-20 Thread arun
Hi,
May be this helps:
df1<- read.table(text="
  t1 t2 t3 t4
  len1 AA AA PP AP
  len2 FALSE AA PP MM
  len3 PP AA AA AP
  len4 PP AM MP PP
  len5 AA FALSE AP PP
  len6 PP AA AA AA
",sep="",header=TRUE,stringsAsFactors=FALSE)

df1[df1[,1]=="PP" & (rowSums(df1[,-1]!="PP")==(ncol(df1)-1)),]
# t1 t2 t3 t4
#len3 PP AA AA AP
#len6 PP AA AA AA
A.K.



- Original Message -
From: Chirag Gupta 
To: r-help@r-project.org
Cc: 
Sent: Saturday, July 20, 2013 6:56 PM
Subject: [R] Extract specific rows from a data frame

Hi

I have a data frame as below



  t1 t1 t3 t4  len1 AA AA PP AP  len2 FALSE AA PP MM  len3 PP AA AA AP  len4
PP AM MP PP  len5 AA FALSE AP PP  len6 PP AA AA AA
I am having trouble extracting only those rows which have "PP" in the first
column but AA or FALSE or all any other value but not PP in rest of the
columns.


-- 
*Chirag Gupta*

    [[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] Linear regression repeat for each column

2013-07-20 Thread Jeff Newmiller
Sure. Read the Posting Guide, and provide a reproducible example with sample 
data.

I suspect the basic idea will be to merge the data frames and then setup the 
model to refer to the desired columns.
---
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.

"iza.ch1"  wrote:
>Hi everyone
>
>I need to calculate abnormal returns for different events applying
>event study methodology. I must create a market model in order to
>perform the analysis. I apply regression analysis to get OLS
>estimators.
>
>I have a problem to create a linear regression which I could repeat for
>each column in two different data frames (one with explainatory and one
>with explaning variables). It means that I want to regress column 1
>from first data frame with column 1 from second data frame,, clumn two
>with column two etc. I tried to use the following code:#x  is matrix
>containing stock returns
>y is matrix containing market index   
>i<-1:length(x)
>t[i] <- lapply(t[i], lm(x[,1]~y[,i]))
>
>but it is not working.
>
>Could anybody help me?
>
>Thanks a lot
>
>Iza
>
>__
>R-help@r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

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


[R] Extract specific rows from a data frame

2013-07-20 Thread Chirag Gupta
Hi

I have a data frame as below



  t1 t1 t3 t4  len1 AA AA PP AP  len2 FALSE AA PP MM  len3 PP AA AA AP  len4
PP AM MP PP  len5 AA FALSE AP PP  len6 PP AA AA AA
I am having trouble extracting only those rows which have "PP" in the first
column but AA or FALSE or all any other value but not PP in rest of the
columns.


-- 
*Chirag Gupta*

[[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] BH correction with p.adjust

2013-07-20 Thread Scott Robinson
Dear List,

I have been trying to use p.adjust() to do BH multiple test correction and have 
gotten some unexpected results. I thought that the equation for this was:

pBH = p*n/i

where p is the original p value, n is the number of tests and i is the rank of 
the p value. However when I try and recreate the corrected p from my most 
significant value it does not match up to the one computed by the method 
p.adjust:

> setwd("C:/work/Methylation/IMA/GM/siteLists")
> 
> hypTable <- read.delim("hypernormal vs others.txt")
> pList <- hypTable$p
> names(pList) <- hypTable$site
> 
> adjusted <- p.adjust(pList, method="BH")
> adjusted[1]
cg27433479 
0.05030589 
> 
> pList[1]*nrow(hypTable)/1
cg27433479 
0.09269194 

I tried to recreate this is a small example of a vector of 5 p values but 
everything worked as expected there. I was wondering if there is some subtle 
difference about how p.adjust operates? Is there something more complicated 
about how to calculate 'n' or 'i' - perhaps due to identical p values being 
assigned the same rank or something? Does anyone have an idea what might be 
going on here?

Many thanks,

Scott
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Linear regression repeat for each column

2013-07-20 Thread iza.ch1
Hi everyone

I need to calculate abnormal returns for different events applying event study 
methodology. I must create a market model in order to perform the analysis. I 
apply regression analysis to get OLS estimators.

I have a problem to create a linear regression which I could repeat for each 
column in two different data frames (one with explainatory and one with 
explaning variables). It means that I want to regress column 1 from first data 
frame with column 1 from second data frame,, clumn two with column two etc. I 
tried to use the following code:#x  is matrix containing stock returns
y is matrix containing market index   
i<-1:length(x)
t[i] <- lapply(t[i], lm(x[,1]~y[,i]))

but it is not working.

Could anybody help me?

Thanks a lot

Iza

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


Re: [R] Different x-axis scales using c() in latticeExtra

2013-07-20 Thread Felix Andrews
latticeExtra's c() can not combine logarithmic with linear x scales,
I'm afraid.  I would recommend displaying each separate plot on one
page using plot.trellis() or the gridExtra function that John Kane
mentioned.

Cheers
Felix


On 21 July 2013 02:50, David Winsemius  wrote:
>
> On Jul 19, 2013, at 8:18 PM, Jeff Stevens wrote:
>
>> Hi,
>>
>> I would like to combine multiple xyplots into a single, multipanel
>> display.  Using R 3.0.1 in Ubuntu, I have used c() from latticeExtra
>> to combine three plots, but the x-axis for two plots are on a log
>> scale and the other is on a normal scale.  I also have included
>> equispace.log=FALSE to clean up the tick labels.  However, when I try
>> all of these, the x-axis scale of the first panel is used for all
>> three.  How do I keep different scales for the different panels?
>>
>> Here is an example:
>> library(lattice)
>> library(latticeExtra)
>> response <- c(76, 14, 15, 44, 26, 19, 74, 123, 49, 8, 56, 17, 18)
>> predictor1 <- c(107, 7, 25, 501, 64, 88, 344, 367, 379, 10, 66, 31, 32)
>> predictor2 <- c(10, 9, 8, 10, 29, 27, 55, 48, 2, 6, 14, 10, 5)
>> predictor3 <- c(67, 22, 66, 41, 72, 64, 69, 63, 64, 70, 60, 75, 78)
>>
>> pred1_plot <- xyplot(response ~ predictor1, scales = list(log = TRUE,
>> equispaced.log = FALSE),
>>  panel = function(x, y, ...) {
>>panel.xyplot(x, y, type = c("p", "r"), cex = 2)
>>panel.text(x = log10(8), y = log10(120), labels = "(a)")
>>  }
>> )
>>
>> pred2_plot <- xyplot(response ~ predictor2, scales = list(log = TRUE,
>> equispaced.log = FALSE),
>>  panel = function(x, y, ...) {
>>panel.xyplot(x, y, type = c("p", "r"), cex = 2)
>>panel.text(x = log10(2), y = log10(120), labels = "(b)")
>>  }
>> )
>>
>> pred3_plot <- xyplot(response ~ predictor3, scales = list(y = list(log
>> = TRUE, equispaced.log = FALSE)),
>>  panel = function(x, y, ...) {
>>panel.xyplot(x, y, type = c("p", "r"), cex = 2)
>>panel.text(x = 22, y = log10(120), labels = "(c)")
>>  }
>> )
>>
>> all_plots <- c(pred1_plot, pred2_plot, pred3_plot, layout = c(3, 1), x.same 
>> = F)
>> update(all_plots, xlab=c("Predictor 1","Predictor 2", "Predictor 3"),
>> scales = list(y=list(log=T, equispaced.log=FALSE), x = c(list(log=T,
>> equispaced.log=FALSE), list(log=T, equispaced.log=FALSE),
>> list(log=F
>>
>> update(all_plots, xlab=c("Predictor 1","Predictor 2", "Predictor 3"),
>> scales = c(list(log = TRUE, equispaced.log = FALSE), list(log = TRUE,
>> equispaced.log = FALSE), list(y=list(log=T, equispaced.log = FALSE
>>
>> Any help is appreciated!
>
> I assume there was a notice o your console that there were warnings, right? 
> You should offer the full texts of warnings and error messages. Here the full 
> text of the first and second warnings:
>
>> warnings()[1:2]
> $`log scales cannot be changed via 'update'`
> update.trellis(all_plots, xlab = c("Predictor 1", "Predictor 2",
> "Predictor 3"), scales = c(list(log = TRUE, equispaced.log = FALSE),
> list(log = TRUE, equispaced.log = FALSE), list(y = list(log = T,
> equispaced.log = FALSE
> $`'x' is NULL so the result will be NULL`
> rep(scales[[nm]], length.out = 2)
>
> The first one is telling you why the results should be different than you 
> expect. I'm not entirely sure what the second one is telling you, but it 
> doesn't sound good.
>
> --
> 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.



-- 
Felix Andrews / 安福立
http://www.neurofractal.org/felix/

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

2013-07-20 Thread Uwe Ligges

Several problems:

1. You havbe an object called "matrix", that actually is a list of two 
data.frames. WinBUGS does not know about data,frames. You have to 
provide a matrix here, hence


bugs(., data=list(Y=as.matrix(Y), Nf=5, ), )


2. In your model file, you have

gamma[1:2 ]
T[1:2 ,1:2 ])
n
an others, all of which need to be passed to WinBUGS as data. I do not 
see a dingle of these objects to be defined anywhere.


3. Then you have

  parameters.to.save = c("p","rho","sigma2")
but these are not mentioned in the model file,

So this is rather hopeless. My suggestion is to seek advice from a local 
BUGS expert or from the BUGS mailing list.


You should start to develop your model in BUSG directly, since the R 
interface is nice for automation, but not for model building, since you 
do not see the error messages as directly as in WinBUGS/OpenBUGS yourself.



Best,
uwe ligges





On 16.07.2013 17:52, Anamika Chaudhuri wrote:

Hi All:
I am getting an error (highlighted) from running R2WinBUGS in R.
To be able to replicate the situation heres the code:
.#Set working directory
setwd("H://AChaudhuri/Testing/CSVS")
matrix=NULL
csvs <- paste("MVN", 1:2, ".csv", sep="")
for(i in 1:length(csvs)){
   matrix[[i]] <- read.csv(file=csvs[i], header=T)
   print(matrix[[i]])
}

So now I have read in 2 simulated datasets which  look like
  Y1 Y2
1 11  6
2  8  5
3 25 13
4  1 13
5  8 22
   Y1 Y2
1  9  1
2  7  9
3 25 13
4  1 18
5  9 12

My next step is to run a multivariate logit normal model on these datasets
and automate this process for such simulated datasets. Heres the model
statement:
model
  {
   for (j in 1 : Nf)

   {
   p1[j, 1:2 ] ~ dmnorm(gamma[1:2 ], T[1:2 ,1:2 ])

   for (i in 1:2)
   {
  logit(p[j,i])<-p1[j,i]

  Y[j,i] ~ dbin(p[j,i],n)
}}

I am trying to use the following code to run it in R
library("R2WinBUGS")
bugs.output <- list()
for(i in 1:2){

Y <-(matrix[i])

bugs.output[[i]] <- bugs(
data=list(Y=Y, Nf=5), # change for no of sites
 inits=NULL,
model.file="M-LN_model_trial.txt",
parameters.to.save = c("p","rho","sigma2"),
n.chains=1, n.iter=12000, n.burnin=5000,
bugs.directory="H://AChaudhuri/winbugs14/WinBUGS14",
working.directory=NULL)}


Error in FUN(X[[1L]], ...) :

   .C(..): 'type' must be "real" for this format

Any suggestion would be helpful.
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.



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


Re: [R] how to download Journal Citation Reports with R

2013-07-20 Thread Ben Bolker
Wet Bell Diver  gmail.com> writes:

> 
> R-3.0.1, Rstudio, Win7 x64
> 
> Dear list,
> 
> I would like to download all the webpages of the Journal Citations 
> Report (science edition), for a given year. I can do so manually, but 
> that it very time intensive, so I would like to use R for that.
> 
> I have tried many things, including:
> download.file(url = 
> "http://admin-apps.webofknowledge.com/JCR/JCR?RQ=SELECT_ALL&cursor=21";, 
> destfile = "test.htm", method = "internal")
> which would get the page starting with journal number 21.
> However, test.htm only includes the message:
> 
>  >>>

  You need to review the RCurl package and look for "cookies", which
will allow you (once you have established a session in a browser) to
copy the cookies (tokens which allow you access) into your R session.
However, you will probably be violating the terms of service of JCR.
You should talk to your librarian about this.  When I wanted to do
a similar project I worked out a system where I generated the URLs 
automatically and got a student assistant to (efficiently) go to the
URLs and paste the results into output files.

  Ben Bolker

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


Re: [R] Windows 7 (Swedish): 'Rcmd INSTALL' fails

2013-07-20 Thread Uwe Ligges



On 21.07.2013 00:26, Göran Broström wrote:

I am trying to build a Windows zip file of a private package by

C:/Program/R/R-3.0.1/bin/x64/Rcmd INSTALL --build --library=.
epigen_0.1.tar.gz


Why --library=. ?
Do you have appropriate poermissions to do that? In this case, you need 
to start everything with admin priviliges explicitly unless your Windows 
is configured differently.





but I get errors like

1: package 'datasets' in options("defaultPackages") was not found

and, finally,

Error in normalsizePath(path.expand(path), winslash, mustWork) :
path[1]="C:/Program/R/R-3.0.1/library/tools": Atkomst nekad
(Access denied)

This is on a Swedish version of Windows 7. I noticed that the R
installer called the installation directory "Program Files" instead of
"Program" (despite my effort to change it), so I tried the same thing


But there is "Program Files", "Program" is just something like a link 
shown by the Windows Explorer that actually points to "Program Files".





with an English version of Windows 7 (on another machine), and there
everything went as expected.

I installed R on both machines today so the setups should be identical,
except for the languages. What can be wrong? Can it be a language/path
thing?


Probably not the language but different admin settings.

Best,
Uwe Ligges



Thanks for any insight!

Göran Broström

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


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


[R] Windows 7 (Swedish): 'Rcmd INSTALL' fails

2013-07-20 Thread Göran Broström

I am trying to build a Windows zip file of a private package by

C:/Program/R/R-3.0.1/bin/x64/Rcmd INSTALL --build --library=. 
epigen_0.1.tar.gz


but I get errors like

1: package 'datasets' in options("defaultPackages") was not found

and, finally,

Error in normalsizePath(path.expand(path), winslash, mustWork) :
path[1]="C:/Program/R/R-3.0.1/library/tools": Atkomst nekad
(Access denied)

This is on a Swedish version of Windows 7. I noticed that the R 
installer called the installation directory "Program Files" instead of 
"Program" (despite my effort to change it), so I tried the same thing 
with an English version of Windows 7 (on another machine), and there 
everything went as expected.


I installed R on both machines today so the setups should be identical, 
except for the languages. What can be wrong? Can it be a language/path 
thing?


Thanks for any insight!

Göran Broström

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


Re: [R] Identify Leverage Points

2013-07-20 Thread Greg Snow
The help page for plot.lm includes mention of ‘lm.influence’,
‘cooks.distance’,  and 'hatvalues’ in the "See Also", section.  Do any of
those accomplish what you want?


On Fri, Jul 19, 2013 at 4:14 PM, Noah Silverman wrote:

> Hello,
>
> I'm working on some fairly standard regression models (linear, logistic,
> and poisson.)  Unfortunately, the data is rather messy.
>
> A visual inspection, using either a histogram or a density plot indicates
> some significant outliers.  Furthermore, summary statistics of the data
> indicate the same thing.
>
> If I fit a linear regression in R using the "lm" command, I can then plot
> the model to look at residuals, etc.
>
> I'm interesting in re-fitting the model with a N% of the high leverage
> points removed.   (Large data set, want to fit "most" of the data.)
>
> Is there a computational way to get the leverage for each data point?
>  That way I can subset the data skipping N% of the highest leverage ones.
>
>
> Thanks!
>
>
> --
> Noah Silverman, M.S., C.Phil
> UCLA Department of Statistics
> 8117 Math Sciences Building
> Los Angeles, CA 90095
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gregory (Greg) L. Snow Ph.D.
538...@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] how to download Journal Citation Reports with R

2013-07-20 Thread Wet Bell Diver
R-3.0.1, Rstudio, Win7 x64

Dear list,

I would like to download all the webpages of the Journal Citations 
Report (science edition), for a given year. I can do so manually, but 
that it very time intensive, so I would like to use R for that.

I have tried many things, including:
download.file(url = 
"http://admin-apps.webofknowledge.com/JCR/JCR?RQ=SELECT_ALL&cursor=21";, 
destfile = "test.htm", method = "internal")
which would get the page starting with journal number 21.
However, test.htm only includes the message:

 >>>


  You do not have a session.

You will need to establish a new session 
 if you wish to 
continue.

<<<
I do, however, already have a session that I manually started (through 
the web browser), but R does not recognize that.

Does anyone have an idea how to download the webpages for JCR science 
edition for a given year? I have no idea what to try next.

thanks,
Peter Verbeet



[[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] How to search for a sequence(and its combination) inside a vector?

2013-07-20 Thread John Kane
My best guess it that you have something like 1 123123 in there somewhere 

try: 
which(cc[,1]  == 6)
and have a look at line 137 

Essentially your data does not look exactly like what you think it does.
John Kane
Kingston ON Canada


> -Original Message-
> From: tmrs...@gmail.com
> Sent: Sat, 20 Jul 2013 13:50:10 -0400
> To: jrkrid...@inbox.com, b...@xs4all.nl
> Subject: Re: [R] How to search for a sequence(and its combination) inside
> a vector?
> 
> Thanks, you guys are correct, I had different data.
> But why I get length 5 and 6, should only be 1 to 3.
> 
> Full R code :
> 
> vec <- c(1, 2, 3, 4, 5, 6, 7, 8, 13, 1, 2, 3, 5, 7, 8, 10, 12, 13, 14,
> 15, 1, 2, 3, 5, 6, 10, 12, 13, 1, 2, 3, 4, 5, 6, 7, 12, 13, 14,
> 15, 1, 2, 3, 6, 9, 10, 11, 13, 14, 1, 7, 10, 13, 1, 2, 3, 4,
> 6, 7, 9, 11, 14, 1, 2, 3, 5, 9, 10, 11, 12, 14, 1, 2, 3, 4, 1,
> 2, 3, 4, 11, 12, 14, 1, 2, 3, 4, 8, 11, 12, 1, 2, 3, 4, 5, 7,
> 8, 9, 11, 12, 15, 3, 14, 1, 2, 3, 6, 10, 11, 13, 14, 1, 2, 3,
> 4, 5, 6, 8, 9, 10, 11, 12, 14, 1, 2, 3, 4, 9, 13, 15, 1, 2, 3,
> 4, 6, 8, 9, 11, 12, 1, 2, 3, 7, 8, 9, 14, 1, 2, 3, 12, 1, 2,
> 3, 4, 5, 10, 14, 1, 2, 3, 4, 5, 7, 8, 12, 13, 14, 1, 2, 3, 10,
> 1, 3, 1, 2, 3, 5, 7, 8, 10, 11, 13, 14, 1, 2, 3, 4, 5, 8, 9,
> 11, 12, 15, 1, 2, 3, 4, 7, 9, 10, 13, 1, 2, 3, 4, 5, 7, 10, 11,
> 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 1, 2, 3, 6, 7,
> 8, 9, 10, 12, 13, 14, 15, 1, 2, 3, 4, 7, 1, 2, 3, 5, 8, 13, 1,
> 2, 3, 5, 8, 11, 15, 1, 2, 3, 1, 2, 3, 10, 1, 2, 3, 4, 7, 8, 9,
> 10, 11, 12, 14, 1, 3, 9, 11, 13, 14, 1, 2, 3, 4, 5, 7, 8, 9,
> 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 13, 14, 15, 1, 2, 3, 11,
> 13, 14, 1, 2, 3, 8, 1, 2, 3, 4, 5, 6, 8, 11, 12, 14, 1, 2, 3,
> 5, 6, 9, 10, 11, 12, 15, 1, 2, 3, 4, 5, 9, 11, 12, 13, 1, 2,
> 3, 4, 5, 13, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15,
> 1, 2, 3, 7, 8, 9, 1, 2, 3, 5, 7, 8, 9, 10, 12, 14, 15, 1, 2,
> 3, 4, 5, 6, 8, 14, 1, 2, 3, 1, 2, 3, 10, 11, 13, 1, 2, 3, 4,
> 9, 10, 12, 13, 14, 1, 2, 3, 4, 5, 6, 12, 1, 2, 3, 4, 5, 6, 7,
> 10, 12, 13, 14, 15, 1, 2, 3, 6, 10, 14, 1, 2, 3, 4, 6, 7, 8,
> 9, 10, 11, 13, 14, 1, 2, 3, 1, 2, 3, 4, 7, 8, 10, 1, 2, 3, 7,
> 8, 11, 13, 15, 1, 2, 3, 4, 7, 8, 14, 15, 1, 2, 3, 4, 14, 1, 2,
> 3, 4, 6, 7, 10, 12, 1, 2, 3, 5, 7, 8, 11, 13, 14, 15, 1, 2, 3,
> 4, 1, 2, 3, 6, 7, 9, 11, 12, 13, 14, 1, 2, 3, 7, 11, 12, 1, 2,
> 3, 5, 6, 8, 9, 10, 12, 15, 1, 2, 3, 5, 6, 8, 9, 11, 1, 2, 3,
> 7, 8, 11, 13, 14, 15, 1, 2, 3, 4, 10, 12, 14, 1, 2, 3, 11, 12,
> 13, 15, 1, 2, 3, 5, 7, 10, 11, 12, 13, 14, 15, 1, 3, 10, 1, 2,
> 3, 1, 2, 3, 8, 10, 15, 1, 2, 3, 4, 7, 10, 12, 14, 1, 2, 3, 9,
> 10, 11, 1, 2, 3, 6, 9, 10, 15, 1, 9, 14, 1, 2, 3, 7, 10, 14,
> 1, 2, 3, 4, 7, 8, 9, 10, 11, 13, 15, 1, 2, 3, 5, 6, 7, 8, 9,
> 11, 12, 13, 14, 15, 1, 2, 3, 6, 8, 11, 12, 1, 7, 1, 2, 3, 8,
> 13, 15, 1, 2, 3, 4, 8, 9, 11, 1, 2, 3, 4, 7, 13, 14, 1, 2, 3,
> 5, 6, 9, 1, 3, 7, 12, 13, 15, 1, 2, 3, 5, 6, 8, 10, 1, 3, 5,
> 7, 8, 10, 11, 1, 2, 3, 5, 6, 11, 14, 1, 2, 3, 4, 9, 10, 11, 13,
> 14, 1, 2, 3, 4, 6, 9, 14, 15, 1, 2, 3, 11, 1, 2, 3, 4, 5, 7,
> 11, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 14, 1, 2, 3, 4,
> 5, 6, 7, 9, 10, 11, 12, 14, 1, 4, 7, 1, 2, 3, 5, 6, 8, 9, 10,
> 12, 13, 15, 1, 2, 3, 4, 5, 8, 10, 12, 13)
> a <- vec %in% c(1, 2, 3)
> b <- rle(a)
> cc  <-  data.frame(b[[1]], b[[2]])
> names(cc)  <-  c("leng", 'val')
> dd  <-  subset(cc, val ==TRUE )
> table(dd)
> 
>> table(dd)
> val
> leng TRUE
>15
>24
>3   81
>51
>64
> 
> btw,
>> length(vec)
> [1] 762
> 
> So, the tally should add up to that if correct.
> 
> -M
> 
> 
> On Sat, Jul 20, 2013 at 1:41 PM, John Kane  wrote:
>> Beats me. I get:
>> table(dd)
>> val
>> leng TRUE
>>13
>>3   12
>> 
>> What does dd look like.  In my case I get this where the first column is
>> the row number
>> dd
>>leng  val
>> 1 3 TRUE
>> 3 3 TRUE
>> 5 3 TRUE
>> 7 3 TRUE
>> 9 3 TRUE
>> 111 TRUE
>> 133 TRUE
>> 153 TRUE
>> 173 TRUE
>> 193 TRUE
>> 213 TRUE
>> 233 TRUE
>> 251 TRUE
>> 273 TRUE
>> 291 TRUE
>> 
>> John Kane
>> Kingston ON Canada
>> 
>> 
>>> -Original Message-
>>> From: tmrs...@gmail.com
>>> Sent: Sat, 20 Jul 2013 13:11:47 -0400
>>> To: jrkrid...@inbox.com
>>> Subject: Re: [R] How to search for a sequence(and its combination)
>>> inside
>>> a vector?
>>> 
>>> Thanks John.
>>> 
>>> Why do I get length of 5 and 6?  I thought I am only tallying up 1 to
>>> 3?
 table(dd)
>>> val
>>> leng TRUE
>>>15
>>>24
>>>3   81
>>>51
>>>64
>>> 
>>> -M
>>> 
>>> On Sat, Jul 20, 2013 at 12:52 PM, John Kane 
>>> wrote:
 Taking Berend's example a bit further, this seems to work
 
 If you use str(b) you will see it is a list
 
 b <- rle(a)
 cc  <-  data.frame(b[[1]], b[[2]])
 names(cc)  <-  c("leng", 'val')
 dd  <-  subset(cc, val ==TRUE )
 table(dd)
 
 John Kane
 Kingston ON Canada
 
 
> -Original Message-
>

Re: [R] How to search for a sequence(and its combination) inside a vector?

2013-07-20 Thread C W
Hi, John
I am doing sparsity recovery from glmnet.

Elements 1, 2, 3 of the repeating sequence are the nonzero elements.
But it's not always recovered.

How my original data frame looks like
> df[1:15, ]
i x
2   1  0.0869399788
3   2 -0.0994713934
4   3  0.0720312837
5   4  0.0075392684
6   5  0.0130364386
7   6  0.0238318855
8   7 -0.0152197121
9   8  0.0097389626
10 13  0.0005068968
12  1  0.0679442455
13  2 -0.0647438953
14  3  0.0656297104
15  5  0.0003406059
16  7  0.0241146788
17  8  0.0093850612


I trimmed out the data column, only grabbing the index.

-M


On Sat, Jul 20, 2013 at 1:50 PM, C W  wrote:
> Thanks, you guys are correct, I had different data.
> But why I get length 5 and 6, should only be 1 to 3.
>
> Full R code :
>
> vec <- c(1, 2, 3, 4, 5, 6, 7, 8, 13, 1, 2, 3, 5, 7, 8, 10, 12, 13, 14,
> 15, 1, 2, 3, 5, 6, 10, 12, 13, 1, 2, 3, 4, 5, 6, 7, 12, 13, 14,
> 15, 1, 2, 3, 6, 9, 10, 11, 13, 14, 1, 7, 10, 13, 1, 2, 3, 4,
> 6, 7, 9, 11, 14, 1, 2, 3, 5, 9, 10, 11, 12, 14, 1, 2, 3, 4, 1,
> 2, 3, 4, 11, 12, 14, 1, 2, 3, 4, 8, 11, 12, 1, 2, 3, 4, 5, 7,
> 8, 9, 11, 12, 15, 3, 14, 1, 2, 3, 6, 10, 11, 13, 14, 1, 2, 3,
> 4, 5, 6, 8, 9, 10, 11, 12, 14, 1, 2, 3, 4, 9, 13, 15, 1, 2, 3,
> 4, 6, 8, 9, 11, 12, 1, 2, 3, 7, 8, 9, 14, 1, 2, 3, 12, 1, 2,
> 3, 4, 5, 10, 14, 1, 2, 3, 4, 5, 7, 8, 12, 13, 14, 1, 2, 3, 10,
> 1, 3, 1, 2, 3, 5, 7, 8, 10, 11, 13, 14, 1, 2, 3, 4, 5, 8, 9,
> 11, 12, 15, 1, 2, 3, 4, 7, 9, 10, 13, 1, 2, 3, 4, 5, 7, 10, 11,
> 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 1, 2, 3, 6, 7,
> 8, 9, 10, 12, 13, 14, 15, 1, 2, 3, 4, 7, 1, 2, 3, 5, 8, 13, 1,
> 2, 3, 5, 8, 11, 15, 1, 2, 3, 1, 2, 3, 10, 1, 2, 3, 4, 7, 8, 9,
> 10, 11, 12, 14, 1, 3, 9, 11, 13, 14, 1, 2, 3, 4, 5, 7, 8, 9,
> 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 13, 14, 15, 1, 2, 3, 11,
> 13, 14, 1, 2, 3, 8, 1, 2, 3, 4, 5, 6, 8, 11, 12, 14, 1, 2, 3,
> 5, 6, 9, 10, 11, 12, 15, 1, 2, 3, 4, 5, 9, 11, 12, 13, 1, 2,
> 3, 4, 5, 13, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15,
> 1, 2, 3, 7, 8, 9, 1, 2, 3, 5, 7, 8, 9, 10, 12, 14, 15, 1, 2,
> 3, 4, 5, 6, 8, 14, 1, 2, 3, 1, 2, 3, 10, 11, 13, 1, 2, 3, 4,
> 9, 10, 12, 13, 14, 1, 2, 3, 4, 5, 6, 12, 1, 2, 3, 4, 5, 6, 7,
> 10, 12, 13, 14, 15, 1, 2, 3, 6, 10, 14, 1, 2, 3, 4, 6, 7, 8,
> 9, 10, 11, 13, 14, 1, 2, 3, 1, 2, 3, 4, 7, 8, 10, 1, 2, 3, 7,
> 8, 11, 13, 15, 1, 2, 3, 4, 7, 8, 14, 15, 1, 2, 3, 4, 14, 1, 2,
> 3, 4, 6, 7, 10, 12, 1, 2, 3, 5, 7, 8, 11, 13, 14, 15, 1, 2, 3,
> 4, 1, 2, 3, 6, 7, 9, 11, 12, 13, 14, 1, 2, 3, 7, 11, 12, 1, 2,
> 3, 5, 6, 8, 9, 10, 12, 15, 1, 2, 3, 5, 6, 8, 9, 11, 1, 2, 3,
> 7, 8, 11, 13, 14, 15, 1, 2, 3, 4, 10, 12, 14, 1, 2, 3, 11, 12,
> 13, 15, 1, 2, 3, 5, 7, 10, 11, 12, 13, 14, 15, 1, 3, 10, 1, 2,
> 3, 1, 2, 3, 8, 10, 15, 1, 2, 3, 4, 7, 10, 12, 14, 1, 2, 3, 9,
> 10, 11, 1, 2, 3, 6, 9, 10, 15, 1, 9, 14, 1, 2, 3, 7, 10, 14,
> 1, 2, 3, 4, 7, 8, 9, 10, 11, 13, 15, 1, 2, 3, 5, 6, 7, 8, 9,
> 11, 12, 13, 14, 15, 1, 2, 3, 6, 8, 11, 12, 1, 7, 1, 2, 3, 8,
> 13, 15, 1, 2, 3, 4, 8, 9, 11, 1, 2, 3, 4, 7, 13, 14, 1, 2, 3,
> 5, 6, 9, 1, 3, 7, 12, 13, 15, 1, 2, 3, 5, 6, 8, 10, 1, 3, 5,
> 7, 8, 10, 11, 1, 2, 3, 5, 6, 11, 14, 1, 2, 3, 4, 9, 10, 11, 13,
> 14, 1, 2, 3, 4, 6, 9, 14, 15, 1, 2, 3, 11, 1, 2, 3, 4, 5, 7,
> 11, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 14, 1, 2, 3, 4,
> 5, 6, 7, 9, 10, 11, 12, 14, 1, 4, 7, 1, 2, 3, 5, 6, 8, 9, 10,
> 12, 13, 15, 1, 2, 3, 4, 5, 8, 10, 12, 13)
> a <- vec %in% c(1, 2, 3)
> b <- rle(a)
> cc  <-  data.frame(b[[1]], b[[2]])
> names(cc)  <-  c("leng", 'val')
> dd  <-  subset(cc, val ==TRUE )
> table(dd)
>
>> table(dd)
> val
> leng TRUE
>15
>24
>3   81
>51
>64
>
> btw,
>> length(vec)
> [1] 762
>
> So, the tally should add up to that if correct.
>
> -M
>
>
> On Sat, Jul 20, 2013 at 1:41 PM, John Kane  wrote:
>> Beats me. I get:
>> table(dd)
>> val
>> leng TRUE
>>13
>>3   12
>>
>> What does dd look like.  In my case I get this where the first column is the 
>> row number
>> dd
>>leng  val
>> 1 3 TRUE
>> 3 3 TRUE
>> 5 3 TRUE
>> 7 3 TRUE
>> 9 3 TRUE
>> 111 TRUE
>> 133 TRUE
>> 153 TRUE
>> 173 TRUE
>> 193 TRUE
>> 213 TRUE
>> 233 TRUE
>> 251 TRUE
>> 273 TRUE
>> 291 TRUE
>>
>> John Kane
>> Kingston ON Canada
>>
>>
>>> -Original Message-
>>> From: tmrs...@gmail.com
>>> Sent: Sat, 20 Jul 2013 13:11:47 -0400
>>> To: jrkrid...@inbox.com
>>> Subject: Re: [R] How to search for a sequence(and its combination) inside
>>> a vector?
>>>
>>> Thanks John.
>>>
>>> Why do I get length of 5 and 6?  I thought I am only tallying up 1 to 3?
 table(dd)
>>> val
>>> leng TRUE
>>>15
>>>24
>>>3   81
>>>51
>>>64
>>>
>>> -M
>>>
>>> On Sat, Jul 20, 2013 at 12:52 PM, John Kane  wrote:
 Taking Berend's example a bit further, this seems to work

 If you use str(b) you will see it is a list

 b <- rle(a)
 cc  <-  data.frame(b[[1]], b[[2]])
 names(cc)  <-  c("leng", 'val')
 dd

Re: [R] How to search for a sequence(and its combination) inside a vector?

2013-07-20 Thread C W
Thanks, you guys are correct, I had different data.
But why I get length 5 and 6, should only be 1 to 3.

Full R code :

vec <- c(1, 2, 3, 4, 5, 6, 7, 8, 13, 1, 2, 3, 5, 7, 8, 10, 12, 13, 14,
15, 1, 2, 3, 5, 6, 10, 12, 13, 1, 2, 3, 4, 5, 6, 7, 12, 13, 14,
15, 1, 2, 3, 6, 9, 10, 11, 13, 14, 1, 7, 10, 13, 1, 2, 3, 4,
6, 7, 9, 11, 14, 1, 2, 3, 5, 9, 10, 11, 12, 14, 1, 2, 3, 4, 1,
2, 3, 4, 11, 12, 14, 1, 2, 3, 4, 8, 11, 12, 1, 2, 3, 4, 5, 7,
8, 9, 11, 12, 15, 3, 14, 1, 2, 3, 6, 10, 11, 13, 14, 1, 2, 3,
4, 5, 6, 8, 9, 10, 11, 12, 14, 1, 2, 3, 4, 9, 13, 15, 1, 2, 3,
4, 6, 8, 9, 11, 12, 1, 2, 3, 7, 8, 9, 14, 1, 2, 3, 12, 1, 2,
3, 4, 5, 10, 14, 1, 2, 3, 4, 5, 7, 8, 12, 13, 14, 1, 2, 3, 10,
1, 3, 1, 2, 3, 5, 7, 8, 10, 11, 13, 14, 1, 2, 3, 4, 5, 8, 9,
11, 12, 15, 1, 2, 3, 4, 7, 9, 10, 13, 1, 2, 3, 4, 5, 7, 10, 11,
15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 1, 2, 3, 6, 7,
8, 9, 10, 12, 13, 14, 15, 1, 2, 3, 4, 7, 1, 2, 3, 5, 8, 13, 1,
2, 3, 5, 8, 11, 15, 1, 2, 3, 1, 2, 3, 10, 1, 2, 3, 4, 7, 8, 9,
10, 11, 12, 14, 1, 3, 9, 11, 13, 14, 1, 2, 3, 4, 5, 7, 8, 9,
10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 13, 14, 15, 1, 2, 3, 11,
13, 14, 1, 2, 3, 8, 1, 2, 3, 4, 5, 6, 8, 11, 12, 14, 1, 2, 3,
5, 6, 9, 10, 11, 12, 15, 1, 2, 3, 4, 5, 9, 11, 12, 13, 1, 2,
3, 4, 5, 13, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15,
1, 2, 3, 7, 8, 9, 1, 2, 3, 5, 7, 8, 9, 10, 12, 14, 15, 1, 2,
3, 4, 5, 6, 8, 14, 1, 2, 3, 1, 2, 3, 10, 11, 13, 1, 2, 3, 4,
9, 10, 12, 13, 14, 1, 2, 3, 4, 5, 6, 12, 1, 2, 3, 4, 5, 6, 7,
10, 12, 13, 14, 15, 1, 2, 3, 6, 10, 14, 1, 2, 3, 4, 6, 7, 8,
9, 10, 11, 13, 14, 1, 2, 3, 1, 2, 3, 4, 7, 8, 10, 1, 2, 3, 7,
8, 11, 13, 15, 1, 2, 3, 4, 7, 8, 14, 15, 1, 2, 3, 4, 14, 1, 2,
3, 4, 6, 7, 10, 12, 1, 2, 3, 5, 7, 8, 11, 13, 14, 15, 1, 2, 3,
4, 1, 2, 3, 6, 7, 9, 11, 12, 13, 14, 1, 2, 3, 7, 11, 12, 1, 2,
3, 5, 6, 8, 9, 10, 12, 15, 1, 2, 3, 5, 6, 8, 9, 11, 1, 2, 3,
7, 8, 11, 13, 14, 15, 1, 2, 3, 4, 10, 12, 14, 1, 2, 3, 11, 12,
13, 15, 1, 2, 3, 5, 7, 10, 11, 12, 13, 14, 15, 1, 3, 10, 1, 2,
3, 1, 2, 3, 8, 10, 15, 1, 2, 3, 4, 7, 10, 12, 14, 1, 2, 3, 9,
10, 11, 1, 2, 3, 6, 9, 10, 15, 1, 9, 14, 1, 2, 3, 7, 10, 14,
1, 2, 3, 4, 7, 8, 9, 10, 11, 13, 15, 1, 2, 3, 5, 6, 7, 8, 9,
11, 12, 13, 14, 15, 1, 2, 3, 6, 8, 11, 12, 1, 7, 1, 2, 3, 8,
13, 15, 1, 2, 3, 4, 8, 9, 11, 1, 2, 3, 4, 7, 13, 14, 1, 2, 3,
5, 6, 9, 1, 3, 7, 12, 13, 15, 1, 2, 3, 5, 6, 8, 10, 1, 3, 5,
7, 8, 10, 11, 1, 2, 3, 5, 6, 11, 14, 1, 2, 3, 4, 9, 10, 11, 13,
14, 1, 2, 3, 4, 6, 9, 14, 15, 1, 2, 3, 11, 1, 2, 3, 4, 5, 7,
11, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 14, 1, 2, 3, 4,
5, 6, 7, 9, 10, 11, 12, 14, 1, 4, 7, 1, 2, 3, 5, 6, 8, 9, 10,
12, 13, 15, 1, 2, 3, 4, 5, 8, 10, 12, 13)
a <- vec %in% c(1, 2, 3)
b <- rle(a)
cc  <-  data.frame(b[[1]], b[[2]])
names(cc)  <-  c("leng", 'val')
dd  <-  subset(cc, val ==TRUE )
table(dd)

> table(dd)
val
leng TRUE
   15
   24
   3   81
   51
   64

btw,
> length(vec)
[1] 762

So, the tally should add up to that if correct.

-M


On Sat, Jul 20, 2013 at 1:41 PM, John Kane  wrote:
> Beats me. I get:
> table(dd)
> val
> leng TRUE
>13
>3   12
>
> What does dd look like.  In my case I get this where the first column is the 
> row number
> dd
>leng  val
> 1 3 TRUE
> 3 3 TRUE
> 5 3 TRUE
> 7 3 TRUE
> 9 3 TRUE
> 111 TRUE
> 133 TRUE
> 153 TRUE
> 173 TRUE
> 193 TRUE
> 213 TRUE
> 233 TRUE
> 251 TRUE
> 273 TRUE
> 291 TRUE
>
> John Kane
> Kingston ON Canada
>
>
>> -Original Message-
>> From: tmrs...@gmail.com
>> Sent: Sat, 20 Jul 2013 13:11:47 -0400
>> To: jrkrid...@inbox.com
>> Subject: Re: [R] How to search for a sequence(and its combination) inside
>> a vector?
>>
>> Thanks John.
>>
>> Why do I get length of 5 and 6?  I thought I am only tallying up 1 to 3?
>>> table(dd)
>> val
>> leng TRUE
>>15
>>24
>>3   81
>>51
>>64
>>
>> -M
>>
>> On Sat, Jul 20, 2013 at 12:52 PM, John Kane  wrote:
>>> Taking Berend's example a bit further, this seems to work
>>>
>>> If you use str(b) you will see it is a list
>>>
>>> b <- rle(a)
>>> cc  <-  data.frame(b[[1]], b[[2]])
>>> names(cc)  <-  c("leng", 'val')
>>> dd  <-  subset(cc, val ==TRUE )
>>> table(dd)
>>>
>>> John Kane
>>> Kingston ON Canada
>>>
>>>
 -Original Message-
 From: tmrs...@gmail.com
 Sent: Sat, 20 Jul 2013 12:36:55 -0400
 To: b...@xs4all.nl
 Subject: Re: [R] How to search for a sequence(and its combination)
 inside
 a vector?

 Hi Berend
 I am looking for a table,
 # of times one element (out of 1, 2, 3) showed up, two elements, and
 all
 three.

 I am trying, don't know if this works:

> aa <- rle(a)
> b <- aa$lengths[aa$values]
> table(b)
 b
  1  3
  3 12

 Mike



 On Sat, Jul 20, 2013 at 12:24 PM, Berend Hasselman 
 wrote:
>
> On 20-07-2013, at 18:05, C W  wrote:
>
>> Hi R list,
>>
>> I have a sequence repeatin

Re: [R] Identify Leverage Points

2013-07-20 Thread Noah Silverman
I'll look at that today.


Thank You,


--
Noah Silverman, C.Phil
UCLA Department of Statistics
8117 Math Sciences Building
Los Angeles, CA 90095

On Jul 19, 2013, at 4:13 PM, Mark Leeds  wrote:

> see the hatvalues function in the car package. also, I highly recommend john's
> CAR book. there's a new edition that came out a year or so ago.
> 
> 
> 
> On Fri, Jul 19, 2013 at 6:14 PM, Noah Silverman  
> wrote:
> Hello,
> 
> I'm working on some fairly standard regression models (linear, logistic, and 
> poisson.)  Unfortunately, the data is rather messy.
> 
> A visual inspection, using either a histogram or a density plot indicates 
> some significant outliers.  Furthermore, summary statistics of the data 
> indicate the same thing.
> 
> If I fit a linear regression in R using the "lm" command, I can then plot the 
> model to look at residuals, etc.
> 
> I'm interesting in re-fitting the model with a N% of the high leverage points 
> removed.   (Large data set, want to fit "most" of the data.)
> 
> Is there a computational way to get the leverage for each data point?  That 
> way I can subset the data skipping N% of the highest leverage ones.
> 
> 
> Thanks!
> 
> 
> --
> Noah Silverman, M.S., C.Phil
> UCLA Department of Statistics
> 8117 Math Sciences Building
> Los Angeles, CA 90095
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] How to search for a sequence(and its combination) inside a vector?

2013-07-20 Thread John Kane
Beats me. I get: 
table(dd)
val
leng TRUE
   13
   3   12

What does dd look like.  In my case I get this where the first column is the 
row number
dd
   leng  val
1 3 TRUE
3 3 TRUE
5 3 TRUE
7 3 TRUE
9 3 TRUE
111 TRUE
133 TRUE
153 TRUE
173 TRUE
193 TRUE
213 TRUE
233 TRUE
251 TRUE
273 TRUE
291 TRUE

John Kane
Kingston ON Canada


> -Original Message-
> From: tmrs...@gmail.com
> Sent: Sat, 20 Jul 2013 13:11:47 -0400
> To: jrkrid...@inbox.com
> Subject: Re: [R] How to search for a sequence(and its combination) inside
> a vector?
> 
> Thanks John.
> 
> Why do I get length of 5 and 6?  I thought I am only tallying up 1 to 3?
>> table(dd)
> val
> leng TRUE
>15
>24
>3   81
>51
>64
> 
> -M
> 
> On Sat, Jul 20, 2013 at 12:52 PM, John Kane  wrote:
>> Taking Berend's example a bit further, this seems to work
>> 
>> If you use str(b) you will see it is a list
>> 
>> b <- rle(a)
>> cc  <-  data.frame(b[[1]], b[[2]])
>> names(cc)  <-  c("leng", 'val')
>> dd  <-  subset(cc, val ==TRUE )
>> table(dd)
>> 
>> John Kane
>> Kingston ON Canada
>> 
>> 
>>> -Original Message-
>>> From: tmrs...@gmail.com
>>> Sent: Sat, 20 Jul 2013 12:36:55 -0400
>>> To: b...@xs4all.nl
>>> Subject: Re: [R] How to search for a sequence(and its combination)
>>> inside
>>> a vector?
>>> 
>>> Hi Berend
>>> I am looking for a table,
>>> # of times one element (out of 1, 2, 3) showed up, two elements, and
>>> all
>>> three.
>>> 
>>> I am trying, don't know if this works:
>>> 
 aa <- rle(a)
 b <- aa$lengths[aa$values]
 table(b)
>>> b
>>>  1  3
>>>  3 12
>>> 
>>> Mike
>>> 
>>> 
>>> 
>>> On Sat, Jul 20, 2013 at 12:24 PM, Berend Hasselman 
>>> wrote:
 
 On 20-07-2013, at 18:05, C W  wrote:
 
> Hi R list,
> 
> I have a sequence repeating 1:15 .  Some numbers are deleted.  I want
> to find how many times 1, 2, 3 appeared.
> Basically, I want to "grab" the beginning of the sequence and tally
> it
> up.
> 
> R code:
> 
>> vec <- c(1, 2, 3, 4, 5, 6, 7, 8, 13, 1, 2, 3, 5, 7, 8, 10, 12, 13,
>> 14,
> 15, 1, 2, 3, 5, 6, 10, 12, 13, 1, 2, 3, 4, 5, 6, 7, 12, 13, 14,
> 15, 1, 2, 3, 6, 9, 10, 11, 13, 14, 1, 7, 10, 13, 1, 2, 3, 4,
> 6, 7, 9, 11, 14, 1, 2, 3, 5, 9, 10, 11, 12, 14, 1, 2, 3, 4, 1,
> 2, 3, 4, 11, 12, 14, 1, 2, 3, 4, 8, 11, 12, 1, 2, 3, 4, 5, 7,
> 8, 9, 11, 12, 15, 3, 14, 1, 2, 3, 6, 10, 11, 13, 14, 1)
> 
>> a <- vec %in% c(1, 2, 3)
>> a
>  [1]  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE
> TRUE  TRUE FALSE FALSE
> [15] FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE FALSE
> FALSE FALSE FALSE FALSE
> [29]  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
> FALSE  TRUE  TRUE  TRUE
> [43] FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE
> TRUE  TRUE  TRUE FALSE
> [57] FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE FALSE FALSE
> FALSE FALSE FALSE FALSE
> [71]  TRUE  TRUE  TRUE FALSE  TRUE  TRUE  TRUE FALSE FALSE FALSE
> FALSE  TRUE  TRUE  TRUE
> [85] FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE FALSE FALSE FALSE
> FALSE FALSE FALSE FALSE
> [99] FALSE  TRUE FALSE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE
> FALSE
> TRUE
> 
>> rle(a)
> Run Length Encoding
>  lengths: int [1:29] 3 6 3 8 3 5 3 8 3 6 ...
>  values : logi [1:29] TRUE FALSE TRUE FALSE TRUE FALSE ...
> 
> What should I do after this?
> 
 
 Well how about
 
 sum(a)
 
 or
 
 b <- rle(a)
 sum(b$lengths[b$values])
 
 Berend
 
> Thanks,
> Mike
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
 
>>> 
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>> 
>> 
>> Receive Notifications of Incoming Messages
>> Easily monitor multiple email accounts & access them with a click.
>> Visit http://www.inbox.com/notifier and check it out!
>> 
>>


FREE ONLINE PHOTOSHARING - Share your photos online with your friends and 
family!
Visit http://www.inbox.com/photosharing to find out more!

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

Re: [R] How to search for a sequence(and its combination) inside a vector?

2013-07-20 Thread Berend Hasselman

On 20-07-2013, at 19:11, C W  wrote:

> Thanks John.
> 
> Why do I get length of 5 and 6?  I thought I am only tallying up 1 to 3?
>> table(dd)
>val
> leng TRUE
>   15
>   24
>   3   81
>   51
>   64

I wouldn't know. Not same data?
It's completely unclear, to me at least, what you actually are trying to do.
With your initial data, my initial proposal and John's procedure I got

> cc  <-  data.frame(b[[1]], b[[2]])
> names(cc)  <-  c("leng", 'val')
> dd  <-  subset(cc, val ==TRUE )
> table(dd)
val
leng TRUE
   13
   3   12

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] How to search for a sequence(and its combination) inside a vector?

2013-07-20 Thread C W
Thanks John.

Why do I get length of 5 and 6?  I thought I am only tallying up 1 to 3?
> table(dd)
val
leng TRUE
   15
   24
   3   81
   51
   64

-M

On Sat, Jul 20, 2013 at 12:52 PM, John Kane  wrote:
> Taking Berend's example a bit further, this seems to work
>
> If you use str(b) you will see it is a list
>
> b <- rle(a)
> cc  <-  data.frame(b[[1]], b[[2]])
> names(cc)  <-  c("leng", 'val')
> dd  <-  subset(cc, val ==TRUE )
> table(dd)
>
> John Kane
> Kingston ON Canada
>
>
>> -Original Message-
>> From: tmrs...@gmail.com
>> Sent: Sat, 20 Jul 2013 12:36:55 -0400
>> To: b...@xs4all.nl
>> Subject: Re: [R] How to search for a sequence(and its combination) inside
>> a vector?
>>
>> Hi Berend
>> I am looking for a table,
>> # of times one element (out of 1, 2, 3) showed up, two elements, and all
>> three.
>>
>> I am trying, don't know if this works:
>>
>>> aa <- rle(a)
>>> b <- aa$lengths[aa$values]
>>> table(b)
>> b
>>  1  3
>>  3 12
>>
>> Mike
>>
>>
>>
>> On Sat, Jul 20, 2013 at 12:24 PM, Berend Hasselman  wrote:
>>>
>>> On 20-07-2013, at 18:05, C W  wrote:
>>>
 Hi R list,

 I have a sequence repeating 1:15 .  Some numbers are deleted.  I want
 to find how many times 1, 2, 3 appeared.
 Basically, I want to "grab" the beginning of the sequence and tally it
 up.

 R code:

> vec <- c(1, 2, 3, 4, 5, 6, 7, 8, 13, 1, 2, 3, 5, 7, 8, 10, 12, 13, 14,
 15, 1, 2, 3, 5, 6, 10, 12, 13, 1, 2, 3, 4, 5, 6, 7, 12, 13, 14,
 15, 1, 2, 3, 6, 9, 10, 11, 13, 14, 1, 7, 10, 13, 1, 2, 3, 4,
 6, 7, 9, 11, 14, 1, 2, 3, 5, 9, 10, 11, 12, 14, 1, 2, 3, 4, 1,
 2, 3, 4, 11, 12, 14, 1, 2, 3, 4, 8, 11, 12, 1, 2, 3, 4, 5, 7,
 8, 9, 11, 12, 15, 3, 14, 1, 2, 3, 6, 10, 11, 13, 14, 1)

> a <- vec %in% c(1, 2, 3)
> a
  [1]  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE
 TRUE  TRUE FALSE FALSE
 [15] FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE FALSE
 FALSE FALSE FALSE FALSE
 [29]  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
 FALSE  TRUE  TRUE  TRUE
 [43] FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE
 TRUE  TRUE  TRUE FALSE
 [57] FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE FALSE FALSE
 FALSE FALSE FALSE FALSE
 [71]  TRUE  TRUE  TRUE FALSE  TRUE  TRUE  TRUE FALSE FALSE FALSE
 FALSE  TRUE  TRUE  TRUE
 [85] FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE FALSE FALSE FALSE
 FALSE FALSE FALSE FALSE
 [99] FALSE  TRUE FALSE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE
 TRUE

> rle(a)
 Run Length Encoding
  lengths: int [1:29] 3 6 3 8 3 5 3 8 3 6 ...
  values : logi [1:29] TRUE FALSE TRUE FALSE TRUE FALSE ...

 What should I do after this?

>>>
>>> Well how about
>>>
>>> sum(a)
>>>
>>> or
>>>
>>> b <- rle(a)
>>> sum(b$lengths[b$values])
>>>
>>> Berend
>>>
 Thanks,
 Mike

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> 
> Receive Notifications of Incoming Messages
> Easily monitor multiple email accounts & access them with a click.
> Visit http://www.inbox.com/notifier and check it out!
>
>

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


Re: [R] read data from a URL with login required

2013-07-20 Thread Prof Brian Ripley

On 20/07/2013 16:43, Hui Du wrote:

Hi All,

How to read a URL requiring log in info in R? For example, I want to download 
some info from Linkedin pages, my username is abc, password is 123. How can I 
download my desired URL page in R?


It really depends what 'login' means.  For some sites this can be 
incorporated into a URL of the form "http://user:pas...@foo.dom.com": 
for others a multi-stage interaction is required.


I would try to do it using e.g. wget or curl and capture the output via 
system().  If curl works, you most likely can do the same with package 
RCurl.


Note that the help for tools usually calls such things 'authentication' 
and reserves 'login' for an ftp URL (you did not tell us the scheme).


Also note: any more detail would be appropriate only for the R-devel 
list (see the posting guide).



Many thanks.

HXD




--
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] How to search for a sequence(and its combination) inside a vector?

2013-07-20 Thread John Kane
Taking Berend's example a bit further, this seems to work

If you use str(b) you will see it is a list

b <- rle(a)
cc  <-  data.frame(b[[1]], b[[2]])
names(cc)  <-  c("leng", 'val')
dd  <-  subset(cc, val ==TRUE )
table(dd)

John Kane
Kingston ON Canada


> -Original Message-
> From: tmrs...@gmail.com
> Sent: Sat, 20 Jul 2013 12:36:55 -0400
> To: b...@xs4all.nl
> Subject: Re: [R] How to search for a sequence(and its combination) inside
> a vector?
> 
> Hi Berend
> I am looking for a table,
> # of times one element (out of 1, 2, 3) showed up, two elements, and all
> three.
> 
> I am trying, don't know if this works:
> 
>> aa <- rle(a)
>> b <- aa$lengths[aa$values]
>> table(b)
> b
>  1  3
>  3 12
> 
> Mike
> 
> 
> 
> On Sat, Jul 20, 2013 at 12:24 PM, Berend Hasselman  wrote:
>> 
>> On 20-07-2013, at 18:05, C W  wrote:
>> 
>>> Hi R list,
>>> 
>>> I have a sequence repeating 1:15 .  Some numbers are deleted.  I want
>>> to find how many times 1, 2, 3 appeared.
>>> Basically, I want to "grab" the beginning of the sequence and tally it
>>> up.
>>> 
>>> R code:
>>> 
 vec <- c(1, 2, 3, 4, 5, 6, 7, 8, 13, 1, 2, 3, 5, 7, 8, 10, 12, 13, 14,
>>> 15, 1, 2, 3, 5, 6, 10, 12, 13, 1, 2, 3, 4, 5, 6, 7, 12, 13, 14,
>>> 15, 1, 2, 3, 6, 9, 10, 11, 13, 14, 1, 7, 10, 13, 1, 2, 3, 4,
>>> 6, 7, 9, 11, 14, 1, 2, 3, 5, 9, 10, 11, 12, 14, 1, 2, 3, 4, 1,
>>> 2, 3, 4, 11, 12, 14, 1, 2, 3, 4, 8, 11, 12, 1, 2, 3, 4, 5, 7,
>>> 8, 9, 11, 12, 15, 3, 14, 1, 2, 3, 6, 10, 11, 13, 14, 1)
>>> 
 a <- vec %in% c(1, 2, 3)
 a
>>>  [1]  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE
>>> TRUE  TRUE FALSE FALSE
>>> [15] FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE FALSE
>>> FALSE FALSE FALSE FALSE
>>> [29]  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
>>> FALSE  TRUE  TRUE  TRUE
>>> [43] FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE
>>> TRUE  TRUE  TRUE FALSE
>>> [57] FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE FALSE FALSE
>>> FALSE FALSE FALSE FALSE
>>> [71]  TRUE  TRUE  TRUE FALSE  TRUE  TRUE  TRUE FALSE FALSE FALSE
>>> FALSE  TRUE  TRUE  TRUE
>>> [85] FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE FALSE FALSE FALSE
>>> FALSE FALSE FALSE FALSE
>>> [99] FALSE  TRUE FALSE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE
>>> TRUE
>>> 
 rle(a)
>>> Run Length Encoding
>>>  lengths: int [1:29] 3 6 3 8 3 5 3 8 3 6 ...
>>>  values : logi [1:29] TRUE FALSE TRUE FALSE TRUE FALSE ...
>>> 
>>> What should I do after this?
>>> 
>> 
>> Well how about
>> 
>> sum(a)
>> 
>> or
>> 
>> b <- rle(a)
>> sum(b$lengths[b$values])
>> 
>> Berend
>> 
>>> Thanks,
>>> Mike
>>> 
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>> 
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


Receive Notifications of Incoming Messages
Easily monitor multiple email accounts & access them with a click.
Visit http://www.inbox.com/notifier and check it out!

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


Re: [R] Different x-axis scales using c() in latticeExtra

2013-07-20 Thread David Winsemius

On Jul 19, 2013, at 8:18 PM, Jeff Stevens wrote:

> Hi,
> 
> I would like to combine multiple xyplots into a single, multipanel
> display.  Using R 3.0.1 in Ubuntu, I have used c() from latticeExtra
> to combine three plots, but the x-axis for two plots are on a log
> scale and the other is on a normal scale.  I also have included
> equispace.log=FALSE to clean up the tick labels.  However, when I try
> all of these, the x-axis scale of the first panel is used for all
> three.  How do I keep different scales for the different panels?
> 
> Here is an example:
> library(lattice)
> library(latticeExtra)
> response <- c(76, 14, 15, 44, 26, 19, 74, 123, 49, 8, 56, 17, 18)
> predictor1 <- c(107, 7, 25, 501, 64, 88, 344, 367, 379, 10, 66, 31, 32)
> predictor2 <- c(10, 9, 8, 10, 29, 27, 55, 48, 2, 6, 14, 10, 5)
> predictor3 <- c(67, 22, 66, 41, 72, 64, 69, 63, 64, 70, 60, 75, 78)
> 
> pred1_plot <- xyplot(response ~ predictor1, scales = list(log = TRUE,
> equispaced.log = FALSE),
>  panel = function(x, y, ...) {
>panel.xyplot(x, y, type = c("p", "r"), cex = 2)
>panel.text(x = log10(8), y = log10(120), labels = "(a)")
>  }
> )
> 
> pred2_plot <- xyplot(response ~ predictor2, scales = list(log = TRUE,
> equispaced.log = FALSE),
>  panel = function(x, y, ...) {
>panel.xyplot(x, y, type = c("p", "r"), cex = 2)
>panel.text(x = log10(2), y = log10(120), labels = "(b)")
>  }
> )
> 
> pred3_plot <- xyplot(response ~ predictor3, scales = list(y = list(log
> = TRUE, equispaced.log = FALSE)),
>  panel = function(x, y, ...) {
>panel.xyplot(x, y, type = c("p", "r"), cex = 2)
>panel.text(x = 22, y = log10(120), labels = "(c)")
>  }
> )
> 
> all_plots <- c(pred1_plot, pred2_plot, pred3_plot, layout = c(3, 1), x.same = 
> F)
> update(all_plots, xlab=c("Predictor 1","Predictor 2", "Predictor 3"),
> scales = list(y=list(log=T, equispaced.log=FALSE), x = c(list(log=T,
> equispaced.log=FALSE), list(log=T, equispaced.log=FALSE),
> list(log=F
> 
> update(all_plots, xlab=c("Predictor 1","Predictor 2", "Predictor 3"),
> scales = c(list(log = TRUE, equispaced.log = FALSE), list(log = TRUE,
> equispaced.log = FALSE), list(y=list(log=T, equispaced.log = FALSE
> 
> Any help is appreciated!

I assume there was a notice o your console that there were warnings, right? You 
should offer the full texts of warnings and error messages. Here the full text 
of the first and second warnings:

> warnings()[1:2]
$`log scales cannot be changed via 'update'`
update.trellis(all_plots, xlab = c("Predictor 1", "Predictor 2", 
"Predictor 3"), scales = c(list(log = TRUE, equispaced.log = FALSE), 
list(log = TRUE, equispaced.log = FALSE), list(y = list(log = T, 
equispaced.log = FALSE
$`'x' is NULL so the result will be NULL`
rep(scales[[nm]], length.out = 2)

The first one is telling you why the results should be different than you 
expect. I'm not entirely sure what the second one is telling you, but it 
doesn't sound good.

-- 
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] How to search for a sequence(and its combination) inside a vector?

2013-07-20 Thread C W
Hi Berend
I am looking for a table,
# of times one element (out of 1, 2, 3) showed up, two elements, and all three.

I am trying, don't know if this works:

> aa <- rle(a)
> b <- aa$lengths[aa$values]
> table(b)
b
 1  3
 3 12

Mike



On Sat, Jul 20, 2013 at 12:24 PM, Berend Hasselman  wrote:
>
> On 20-07-2013, at 18:05, C W  wrote:
>
>> Hi R list,
>>
>> I have a sequence repeating 1:15 .  Some numbers are deleted.  I want
>> to find how many times 1, 2, 3 appeared.
>> Basically, I want to "grab" the beginning of the sequence and tally it up.
>>
>> R code:
>>
>>> vec <- c(1, 2, 3, 4, 5, 6, 7, 8, 13, 1, 2, 3, 5, 7, 8, 10, 12, 13, 14,
>> 15, 1, 2, 3, 5, 6, 10, 12, 13, 1, 2, 3, 4, 5, 6, 7, 12, 13, 14,
>> 15, 1, 2, 3, 6, 9, 10, 11, 13, 14, 1, 7, 10, 13, 1, 2, 3, 4,
>> 6, 7, 9, 11, 14, 1, 2, 3, 5, 9, 10, 11, 12, 14, 1, 2, 3, 4, 1,
>> 2, 3, 4, 11, 12, 14, 1, 2, 3, 4, 8, 11, 12, 1, 2, 3, 4, 5, 7,
>> 8, 9, 11, 12, 15, 3, 14, 1, 2, 3, 6, 10, 11, 13, 14, 1)
>>
>>> a <- vec %in% c(1, 2, 3)
>>> a
>>  [1]  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE
>> TRUE  TRUE FALSE FALSE
>> [15] FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE FALSE
>> FALSE FALSE FALSE FALSE
>> [29]  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
>> FALSE  TRUE  TRUE  TRUE
>> [43] FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE
>> TRUE  TRUE  TRUE FALSE
>> [57] FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE FALSE FALSE
>> FALSE FALSE FALSE FALSE
>> [71]  TRUE  TRUE  TRUE FALSE  TRUE  TRUE  TRUE FALSE FALSE FALSE
>> FALSE  TRUE  TRUE  TRUE
>> [85] FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE FALSE FALSE FALSE
>> FALSE FALSE FALSE FALSE
>> [99] FALSE  TRUE FALSE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE
>>
>>> rle(a)
>> Run Length Encoding
>>  lengths: int [1:29] 3 6 3 8 3 5 3 8 3 6 ...
>>  values : logi [1:29] TRUE FALSE TRUE FALSE TRUE FALSE ...
>>
>> What should I do after this?
>>
>
> Well how about
>
> sum(a)
>
> or
>
> b <- rle(a)
> sum(b$lengths[b$values])
>
> Berend
>
>> Thanks,
>> Mike
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>

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


Re: [R] Different x-axis scales using c() in latticeExtra

2013-07-20 Thread John Kane
No idea what I happening but does this give what you expect

library(gridExtra)
preds  <-  grid.arrange(pred1_plot,pred2_plot, pred3_plot, ncol=3)
preds

John Kane
Kingston ON Canada


> -Original Message-
> From: stev0...@gmail.com
> Sent: Fri, 19 Jul 2013 22:18:47 -0500
> To: r-help@r-project.org
> Subject: [R] Different x-axis scales using c() in latticeExtra
> 
> Hi,
> 
> I would like to combine multiple xyplots into a single, multipanel
> display.  Using R 3.0.1 in Ubuntu, I have used c() from latticeExtra
> to combine three plots, but the x-axis for two plots are on a log
> scale and the other is on a normal scale.  I also have included
> equispace.log=FALSE to clean up the tick labels.  However, when I try
> all of these, the x-axis scale of the first panel is used for all
> three.  How do I keep different scales for the different panels?
> 
> Here is an example:
> library(lattice)
> library(latticeExtra)
> response <- c(76, 14, 15, 44, 26, 19, 74, 123, 49, 8, 56, 17, 18)
> predictor1 <- c(107, 7, 25, 501, 64, 88, 344, 367, 379, 10, 66, 31, 32)
> predictor2 <- c(10, 9, 8, 10, 29, 27, 55, 48, 2, 6, 14, 10, 5)
> predictor3 <- c(67, 22, 66, 41, 72, 64, 69, 63, 64, 70, 60, 75, 78)
> 
> pred1_plot <- xyplot(response ~ predictor1, scales = list(log = TRUE,
> equispaced.log = FALSE),
>   panel = function(x, y, ...) {
> panel.xyplot(x, y, type = c("p", "r"), cex = 2)
> panel.text(x = log10(8), y = log10(120), labels = "(a)")
>   }
> )
> 
> pred2_plot <- xyplot(response ~ predictor2, scales = list(log = TRUE,
> equispaced.log = FALSE),
>   panel = function(x, y, ...) {
> panel.xyplot(x, y, type = c("p", "r"), cex = 2)
> panel.text(x = log10(2), y = log10(120), labels = "(b)")
>   }
> )
> 
> pred3_plot <- xyplot(response ~ predictor3, scales = list(y = list(log
> = TRUE, equispaced.log = FALSE)),
>   panel = function(x, y, ...) {
> panel.xyplot(x, y, type = c("p", "r"), cex = 2)
> panel.text(x = 22, y = log10(120), labels = "(c)")
>   }
> )
> 
> all_plots <- c(pred1_plot, pred2_plot, pred3_plot, layout = c(3, 1),
> x.same = F)
> update(all_plots, xlab=c("Predictor 1","Predictor 2", "Predictor 3"),
> scales = list(y=list(log=T, equispaced.log=FALSE), x = c(list(log=T,
> equispaced.log=FALSE), list(log=T, equispaced.log=FALSE),
> list(log=F
> 
> update(all_plots, xlab=c("Predictor 1","Predictor 2", "Predictor 3"),
> scales = c(list(log = TRUE, equispaced.log = FALSE), list(log = TRUE,
> equispaced.log = FALSE), list(y=list(log=T, equispaced.log = FALSE
> 
> Any help is appreciated!
> 
> Thanks,
> Jeff
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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 ONLINE PHOTOSHARING - Share your photos online with your friends and 
family!
Visit http://www.inbox.com/photosharing to find out more!

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


Re: [R] How to search for a sequence(and its combination) inside a vector?

2013-07-20 Thread Berend Hasselman

On 20-07-2013, at 18:05, C W  wrote:

> Hi R list,
> 
> I have a sequence repeating 1:15 .  Some numbers are deleted.  I want
> to find how many times 1, 2, 3 appeared.
> Basically, I want to "grab" the beginning of the sequence and tally it up.
> 
> R code:
> 
>> vec <- c(1, 2, 3, 4, 5, 6, 7, 8, 13, 1, 2, 3, 5, 7, 8, 10, 12, 13, 14,
> 15, 1, 2, 3, 5, 6, 10, 12, 13, 1, 2, 3, 4, 5, 6, 7, 12, 13, 14,
> 15, 1, 2, 3, 6, 9, 10, 11, 13, 14, 1, 7, 10, 13, 1, 2, 3, 4,
> 6, 7, 9, 11, 14, 1, 2, 3, 5, 9, 10, 11, 12, 14, 1, 2, 3, 4, 1,
> 2, 3, 4, 11, 12, 14, 1, 2, 3, 4, 8, 11, 12, 1, 2, 3, 4, 5, 7,
> 8, 9, 11, 12, 15, 3, 14, 1, 2, 3, 6, 10, 11, 13, 14, 1)
> 
>> a <- vec %in% c(1, 2, 3)
>> a
>  [1]  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE
> TRUE  TRUE FALSE FALSE
> [15] FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE FALSE
> FALSE FALSE FALSE FALSE
> [29]  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
> FALSE  TRUE  TRUE  TRUE
> [43] FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE
> TRUE  TRUE  TRUE FALSE
> [57] FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE FALSE FALSE
> FALSE FALSE FALSE FALSE
> [71]  TRUE  TRUE  TRUE FALSE  TRUE  TRUE  TRUE FALSE FALSE FALSE
> FALSE  TRUE  TRUE  TRUE
> [85] FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE FALSE FALSE FALSE
> FALSE FALSE FALSE FALSE
> [99] FALSE  TRUE FALSE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE
> 
>> rle(a)
> Run Length Encoding
>  lengths: int [1:29] 3 6 3 8 3 5 3 8 3 6 ...
>  values : logi [1:29] TRUE FALSE TRUE FALSE TRUE FALSE ...
> 
> What should I do after this?
> 

Well how about

sum(a)

or 

b <- rle(a)
sum(b$lengths[b$values])

Berend

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

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


[R] problem with minus signs when using postscript/pdf functions with ComputerModernItalic family

2013-07-20 Thread dbp
When I use the postscript with the ComputerModernItalic family, minus signs are 
not properly displayed, but are changed into capital gammas.   The attached 
test-postscript.pdf file illustrates the problem, which I created starting with 
the following R code:

> postscript("test-postscript.eps", family = "ComputerModernItalic")
> plot(seq(-5,5,1),seq(-5,5,1))
> dev.off()

I then created the attached .pdf file from the .eps file using the Preview 
application on a MacBook Pro (see below for details about my R session).  I 
have also attempted to create the same plot using the pdf function.  For some 
reason, pdf does not like `family = "ComputerModernItalic"', so I needed to do 
the following.

> CMitalic <- Type1Font("ComputerModern2",
+   c("CM_regular_10.afm", "CM_boldx_10.afm",
+ "cmti10.afm", "cmbxti10.afm",
+ "CM_symbol_10.afm"),
+   encoding = "TeXtext.enc")
> pdf("test-pdf.pdf", family = CMitalic)
> plot(seq(-5,5,1),seq(-5,5,1))
> dev.off()

The attached test-pdf.pdf file shows the minus signs are no longer replaced by 
capital gammas, but are now blanked out.
   For the record, I noticed this problem several years ago and have been 
hoping that it would disappear with each new release of R.  At the time that I 
first noted it, I asked a colleague to run an example on a Windows box, and the 
same problem occurred, leading me to conclude that the problem is not unique to 
Mac OS-X.  Any help or workarounds for the problem would be greatly 
appreciated!  Regards,
- Don Percival

> sessionInfo()
R version 2.15.3 (2013-03-01)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] C

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

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






test-postscript.pdf
Description: Adobe PDF document



test-pdf.pdf
Description: Adobe PDF document




===
d...@apl.washington.edu
Applied Physics Laboratory
Box 355640
University of Washington
Seattle, WA 98195-5640
Phones: 206-543-1368  Fax: 206-543-6785
   206-543-1300
http://faculty.washington.edu/dbp
===

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 search for a sequence(and its combination) inside a vector?

2013-07-20 Thread C W
Hi R list,

I have a sequence repeating 1:15 .  Some numbers are deleted.  I want
to find how many times 1, 2, 3 appeared.
Basically, I want to "grab" the beginning of the sequence and tally it up.

R code:

> vec <- c(1, 2, 3, 4, 5, 6, 7, 8, 13, 1, 2, 3, 5, 7, 8, 10, 12, 13, 14,
15, 1, 2, 3, 5, 6, 10, 12, 13, 1, 2, 3, 4, 5, 6, 7, 12, 13, 14,
15, 1, 2, 3, 6, 9, 10, 11, 13, 14, 1, 7, 10, 13, 1, 2, 3, 4,
6, 7, 9, 11, 14, 1, 2, 3, 5, 9, 10, 11, 12, 14, 1, 2, 3, 4, 1,
2, 3, 4, 11, 12, 14, 1, 2, 3, 4, 8, 11, 12, 1, 2, 3, 4, 5, 7,
8, 9, 11, 12, 15, 3, 14, 1, 2, 3, 6, 10, 11, 13, 14, 1)

> a <- vec %in% c(1, 2, 3)
> a
  [1]  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE
TRUE  TRUE FALSE FALSE
 [15] FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE FALSE
FALSE FALSE FALSE FALSE
 [29]  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
FALSE  TRUE  TRUE  TRUE
 [43] FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE
TRUE  TRUE  TRUE FALSE
 [57] FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE FALSE FALSE
FALSE FALSE FALSE FALSE
 [71]  TRUE  TRUE  TRUE FALSE  TRUE  TRUE  TRUE FALSE FALSE FALSE
FALSE  TRUE  TRUE  TRUE
 [85] FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE FALSE FALSE FALSE
FALSE FALSE FALSE FALSE
 [99] FALSE  TRUE FALSE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE

> rle(a)
Run Length Encoding
  lengths: int [1:29] 3 6 3 8 3 5 3 8 3 6 ...
  values : logi [1:29] TRUE FALSE TRUE FALSE TRUE FALSE ...

What should I do after this?

Thanks,
Mike

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


[R] read data from a URL with login required

2013-07-20 Thread Hui Du
Hi All,

How to read a URL requiring log in info in R? For example, I want to download 
some info from Linkedin pages, my username is abc, password is 123. How can I 
download my desired URL page in R?

Many thanks.

HXD

[[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] S4 method signature - integer matrix

2013-07-20 Thread Simon Zehnder
Hi David,

thanks for the reply! 

The prototype solution is I think not the appropriate solution, when the method 
adds the integer matrix next to the class object into the argument list. Also 
the .validObject method can only be applied to the object for which the method 
is called or I have to write an integer matrix class that has its own 
.validObject method.

>From your suggestions I had a direction to search more precisely and I found 
>this: 

Set the signature to "matrix": checks for matrix when method is called.
Then check for typeof(mymatrix) == "integer": Return an exception if FALSE.
In case of an index I can add then an all(apply(mymatrix, c(1, 2), ">", 0)): 
Return an exception if FALSE

Thank you very much for your advice. It helped me to find a good solution.


Best 

Simon


On Jul 20, 2013, at 12:03 AM, David Winsemius  wrote:

> 
> On Jul 19, 2013, at 9:54 AM, Simon Zehnder wrote:
> 
>> Dear R-Users and R-Devels,
>> 
>> I am programming a package with S4 classes and I search for a solution of 
>> the following problem: 
>> 
>> If you want an S4 method to await an integer argument you set the signature 
>> like this
>> 
>> setMethod("myfunction", signature(object = "myClass", y = "integer"), 
>> function(object, y) {//Do sth})
>> 
>> Now, if you want the method to await an integer matrix or array there is 
>> only one way how to define it
>> 
>> setMethod("myfunction", signature(object = "myClass", y = "matrix"), 
>> function(object, y) {//Do sth}) or
>> setMethod("myfunction", signature(object = "myClass", y = "array"), 
>> function(object, y) {//Do sth}) 
>> 
>> am I right?
> 
> I don't think that is the only way. You could also test for mode being 
> 'numeric' at the signature level and then within the validation check to see 
> whether it has dimensions. See ?is.numeric and ?validObject
> 
> There is also the option of using a prototype.
> 
> As I understand the S4 checks they will apply an is. or is. test 
> as long as there is an correspond function that returns a logical. see ... ?is
> 
> 
>> WIth this you can also pass a numeric matrix.
>> 
>> How would you check for an integer matrix in an S4 method (in the index 
>> function of R I think it is just coerced to integer)?
> 
> It would need be both integer mode...   ?is.integer and have dimensions...  
> ?dim
> 
>> Furthermore: How would you check for an integer matrix with values 
>> bigger one (so the typical R indices)?
> 
> Just add a test in the 'validity' code. See ... ?setClass
> 
>> Is there a way how it is usually done in R (I think probably with apply())? 
>> Or is it usually better to throw an exception?
> 
> 
> I don't see a reason to use apply.
> 
> -- 
> 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] cut into groups of equal nr of elements...

2013-07-20 Thread Wet Bell Diver


Witold,

Here's one way:

Vec <- rnorm(30)
Vec.cut <- cut(Vec, breaks=c(quantile(Vec, probs = seq(0, 1, by = 0.20))),
labels=c("0-20","20-40","40-60","60-80","80-100"), 
include.lowest=TRUE)

table(Vec.cut)


or determine the breaks automatically:

cut.size <- function(x, size) {
  cut.prob <- size/length(x)
  if (length(x)%%size != 0) warning("Equal sized groups only possible 
by dropping some elements from x")
  Vec.cut <- cut(x, breaks=c(quantile(x, probs = seq(0, 1, by = 
size/length(x, include.lowest=TRUE)

}
CUT <- cut.size(Vec, 6)
table(CUT)


Of course, when asking for
cut.size(Vec, 7)
this will yield 4 equal-sized groups of 7, because there is no way to 
perfectly split 30 observations in groups of 7 each (the highest two 
values from Vec will be dropped).


HTH,
Peter



Op 18-7-2013 0:02, Greg Snow schreef:

You could use the quantile function to choose the cut points and pass that
to cut.

Or you could sort the vector and just take the first n elements as the 1st
group, etc.


On Wed, Jul 17, 2013 at 3:43 PM, Witold E Wolski  wrote:


I would like to "cut" a vector into groups of equal nr of elements.
looking for a function on the lines of cut but where I can specify
the size of the groups instead of the nr of groups.




--
Witold Eryk Wolski

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






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


[R] RE : how to calculate the average values of each row in a matrix

2013-07-20 Thread Guibert TCHINDE
> vec = matrix(data=round(rnorm(15,1,2)),ncol=3)
> vec
 [,1] [,2] [,3]
[1,]11   -1
[2,]62   -1
[3,]002
[4,]0   -3   -2
[5,]112
> rowMeans(vec)
[1]  0.333  2.333  0.667 -1.667  1.333
> apply(vec,1,mean)
[1]  0.333  2.333  0.667 -1.667  1.333

may be this helps

GT

De : r-help-boun...@r-project.org [r-help-boun...@r-project.org] de la part de 
R. Michael Weylandt  [michael.weyla...@gmail.com]
Date d'envoi : samedi 20 juillet 2013 03:33
À : Elaine Kuo
Cc : r-h...@stat.math.ethz.ch
Objet : Re: [R] how to calculate the average values of each row in a matrix

On Jul 19, 2013, at 20:19, Elaine Kuo  wrote:

> Hello,
>
> I have a matrix (class matrix) composed of GridCell (row and column).
> The matrix value is the beta diversity index value between two grids.
>
> Now I would like to get the average value of each GridCell.
> Please kindly advise how to make the calculation.
> Thank you.
>

Perhaps the rowMeans() function?

MW

> Elaine
>
> The matrix looks like (cited from Michael Friendly)
> I would like to get the average value of each color.
>
>
>  Obs  stim   RPur   Red   Yel   Gy1   Gy2  Green  Blue  BlP  Pur1
> Pur2
>
>  1  RPur . . . . .  . .
> . . .
>  2  Red11.5. . . .  . .
> . . .
>  3  Yel13.1   6.0. . .  . .
> . . .
>  4  Gy112.6   7.9   6.2. .  . .
> . . .
>  5  Gy210.6   8.4   8.4   5.2.  . .
> . . .
>  6  Green  10.6   9.4   9.9   6.5   4.1 . .
> . . .
>  7  Blue   10.8  10.2  10.3   8.8   7.06.4.
> . . .
>   8  BlP 7.3  11.3  12.7  11.2  10.49.9   4.2
>  . . .
>   9  Pur15.4  11.5  12.9  11.7  10.89.4   8.4
> 4.5. .
>  10  Pur25.0  11.5  10.7  10.2  10.6   10.1   8.1
> 6.43 .
>
>[[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.


Click 
https://www.mailcontrol.com/sr/0NMwdyLXvWXGX2PQPOmvUlvAwUAcTfZn4fkKLlvv9q+YH6kYUkFzXm6zZ2oqmDGRhRWtQ2HzzdeVGm43FW9a3A==
  to report this email as spam.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Adding across columns ignoring NA

2013-07-20 Thread arun
HI,
 sum(var1,var2,var3,var4,var5,na.rm=TRUE)
#[1] 8
A.K.




- Original Message -
From: Jin Choi 
To: "r-help@r-project.org" 
Cc: 
Sent: Saturday, July 20, 2013 12:37 AM
Subject: [R] Adding across columns ignoring NA

I am having difficulty finding a solution to devising an R code to do the
following:

I have 5 numerical variables and I would like to create a new variable that
is the sum of those 5 variables. However, there are many NA values
throughout these 5 variables and everytime I run the following code

new_variable=var1+var2+var3+var4+var5

I get NA as the sum whenever one of those 5 variables are NA. I cannot
figure out a way to have new_variable represent the sum for only those
values that are not NA.

As an example,
if var1=3
var2=3
var3=NA
var4=NA
var5=2

I would like new_variable to be 8 but I keep getting NA and I have
unsuccessfully tried different methods to do so. I feel there is a simple
method to solve my problem but I am unaware of such. I would appreciate any
guidance!

Thank you
JC

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