Re: [R] two question about plot

2011-09-01 Thread Petr PIKAL
Hi
> 
> Re: [R] two question about plot
> 
> The help for boxplot offers suggestions for both those things. You may 
be
> particularly interested in:
> 
>names: group labels which will be printed under each boxplot.  Can
>   be a character vector or an expression (see plotmath).
> 
> add: logical, if true _add_ boxplot to current plot.
> 
> Sarah

It could be also worth to consult also bwplot from lattice or especially 
ggplot2 package for plotting.

Regards
Petr



> 
> 
> On Thu, Sep 1, 2011 at 1:31 PM, Jie TANG  wrote:
> > 1) how to modify the the tickment of x-axis or y-axis.
> >   boxplot(data[,1:5])
> >  the tickment in x-axis in V1 V2 V3 V4 V5 ,I want to be some name for
> > example
> >  name<-c("1day","2day","3day","4day","5day")
> >
> > 2) how to overlap two plot into one figure?
> >  plot(data[1:5])
> >  boxplot(newdata[,1:5])
> > ?
> >
> > --
> > TANG Jie
> >
> 
> 
> 
> -- 
> Sarah Goslee
> http://www.functionaldiversity.org
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] convert to grid file

2011-09-01 Thread Petr PIKAL
Hi

I do not know sp package therefore I can not help you. Anyway without 
knowing "what is wrong" and without some reproducible example you hardly 
get any reasonable answer.

It seems to me that your d list especially x and y is not what you expect 
to be. 

see

str(d)

430071.4887:460006.8067

will resilt in row of integers from 430071 to 460006. I believe it is not 
what you want.

Regards
Petr


> 
> Thank you
> 
> I want to make a map from my spatial data that I can show it in GIS. 
> I used the package sp and 
> 
> d<- list(x=430071.4887:460006.8067, y =3390040.0591:3420006.2701, z = 
> matrix(mat, 970, 960))
> gt<- GridTopology(cellcentre.offset = c(d$x[1], d$y[1]),
> cellsize=c(diff(d$x[1:2]), diff(d$y[1:2])), cells.dim = dim(d$z))
> grdatts<-SpatialGridDataFrame(gt, data.frame(depth =
> as.vector(d$z[,ncol(d$z):1])))
> image(grd.atts, axes=TRUE)
> grd<-SpatialGridDataFrame(gt, data.frame(depth =
> as.vector(d$z[,ncol(d$z):1])))
> 
> It doesn't work and I think it is wrong. 
> 
> Thanks
> 
> From: Petr PIKAL 
> To: azam jaafari 
> Cc: R-help 
> Sent: Thursday, September 1, 2011 10:22 AM
> Subject: Re: [R] convert to grid file
> 
> Hi
> 
> > Thank you Petr
> > 
> > It work. 
> > 
> > Now I have a matrix 970*960. If I want to convert to spatial grid 
(each 
> > pixel has x and y coordinate). 
> > How can I do? 
> 
> I do not understand. What do you want to do with your data? Maybe you 
> could consult spatial package or CRAN Task views. One option could be to 

> make vectors of row and columns coordinates. But it depends on what you 
> want to do with your data.
> 
> Regards
> Petr
> 
> 
> > 
> > Thanks
> > 
> > 
> > From: Petr PIKAL 
> > To: azam jaafari 
> > Cc: R-help 
> > Sent: Thursday, September 1, 2011 8:59 AM
> > Subject: Re: [R] convert to grid file
> > 
> > Hi
> > 
> > > 
> > > Hi
> > > 
> > > I computed probability in each cell.
> > > I have:
> > > 
> > >  [99883,] -0.0062412957690
> > >  [99884,] -0.0062412957690
> > >  [99885,] -0.0062412957690
> > >  [99886,] -0.0062412957690
> > >  [99887,] -0.0062412957690
> > >  [99888,] -0.0062412957690
> > >  [99889,]  0.9909126638948
> > >  [99890,]  0.9909126638948
> > >  [99891,]  0.9909126638948
> > >  [99892,]  0.9909126638948
> > >  [99893,]  0.9909126638948
> > >  [99894,]  0.9909126638948
> > >  [99895,]  0.9909126638948
> > >  [99896,]  0.9909126638948
> > >  [99897,]  0.9909126638948
> > >  [99898,]  0.9909126638948
> > >  [99899,]  0.9909126638948
> > >  [99900,]  0.9909126638948
> > >  [99901,]  0.9909126638948
> > >  [99902,]  0.9909126638948
> > >  [99903,]  0.9909126638948
> > > 
> > >  [9,] -0.0062412957690
> > >  [ reached getOption("max.print") -- omitted 839931 rows ]]
> > > 
> > > How want to convert this matrix to a grid file with 970*960 pixel.
> > 
> > Assuming your object is one column matrix called mat1
> > 
> > You can simply change its dimension
> > 
> > dim(mat) <- c(970, 960)
> > 
> > regards
> > Petr
> > 
> > 
> > 
> > 
> > > 
> > > Thanks alot
> > >[[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] convert to grid file

2011-09-01 Thread Petr PIKAL
Hi

> Thank you Petr
> 
> It work. 
> 
> Now I have a matrix 970*960. If I want to convert to spatial grid (each 
> pixel has x and y coordinate). 
> How can I do? 

I do not understand. What do you want to do with your data? Maybe you 
could consult spatial package or CRAN Task views. One option could be to 
make vectors of row and columns coordinates. But it depends on what you 
want to do with your data.

Regards
Petr


> 
> Thanks
> 
> 
> From: Petr PIKAL 
> To: azam jaafari 
> Cc: R-help 
> Sent: Thursday, September 1, 2011 8:59 AM
> Subject: Re: [R] convert to grid file
> 
> Hi
> 
> > 
> > Hi
> > 
> > I computed probability in each cell.
> > I have:
> > 
> >  [99883,] -0.0062412957690
> >  [99884,] -0.0062412957690
> >  [99885,] -0.0062412957690
> >  [99886,] -0.0062412957690
> >  [99887,] -0.0062412957690
> >  [99888,] -0.0062412957690
> >  [99889,]  0.9909126638948
> >  [99890,]  0.9909126638948
> >  [99891,]  0.9909126638948
> >  [99892,]  0.9909126638948
> >  [99893,]  0.9909126638948
> >  [99894,]  0.9909126638948
> >  [99895,]  0.9909126638948
> >  [99896,]  0.9909126638948
> >  [99897,]  0.9909126638948
> >  [99898,]  0.9909126638948
> >  [99899,]  0.9909126638948
> >  [99900,]  0.9909126638948
> >  [99901,]  0.9909126638948
> >  [99902,]  0.9909126638948
> >  [99903,]  0.9909126638948
> > 
> >  [9,] -0.0062412957690
> >  [ reached getOption("max.print") -- omitted 839931 rows ]]
> > 
> > How want to convert this matrix to a grid file with 970*960 pixel.
> 
> Assuming your object is one column matrix called mat1
> 
> You can simply change its dimension
> 
> dim(mat) <- c(970, 960)
> 
> regards
> Petr
> 
> 
> 
> 
> > 
> > Thanks alot
> >[[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] convert to grid file

2011-09-01 Thread Petr PIKAL
Hi

> 
> Hi
>  
> I computed probability in each cell.
> I have:
>  
>  [99883,] -0.0062412957690
>  [99884,] -0.0062412957690
>  [99885,] -0.0062412957690
>  [99886,] -0.0062412957690
>  [99887,] -0.0062412957690
>  [99888,] -0.0062412957690
>  [99889,]  0.9909126638948
>  [99890,]  0.9909126638948
>  [99891,]  0.9909126638948
>  [99892,]  0.9909126638948
>  [99893,]  0.9909126638948
>  [99894,]  0.9909126638948
>  [99895,]  0.9909126638948
>  [99896,]  0.9909126638948
>  [99897,]  0.9909126638948
>  [99898,]  0.9909126638948
>  [99899,]  0.9909126638948
>  [99900,]  0.9909126638948
>  [99901,]  0.9909126638948
>  [99902,]  0.9909126638948
>  [99903,]  0.9909126638948
>  
>  [9,] -0.0062412957690
>  [ reached getOption("max.print") -- omitted 839931 rows ]]
>  
> How want to convert this matrix to a grid file with 970*960 pixel.

Assuming your object is one column matrix called mat1

You can simply change its dimension

dim(mat) <- c(970, 960)

regards
Petr




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

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


Re: [R] !!!function to do the knn!!!

2011-09-01 Thread Petr PIKAL
Hi

Try to call 112 if you are in Europe.

Regards
Petr

> Re: [R] !!!function to do the knn!!!
> 
> help, help ,help!!!
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/function-to-
> do-the-knn-tp3781137p3781738.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] : reshape/aggregate

2011-08-31 Thread Petr PIKAL
Hi

> The plyr solution is:
> 
> library(plyr)
> ddply(dfx,  .(group, time), summarize, mean = mean(value), sd = 
sd(value))

I tried to do the task by ddply but I had difficulties to understand the 
correct syntax. Maybe in next issue of plyr summarise could be referenced 
in ddply help page.

Or add something like:

When performing summary values for a data frame according to levels of a 
factor you shall use syntax
ddply(.data, .variables, summarise, .fun, ...)

Regards
Petr


> 
> Best,
> Ista
> 
> On Wed, Aug 31, 2011 at 7:13 AM, Petr PIKAL  
wrote:
> > Hi
> >
> >> Hi all,
> >> I apologize for this probably stupid question, but I really can't 
figure
> > it
> >> out.
> >> I have a dataframe like this:
> >>
> >> group <- c(rep('A', 8), rep('B', 15), rep('C', 6))
> >> time <- c(rep(seq(1:4), 2), rep(seq(1:5), 3), rep(seq(1:3), 2))
> >> value <- runif (29, 1, 10)
> >> dfx <- data.frame (group, time, value)
> >>
> >> I want to calculate mean and standard deviation for all values that
> > belong
> >> to the same group and the same time and end up with a dataframe with 
the
> >> columns time, group, mean and sd that contains the calculated values 
for
> >> every group at every time point only once (12).
> >> What is the most elegant way to do this? Oh, and I would like to 
avoid
> >> renaming columns (like the _X1/_X2 created by casting with multiple
> >> functions), if possible.
> >> I am sure that this is pretty basic, but I have already wasted a
> > ridiculous
> >> amount of time on this.
> >
> > see
> > ?aggregate
> >
> > aggregate(dfx$value, list(group=dfx$group, time=dfx$time), function(x)
> > c(mean(x), sd(x)))
> >
> > and maybe also plyr package could help you
> >
> > Regards
> > Petr
> >
> >
> >>
> >> Thanks,
> >>
> >> Kai
> >>
> >>[[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.
> >
> 
> 
> 
> -- 
> Ista Zahn
> Graduate student
> University of Rochester
> Department of Clinical and Social Psychology
> http://yourpsyche.org

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


[R] Odp: reshape/aggregate

2011-08-31 Thread Petr PIKAL
Hi

> Hi all,
> I apologize for this probably stupid question, but I really can't figure 
it
> out.
> I have a dataframe like this:
> 
> group <- c(rep('A', 8), rep('B', 15), rep('C', 6))
> time <- c(rep(seq(1:4), 2), rep(seq(1:5), 3), rep(seq(1:3), 2))
> value <- runif (29, 1, 10)
> dfx <- data.frame (group, time, value)
> 
> I want to calculate mean and standard deviation for all values that 
belong
> to the same group and the same time and end up with a dataframe with the
> columns time, group, mean and sd that contains the calculated values for
> every group at every time point only once (12).
> What is the most elegant way to do this? Oh, and I would like to avoid
> renaming columns (like the _X1/_X2 created by casting with multiple
> functions), if possible.
> I am sure that this is pretty basic, but I have already wasted a 
ridiculous
> amount of time on this.

see
?aggregate

aggregate(dfx$value, list(group=dfx$group, time=dfx$time), function(x) 
c(mean(x), sd(x)))
 
and maybe also plyr package could help you

Regards
Petr


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

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


Re: [R] Help with the 'reshape' package

2011-08-30 Thread Petr PIKAL
Hi
> Hi all,
> 
> I am reading previous posts and guidance on the 'reshape' package in 
order
> to solve the simple problem below. Thinking that this might be very 
> trivial for most of you, I thought there could be a fast solution coming 

> from you guys, and I´d be very thankful for that.
> 
> I have a matrix with dates, companies, prices, just like
> 
> Date   Company   Price
> set-11   A   3
> dez-11   A   3,2
> jan-12   A   3,3
> fev-12   A   2,7
> mar-12   A   2,7
> abr-12   A   2,8
> mai-12   A   2,9
> jun-12   A   3
> jul-12   A   3,1
> mar-12   B   5
> abr-12   B   5,5
> mai-12   B   5,7
> jun-12   B   7
> jul-12   B   6,6
> dez-11   C   1
> jan-12   C   1,1
> fev-12   C   1,11
> mar-12   C   1,2
> abr-12   C   1,3
> 
> and I want to convert it into something like below (missing data can be 
> zeros or NAs)
> 
>   A   B   C
> set-11   3   NA   NA
> dez-11   3,2   NA   1
> jan-12   3,3   NA   1,1
> fev-12   2,7   NA   1,11
> mar-12   2,7   5   1,2
> abr-12   2,8   5,5   1,3
> mai-12   2,9   5,7   NA
> jun-12   3   7   NA
> jul-12   3,1   6,6   NA



You have already melted data (long format). So simply cast

 cast(test, Date~Company)
Using Price as value column.  Use the value argument to cast to override 
this choice
Date   A   BC
1 abr-12 2.8 5.5 1.30
2 dez-11 3.2  NA 1.00
3 fev-12 2.7  NA 1.11
4 jan-12 3.3  NA 1.10
5 jul-12 3.1 6.6   NA
6 jun-12 3.0 7.0   NA
7 mai-12 2.9 5.7   NA
8 mar-12 2.7 5.0 1.20
9 set-11 3.0  NA   NA

Shall be OK.

Regards
Petr



> 
> Workspace is attached. Thanks in advance.
> 
> "This message and its attachments may contain confidential and/or 
> privileged information. If you are not the addressee, please, advise the 

> sender immediately by replying to the e-mail and delete this message."
> 
> "Este mensaje y sus anexos pueden contener información confidencial o 
> privilegiada. Si ha recibido este e-mail por error por favor bórrelo y 
> envíe un mensaje al remitente."
> 
> "Esta mensagem e seus anexos podem conter informação confidencial ou 
> privilegiada. Caso não seja o destinatário, solicitamos a imediata 
> notificação ao remetente e exclusão da 
> mensagem."__
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Showing zero frequencies with xtabs

2011-08-30 Thread Petr PIKAL
Hi
> 
> Hi,
> 
> Does anyone know how to show zero frequencies variable levels with the 
> xtabs command? They show with the table(x,y) command but I need to apply 

> weight to frequency tables and I also need to cbind several tables 
> together, which implies that they all need to show the same number of 
rows. 

Do you use factors?

x<-sample(letters[1:5], 20, replace=T)
xtabs(~x)
x
a b c d e 
2 1 5 4 8 

x.f<-factor(x)
x[x=="b"]<-NA
x.f[x.f=="b"]<-NA

> xtabs(~x)
x
a c d e 
2 5 4 8 

> xtabs(~x.f)
x.f
a b c d e 
2 0 5 4 8 

With factors you can specify also non existent levels so they shall appear 
as zeroes in table or xtabs.

Regards
Petr

> 
> Alternatively, do you know how to column bind tables with different 
number
> of rows? I cannot use merge as it requires daata.frame and that modifies 

> the look of the banner table I am trying to create...
> 
> Thanks,
> Luca
> 
> 
> Mr. Luca Meyer
> www.lucameyer.com
> R version 2.13.1 (2011-07-08)
> Mac OS X 10.6.8
> 
> 
> 
> 
> 
> 
> 
>[[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] Odp: Extracting values in table

2011-08-29 Thread Petr PIKAL
Hi

> Hi All,
> 
> I am a beginner in programming in r and please do forgive me if my 
question
> seems to be silly and sometimes not understandable. 
> 
> 1. we have a list of elements in a list say:
> 
> ls<-list("N","E","E","N","P","E","M","Q","E","M")
> 
> 2. We have an another list of tables in a list say:
> 
> n <- list("M", "N","E","P","Q","M","N","E","Q","N")
> 
> tb <- lapply(1:10, function(i)matrix(sample(4), 2, 2,
> dimnames=list(n[sample(10,2)], n[sample(2,2)])))
> 
> 3. we need to extract values from the table in the list where colname is
> always "M" , wherein the rowname should be the 1st element in the list 
ls
> for table 1 in the list tb and 2nd element in table 2 and so on...
> 
> for ex: 
>M N
> N 4 1
> P 3 2
> 
> In table 1 , we need to extract value 4.

I can not provide you with canned solution but

x = sapply(tb, function(x) which(dimnames(x)[[2]]=="M"))

gives you vector of M positions in column names

for (i in seq_along(ls1)) print(which(rownames(tb[[i]]) %in% ls[[i]]))

# for (i in seq_along(ls1)) y[i] <- which(rownames(tb[[i]]) %in% ls[[i]])
# does not work as there is sometimes no match

gives you position of row names (if they exist)

then you can use that for selection of items from list tb

e.g. for the first table

tb[[1]][x[1],y[[1]]]

> tb[[1]]
  M N
N 3 2
Q 1 4

tb[[1]][x[1],y[1]]
[1] 3

Regards
Petr

> 
> 
> Thanks to all in advance.
> 
> 
> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/Extracting-
> values-in-table-tp3771272p3771272.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Placing a column name in a variable XXXX

2011-08-28 Thread Petr PIKAL
Hi

or if Dan prefers data frame (which is also a list)

CInew2 <-function(x,alpha){
data.frame(variable = deparse(substitute(x)), mean=mean(x), alpha = alpha)
}


> CInew2(JOBSTAT, 0.05)
  variable  mean alpha
1  JOBSTAT 0.4567117  0.05

Regards
Petr


> 
> In this case you want to use a 'list' since you want character and
> numerics returned:
> 
> > JOBSTAT<-rnorm(10)
> >
> >
> > # new function that does not return 'x'
> >
> > CInew <-function(x,alpha){
> + list(variable = deparse(substitute(x)), mean=mean(x), alpha = alpha)
> + }
> >
> > CInew(JOBSTAT, 0.05)
> $variable
> [1] "JOBSTAT"
> 
> $mean
> [1] -1.113034
> 
> $alpha
> [1] 0.05
> 
> >
> >
> 
> 
> On Sat, Aug 27, 2011 at 6:58 PM, Dan Abner  
wrote:
> >
> >
> > I want to it return:
> >
> > Variable Meanalpha
> > JOBSTAT  -0.1240675  0.05
> >
> > How do I get the function parameter x to equal the name of the object 
that
> > is specified as x as a character string?
> >
> >
> > On Sat, Aug 27, 2011 at 6:41 PM, jim holtman  
wrote:
> >>
> >> The function is doing exactly what you are telling it to do.  You 
have
> >> 'cbind(x, mean(x), alpha)' which is creating a matrix where the first
> >> column is all the values in 'x' and the next two are the recycled
> >> values of mean and alpha.  Is this what you want:
> >>
> >> > JOBSAT<-rnorm(10)
> >> >
> >> > CI<-function(x,alpha){
> >> + cbind(x,mean=mean(x),alpha)
> >> + }
> >> > CI(JOBSAT,.05)
> >>   x   mean alpha
> >>  [1,]  0.8592324 -0.1240675  0.05
> >>  [2,] -0.3128362 -0.1240675  0.05
> >>  [3,] -2.0042218 -0.1240675  0.05
> >>  [4,] -0.4675232 -0.1240675  0.05
> >>  [5,] -0.5776273 -0.1240675  0.05
> >>  [6,]  1.5696650 -0.1240675  0.05
> >>  [7,]  0.8070593 -0.1240675  0.05
> >>  [8,] -0.8257525 -0.1240675  0.05
> >>  [9,]  0.6167636 -0.1240675  0.05
> >> [10,] -0.9054347 -0.1240675  0.05
> >> >
> >> > # new function that does not return 'x'
> >> >
> >> > CInew <-function(x,alpha){
> >> + c(mean=mean(x), alpha = alpha)
> >> + }
> >> > CInew(JOBSAT,.05)
> >>  mean  alpha
> >> -0.1240675  0.050
> >>
> >>
> >> On Sat, Aug 27, 2011 at 5:38 PM, Dan Abner  
wrote:
> >> > Hi everyone,
> >> >
> >> > How does one place an object name (in this case a vector name) into
> >> > another
> >> > object (while essentially masking the values of the first object?
> >> >
> >> > For example:
> >> >
> >> >> JOBSAT<-rnorm(40)
> >> >>
> >> >> CI<-function(x,alpha){
> >> > + result<-cbind(x,mean=mean(x),alpha)
> >> > + print(result)
> >> > + }
> >> >> CI(JOBSAT,.05)
> >> >
> >> > I want this to return:
> >> >
> >> > Variablemean  alpha
> >> > JOBSTAT 0.02844131  0.05
> >> > Instead, I am getting:
> >> >
> >> >x   mean alpha
> >> >  [1,] -1.07694997 0.02844131  0.05
> >> >  [2,] -1.13910850 0.02844131  0.05
> >> >  [3,] -0.21922026 0.02844131  0.05
> >> >  [4,]  0.38618008 0.02844131  0.05
> >> >  [5,] -1.24303799 0.02844131  0.05
> >> >  [6,] -0.74903752 0.02844131  0.05
> >> >  [7,]  0.96136975 0.02844131  0.05
> >> >  [8,] -0.38891237 0.02844131  0.05
> >> >  [9,] -0.20195871 0.02844131  0.05
> >> > [10,]  0.78104508 0.02844131  0.05
> >> > [11,]  0.87468778 0.02844131  0.05
> >> > [12,] -1.89131480 0.02844131  0.05
> >> >
> >> >
> >> > Thank you!
> >> >
> >> > Dan
> >> >
> >> > [13,]  0.74377795 0.02844131  0.05
> >> > [14,] -0.60006285 0.02844131  0.05
> >> > [15,] -0.76661652 0.02844131  0.05
> >> > [16,]  1.06005258 0.02844131  0.05
> >> > [17,]  0.02173877 0.02844131  0.05
> >> > [18,] -0.36558980 0.02844131  0.05
> >> > [19,] -1.92481588 0.02844131  0.05
> >> > [20,] -0.50337507 0.02844131  0.05
> >> > [21,]  0.82205272 0.02844131  0.05
> >> > [22,]  1.59277572 0.02844131  0.05
> >> > [23,]  0.59965718 0.02844131  0.05
> >> >
> >> >[[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.
> >> >
> >>
> >>
> >>
> >> --
> >> Jim Holtman
> >> Data Munger Guru
> >>
> >> What is the problem that you are trying to solve?
> >
> >
> 
> 
> 
> -- 
> Jim Holtman
> Data Munger Guru
> 
> What is the problem that you are trying to solve?
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Odp: all combinations of the elements of two vectors

2011-08-28 Thread Petr PIKAL
Hi
> 
> Dear R-help readers,
> 
> I'm sure this problem has been answered but I can't find the solution.
> 
> I have two vectors
> v1 <- c("a","b")
> v2 <- c(1,2,3)
> I want an easy way to produce every possible combination of v1, v2 
elements
> Ie I want to produce
> c("a1","a2","a3", "b1","b2","b3")

Another option is

z<-outer(x,y, paste, sep="")
dim(z)<-NULL
> z
[1] "a1" "b1" "c1" "a2" "b2" "c2" "a3" "b3" "c3"

which gives the result in different order

or

z<-as.vector(t(z))
> z
[1] "a1" "a2" "a3" "b1" "b2" "b3" "c1" "c2" "c3"

Which gives you desired order.

Regards
Petr

> 
> regards
> Desmond
> 
> Desmond Campbell
> Dept of Biostatistics and Computing, Institute of Psychiatry (KCL),
> PO Box 20, De Crespigny Park, Denmark Hill London, SE5 8AF
> 
> Tel 020 7848 0309
> Email d.campb...@iop.kcl.ac.uk
> 
> 
> 
>[[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] cbind giving NA's?

2011-08-26 Thread Petr PIKAL
I was rather too quick

It has probably something to do with versions of zoo and xts

after updating to zoo 1.7.4 and xts 0.8.2 I got with your examples

> merge(a,b)
   ZWD.UGX SCHB.Close
2010-04-01  NA  28.02
2010-04-01  7.6343 NA
2010-04-02  7.6343 NA
2010-04-03  7.5458 NA
2010-04-04  7.4532 NA
2010-04-05  NA  28.30
2010-04-05  7.4040 NA
2010-04-06  NA  28.38
2010-04-06  7.3317 NA
2010-04-07  NA  28.21
2010-04-08  NA  28.31
2010-04-09  NA  28.47

but when I did

> a<-as.zoo(a)
> b<-as.zoo(b)

I got

> merge(a,b)
   ZWD.UGX SCHB.Close
2010-04-01  7.6343  28.02
2010-04-02  7.6343 NA
2010-04-03  7.5458 NA
2010-04-04  7.4532 NA
2010-04-05  7.4040  28.30
2010-04-06  7.3317  28.38
2010-04-07  NA  28.21
2010-04-08  NA  28.31
2010-04-09  NA  28.47

which is probably what you want.

Regards
Petr

> 

> Hi
> 
> > 
> > On 26 August 2011 03:37, R. Michael Weylandt 
 wrote:
> > > If you could, dput() them so we can see everything about them. You 
also
> > > might see if merge() gives you more expected behavior
> > 
> > Ok...
> > > dput(a)
> > structure(c(7.6343, 7.6343, 7.5458, 7.4532, 7.404, 7.3317), class = 
c("xts",
> > "zoo"), .indexCLASS = "Date", .indexTZ = "", index = 
structure(c(1270105200,
> > 1270191600, 1270278000, 1270364400, 1270450800, 1270537200), tzone =
> > "", tclass = "Date"), .Dim = c(6L,
> > 1L), .Dimnames = list(NULL, "ZWD.UGX"))
> > > dput(b)
> > structure(c(28.02, 28.3, 28.38, 28.21, 28.31, 28.47), .indexCLASS =
> > "Date", .indexTZ = "", src = "yahoo", updated =
> > structure(1314356091.21457, class = c("POSIXct",
> > "POSIXt")), class = c("xts", "zoo"), index = structure(c(1270072800,
> > 1270418400, 1270504800, 1270591200, 1270677600, 1270764000), tzone =
> > "", tclass = "Date"), .Dim = c(6L,
> > 1L), .Dimnames = list(NULL, "SCHB.Close"))
> > > merge(a,b)
> > > merge(a,b)
> >ZWD.UGX SCHB.Close
> > 2010-04-01  NA  28.02
> > 2010-04-01  7.6343 NA
> > 2010-04-02  7.6343 NA
> > 2010-04-03  7.5458 NA
> > 2010-04-04  7.4532 NA
> > 2010-04-05  NA  28.30
> > 2010-04-05  7.4040 NA
> > 2010-04-06  NA  28.38
> > 2010-04-06  7.3317 NA
> > 2010-04-07  NA  28.21
> > 2010-04-08  NA  28.31
> > 2010-04-09  NA  28.47
> > > q()

> I get slightly different result
> 
> > xx<-(merge(a,b))
> > xx
>ZWD.UGX SCHB.Close
> 1270072800  NA  28.02
> 1270105200  7.6343 NA
> 1270191600  7.6343 NA
> 1270278000  7.5458 NA
> 1270364400  7.4532 NA
> 1270418400  NA  28.30
> 1270450800  7.4040 NA
> 1270504800  NA  28.38
> 1270537200  7.3317 NA
> 1270591200  NA  28.21
> 1270677600  NA  28.31
> 1270764000  NA  28.47
> 
> but from what you want it seems to me that aggregate could be suitable 
second step.
> 
> something like
> 
> aggregate(xx, list(those dates you have but I don't), mean, na.rm=T)
> 
> could do what you want.
> 
> Regards
> Petr
> 
> > 
> > So, no, merge doesn't work...
> > -- 
> > Sent from my mobile device
> > Envoyait de mon telephone mobil
> > 
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/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] cbind giving NA's?

2011-08-26 Thread Petr PIKAL
Hi

> 
> On 26 August 2011 03:37, R. Michael Weylandt 
 wrote:
> > If you could, dput() them so we can see everything about them. You 
also
> > might see if merge() gives you more expected behavior
> 
> Ok...
> > dput(a)
> structure(c(7.6343, 7.6343, 7.5458, 7.4532, 7.404, 7.3317), class = 
c("xts",
> "zoo"), .indexCLASS = "Date", .indexTZ = "", index = 
structure(c(1270105200,
> 1270191600, 1270278000, 1270364400, 1270450800, 1270537200), tzone =
> "", tclass = "Date"), .Dim = c(6L,
> 1L), .Dimnames = list(NULL, "ZWD.UGX"))
> > dput(b)
> structure(c(28.02, 28.3, 28.38, 28.21, 28.31, 28.47), .indexCLASS =
> "Date", .indexTZ = "", src = "yahoo", updated =
> structure(1314356091.21457, class = c("POSIXct",
> "POSIXt")), class = c("xts", "zoo"), index = structure(c(1270072800,
> 1270418400, 1270504800, 1270591200, 1270677600, 1270764000), tzone =
> "", tclass = "Date"), .Dim = c(6L,
> 1L), .Dimnames = list(NULL, "SCHB.Close"))
> > merge(a,b)
> > merge(a,b)
>ZWD.UGX SCHB.Close
> 2010-04-01  NA  28.02
> 2010-04-01  7.6343 NA
> 2010-04-02  7.6343 NA
> 2010-04-03  7.5458 NA
> 2010-04-04  7.4532 NA
> 2010-04-05  NA  28.30
> 2010-04-05  7.4040 NA
> 2010-04-06  NA  28.38
> 2010-04-06  7.3317 NA
> 2010-04-07  NA  28.21
> 2010-04-08  NA  28.31
> 2010-04-09  NA  28.47
> > q()

I get slightly different result

> xx<-(merge(a,b))
> xx
   ZWD.UGX SCHB.Close
1270072800  NA  28.02
1270105200  7.6343 NA
1270191600  7.6343 NA
1270278000  7.5458 NA
1270364400  7.4532 NA
1270418400  NA  28.30
1270450800  7.4040 NA
1270504800  NA  28.38
1270537200  7.3317 NA
1270591200  NA  28.21
1270677600  NA  28.31
1270764000  NA  28.47

but from what you want it seems to me that aggregate could be suitable 
second step.

something like

aggregate(xx, list(those dates you have but I don't), mean, na.rm=T)

could do what you want.

Regards
Petr



> 
> So, no, merge doesn't work...
> -- 
> Sent from my mobile device
> Envoyait de mon telephone mobil
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Odp: Using write.table i have a table with two columns i would like to save it as an excel file

2011-08-26 Thread Petr PIKAL
Hi

I use this kind of output to excel if the table is not too big

write.table(tab, "clipboard", sep = "\t", row.names = F)

In excel sheet I press ctrl - V to copy from clipboard

Regards
Petr
 
> Using write.table i would like to save data  as an excel file to a 
folder. I
> am not too sure how to write the file path or what to name the file. I 
would
> appreciate any feedback. 
> 
> 
> > write.table(x, file = "", append = FALSE, quote = TRUE, sep = " ",
> + eol = "\n", na = "NA", dec = ".", row.names = TRUE,
> + col.names = TRUE, qmethod = c("escape", "double"),
> + fileEncoding = "")
> "area" "bedrooms" "sale.price"
> 
> "9" 694 4 192
> "10" 905 4 215
> "11" 802 4 215
> "12" 1366 4 274
> "13" 716 4 112.7
> "14" 963 4 185
> "15" 821 4 212
> "16" 714 4 220
> "17" 1018 4 276
> "18" 887 4 260
> "19" 790 4 221.5
> "20" 696 5 255
> "21" 771 5 260
> "22" 1006 5 293
> "23" 1191 6 375
> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/Using-write-
> 
table-i-have-a-table-with-two-columns-i-would-like-to-save-it-as-an-excel-
> file-tp3768829p3768829.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] read.table truncated data?

2011-08-26 Thread Petr PIKAL
Hi

> 
> Thanks, Jim. quote='' works. And then I found a single quote in each of
> these lines:
> 3262
> 10403
> 17544
> 24685
> 31826
> 38967
> 
> None of them near the position the table got truncated. Why is it?
> 
> And read.table is a great function. Is it possible for it to give a 
warning
> message when the data gets truncated? In my case I almost looked over 
the
> truncation...

When I read in some big data I usually do

str(data)

which tells me if there is some problem with data types (conversion of 
numeric to factor due to any problematic item)

and/or

dim(data)

to see that size is as expected.

Regards
Petr

> 
> On Thu, Aug 25, 2011 at 11:57 AM, jim holtman  
wrote:
> 
> > But did you try the following:
> >
> > x <- read.table(, comment.char = '', quote = '')
> >
> > Most cases is that there is a missing quote somewhere in your data.
> > use a text editor and search for single and double quotes.
> >
> > On Thu, Aug 25, 2011 at 11:49 AM, zhenjiang xu 

> > wrote:
> > > Thanks for your replies. I looked at those lines and didn't spot 
anything
> > > unusual.
> > >
> > >> tail(a)
> > >test_id gene_id gene   locus sample_1 sample_2 
status
> > > 21418 tY(GUA)J1   - SUP7 chr10:354243-354332 air1rrp6 air2rrp6  
OK
> > > 21419 tY(GUA)J2   - SUP4 chr10:542955-543044 air1rrp6 air2rrp6  
OK
> > > 21420 tY(GUA)M1   - SUP5 chr13:168794-168883 air1rrp6 air2rrp6  
OK
> > > 21421 tY(GUA)M2   - SUP8 chr13:837927-838016 air1rrp6 air2rrp6  
OK
> > > 21422  tY(GUA)O   - SUP3 chr15:288191-288280 air1rrp6 air2rrp6  
OK
> > > 21423  tY(GUA)Q   --   chrmt:70823-70907 air1rrp6 air2rrp6
> > OK
> > >  value_1 value_2 ln.fold_change. test_stat  p_value  q_value
> > > significant
> > > 21418 0.0  0.0.00   0.0 1.00 1.011650
> > >  no
> > > 21419 0.0  0.0.00   0.0 1.00 1.011480
> > >  no
> > > 21420 0.0  0.0.00   0.0 1.00 1.011500
> > >  no
> > > 21421 0.0  0.0.00   0.0 1.00 1.011520
> > >  no
> > > 21422 0.0  0.0.00   0.0 1.00 1.011550
> > >  no
> > > 21423 6.68356 10.73970.474301  -1.08614 0.277417 0.455917
> > >  no
> > >
> > >
> > > tY(GUA)J1   -   SUP7chr10:354243-354332 rrp6 
air1rrp6
> > >   OK  0   0   0   0   11.00404  no
> > > tY(GUA)J2   -   SUP4chr10:542955-543044 rrp6 
air1rrp6
> > >   OK  0   0   0   0   11.00497  no
> > > tY(GUA)M1   -   SUP5chr13:168794-168883 rrp6 
air1rrp6
> > >   OK  0   0   0   0   11.00492  no
> > > tY(GUA)M2   -   SUP8chr13:837927-838016 rrp6 
air1rrp6
> > >   OK  0   0   0   0   11.00488  no
> > > tY(GUA)O-   SUP3chr15:288191-288280 rrp6 
air1rrp6
> > >   OK  0   0   0   0   11.00485  no
> > > tY(GUA)Q-   -   chrmt:70823-70907   rrp6 
air1rrp6
> > >   OK  4.49644 6.68356 0.396365-0.766052 0.443645
> > >  0.634724no
> > > 15S_rRNA-   15S_RRNAchrmt:6545-8194 WT air2rrp6
> > >   OK  2288.88 711.697 -1.168172.78772   0.00530801
> > >  0.0167772   yes
> > > 21S_rRNA-   21S_RRNAchrmt:58008-62447   WT
> > >  air2rrp6OK  4134.59 1927.04 -0.7634 1.58991 0.111855
> > >   0.22339 no
> > > ETS1-1  -   ETS1-1  chr12:457732-458432 WT  air2rrp6
> >  OK
> > >   3258.97 1114.76 -1.072772.91211 0.00359   0.0121587
> > yes
> > > ETS1-2  -   ETS1-2  chr12:466869-467569 WT  air2rrp6
> >  OK
> > >   3258.97 1114.76 -1.072772.91211 0.00359   0.0121597
> > yes
> > >
> > >
> > > On Wed, Aug 24, 2011 at 2:34 PM, Sarah Goslee 
 > >wrote:
> > >
> > >> Hi,
> > >>
> > >> On Wed, Aug 24, 2011 at 2:18 PM, zhenjiang xu 

> > >> wrote:
> > >> > Hi R users,
> > >> >
> > >> > I was using read.table to read a file. The data.fame looked 
alright,
> > but
> > >> I
> > >> > found not all rows are read by the read.table. What's wrong with 
it?
> > It
> > >> > didn't give me any warning or error messages. Why the data are
> > truncated?
> > >> > Thanks.
> > >> >
> > >> > $ wc -l all/isoform_exp.diff
> > >> > 42847 all/isoform_exp.diff
> > >> >
> > >> >> a=read.table('all/isoform_exp.diff', header=T, sep='\t')
> > >> >> nrow(a)
> > >> > [1] 21423
> > >>
> > >> This is a common problem. You need to take a look at the last row 
that
> > >> was imported, and the rows around 21423 in the original file.
> > >>
> > >> Common causes include stray single or double quotation marks, and
> > >> other special characters in your file like the default comment.char 
#
> > >>
> > >> Sarah
> > >> --
> > >> Sarah Goslee
> > >> http://www.functionaldiversity.org
> > >>
> > >
> > >
> > >
> > > --
> > > Best,
> > > Zhenjiang
> > >
> > >[[alternative HTML version deleted

[R] Odp: {R} How to extract correctly from vector?

2011-08-25 Thread Petr PIKAL
> 
> Dear list,
> 
> 
> 
> I have problem that I cannot solve and would like to ask your opinion. I
> tried to ask a few days ago already but got no answer and all my 
attempts to
> solve it by myself since then failed. Sorry for repeated posting! Here 
the
> problem broken down a bit.
> 
> 
> 
> My problem basically is, that I want to use the elements of a character
> vector as names for objects and by recalling only the subscript of the
> character vector get the object information I assigned.
> 
> 
> 
> Example:
> 
> 
> 
> vector of names created as follows:
> 
> char <- paste("A",1,sep="")
> 
> for (i in 2:10) {char[i] <- paste("A",i,sep="")}
> 
> char 
> 
> [1] "A1"  "A2"  "A3"  "A4"  "A5"  "A6"  "A7"  "A8"  "A9"  "A10"

Slightly better

 char <- paste("A",1:10,sep="")


> 
> Now assign each element as name for a data frame:
> 
> (d <-
> 
data.frame(cbind(X1=1,Y1=1:10,X2=1,Y2=1:10,X3=1,Y3=1:10,X4=1,Y4=1:10,X5=1,Y5
> =1:10,
> 
> 
> X6=1,Y6=1:10,X7=1,Y7=1:10,X8=1,Y8=1:10,X9=1,Y9=1:10,X10=1,Y10=1:10)))

One right parentheses more.

> 
> x <- paste("X",1,sep="")
> 
> y <- paste("Y",1,sep="")
> 
> for (i in 2:10) {x[i] <- paste("X",i,sep="")
> 
>  y[i] <- paste("Y",i,sep="")}

Maybe you wanted

x <- paste("X",1:10,sep="")
y <- paste("Y",1:10,sep="")


> 
> for (k in 1:10) {assign(char[k],d[,c(x[k],y[k])])}

I would use list.

lll<- vector(mode="list", 10)
names(lll) <- char
for(k in 1:10) lll[[k]] <- d[,c(x[k],y[k])]

instead of many An objects you have one object with names An and you can 
easily subset it.

lll[[1]]
lll[["A5"]]

> 
> 
> 
> If I call "A1", I get a dataframe with columns "X1" and "Y1", so far so
> good.
> 
> 
> 
> Now the trouble part:
> 
> nam <- paste("test",1,sep="")
> 
> for (i in 2:10) {nam[i] <- paste("test",i,sep="")}

nam <- paste("test",1:10,sep="")


> 
> 
> 
> for (i in 1:10){assign(nam[i],as.ltraj(xy=char[1],date=DATE,...)

So the same applies here

lll<- vector(mode="list", 10)
names(lll) <- char
for (i in 1:10) lll[[i]] <- as.ltraj(xy=char[i],date=DATE,...)

However I do not know as.ltraj which may require different input of 
parameters.

Anyway in this case are lists by my opinion the only way to be able to 
handle such things smoothly and without much headache.

Regards
Petr


> 
> 
> 
> 
> Please don't get carried away by as.ltraj, it's an object type of the
> package adehabitat to analyze animal tracks. However, I need to feed it 
the
> xy (coordination) information in form of a data frame. I have 20 animals 
to
> analyze (per different setup), so I want it to work in a handier way 
than
> keep pushing buttons. By the way I handle it now, I only hand over the 
term
> "A1" but not the data frame "A1".
> 
> 
> 
> How can I solve this. Turning the vector into a list does not work and I 
am
> not sure if there's something I can do...
> 
> 
> 
> Please help if you can! Many thanks in advance already.
> 
> 
> 
> Jacqueline
> 
> 
> 
> 
>[[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] Odp: Howto convert Linear Regression data to text

2011-08-25 Thread Petr PIKAL
> 
> Dear all,
> 
> How can I covert lm data to text in the form of "y=ax+b, r2" and how do 
I
> calculate R-squared(r2)?
> 
> Thanks. 
> 
> Code:
> x=18:29
> y=c(7.1,7,7.7,8.2,8.8,9.7,9.9,7.1,7.2,8.8,8.7,8.5)
> res=lm(y~x)

I am not sure what do you mean by text. There are some lm extraction 
functions for evaluating your results which you can use in some paste 
construction according to your wished formating.

summary(res)

Call:
lm(formula = y ~ x)

Residuals:
 Min   1Q   Median   3Q  Max 
-1.27448 -0.62684 -0.07483  0.35079  1.62517 

Coefficients:
Estimate Std. Error t value Pr(>|t|) 
(Intercept)  5.883221.97455   2.980   0.0138 *
x0.099650.08313   1.199   0.2583 
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Residual standard error: 0.9941 on 10 degrees of freedom
Multiple R-squared: 0.1256, Adjusted R-squared: 0.0382 
F-statistic: 1.437 on 1 and 10 DF,  p-value: 0.2583 

summary(res)$r.squared
[1] 0.1256375

> coef(res)
(Intercept)   x 
 5.88321678  0.09965035

Regards
Petr


> 
> --
> View this message in context: 
http://r.789695.n4.nabble.com/Howto-convert-
> Linear-Regression-data-to-text-tp3766230p3766230.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] Odp: Boxplot orders

2011-08-25 Thread Petr PIKAL
Hi

> 
> Hi there,
> 
> I have length data of an organism over the year and I want to make a
> boxplot. I get the boxplot just fine but the months are all out of 
order. In
> the data set they are in order from Jan-Dec...how can I fix this 
problem?

Probably months are either character or factor values. If they are factor 
type you can easily change their ordering.

factor(month.factor.variable, levels= vector of properly ordered months)

Regards
Petr

> 
> Thanks so much in advance!!
> 
> Phoebe
> 
>[[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] Odp: boxplot from mean and SD data

2011-08-24 Thread Petr PIKAL
Hi
> 
> Dear all,
> 
> I have a dataset of 3 categorical factors, the mean and the standard 
> deviation of each value. I want to use these values to plot a boxplot, 
> grouped by each of the 3 categorical factors (24 boxplots in total). I 
> don't have a clue on how to do the boxplot from mean and SD data already 
calculated.

I am afraid that you can not do it. Only if you you accept assumption that 
distribution within each factor is normal and therefore median equals 
mean. You can than also use 25 an 75 percentile for box construction.

see ?boxplot and ?bxp for internals of plotting function.

One possibility also is to generate values by mean and sd parameters to 
rnorm, although I do not see the reason for doing it.

Regards
Petr


> 
> Thanks in advance
> 
> 
>[[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] spectral analysis

2011-08-24 Thread Petr PIKAL
> 
> Is there anything in R similar to spectogram command in matlab? 

As I do not use matlab I can not know what spectogram does.

What is wrong with fft or spectrum functions?

Regards
Petr


> On Tue, Aug 23, 2011 at 10:20 AM, Petr PIKAL  
wrote:
> Hi
> 
> 
> > Hi all,
> >
> > I am trying to do spectral analysis of a time series data. But I am 
not
> sure
> > how to do it. Can anyone tell me if there are any package I can use to
> do
> > the analysis using fast fourier transform?

> Maybe ?fft or ?spectrum
> 
> Regards
> Petr
> 
> >
> > Thanks in advance.
> >
> >
> > Cassie
> >
> >[[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.

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


[R] Odp: spectral analysis

2011-08-23 Thread Petr PIKAL
Hi

 
> Hi all,
> 
> I am trying to do spectral analysis of a time series data. But I am not 
sure
> how to do it. Can anyone tell me if there are any package I can use to 
do
> the analysis using fast fourier transform?

Maybe ?fft or ?spectrum

Regards
Petr

> 
> Thanks in advance.
> 
> 
> Cassie
> 
>[[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] Odp: Mapping strings to integers

2011-08-23 Thread Petr PIKAL
Hi

> Dear All,
> I am quite a newbie to R. Trying to learn it these days. Sorry for 
asking
> such a basic question, but could you kindly tell me how to map unique 
string
> values to integers in a data frame? I have a graph which has, most of 
its,
> vertices' attributes in a string format. I would like to replace them 
with
> ascending integers. For example, first unique value in column 1 changes 
to
> "0". I'd like to have it so that I could use my computer's resources
> efficiently and also could easily perform statistical measures on it. I 
am
> looking for a two way mapping, so that, after analysis, I could see
> meaningful results in terms of the same but in reverse order mappings. 
Hope
> I was clear in my question.

I doubt it. Maybe others can resolve your intention without any data or 
code. I can only guess that you have some character values in some king of 
object (data.frame?, vector?, matrix?0

basically you can change it to factor and do as.numeric to this factor. 
Something like

x<-sample(letters[1:5], 20, replace=TRUE)
 [1] 5 4 4 2 5 3 4 5 5 3 3 2 5 3 3 3 4 1 4 3
data.frame(x=x, x.n=as.numeric(factor(x)))
   x x.n
1  e   5
2  d   4
3  d   4
4  b   2
5  e   5
6  c   3
7  d   4
8  e   5
9  e   5
10 c   3
11 c   3
12 b   2
13 e   5
14 c   3
15 c   3
16 c   3
17 d   4
18 a   1
19 d   4
20 c   3

Regards
Petr

> 
> Thanks!
> 
> Cheers,
> Ali
> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/Mapping-
> strings-to-integers-tp3762828p3762828.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Sequence

2011-08-23 Thread Petr PIKAL
Hi

as far as I understand your question it seems to me that

round(5*(1.4^(0:10)))

gives you your sequence

and 

cumsum(round(5*(1.4^(0:10

gives you summary sequence.

Regards
Petr

> 
> I definitely used too much lines s of code because I still don't know 
how to
> do some staff.
> but it works:
> seq=5 #starting value
> var=5# starting value
> long= 1:10   # length of the vector
> for (x in long){
> var=var+((var/100)*40)
> seq=append(seq,var)
> }
> seq=round(seq)
> seq=cumsum(seq)
> 
> > seq
>  [1]5   17   39   75  130  212  332  505  752 1102 1597
> 
> 
> Probably I could set just a variable instead of 2 ( var and seq)
> and set the value of long directly to 10, but as I said I just started 
using
> R
> 
> 
> Thanks :)
> 
> ?cumsum
> > cumsum(yoursequence)
> >
> > HTH,
> > Jorge
> >
> >
> > On Mon, Aug 22, 2011 at 8:36 PM, Claudio Zanettini <> wrote:
> >
> >> Hello everyone,
> >> I would like to generate a sequence
> >> such as, starting from 5, every value  is
> >>  40% of the value before+ all the preceeding values.
> >> es:
> >> this is the seq of all the value+40% of the preceding value:
> >> 5 71014192738
> >> 5374   103   145   202   283   397
> >> 556   778  1089  1525  2134  2988  4183
> >>
> >> then the vector tha I need is
> >>  5 , 5+7, 5+7+10, 5+7+10+14 and so on
> >>
> >> I can generate the first sequence but I don t know how to generate 
the
> >> last.
> >>
> >> I would really appreciate your help.
> >> Thanks
> >> HVZ
> >>
> >>[[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.

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


Re: [R] I have a problem with R!!

2011-08-22 Thread Petr PIKAL
Hi

Your code is rather baroque and it is difficult to see what is exactly 
going on without having appropriate data. I does not consider your process 
of reading data from Excel problematic.

Maybe the difference is in that

d<- rnorm(whatever) 

produces vector while

d<- read.delim("clipboard", header = T, dec = ",")

produces data frame

you can subset vector by

d[indices]

but doing the same with data.frame you try to subset columns which, in 
your case should not be what you want.

at least showing us 

str(data.readed.from.Excel)

can help us to help you.

Regards
Petr

> 
> On 08/21/2011 05:29 AM, nferr...@fceia.unr.edu.ar wrote:
> > Dear all
> >
> > i´m working with a program i´ve made in R (using functions that others
> > created)
> >
> > to run my program i need a sample. if i generate the sample using  for
> > example, rnorm(n, mu, sigma) i have no problem
> >
> > but if i obtain a sample from a column in excel and i copy it, the 
program
> > says that there is a mistake: it says "Error en `[.data.frame`(data,
> > indices) : undefined columns selected"
> >
> > my program is:
> >
> > d<- read.delim("clipboard", header = T, dec = ",")
> > #Para determinar los valores de las componentes del vector de 
capacidad es
> > necesario definir primero las especificaciones y el valor objetivo, T, 
así
> > como el máximo valor admitido para la proporción de producción no
> > conforme, a cada lado de los límites de especificaciones#
> > # Ingrese ahora el valor del límite inferior de especificaciones#
> > LIE<- 13
> > # Ingrese ahora el valor del límite superior de especificaciones#
> > LSE<- 17
> > # Ingrese ahora el valor objetivo#
> > T<- 14.5
> > # Ingrese ahora el máximo valor admitido para la proporción de 
producción
> > no conforme a cada lado de los límites de especificaciones#
> > MA<- 0.00135
> > D<- min ((LSE-T), (T-LIE))
> > compo1<- function(data, indices)
> > {
> > d<- data[indices]
> > n = length (d)
> > desvio<- sd(d)
> > y<- rep(1:n)
> > y[x<= mean(d)]<- 1
> > y[x>mean(d)]<- 0
> > RI1<- D/(3*desvio*2*mean(y))
> > RI2<- D/(3*desvio*2*(1-mean(y)))
> > return (min (RI1, RI2))
> > }
> > compo2<- function(data, indices)
> > {
> > d<- data[indices]
> > c2<- (abs(mean(d) - T))/D
> > return (1-c2)
> > }
> > compo3<-function(data, indices)
> > {
> > d<- data[indices]
> > n<- length (d)
> > y<- rep(1:n)
> > y[d<  LIE]<- 1
> > y[d>= LIE]<- 0
> > INFE<- mean (y);
> > y<- rep(1:n)
> > y[d>  LSE]<- 1
> > y[d<= LSE]<- 0
> > SUPE<- mean (y);
> > PPI<- (1 - INFE)/(1-MA)
> > PPS<- (1 - SUPE)/(1-MA)
> > return (min (PPI, PPS))
> > }
> > save(file = "compo1.RData")
> > save(file = "compo2.RData")
> > save(file = "compo3.RData")
> > compos<- function(data, indices)
> > {
> > d<- data[indices]
> > capacidad<- c(compo1(d), compo2(d), compo3(d))
> > return(capacidad)
> > }
> > save(file = "compos.RData")
> > require (boot)
> > vectorcapacidad<- boot (d, compos, R = 3000)
> >
> > ETC. ETC.
> >
> >
> >
> > WHEN I START MY PROGRAM WRITING:
> > d<- rnorm (n, mu, sigma)
> >
> > I HAVE NO PROBLEM. BUT WHEN I READ A VECTOR FROM EXCEL, R TELLS ME
> > "Error en `[.data.frame`(data, indices) : undefined columns selected"
> >
> >
> > CAN YOU HELP ME THANK YOU VERY MUCH!
> >
> > NOEMI FERRERI, ROSARIO, ARGENTINA
> > SCHOOL OF INDUSTRIAL ENGINEERING
> >
> Hi Noemi,
> Without some sample data, I can only guess, but I would first try saving 

> the Excel spreadsheet in CSV format and then reading the data in with 
> read.csv. This might solve your problem.
> 
> Jim
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] queue waiting times comparison

2011-08-18 Thread Petr PIKAL
Hi Jim

> 
> If those values represent response times in a system, then when I was
> responsible for characterizing what the system would do from the
> viewpoint of an SLA (service level agreement) with customers using the
> system, we usually specified that "90% of the transactions would have
> a response time of --- or less".  This took care of most "long tails".
>  So it depends on how you are planning to use this data.  We usually
> monitored the 90th or 95th percentile to see how a system was
> operating day to day.

I get the point. This can be an option. I will discuss it with my 
colleagues.

Thank you for your time and an answer.

Best regards
Petr

> 
> On Thu, Aug 18, 2011 at 8:52 AM, Petr PIKAL  
wrote:
> > Hallo Jim
> >
> > Thank you and see within text.
> >
> > jim holtman  napsal dne 18.08.2011 14:09:11:
> >
> >> I am not sure why you say that "lapply(ml, mean)" shows (incorrectly)
> >> that the second year has a larger average; it is correct for the 
data:
> >>
> >> > lapply(ml, my.func)
> >> $y1
> >> Count  MeanSD   MinMedian   90%   95%
> >>  Max   Sum
> >>  18.0  16.8  12.42980   4.0  12.5  37.2  41.05000
> >> 47.0 303.0
> >>
> >> $y2
> >> Count  MeanSD   MinMedian   90%   95%
> >>  Max   Sum
> >>  15.0  20.06667  25.27694   4.0  11.0  45.8  70.4
> >> 97.0 301.0
> >>
> >>
> >> You have a larger "outlier" in the second year that causes the mean 
to
> >> be higher.  The median is lower, but I usually look at the 90th
> >> percentile if I am looking at response time from a system and again
> >> the second year has a higher value.
> >>
> >> So exactly why do you not "trust" your data?
> >
> > Well. I trust them, however mean is "correct" central value only when 
data
> > are normally distributed or at least symmetrical. As the values are
> > heavily  distorted I feel that I shall not use mean for comparison of 
such
> > sets. Anyway t.test tells me that there is no difference between y2 
and
> > y1.
> >
> >> t.test(ml[[1]], ml[[2]])
> >
> >Welch Two Sample t-test
> >
> > data:  ml[[1]] and ml[[2]]
> > t = -0.452, df = 19.557, p-value = 0.6563
> > alternative hypothesis: true difference in means is not equal to 0
> > 95 percent confidence interval:
> >  -18.17781  11.71115
> > sample estimates:
> > mean of x mean of y
> >  16.8  20.06667
> >
> > So based on this I probably will never get conclusive result as sd due 
to
> > "outliers" will be quite high.
> >
> > When I do
> > plot(ecdf(ml[[2]]))
> > plot(ecdf(ml[[1]]), add=T, col=2)
> >
> > it seems to me that both sets are almost the same and they differ
> > substantially only with those "outlier" values.
> >
> > If I decreased small values of y2 (e.g.)
> >
> > ml[[2]][ml[[2]]<20] <- ml[[2]][ml[[2]]<20]/2
> >
> > I get same mean
> >
> > lapply(ml, mean)
> > $y1
> > [1] 16.8
> >
> > $y2
> > [1] 16.1
> >
> > and t.test tells me that there is no difference between those two 
sets,
> > although I know that most events take half of the time and only few 
last
> > longer so for me such set is better (we improved performance for most 
of
> > the time however there are still scarce events which take a long 
time).
> >
> > plot(ecdf(ml[[2]]))
> > plot(ecdf(ml[[1]]), add=T, col=2)
> >
> > So still the question stays - what procedure to use for comparison of 
two
> > or more sets with such long tailed distribution? - Trimmed mean?, 
Median?,
> > ...
> >
> > Thanks.
> >
> > Regards
> > Petr
> >
> >>
> >> On Thu, Aug 18, 2011 at 7:49 AM, Petr PIKAL 
> > wrote:
> >> > Hallo all
> >> >
> >> > I try to find a way how to compare set of waiting times during
> > different
> >> > periods. I tried learn something from queueing theory and used also 
R
> >> > search. There is plenty of ways but I need to find the easiest and
> > quite
> >> > simple.
> >> > Here is a list with actual waiting times.
> >> >
> >> > ml <- structure(list(y1 = c(10, 9, 9, 10, 8, 20, 16, 47, 4, 7, 15,
> >> > 18, 36, 5, 24, 15, 40, 10), y2 = c(97, 10, 26, 11,

[R] Odp: what characteristics of model curve do parameters denote

2011-08-18 Thread Petr PIKAL
Hi
> 
> Dear list,
> 
> I'm trying to fit a chapman-richards equation to my data, only I
> cannot interpret the parameters a, b and d. I know that the parameter
> b denotes the asymptote, but for the others I couldn't figure out. But

No. d Is asymptote. You can easily check how the function behives by

fff<- function(x, a=1,b=1,d=1) d*(1-exp(-b *x))^a

and changing the values of a,b,d,

plot(1:100, fff(1:100, a=..., b=..., d=...)

e.g. 

plot(1:100, fff(1:100, a=1000, b=1,d=10))
points(1:100, fff(1:100, a=1000, b=.1,d=10), col=2)

Regards
Petr


> I do need to know this in order to set my starting values. Here's the
> model:
> 
> modPoplar<- nls(Diameter ~ d*(1-exp(-b *Age))^a 
,start=list(a=20,b=0.9,d=33))
> 
> I attached the graph, too.
> 
> Hoping for your answers!
> 
> Best, Anna
> 
> -- 
> 
> 
> 
> Der Inhalt dieser E-Mail ist vertraulich. Sollte Ihnen die E-Mail
> irrtümlich zugesandt worden sein, bitte ich Sie, mich unverzüglich zu
> benachrichtigen und die E-Mail zu löschen.
> 
> This e-mail is confidential. If you have received it in error, please
> notify me immediately and delete it from your system.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] queue waiting times comparison

2011-08-18 Thread Petr PIKAL
Hallo Jim

Thank you and see within text.

jim holtman  napsal dne 18.08.2011 14:09:11:

> I am not sure why you say that "lapply(ml, mean)" shows (incorrectly)
> that the second year has a larger average; it is correct for the data:
> 
> > lapply(ml, my.func)
> $y1
> Count  MeanSD   MinMedian   90%   95%
>  Max   Sum
>  18.0  16.8  12.42980   4.0  12.5  37.2  41.05000
> 47.0 303.0
> 
> $y2
> Count  MeanSD   MinMedian   90%   95%
>  Max   Sum
>  15.0  20.06667  25.27694   4.0  11.0  45.8  70.4
> 97.0 301.0
> 
> 
> You have a larger "outlier" in the second year that causes the mean to
> be higher.  The median is lower, but I usually look at the 90th
> percentile if I am looking at response time from a system and again
> the second year has a higher value.
> 
> So exactly why do you not "trust" your data?

Well. I trust them, however mean is "correct" central value only when data 
are normally distributed or at least symmetrical. As the values are 
heavily  distorted I feel that I shall not use mean for comparison of such 
sets. Anyway t.test tells me that there is no difference between y2 and 
y1.

> t.test(ml[[1]], ml[[2]])

Welch Two Sample t-test

data:  ml[[1]] and ml[[2]] 
t = -0.452, df = 19.557, p-value = 0.6563
alternative hypothesis: true difference in means is not equal to 0 
95 percent confidence interval:
 -18.17781  11.71115 
sample estimates:
mean of x mean of y 
 16.8  20.06667 

So based on this I probably will never get conclusive result as sd due to 
"outliers" will be quite high.

When I do
plot(ecdf(ml[[2]]))
plot(ecdf(ml[[1]]), add=T, col=2)

it seems to me that both sets are almost the same and they differ 
substantially only with those "outlier" values.

If I decreased small values of y2 (e.g.)

ml[[2]][ml[[2]]<20] <- ml[[2]][ml[[2]]<20]/2

I get same mean

lapply(ml, mean)
$y1
[1] 16.8

$y2
[1] 16.1

and t.test tells me that there is no difference between those two sets, 
although I know that most events take half of the time and only few last 
longer so for me such set is better (we improved performance for most of 
the time however there are still scarce events which take a long time).

plot(ecdf(ml[[2]]))
plot(ecdf(ml[[1]]), add=T, col=2)

So still the question stays - what procedure to use for comparison of two 
or more sets with such long tailed distribution? - Trimmed mean?, Median?, 
...

Thanks.

Regards
Petr

> 
> On Thu, Aug 18, 2011 at 7:49 AM, Petr PIKAL  
wrote:
> > Hallo all
> >
> > I try to find a way how to compare set of waiting times during 
different
> > periods. I tried learn something from queueing theory and used also R
> > search. There is plenty of ways but I need to find the easiest and 
quite
> > simple.
> > Here is a list with actual waiting times.
> >
> > ml <- structure(list(y1 = c(10, 9, 9, 10, 8, 20, 16, 47, 4, 7, 15,
> > 18, 36, 5, 24, 15, 40, 10), y2 = c(97, 10, 26, 11, 11, 10, 5,
> > 13, 19, 5, 5, 59, 4, 16, 10)), .Names = c("y1", "y2"))
> >
> > par(mfrow=c(1,2))
> > lapply(ml, hist)
> >
> > shows that in the first year is more longer waiting times
> >
> > lapply(ml, mean)
> >
> > shows (incorrectly) that in the second year there is longer average
> > waiting time.
> >
> > lapply(ml, mean)
> >
> > gives me completely reversed values.
> >
> > Can you please give me some hints what to use for "correct" and 
"simple"
> > comparison of  waiting times in two or more periods.
> >
> > Thank you
> > Petr
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
> 
> 
> 
> -- 
> Jim Holtman
> Data Munger Guru
> 
> What is the problem that you are trying to solve?

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


[R] queue waiting times comparison

2011-08-18 Thread Petr PIKAL
Hallo all

I try to find a way how to compare set of waiting times during different 
periods. I tried learn something from queueing theory and used also R 
search. There is plenty of ways but I need to find the easiest and quite 
simple.
Here is a list with actual waiting times.

ml <- structure(list(y1 = c(10, 9, 9, 10, 8, 20, 16, 47, 4, 7, 15, 
18, 36, 5, 24, 15, 40, 10), y2 = c(97, 10, 26, 11, 11, 10, 5, 
13, 19, 5, 5, 59, 4, 16, 10)), .Names = c("y1", "y2"))

par(mfrow=c(1,2))
lapply(ml, hist)

shows that in the first year is more longer waiting times

lapply(ml, mean)

shows (incorrectly) that in the second year there is longer average 
waiting time.

lapply(ml, mean)

gives me completely reversed values.

Can you please give me some hints what to use for "correct" and "simple" 
comparison of  waiting times in two or more periods.

Thank you
Petr

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 get the descriptive statistic of the whole dataframe?

2011-08-18 Thread Petr PIKAL
Hi

> 
> look into the *apply series of functions. In your case
> 
> apply(name.of.your.data.frame,2,min)
> 
> or 
> 
> apply(name.of.your.data.frame,2,max)
> 
> will do. You can also put any summary function to your liking instead of
> min/max.

And summary has its own data frame method so simply

summary(name.of.your.data.frame)

There is also fivenum function and more elaborated describe in Hmisc I 
believe :-)

Regards
Petr

> 
> Best,
> Daniel
> 
> 
> Lao Meng wrote:
> > 
> > Hi all:
> > If I have a dataframe of N columns.If I wanna get the min(or max,or
> > mean...etc)of the whole dataframe,how to do it quickly?
> > What I can do is only:
> > min(data[,1:ncol(data)])
> > 
> > Any other suggestion?
> > 
> > Thanks!
> > 
> > best
> > 
> >[[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.
> > 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/How-to-get-
> the-descriptive-statistic-of-the-whole-dataframe-tp3751857p3752007.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] Odp: how to analysis a dataset with some missing value?

2011-08-18 Thread Petr PIKAL
Hi
> 
> my qustion is if my miss value in my dataset is -
> for example :
>   1 3 21 33 -  23  33  -
> how can I plot or analysis this dataset ignoring the missing value ? 
thanks
> .

Use NA instead of - and things will get better

x<-as.numeric(read.table(textConnection("1 3 21 33 -  23  33 -")))
y<- sample(x, 1000, replace=T)
plot(y)


y[y== -]<-NA
plot(y)
 
Regards
Petr

> 
> -- 
> TANG Jie
> 
>[[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] Chi square test on data frame

2011-08-18 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 17.08.2011 21:07:43:

> 
> Dear Michael,
> 
> Thanks a lot for your reply and for your help.I was struggling so much 
but
> your suggestion showed me a path to the solution of my problem.I have 
> tried your code on my data frame step wise and it looks fine to me.But 
> when i tried chi square test-
> 
> res=chisq.test(y1[id],p=y2[id],rescale.p=T)
> 
> Chi-squared test for given probabilities
> 
> data:  y1[id] 
> X-squared = NaN, df = 19997, p-value = NA
> 
> Warning message:
> In chisq.test(y1[id], p = y2[id], rescale.p = T) :
>   Chi-squared approximation may be incorrect

Check what Y1[id] is.

Split Yn to lists
l1<-split(Y1[id], rep(1:6, each=2))
l2<-split(Y2[id], rep(1:6, each=2))

do mapply on those list. But the result is rather silly as Michael pointed 
out.

mapply(chisq.test, l1, l2, SIMPLIFY=F)

or to get only p values

lapply(mapply(chisq.test, l1, l2, SIMPLIFY=F),"[", 3)

Regards
Petr

> 
> It is not giving p value.Then i checked observed and expected values,it 
is
> taking all numbers under consideration.but as i mentioned earlier i want 
p
> value for each row and therefore degree of freedom will be 1. example-
> 
> I have a data frame with 8 columns-
>   V1   V2   V3   V4  W1   W2W3   W4
> 1 084   22   10   0  84  0  0
> 2358400 22  84  0  0
> 3 0 0  0  48   0   00 48
> 4 04800   0  48   0  0
> 5 08400   0  84   0  0
> 6 0 00   48   0   00 48
> 
> example for first row is-
> 
> first two largest values are 84(in V2) and 22 (in V3).so these are 
> considered as observed values.Now if the largest values are in V2 and 
> V3,we have to pick expected values from W2 and W3 which are 84 and 0.I 
> know for chi square test values should not be 0 but we will ignore the 
warning.
> 
> now it should generate p value for next row taking 35 and 84 (v1 and v2) 

> as observed and 22 and 84 (w1 and w2) as expected.so here it will do chi 

> square test for all 6 rows and will generate 6 p values.My data frame 
has 
> lot of rows(approx. ).
> 
> Can you please help me with this.
> 
> 
> 
> Thanking you,
> Warm Regards
> Vikas Bansal
> Msc Bioinformatics
> Kings College London
> 
> From: R. Michael Weylandt [michael.weyla...@gmail.com]
> Sent: Wednesday, August 17, 2011 7:11 PM
> To: Bansal, Vikas
> Cc: r-help@r-project.org
> Subject: Re: [R] Chi square test on data frame
> 
> I think everything below is right, but it's all a little helter-skelter 
so
> take it with a grain of salt:
> 
> First things first, make your data with dput() for the list.
> 
> Y = structure(c(0, 35, 0, 0, 0, 0, 84, 84, 0, 48, 84, 0, 22, 0, 0,
> 0, 0, 0, 10, 0, 48, 0, 0, 48, 0, 22, 0, 0, 0, 0, 84, 84, 0, 48,
> 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 48, 0, 0, 48), .Dim = c(6L, 8L
> ), .Dimnames = list(c("1", "2", "3", "4", "5", "6"), c("V1",
> "V2", "V3", "V4", "W1", "W2", "W3", "W4")))
> 
> Now,
> 
> Y1 = Y[,1:4]
> Y2 = Y[,-(1:4)]
> 
> id = apply(Y1,1,order,decreasing=T)[1:2,]
> # This has the columns you want in each row, but it's not directly 
> appropriate for subsetting
> # Specifically, the problem is that the row information is implicit in 
> where the col index is in id
> # We directly extract and force into a 2-col vector that gives rows and 
> columns for each data point
> id = cbind(as.vector(col(id)),as.vector(id))
> 
> Now you can take
> 
> Y1[id] as the observed values and Y2[id] as the expected.
> 
> But, to be honest, it sounds like you have more problems in using a 
chi-sq
> test than anything else. Beyond all the zeros, you should note that you 
> always have #obs >= #expected because Y1>= Y2. I'll leave that up to you 
though.
> 
> Hope this helps and please make sure you can take my code apart piece by 

> piece to understand it: there's some odd data manipulation that takes 
> advantage of R's way of coercing matrices to vectors and if your actual 
> data isn't like the provided example, you may have to modify.
> 
> Michael Weylandt
> 
> On Wed, Aug 17, 2011 at 10:26 AM, Bansal, Vikas  mailto:vikas.ban...@kcl.ac.uk>> wrote:
> Is there anyone who can help me with chi square test on data frame.I am 
> struggling from last 2 days.I will be very  thankful to you.
> 
> Dear all,
> 
> I have been working on this problem from so many hours but did not find 
> any solution.
> I have a data frame with 8 columns-
>   V1   V2   V3   V4  W1   W2W3   W4
> 1 084   22   10   0  84  0  0
> 2358400 22  84  0  0
> 3 0 0  0  48   0   00 48
> 4 04800   0 

[R] Odp: write.table extra column

2011-08-15 Thread Petr PIKAL
Hi

> In the following data.frame there are 6 columns, but 7 are written to
> the CSV file.
> 
> install.packages("pmlr")
> library(pmlr)
> data(enzymes)
> write.table(enzymes, sep=",", eol="\n",file="albert.csv")

see row.names option in ?write.table

Regards
Petr

> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Renaming levels of a factor in a dataframe

2011-08-15 Thread Petr PIKAL
Hi
> 
> Here's an example of relevel used to relevel and combine groups
> 
> InsectSprays2<-InsectSprays
> levels(InsectSprays2$spray)
> 
levels(InsectSprays2$spray)<-list(new1=c("A","C"),YEPS=c("B","D","E"),LASTLY="F")
> levels(InsectSprays2$spray)
> InsectSprays2
> 
> So for you try...
> levels (Data1$Site) <- list(Fw =c( "AB"), Est = c("DE"))

Or simply 

levels (Data1$Site) <- c("Fw", "Est")

it is also pretty easy to change only some levels

> x.f
  [1] c a a e a d a d d e a c c c e c c a a b d b d b a e b a b a b d e e 
c b b
 [38] d c a d b a d e b d c e e d e a d e b c a d d c c b a a e c c c d c 
a d c
 [75] a a b a c c a e d d d e a e d d c a c c c d e a c d
Levels: a b c d e
> levels(x.f)[1:3]<-"A"
> x.f
  [1] A A A e A d A d d e A A A A e A A A A A d A d A A e A A A A A d e e 
A A A
 [38] d A A d A A d e A d A e e d e A d e A A A d d A A A A A e A A A d A 
A d A
 [75] A A A A A A A e d d d e A e d d A A A A A d e A A d
Levels: A d e
> levels(x.f)[2:3]<-c("x", "y")
> x.f
  [1] A A A y A x A x x y A A A A y A A A A A x A x A A y A A A A A x y y 
A A A
 [38] x A A x A A x y A x A y y x y A x y A A A x x A A A A A y A A A x A 
A x A
 [75] A A A A A A A y x x x y A y x x A A A A A x y A A x
Levels: A x y
>

Regards
Petr


>

> 
> 
> > From: deel...@hotmail.com
> > To: r-help@r-project.org
> > Date: Sun, 14 Aug 2011 12:56:25 -0300
> > Subject: [R] Renaming levels of a factor in a dataframe
> > 
> > 
> > 
> > Dear Helplist:
> > 
> > 
> > 
> > I am trying, unsuccessfully, to rename levels of a factor in a 
> dataframe. The dataframe consists of two factor variables and one 
numeric 
> variable as follows:
> > 
> > Factor Site has 2 levels AB and DE, factor Fish has 30 levels, 15 
> associated with each Site e.g. 1-1, 1-2,.2-1, 2-2 I am trying to 

> rename the levels of factor Site from AB to Fw and DE to Est while 
keeping
> them as factors. The following 2 approaches do not work, each giving a 
> NULL response and creating a character string. 
> > 
> > 
> > 
> > levels (Data1$Site <- c("Fw", "Est")) This simply gives an alternating 

> list of Fw, Est, Fw, Est... not the desired 15 concurrent rows of Fw 
> followed by 15 of Est.
> > 
> > 
> > 
> > #levels (Data1$Site <- list(Fw = "AB", Est = "DE")) This gives the 
same 
> result. I have tried other approaches to no avail. It seems a simple 
> problem but has not been so. 
> > 
> > 
> > 
> > Any suggestions for solving this problem would be much appreciated.
> > 
> > 
> > 
> > Regards,
> > 
> > BJ 
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/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.

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


Re: [R] To import data to R from Excel

2011-08-11 Thread Petr PIKAL
Hi
> 
> In Excel, make sure that your data has a format that corresponds to an R 

> data frame (first row with column names, consistent column size and data 
type).
> Export your .XLS worksheet as .CSV file (mydata.csv).
> In R, read it into a data frame with
> 
> > read.csv( "mydata.csv" ) 

Another option is simple copy/paste way.

In Excel select the data area you want to transfer (preferably formatted 
like stated above.
Press Ctrl-C
Change to R
In R command window write 

my.data.frame <- read.delim("clipboard",...further options according to 
your locale...)

Regards
Petr

> 
> >From here, you shold be able to reshapte the data in a way that you can 

> draw your boxplot.
> 
> Rgds,
> Rainer
> 
> 
> On Thursday 11 August 2011 11:29:23 Blessy chemmannur Francis wrote:
> > Sir,
> >   I am a beginner in R language. I want to import data from 
excel to
> > R. My data contains not only numeric values but also string values.I 
want to
> > draw a boxplot graph . I can't import or write this string data. it is
> > essential for my graph.Please give me a suggestion for This.
> >Thanking You,
> > 
> > 
> > BLESSY.C.F.
> > 
> >[[alternative HTML version deleted]]
> > 
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Odp: assign names to vectors in loop

2011-08-09 Thread Petr PIKAL
Hi

> Dear List,
> I like to assign names to vectors in a loop.
> Here is a short example:
> DMUs <-
> 
as.data.frame(matrix(c("b","c","d","a","e","h","i","f","g","j","k","l"),ncol
> =7, nrow=10))
> 
> colnames(DMUs) <- v_DMUs <- c("a","b","c","d","e","f","g")
> 
> for (i in v_DMUs)
> 
> assign(paste("eff_val",i,sep="."),abs(rnorm(10)))
> 
> Now I like to find a solution for applying following operation in a loop 
for
> all vectors eff_val.i (with i = a:g) and names in columns (columns i = 
a:g)
> of dataframe DMUs. Perhaps there is a solution without loop, too?!
> 
> names(eff_val.a) <- t(subset(DMUs, select="a"))
> 
> I tried the following. But this results in an error-message! 
> 
> for (i in v_DMUs)
> 
> names(paste("eff_val.",i,sep="")) <- t(subset(DMUs,select =
> paste("",i,sep="")))
> 
> 
> I don't know how to beat this bastard ;-)

Pardon me that I do not solve your problem in suggested way. I am not sure 
what you really want to do but seems to me that keeping your values in 
list could be faR betteR way.

#So i first made a vector from eff_val.x values
vec<-NULL
for (i in v_DMUs) vec<-c(vec,get(paste("eff_val.",i,sep="")))

#transform DMUs back to matrix 
mat<-as.matrix(DMUs)

#got rid of dimensons
dim(mat)<-NULL

#put names from mat and values from vec alongside to data frame
result<-data.frame(name=mat, num=vec)

#split the result to those seven chunks
split(result, rep(1:7, each=10)

I am almost sure that it is not what you was about but I feel that you 
shall give it a thought.

Lists are much more easier to handle with R then many variables with 
yy.xx.i names.

Regards
Petr

> 
> Thanks for your support. 
> Henning
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Odp: nls, how to determine function?

2011-08-09 Thread Petr PIKAL
Hi

> Hi R help,
> 
> I am trying to determine how nls() generates a function based on the
> self-starting SSlogis and what the formula for the function would be.
> I've scoured the help site, and other literature to try and figure
> this out but I still am unsure if I am correct in what I am coming up
> with.

Thanks for providing data and your code

> 
> 
> 
**
> dat <- c(75.44855206,NA,NA,NA,82.70745342,82.5335019,88.56617647,80.
> 00128866,94.15418227,86.63987539,93.91052952,74.10612245,86.62289562,90.
> 47961047,NA,NA,82.45320197,72.14371257,NA,71.44104803,72.59742896,68.
> 36363636,NA,NA,61,NA,NA,71.26502909,NA,85.9333,84.34248284,79.
> 00522193,79.64223058,97.2074017,88.43700548,96.40413877,95.13511869,92.
> 57379057,93.97498475,NA,97.55995131,89.53321146,97.21728545,93.21980198,
> 77.54054054,95.85392575,86.25684723,97.55325624,80.03950617,NA,91.
> 34023128,92.42906574,88.59433962,65.77272727,89.63772455,NA,NA,NA,NA,74.
> 86344239,83.57594937,70.22516556,65.30543319,NA,NA,67.84852294,60.
> 90909091,54.79303797,NA,52.18735363,33.47003155,NA,41.34693878,24.
> 5047043,NA,NA,NA,NA,9.9,13.6875,NA,11.90267176,84.14285714,3.
> 781456954,NA,1.432926829,4.26557377,1.823529412,0.444620253,4.
> 
711155378,NA,6.320284698,0.581632653,0.144578313,3.7,0,0,0,0,0,NA,
> 0.032947462,0,0,10.54545455,0,NA,0.561007958,0.75,NA,0.048780488,0.
> 74137931,NA,2.023339318,0,0,0,NA,NA,0.156950673,NA,0.283769634,32.
> 
81818182,NA,NA,0,NA,0,0,0,NA,0.212454212,3.120181406,NA,0.011811024,NA,0,
> 
0.120430108,5.928571429,1.75,0.679292929,0.97,NA,0,NA,NA,1,0.38547486,NA,
> 1.460732984,0.007795889,0.05465288,0.004341534)

> dat.df.1 <- data.frame(dat)
unnecessary

> dat.df.2 <- data.frame(x=x.seq, dat.df=dat.df.1)

some correction
dat.df.2 <- data.frame(x=seq_along(dat), dat=dat)

> fit.dat <-nls(dat ~ SSlogis(x, Asym, xmid,scal), data = dat.df.2,
> start =list(Asym=90, xmid = 75, scal = -6))
> plot(dat.df.2, axes=FALSE, ann=FALSE, ylim=c(0,100))
> lines(dat.df.2$x[complete.cases(dat.df.2)], predict(fit.dat), 
ylim=c(0,100))
> 
> summary(fit.dat)
> 
> 
**
> Formula: dat ~ SSlogis(x, Asym, xmid, scal)
> 
> Parameters:
>  Estimate Std. Error t value Pr(>|t|)
> Asym   85.651  1.716  49.900  < 2e-16 ***
> xmid   72.214  1.036  69.697  < 2e-16 ***
> scal   -6.150  0.850  -7.236  7.9e-11 ***
> ---
> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> 
> Residual standard error: 10.33 on 105 degrees of freedom
> 
> Number of iterations to convergence: 10
> Achieved convergence tolerance: 4.405e-06
>   (45 observations deleted due to missingness)
> 
**
> 
> >From r-help, SSlogis parameters asym, xmid and scal are defined as:
> 
> Asym: a numeric parameter representing the asymptote.
> 
> xmid: a numeric parameter representing the x value at the inflection
> point of the curve. The value of SSlogis will be Asym/2 at xmid.
> 
> scal: a numeric scale parameter on the input axis.
> 
> and it states that the value of SSlogis "is a numeric vector of the
> same length as input. It is the value of the expression
> sym/(1+exp((xmid-input)/scal)). If all of the arguments Asym, xmid,
> and scal are names of objects the gradient matrix with respect to
> these names is attached as an attribute named gradient."
> 
> However, how do I get the actual function for the curve that is
> generated? I don't think it can just be: y=
> asym/((1+e^((xmid-x)/scal)))?

Yes. I think that the best source of information about nonlinear 
regression is book by Bates, Pinheiro - Mixed effect models with S and S+. 
There you can find how to determine starting parameters, how to construct 
and use your own function together with selfstart feature.

> 
> Also, how do you determine the starting parameters to input in for
> asym, xmin, and scal?
> 
> Perhaps I need to start at the beginning and define my own function,
> and not rely on SSlogis to provide it?
> 
> What I want to be able to do is determine a local maximum for my curve
> (the x value at which this curve inflects (the upper inflection)), and
> the x value for the local minimum (the lower inflection curve), and
> the x value counts in between these values. I think in order to do
> this I need to differentiate the function.

Maybe I do not understand well but looking at the picture it seems to me 
that logistic model is fitting your data quite well. You can use also four 
parameter logistic model. 

> fit.dat.2 <-nls(dat ~ SSfpl(x, A, B, xmid,scal), data = dat.df.2, start 
=list(A=85.65, B=0, xmid = 72, scal = -6))
> summary(fit.dat.2)

Formula: dat ~ SSfpl(x, A, B, xmid, scal)

Parameters:
 Estimate Std. Error t value Pr(>|t|) 
A  1.6729 1.5927   1.0500.296 
B 85. 1.7065  50.134  < 2e-16 ***
xmid  71.7628 1.0762  66.679  < 2

r-help@r-project.org

2011-08-08 Thread Petr PIKAL
ult[5]<-ctver[4]
result[1]<-(ctver[1]-ctver[4]-result[3]*opak)/(volop*opak)
result[2]<-(ctver[2]-ctver[4]-result[3]*opak)/(volvzor*opak)

if (result[2]<0) result[2]<-0

result[4]<-result[2]+result[3]
result[6]<-result[4]+result[5]
result[7]<-result[1]+result[6]


result<-abs(result)
proc<-result/result[7]*100
smodch<-sqrt(result)
smodch5<-smodch*sigma
proc.smodch<-smodch/smodch[7]*100
proc.toler<-smodch5/toler*100

result<-cbind(result,smodch,smodch5,proc,proc.smodch,proc.toler)

result<-data.frame(result,row.names=c("Vzorky","Oper","Interakce","Reprod","Opak","O&R","Suma"))

meno<-c("rozptyl","smer.odch", "5.15 sm.odch" ,"proc.rozpt." 
,"proc.sm.odch", "toler.sm.odch")

velik<-dim(result)[2]

names(result)<-meno[1:velik]

suma<-summary(fit)

kateg<-trunc(smodch[1]/smodch[6]*1.41)+1

if (plotit) 

{

par(mfrow=c(3,2))
posice<-volvzor*1:volop
mat<-aggregate(vysledek,list(vzorek,operator),mean,na.rm=T)
mat1<-aggregate(vysledek,list(vzorek,operator),sd,na.rm=T)

#fig1

hmdm<-c(mean(mat$x)+(mean(mat1$x)/.9)/sqrt(opak)*3, 
mean(mat$x)-(mean(mat1$x)/.9)/sqrt(opak)*3)
plot(mat$x,type="b",ylab="Prumery")
abline(h=mean(mat$x),col=3)
abline(h=hmdm,col=2)
abline(v=posice+.5,col="grey",lwd=2,lty=2)
text(posice-volvzor/2,max(mat$x),levels(operator[,drop=T]))

#fig2
# mat<-reshape(mat,direction="wide",idvar="Group.1",timevar="Group.2")
# 
matplot(as.matrix(mat[,2:(1+volop)]),type="b",pch=1:volop,col=1:volop,ylab="Prumer",axes=F)
#   axis(side=1,at=1:volvzor,labels=levels(vzorek[,drop=T]))
#   box()
#   axis(2)
# 
legend(1,min(mat[,2:(1+volop)]),levels(operator[,drop=T]),pch=1:volop,col=1:volop,cex=.8,horiz=T,yjust=0,xjust=0)

 mat<-reshape(mat,direction="wide",idvar="Group.1",timevar="Group.2")

matplot(as.matrix(mat[,2:(1+volop)]),type="b",pch=1:volop,col=1:volop,ylab="Prumer",axes=F)
axis(side=1,at=1:volvzor,labels=levels(vzorek[,drop=T]))
box()
axis(2)

legend(1,min(mat[,2:(1+volop)]),levels(operator[,drop=T]),pch=1:volop,col=1:volop,cex=.8,horiz=T,yjust=0,xjust=0)


#fig3
hmdm<-c(mean(mat1$x)*sqrt(qchisq(.99865,opak,lower.tail=F)/(opak-1)), 
mean(mat1$x)*sqrt(qchisq(.99865,opak)/(opak-1)))

plot(mat1$x,type="b",ylab="Smerod. odch")
abline(h=mean(mat1$x),col=3)
abline(h=hmdm,col=2)
abline(v=posice+.5,col="grey",lwd=2,lty=2)
text(posice-volvzor/2,max(mat1$x),levels(operator[,drop=T]))


#fig4
boxplot(split(vysledek,operator),notch=T)
#fig5
barplot(t(as.matrix(result[c(1,4,5,6),4:velik])),beside=T)
#fig6
boxplot(split(vysledek,vzorek),notch=T)

par(mfrow=c(1,1))

mtext(paste("R+R analýza",  deparse(substitute(vysledek))), side=3, 
line=2, cex=1.5)


}
rozlis<-smodch[6]*qnorm(0.975)
list(tabulka=round(result,dig),vartab=suma,kategorie=kateg,rozlisitelnost=rozlis)


}


#


Elaine Jones  napsal dne 05.08.2011 21:41:10:

> 
> Hi Petr,
> 
> I found this post on the R-help website:
> http://www.mail-archive.com/r-help@r-project.org/msg00447.html
> 
> A coworker just asked me to help him with some GR&R studies.  Could you
> tell me  about how your function works? How is the input data 
structured?
> What is vysledek? (the response variable?)
> 
> I was surprised to see very few posts about GR&R on the R-help website, 
and
> packages.  Any help you can offer is appreciated.
> 
>   [R] Odp: GR&R - Best methods in R
> 
> 
>   Petr PIKAL
>   Mon, 17 Sep 2007 01:04:27 -0700
> 
> 
>   Hi
> 
>   below you can find a function I wrote to mimic a Minitab R+R
>   procedure. It
>   is intended for myself only so it is not commented. If you want to
>   know
>   how it functions contact me off-list.
> 
>   Regards
> 
>   Petr
> 
> 
> 
> Sincerely,
>  Elaine McGovern Jones 
> 
>Phone:  408  705-9588  Internal tieline: 587-9588
>jon...@us.ibm.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] Very silent R

2011-08-05 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 05.08.2011 15:21:34:

> khadeeja ismail  
> Odeslal: r-help-boun...@r-project.org
> 
> 
> 
> My version of R is not silent:
> 
> > setwd("/notHere")
> Error in base::setwd(dir) : cannot change working directory
> > library(is notHere)
> Error in library(notHere) : there is no package called 'notHere'
> 
> 
> That is the exact problem.
> If I type the above commands, R says nothing and just displays the 
prompt.
> > setwd("/notHere")
> >
> > library(is notHere)
> >

R version, OS?

You can try it with -vanilla switch when starting R session? This shall 
start plain R with only necessary packages and without any data.

Regards
Petr


> 
> ...and it is so annoying :\
> 
> Hajja
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Can you give the specific context in which you are using it.
> 
> On Fri, Aug 5, 2011 at 7:54 AM, khadeeja ismail  
wrote:
> > Dear List,
> >
> > How can I get R to display error messages, for example, if I try to 
> change to a non-existent directory or try to load a library that is not 
> installed? Currently R is very silent. I did fix the problem once using 
> 'options' (show.error.messages, I think), but id doesn't seem to be 
> working any more, and R doesn't tell me if I have an error in my 
command.
> > Please let me know how I can fix this.
> >
> > Regards,
> > Hajja
> >
> >
> >
> >[[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.
> >
> 
> 
> 
> -- 
> Jim Holtman
> Data Munger Guru
> 
> What is the problem that you are trying to solve?
> 
>[[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] fit a 2-variables function to data

2011-08-05 Thread Petr PIKAL
> 
> Thanks Petr for your response.
>  
> The function I wnat to fit is
>  
> y = (k1 * v2_Kd *p1^v2_h) / ( (v2_Kd^v2_h) + p1^v2_h ) ) * ( 1/(1 + (p6/
> v5_Kd)^v5_h) ) 
> where p1 and p2 are the independent variables. 
>  
> v2_K2, v2_h, v5_Kd and v5_h are the parameters I have to estimate.

In that case you should look to 
?nls or maybe ?optim

Regards
Petr

>  
> Paola.
> 
> 
>  
> On Fri, Aug 5, 2011 at 2:55 PM, Petr PIKAL  
wrote:
> Hi
> >
> > Dearl all,
> >
> > I have to fit a function
> >
> > y = f(x1, x2)
> > to data experiemntal data describing the measured behavior of y.
> >
> > x1 and x2 are the independent variables.
> >
> > Could you suggest me wich R package can I use for this purpose?

> ?nls
> ?lm
> ?loess
> ?glm
> 
> And there are plenty more if you do not stick to base packages. Hard to
> say without knowing what function do you want to use.
> 
> Regards
> Petr
> 
> 
> >
> > Thanks,
> > Paola.
> >
> >
> > --
> > *Paola Lecca, PhD*
> > *The Microsoft Research - University of Trento*
> > *Centre for Computational and Systems Biology*
> > *Piazza Manci 17 38123 Povo/Trento, Italy*
> > *Phome: +39 0461282843*
> > *Fax: +39 0461282814*
> >
> >[[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.

> 
> 
> 
> -- 
> Paola Lecca, PhD
> The Microsoft Research - University of Trento
> Centre for Computational and Systems Biology
> Piazza Manci 17 38123 Povo/Trento, Italy
> Phome: +39 0461282843
> Fax: +39 0461282814

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Odp: fit a 2-variables function to data

2011-08-05 Thread Petr PIKAL
Hi
> 
> Dearl all,
> 
> I have to fit a function
> 
> y = f(x1, x2)
> to data experiemntal data describing the measured behavior of y.
> 
> x1 and x2 are the independent variables.
> 
> Could you suggest me wich R package can I use for this purpose?

?nls
?lm
?loess
?glm

And there are plenty more if you do not stick to base packages. Hard to 
say without knowing what function do you want to use.

Regards
Petr


> 
> Thanks,
> Paola.
> 
> 
> -- 
> *Paola Lecca, PhD*
> *The Microsoft Research - University of Trento*
> *Centre for Computational and Systems Biology*
> *Piazza Manci 17 38123 Povo/Trento, Italy*
> *Phome: +39 0461282843*
> *Fax: +39 0461282814*
> 
>[[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] Very silent R

2011-08-05 Thread Petr PIKAL
> 
> My version of R is not silent:

Neither mine

> library(akima)
Error in library(akima) : there is no package called ‘akima’
>

Regards
Petr

> 
> > setwd("/notHere")
> Error in base::setwd(dir) : cannot change working directory
> > library(notHere)
> Error in library(notHere) : there is no package called 'notHere'
> 
> 
> 
> Can you give the specific context in which you are using it.
> 
> On Fri, Aug 5, 2011 at 7:54 AM, khadeeja ismail  
wrote:
> > Dear List,
> >
> > How can I get R to display error messages, for example, if I try to 
> change to a non-existent directory or try to load a library that is not 
> installed? Currently R is very silent. I did fix the problem once using 
> 'options' (show.error.messages, I think), but id doesn't seem to be 
> working any more, and R doesn't tell me if I have an error in my 
command.
> > Please let me know how I can fix this.
> >
> > Regards,
> > Hajja
> >
> >
> >
> >[[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.
> >
> 
> 
> 
> -- 
> Jim Holtman
> Data Munger Guru
> 
> What is the problem that you are trying to solve?
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Odp: Scatter plot in R

2011-08-05 Thread Petr PIKAL
Hi
> 
> Hi,
> 
> I have 334 records, with two columns:
> 
> Column (1): Resolution Column (2): Number of images with a specific
> resolution
> 
> How can I make a scatter plot in R with this data? Is there a way to 
*import

If you have your data in two column data frame you can just

plot(your.data.frame)

> * the records, since it will be time consuming to enter 334 records?

Where do you have those 334 records. If on paper I can not see any other 
way then manually enter the records into computer. If they are aready in 
some kind of file you can use

read.table or its relatives see
?read.table

But without being more specific you can get only vague answers.

Regards
Petr


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


[R] Odp: excel dates and times in R

2011-08-05 Thread Petr PIKAL
Hi
> 
> Hello,
> 
> I am having some fun dealing with dates and times. My input is a excel 
csv
> file with two columns with data in the following format: 
> 
> date   time
> 25-Jun-1961   04:00:00
> 
> i.e. day - month - year   hour:min:sec
> 
> I would like to have a single object in R that combines these and 
converts
> them into a sensible R format (e.g.
> ISOdatetime(1961,06,25,04,00,00,tz="GMT"). 
> 
> I have played with the function chron and also strptime but can't seem 
to
> get them to work. 

Maybe you did not set appropriate locale. See
Sys.getlocale()

> Sys.setlocale("LC_TIME","us")
[1] "English_United States.1252"
> strptime(paste(date, time, sep=" "), format="%d-%b-%Y %H:%M:%S")
[1] "1961-06-25 04:00:00"
>

But AFAIK Jun is used in Great Britain similarly like in US so you shall 
not have problems.

Regards
Petr

> 
> Can anybody help me out please? 
> 
> Thanks
> 
> Bevare
> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/excel-dates-
> and-times-in-R-tp3720887p3720887.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] Odp: A problem of is.list function

2011-08-05 Thread Petr PIKAL
Hi
> 
> Hi all
> 
> I want to use function of is.list and is.data.frame in if-else 
statement,
> but I get a trouble. To replicate this trouble, I run codes like that:
> 
> > set.seed(123)
> > x <- rnorm(100)
> > x <- data.frame(matrix(x, 10, 10))
> > class(x)
> [1] "data.frame"
> > is.list(x)
> [1] TRUE
> > is.data.frame(x)
> [1] TRUE
> 
> > version
>_
> platform   i386-pc-mingw32
> arch   i386
> os mingw32
> system i386, mingw32
> status
> major  2
> minor  13.1
> year   2011
> month  07
> day08
> svn rev56322
> language   R
> version.string R version 2.13.1 (2011-07-08)
> 
> 
> The class of x is data frame, but when I use is.list, I also get a TRUE
> result. Why does this happen?

R-intro document which shall be included in any installation tells you 
about data frame

6.3 Data frames
A data frame is a list with class "data.frame". There are restrictions on 
lists that may be made into data frames, namely 
The components must be vectors (numeric, character, or logical), factors, 
numeric matrices, lists, or other data frames. 
Matrices, lists, and data frames provide as many variables to the new data 
frame as they have columns, elements, or variables, respectively. 
Numeric vectors, logicals and factors are included as is, and character 
vectors are coerced to be factors, whose levels are the unique values 
appearing in the vector. 
Vector structures appearing as variables of the data frame must all have 
the same length, and matrix structures must all have the same row size. 

Regards
Petr


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

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


[R] Odp: Translate Sine Function in R?

2011-08-05 Thread Petr PIKAL
Hi

Are you sure about sine fit? Seems to me that logistics would be better

fit<-nls(dat ~ SSlogis(x, Asym, xmid,scal), data = dat.df, start = 
list(Asym=90, xmid = 75, scal = -6))
plot(dat.df)
lines(dat.df$x[complete.cases(dat.df)], predict(fit))

Regards
Petr



> 
> Hello, I'm trying to generate a sine wave in R to fit my observations 
using
> the general formula:
> 
> y=a*sin(b[x+h*pi)]+k
> 
> where a = amplitude, b=period, h=phase shift, and k=vertical shift
> 
> I want to use following translation to bring the sine function up onto 
the
> y-axis to range from 0-1, and this will place the wave on the x-axis 
from
> 0-pi/2.
> 
> y=1/2sin(2[x+ 1/4*pi]) + 1/2
> 
> Additionally, I need to spread this along a x-axis that spans 1-153 
(days).
> 
> Can anyone help with this? I seem to be able to use the curve function 
fine,
> but entering the translations doesn't seem to provide an answer.
> 
> Here is an example of the data set I am trying to 'match' using this
> function.
> 
> dat <-
> 
c(75.44855206,NA,NA,NA,82.70745342,82.5335019,88.56617647,80.00128866,94.
> 15418227,86.63987539,93.91052952,74.10612245,86.62289562,90.
> 47961047,NA,NA,82.45320197,72.14371257,NA,71.44104803,72.59742896,68.
> 36363636,NA,NA,61,NA,NA,71.26502909,NA,85.9333,84.34248284,79.
> 00522193,79.64223058,97.2074017,88.43700548,96.40413877,95.13511869,92.
> 57379057,93.97498475,NA,97.55995131,89.53321146,97.21728545,93.21980198,
> 77.54054054,95.85392575,86.25684723,97.55325624,80.03950617,NA,91.
> 34023128,92.42906574,88.59433962,65.77272727,89.63772455,NA,NA,NA,NA,74.
> 86344239,83.57594937,70.22516556,65.30543319,NA,NA,67.84852294,60.
> 90909091,54.79303797,NA,52.18735363,33.47003155,NA,41.34693878,24.
> 5047043,NA,NA,NA,NA,9.9,13.6875,NA,11.90267176,84.14285714,3.
> 781456954,NA,1.432926829,4.26557377,1.823529412,0.444620253,4.
> 
711155378,NA,6.320284698,0.581632653,0.144578313,3.7,0,0,0,0,0,NA,
> 0.032947462,0,0,10.54545455,0,NA,0.561007958,0.75,NA,0.048780488,0.
> 74137931,NA,2.023339318,0,0,0,NA,NA,0.156950673,NA,0.283769634,32.
> 
81818182,NA,NA,0,NA,0,0,0,NA,0.212454212,3.120181406,NA,0.011811024,NA,0,
> 
0.120430108,5.928571429,1.75,0.679292929,0.97,NA,0,NA,NA,1,0.38547486,NA,
> 1.460732984,0.007795889,0.05465288,0.004341534)
> plot(dat/100)
> par(new=F)
> x.seq <- seq(100, 0, , 153)
> y <- ??? #*y = 2 sin 2Ď€ (x - 1/4)* or y ~ a + c*sin(x+b)
> 
> However, I can't find a reference for the no place for k. Also, I've 
tried a
> lot of different iterations, but can't seem to figure out how to do this 
in
> R.
> 
> Any thoughts or ideas on this?
> 
> Thank you,
> 
> Katrina
> 
>[[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] Odp: How to see the previous commands after save workspace/load workspace ?

2011-08-04 Thread Petr PIKAL
Hi

> 
> I did save workspace and when I load it, I can see the variables,
> using ls().
> But I cannot see the commands from the program I saved. How to do
> that?

Perhaps you can check .Rhistory file.

Regards
Petr

> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Odp: Counting rows given conditional

2011-08-04 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 04.08.2011 14:56:09:

> a217  
> Odeslal: r-help-boun...@r-project.org
> 
> 04.08.2011 14:56
> 
> Komu
> 
> r-help@r-project.org
> 
> Kopie
> 
> Předmět
> 
> [R] Counting rows given conditional
> 
> Hello,
> 
> I have an input file that contains multiple columns, but the column I'm
> concerned about looks like:
> 
> "TR"
> 5
> 0
> 4
> 1
> 0
> 2
> 0
> 
> To count all of the rows in the column I know how to do NROW(x$TR) which
> gives 7.
> 
> However, I would also like to count only the number of rows with values 
>=1
> (i.e. not 0). I've tried NROW(x$TR>=1) which did not give the intended
> output.

You are quite close. 
x$TR>=1
gives you logical vector TRUE/FALSE. You can compute count of TRUE values 
by
sum(logical.vector) e.g.
sum(x$TR>=1)

Regards
Petr



> 
> Do any of you have any suggestions as to where I'm going wrong?
> 
> 
> 
> --
> View this message in context: 
http://r.789695.n4.nabble.com/Counting-rows-
> given-conditional-tp3718541p3718541.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] Odp: conditional data replace (recode, change or whatsoever)

2011-08-03 Thread Petr PIKAL
Hi
> 
> Hello,
> I have a big data.frame, a piece of it as follows.
> 
> a   b  c   d
> 1   58009   2010-11-02   0   NA
> 2   114761   NA  1   2008-11-05
> 3   184440   NA  1   2009-12-08
> 4   189372   NA  0   NA
> 5   105286   NA  0   NA
> 6   186717   NA  0   NA
> 7   189106   NA  0   NA
> 8   127306   NA  0   NA
> 9   157342   2011-04-25   0   NA
> 
> I want to replace b[NA] values with "20011-07-28" where c==0. I use 
rstudio
> and i'm a novice.

I believe there are better solutions but I would use two steps

select rows where c==0 (see also FAQ 7.31)
sel<-which(big.data.frame$c==0)

change NA values in b column based on sel
big.data.frame$b[sel][is.na(big.data.frame$b[sel])]<-"20011-07-28"

Beware of data types AFAIK R can not accept "20011-07-28" as a date.

Regards
Petr

> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/conditional-
> data-replace-recode-change-or-whatsoever-tp3714715p3714715.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] Odp: Using Function

2011-08-02 Thread Petr PIKAL
Hi

> 
> Hi,
> 
> I have some simple statistics to calculate for a large 
> number of variables.
> I created a simple function to apply to variables.
> I would like the variable name to be placed automatically.
> I tried the following function but is not working.
> 
> desc = function(x){
>  media = mean(x, na.rm=T)
>  desvio = sd(x, na.rm=T)
>  cv = desvio/media*100
>  saida = cbind(media, desvio, cv)
>  colnames(saida) = c(NULL, 'Média', 
> 'Desvio', 'CV')
>  rownames(saida) = c(x)
>  saida
>  }

You are quite close. This seems to do what you want if I presume that your 
variables are located in data frame

desc = function(x){
 media = mean(x, na.rm=T)
 desvio = sd(x, na.rm=T)
 cv = desvio/media*100
 saida = data.frame(Media=media, Desvio=desvio, CV=cv)
 saida
 }

iris4 <- iris[,1:4]

sapply(iris4, desc)
   Sepal.Length Sepal.Width Petal.Length Petal.Width
Media  5.84 3.0573333.7581.199333 
Desvio 0.82806610.4358663   1.765298 0.7622377 
CV 14.17113 14.2564246.97441 63.55511 

If you want switch rows and cols use 

t(sapply(iris4, desc))

Regards
Petr


> 
> desc(Idade)
> 
>  Média  Desvio  CV
> Idade 44.04961 16.9388 38.4539
> 
> How do you get the variable name is placed as the first 
> element?
> 
> My objective is get something like:
> 
> rbind(
> desc(Altura),
> desc(Idade),
> desc(IMC),
> desc(FC),
> desc(CIRCABD),
> desc(GLICOSE),
> desc(UREIA),
> desc(CREATINA),
> desc(CTOTAL),
> desc(CHDL),
> desc(CLDL),
> desc(CVLDL),
> desc(TRIG),
> desc(URICO),
> desc(SAQRS),
> desc(SOKOLOW_LYON),
> desc(CORNELL),
> desc(QRS_dur),
> desc(Interv_QT)
> )
> 
> Thanks a lot,
> 
> --
> Silvano Cesar da Costa
> Departamento de Estatística
> Universidade Estadual de Londrina
> Fone: 3371-4346
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Standard Deviation of a matrix

2011-08-02 Thread Petr PIKAL
Hi

>  Hi!
> 
> The sample below should give you what you want:
> 
> M = matrix(runif(100), 10, 10)
> sd(as.numeric(M))
> 
> So the as.numeric command is the key. It transforms the matrix to a 1D
> vector. Or alternatively without using as.numeric:
> 
> M = matrix(runif(100), 10, 10)
> M
> dim(M) = 100

or dim(M)<-NULL

> M
> sd(M)
> 
> Here I use the dim command to set the dimensions to a vector of 100 
long.
> 
> cheers,
> Paul
> 
> On 08/02/2011 11:07 AM, chakri wrote:
> > Hello,
> >
> > My R knowledge could not take me any further, so this request !
> >
> > I have a matrix of dimensions (1185 X 1185). I want to calculate 
standard
> > deviation of entire matrix. 
> > sd function of {stats} calculates standard deviation for each 
row/column,
> > giving 1 X 1185 matrix as result. I would like to have 1 X 1 matrix as
> > result.
> >
> > Any ideas, how to do this ?
> >
> > TIA
> > Chakri 
> >
> > --
> > View this message in context: http://r.789695.n4.nabble.com/Standard-
> Deviation-of-a-matrix-tp3711991p3711991.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.
> 
> 
> -- 
> Paul Hiemstra, Ph.D.
> Global Climate Division
> Royal Netherlands Meteorological Institute (KNMI)
> Wilhelminalaan 10 | 3732 GK | De Bilt | Kamer B 3.39
> P.O. Box 201 | 3730 AE | De Bilt
> tel: +31 30 2206 494
> 
> http://intamap.geo.uu.nl/~paul
> http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] if function problems

2011-08-02 Thread Petr PIKAL
Hi

another possibility is to use logical values properties

> (x < 0)*x
[1] -3 -2 -1  0  0  0  0

Regards
Petr

> 
> In addition to what David said:
> 
> On Mon, Aug 1, 2011 at 6:57 PM, zoe_zhang <1987.zhan...@gmail.com> 
wrote:
> > Dear All,
> > Sorry to bother
> > I want to write a function in R using if
> > Say I have a dataset x,
> > if x[i]<0, then x[i]=x[i],
> > if x[i]>0, then x[i]=0
> >
> > for example, x=-3:3,
> > then using the function, x becomes [-3,-2,-1,0,0,0,0]
> >
> > I write the codes as follows,
> >
> > gjr=function(x)
> > {lena=length(x)
> > for(i in 1:lenx)
> > if (x[i]<0) return (x[i])
> > if (x[i]>0) return (0)
> > x}
> >
> > but then, doing
> > gjr(x)
> > it only comes out with one number
> >
> > Does anyone have any suggestions?
> 
> You define `lena`, but then use `lenx` in `for (i in 1:lenx)` in your
> function ... I guess this might have something to do with it.
> 
> You shouldn't use a for loop, though, and just follow david's advice
> by using logical indexing, or the `ifelse` function, ie:
> 
> R> ifelse(x < 0, x, 0)
> 
> HTH,
> -steve
> 
> -- 
> Steve Lianoglou
> Graduate Student: Computational Systems Biology
>  | Memorial Sloan-Kettering Cancer Center
>  | Weill Medical College of Cornell University
> Contact Info: http://cbio.mskcc.org/~lianos/contact
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Odp: converting factor to numeric gives "NAs introduced by coercion"

2011-08-01 Thread Petr PIKAL
Hi

> Hi,
> 
> I have a dataframe that I imported from a .txt file by:
> 
> skogTemp <- read.delim2("Skogaryd_shoot_data.txt", header=TRUE, 
fill=TRUE)
> 
> and the data are factors, how can avoid factors from the beginning? 
Although
> the file contains both characters and numbers.

You have got an answer but here are some comments. If you have characters 
and numbers in one column the character values are converted to NA by 
as.numeric

> 
> I tried to convert some of the columns from factor to numeric and as I
> understood it you can not use only as.numeric but as.character first. I 
got
> this warning message:
> 
> > skogTemp_1 <- as.numeric(as.character(skogTemp_1[,2:4]))
> Warning message:
> NAs introduced by coercion 

What is skogTemp_1? I presume skogTemp is data frame and in that case you 
can not use such construction directly.

> 
> I have lots of NAs in my data. Tries to check what class I had now but
> another warning is given me:
> > class(skogTemp_1[,2])


skogTemp_1 is probably a vector with only one dimension therefore you get 
this error.
class(skogTemp_1)

shall give you the desired result, however I prefer 

?str

Regards
Petr

> Error in skogTemp_1[, 2] : incorrect number of dimensions
> > class(skogTemp_1[1,2])
> Error in skogTemp_1[1, 2] : incorrect number of dimensions
> 
> frustrating... I don't know what this mean.
> 
> Can anyone help?
> 
> Thank you,
> Angelica
> 
> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/converting-
> 
factor-to-numeric-gives-NAs-introduced-by-coercion-tp3703408p3703408.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] Odp: Multifactor boxplots

2011-07-29 Thread Petr PIKAL
Hi

> 
> Dear All
> 
> I would like to produce interaction boxplots and this seems to work:
> 
> par(mfrow=c(2,2))
> A=sample(rnorm(50,50,10))
> B=sample(rnorm(50,100,10))
> Test=merge(A,B,by=0)#by=0 where 0 is the row.names
> TreatA=(gl(2,50,100,labels=c("High","Low")))
> TreatB=rep(gl(2,25,50,labels=c("High","Low")),2)
> Newdata=data.frame(TreatA,TreatB,Test)
> 
> bwplot(x~TreatA:TreatB,data=Newdata)
> 
> However, I would prefer the X axis labels to be different, such that 
there
> are two label rows (TreatA and TreatB) something like this:
> 
> TreatAHigh HighLow   Low
> TreatBHigh Low High  Low
> 
> any guidance on achieving this much appreciated.

Combination of axes=FALSE

boxplot(x~TreatA:TreatB,data=Newdata, axes=F)

and following axis and mtext commands seems to do what you want
axis(2)
axis(1, at= 1:4,labels=c("H", "H", "L", "L"))


Regards
Petr

>

> 
> Regards
> 
> Tom
> 
> 
>[[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] Big data and column correspondence problem

2011-07-26 Thread Petr PIKAL
Hi

> Re: [R] Big data and column correspondence problem
> 
> Daniel, thanks for the answer.
> I will try to make myself i little bit clearer. Doing step by step I 
would
> have (using a loop trough the lines of 'A'):

I am not sure if you are successful in your clarifying.

> 
> 1. AA[1] is 4. As so, I would have to compare A1[1] = 20 and A2[1] =3 
with

I can not see A1[1]=20 in your example data.

> A[1,]
AA A1 A2 
 4  3  3 

gives me this.


> 
>B1 B2 B3
> B[3,2:4] 7 11 NA

Why B[3,]? 

> 
> beacause BB[3]=4. Since there is no match, this would retrieve me a 
zero.
> The same would happen with AA[2]. For AA[3] I have 
> 
>  AA A1 A2
> [3,]  4 11  7
> 
> Since  both A1[3] = 20 and A2[3] =3 match with B[3,2:4] this would 
retrieve
> me 1.

In what sense those two lines match?
A[3,]
AA A1 A2 
 4  5  5 
B[3,]
BB B1 B2 B3 
 4  7 11 NA 

I must say I am completely lost.

Maybe you could try to present a code with your toy data which give 
desired result but is too slow with original data.

Regards
Petr


> 
> 2. For AA[4:5] i would have to compare each line with B[1:2,2:4]. That 
is,
> for AA[4]=2 i have a match with BB[1] and BB[2]. Then I have to compare
> 
>   A1 A2
> [4,]  5  5
> 
> with 
> 
>B1 B2 B3
> B[1,2:4] 5  3  12
> 
> and
> 
> B1 B2 B3
> B[2,2:4] 11 12 13
> 
> Again, for A1[4] and A2[4] and would have no match. But A1[5] and A1[5]
> match with B2[1] and B1[1].
> 
> 3. And so on for the other lines of A.
> 
> The problem is that if I perform that as a loop it really takes to long.
> Hope i could make it clearer.
> 
> --
> View this message in context: 
http://r.789695.n4.nabble.com/Big-data-and-
> column-correspondence-problem-tp3694912p3695795.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] Odp: How to merge a matrix and a dataframe with different types of columns

2011-07-25 Thread Petr PIKAL
Hi


> [R] How to merge a matrix and a dataframe with different types of 
columns
> 
> Hi,
> 
> 
> 
> I hope someone can help here.  I have been scratching my head for many
> hours, trying to find out how to merge two datasets that were created by
> different means. The initial miniMarket contains dates without
> discontinuities (weekends).  This matrix was created using seq and has a
> character nature right now.
> 
> 
> 
> > miniMarket
> 
> [1] "2011-07-22" "2011-07-21" "2011-07-20" "2011-07-19" "2011-07-18"
> "2011-07-17" "2011-07-16" "2011-07-15"
> 
> [9] "2011-07-14" "2011-07-13" "2011-07-12" "2011-07-11" "2011-07-10"
> "2011-07-09" "2011-07-08" "2011-07-07"
> 
> [17] "2011-07-06" "2011-07-05" "2011-07-04" "2011-07-03"
> 

Hm. You are not telling the whole story

 typeof(seq(as.Date(Sys.time())-100, as.Date(Sys.time()),10) )
[1] "double"

 str(seq(as.Date(Sys.time())-100, as.Date(Sys.time()),10) )
 Date[1:11], format: "2011-04-16" "2011-04-26" "2011-05-06" "2011-05-16" 
...
 
> 
> 
> > typeof(miniMarket)
> 
> [1] "character"
> 

Anyway, you can change it to date by as.Date function.


> 
> 
> The miniTechies dataframe was the resulted of a sql query and had a 
double
> nature (typeof), despite of being presented as a date 
> 
> 
> 



> 
> When I try to merge them by the dates, I fail
> 
> > mergedM <- as.matrix(merge(miniMarket,miniTechies[,2],by=1,all=TRUE))

Why as.matrix? this transforms it to matrix which needs to have the same 
type of data so R tries it best to transform everithing to suit this 
condition.

what do you mean by=1

By my opinion you need

Convert both sets to data frame and for further operation to name the 
columns you want to merge by with the same name.

Transform values in both common columns to the same type of data, in your 
case most probably by as.Date

do
mergedM <- merge(df1, df2, all=T)

Regards
Petr

BTW I needed to look at merge help page and the same should do you.

> 
> Warning message:
> 
> In `[<-.factor`(`*tmp*`, ri, value = c(20L, 19L, 18L, 17L, 16L,  :
> 
>   invalid factor level, NAs generated
> 
> 
> 
> > mergedM
> 
>   x 
> 
>  [1,] "2011-07-03"
> 
> [2,] "2011-07-04"
> 
> [3,] "2011-07-05"
> 
> [4,] "2011-07-06"
> 
> [5,] "2011-07-07"
> 
> [6,] "2011-07-08"
> 
> [7,] "2011-07-09"
> 
> [8,] "2011-07-10"
> 
> [9,] "2011-07-11"
> 
> [10,] "2011-07-12"
> 
> [11,] "2011-07-13"
> 
> [12,] "2011-07-14"
> 
> [13,] "2011-07-15"
> 
> [14,] "2011-07-16"
> 
> [15,] "2011-07-17"
> 
> [16,] "2011-07-18"
> 
> [17,] "2011-07-19"
> 
> [18,] "2011-07-20"
> 
> [19,] "2011-07-21"
> 
> [20,] "2011-07-22"
> 
> [21,] NA 
> 
> [22,] NA 
> 
> [23,] NA 
> 
> [24,] NA 
> 
> [25,] NA
> 
> 
> 
> I didn't try to reproduce the means to create these datasets because I 
don't
> really understand how the Date is being represented in the miniTechies
> dataframe.
> 
> 
> 
> Could anyone provide me some hint on how to merge these datasets. What I
> want is a dataset with all dates and not only dates for which there is 
data
> on the miniTechies dataframe.
> 
> 
> 
> Thanks,
> 
> 
> 
> Marco
> 
> 
>[[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Problem with random number simulation

2011-07-25 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 25.07.2011 05:23:51:

> Re: [R] Problem with random number simulation
> 
> Hi,
> 
> I was just hoping someone could try running the program to see if they 
get
> any output.  This is independent research.  I just need to run this
> simulation to see how a computer could be manipulated given certain
> conditions in the Von Neumann game.
> 
> Currently, my code is not giving any errors, but there is no output 
either. 
> I type "x" afterwards and nothing happens. 


I got many errors the first one is

+ {
+ if(y[count] {
+

And it is really difficult to debug such code in R. Maybe you could put it 
in a function and try 

?debug 

to see what values you get in each line of code

Regards
Petr



> 
> I can add comments but I don't know how to edit the original post.
> 
> 
> 
> --
> View this message in context: 
http://r.789695.n4.nabble.com/Problem-with-
> random-number-simulation-tp3691308p3691619.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] Odp: Using t tests

2011-07-08 Thread Petr PIKAL
Hi

> [R] Using t tests
> 
> Dear Sir,
> 
> I am doing some work on a population of patients. About half of them are 
 
> admitted into hospital with albumin levels less than 33. The other half 
have 
> albumin levels greater than 33, so I stratify them into 2 groups, x and 
y 
> respectively.
> 
> I suspect that the average length of stay in hospital for the group of 
> patients (x) with albumin levels less than 33 is greater than those with 

> albumin levels greater than 33 (y).
> 
> What command function do I use (assuming that I will be using the chi 
> square test) to show that the length of stay in hospital of those in 
group x is 
> statistically significantly different from those in group y?

I am not an expert statistician but you suggested t test which seems to me 
appropriate.

About how to use it see

?t.test

Regards
Petr

> 
> I look forward to your thoughts.
> 
> Ivo Gwanmesia
> 
>[[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] Odp: coefficients lm of data.frame

2011-07-07 Thread Petr PIKAL
Hi

divide and conquer

Split your data frame to required portions

dat<-as.data.frame(cbind(rnorm(1:12),rnorm(1:12)))
dat.s<-split(dat, rep(1:4, each=3))

apply lm to each portion

sapply(dat.s, function(x) coef(lm(V2~V1, x)))
 1  2  3  4
(Intercept) 1.21745328 -0.7783777 -0.1736094  0.1042114
V1  0.03639838  2.6203724  1.3167433 -0.2350888
 
Add those values to your data frame.

hint: use rep(..., each=4)

Regards
Petr


r-help-boun...@r-project.org napsal dne 07.07.2011 16:09:51:

> Alfredo Alessandrini  
> Odeslal: r-help-boun...@r-project.org
> 
> 07.07.2011 16:09
> 
> Komu
> 
> r-help@r-project.org
> 
> Kopie
> 
> Předmět
> 
> [R] coefficients lm of data.frame
> 
> Hi,
> 
> I've a data frame like this:
> 
> > as.data.frame(cbind(rnorm(1:12),rnorm(1:12)))
> V1  V2
> 1  -1.30849402 -0.52094136
> 2   0.96157302  0.76217871
> 3  -0.44223351 -1.72630871
> 4  -0.10432438 -1.04732942
> 5  -1.38748914  0.95877311
> 6  -0.63965975  0.65494811
> 7  -0.24058318  0.19496830
> 8  -0.11172988  1.01680655
> 9   0.08065333  0.22168589
> 10  0.25196536  0.84619914
> 11 -0.59536986 -0.08243074
> 12  1.09115054  0.49822977
> 
> I need to add two columns as result of the fitting of linear model
> based on a preset numbers of row.
> 
> For example if I need to compute a lm each 4 rows, I get the
> data.frame below, where intercept1 and coeff1 is obtained from V1 and
> V2 of first 4 rows lm(V2 ~ V1), and so on...
> 
> 
>   V1  V2 "intercept" "coeff"
> 1   0.6931694  0.05797771   intercept1   coeff1
> 2  -1.4069786  0.23983307   intercept1  coeff1
> 3  -1.4901708  0.45079601   intercept1   coeff1
> 4   0.2215696  1.87888983   intercept1   coeff1
> 5  -0.5828106  0.90376622   intercept2   coeff2
> 6  -0.7607985  0.71419938   intercept2   coeff2
> 7   0.1273495  0.06199312   intercept2   coeff2
> 8  -0.5612245  1.02223971   intercept2  coeff2
> 9  -0.1439178  0.92135354   intercept3   coeff3
> 10 -1.1011662  0.02894731   intercept3   coeff3
> 11 -0.4098710 -0.01231322   intercept3   coeff3
> 12  1.1511811 -0.63923140   intercept3   coeff3
> 
> 
> Thanks in advance,
> 
> Alfredo
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Odp: aggregation question

2011-07-07 Thread Petr PIKAL
OK

> Petr,
> 
> Maybe I did not make it clear, I apologize for that:
> 
> I want January to December on the X Axis (as 12 discrete (months))
> and then for each month the values for each year as bars in
> different colors next to each other, ie Jan-2009, Jan-2011,
> Jan-2011...Dec-2009, Dec-2011, Dec-2011 whereas at the moment I get
> Jan-2009, Feb-2009, Mar-2009...Oct-2011, Nov-2011, Dec-2011

Well you can look at examples of barplot, especially this one

barplot(VADeaths, beside = TRUE,
col = c("lightblue", "mistyrose", "lightcyan",
"lavender", "cornsilk"),
legend = rownames(VADeaths), ylim = c(0, 100))
title(main = "Death Rates in Virginia", font.main = 4)


If you look at VADeaths structure you see you need some structured data

x<-seq(as.Date("2000/1/1"), by="month", length.out=24)
x.m<-aggregate(1:24, list(format(x, "%m"), format(x, "%Y")), sum)
x.m
   Group.1 Group.2  x
1   012000  1
2   022000  2
3   032000  3
4   042000  4
5   052000  5


and you can use e.g. xtabs or maybe cast from reshape package

x.xt<-xtabs(x~Group.1+Group.2,x.m)
barplot(x.xt, beside=TRUE, col=rainbow(12))
x.xt<-xtabs(x~Group.2+Group.1,x.m)
barplot(x.xt, beside=T, col=1:2)

Or you could look at ggplot2 package.

Regards
Petr




> 
> In SQL something like GROUP BY MONTH, YEAR as opposed to GROUP BY
> YEAR, MONTH.
> 
> greetings, el
> 
> on 2011-07-07 11:08 Petr PIKAL said the following:
> [...]
> >> How do I get the monthly aggregated payments in different colors
> >> next to each other (ie for each year in a different color with the x
> >> axis showing the months)?
> > 
> > What about putting suitable set of colours to col argument?
> > 
> > Regards
> > Petr
> [...]
> 
> -- 
> Dr. Eberhard W. Lisse  \/ Obstetrician & Gynaecologist (Saar)
> e...@lisse.na el108-ARIN / * |   Telephone: +264 81 124 6733 (cell)
> PO Box 8421 \ /   Please do NOT email to this address
> Bachbrecht, Namibia ;/if it is DNS related in ANY way

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

2011-07-07 Thread Petr PIKAL
Hi
> 
> Hi,
> 
> I am reading payment data like so
> 
> 2010-01-01,100.00
> 2010-01-04,100.00
> ...
> 2011-01-01,200.00
> 2011-01-07,100.00
> 
> and plot it aggregated per month like so
> 
> library(zoo)
> df <- read.csv("daily.csv", colClasses=c(d="Date",s="numeric"))
> z <- zoo(df$s, df$d)
> z.mo <- aggregate(z, as.yearmon, sum)
> barplot(z.mo, col="darkblue")
> 
> How do I get the monthly aggregated payments in different colors
> next to each other (ie for each year in a different color with the x
> axis showing the months)?

What about putting suitable set of colours to col argument?

Regards
Petr


> 
> Solution preferred, but pointers to documentation welcome :-)-O
> 
> greetings, el
> -- 
> Dr. Eberhard W. Lisse  \/ Obstetrician & Gynaecologist (Saar)
> e...@lisse.na el108-ARIN / * |   Telephone: +264 81 124 6733 (cell)
> PO Box 8421 \ /   Please do NOT email to this address
> Bachbrecht, Namibia ;/if it is DNS related in ANY way
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Odp: defining new variable

2011-07-01 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 01.07.2011 14:32:31:

> B Marktplaats  
> Odeslal: r-help-boun...@r-project.org
> 
> 01.07.2011 14:32
> 
> Komu
> 
> r-help@r-project.org
> 
> Kopie
> 
> Předmět
> 
> [R] defining new variable
> 
> Hello,
> 
> I'm new to R and I'm trying to define new quite simple variable but I'm
> struggling with R syntax (when coming to dates) for a while and still
> getting   on it.
> 
> I would be very grateful if someone could help me with this, to be able 
to
> move on.
> 
> I have the following variables:
> 
>  - Transplant.date
>  - Faildate
>  - Death.date
> 
> The new variable Time should do the following thing:
> 
> Time <-
> 
>  If Not IsNull() Then DaysBetween( 
,)
> Else If IsNull() And Not IsNull() Then
> DaysBetween( ,) Else If IsNull() 
And
> IsNull() Then DaysBetween( ,CurrentDate())

I bet there is more elegant solution but

with such data frame you can

> df
  td fd dd
1 2011-06-11 2011-06-16   
2 2011-06-122011-06-22
3 2011-06-132011-06-23
4 2011-06-142011-06-24
5 2011-06-15  

df$days<-rowSums(sapply(df[,2:3], "-", df$td), na.rm=T)

Then you can check for NA values in fd and dd and change respective values 
by 

df$days[rowSums(is.na(df[,2:3]))==2] <- 
Sys.Date()-df$td[rowSums(is.na(df[,2:3]))==2]
df
  td fd dd days
1 2011-06-11 2011-06-16   5
2 2011-06-122011-06-22   10
3 2011-06-132011-06-23   10
4 2011-06-142011-06-24   10
5 2011-06-15 16
>

Regards
Petr


> 

> 
> 
> 
> Thank you very much!!
> 
> Laura
> 
>[[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] Odp: Find the function of a line

2011-06-29 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 29.06.2011 11:38:17:

> Ida Dolciotti  

> Hello everybody,
> 
> I have drawn a line in a x y plot  that links the minimum and maximum 
> points in the plot
> 
> plot(xx,yy)
> 
> a=max(yy)
> b=min(yy)
> 
> lines(c(xx[yy==a],xx[yy==b]),c(a,b))
> 
> Now I would like to know if it is possible to extrapolate the 
> characteristic of the line (intercept and slope).
> 
> Is it there and appropriate function for this?

Maybe ?abline

Regards
Petr


> 
> Thanks for your help!
> 
> Ida D.
> 
> -- 
> Ida Dolciotti, M.Sc.
> Phd student, Dept. System Ecotoxicology
> Helmholtz Centre for Environmental Research - UFZ
> Permoserstr. 15
> 04318 Leipzig
> 
> phone:   +49 - 341/235-1498
> fax:+49 - 341/235-1785
> 
> email: ida.dolcio...@ufz.de
> website: http://www.ufz.de/index.php?en=17738
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Odp: data.frame: How to get the classes of all components and how to remove their factor structure?

2011-06-28 Thread Petr PIKAL
> 
> Dear expeRts,
> 
> I have two questions concerning data frames:
> (1) How can I apply the class function to each component in a 
data.frame? 
> As you can see below, applying class to each column is not the right 
> approach; applying it to each component seems bulky.
> (2) After transforming the data frame a bit, the classes of certain 
> components change to factor. How can I remove the factor structure?
> 
> Cheers,
> 
> Marius
> 
> x <- c(2004:2010, 2002:2011, 2000:2011)
> df <- data.frame(x=x, group=c(rep("low",7), rep("middle",10), 
rep("high",12)), 
>  y=x+100*runif(length(x))) 
> 
> ## Question (1): why do the following lines do not give the same 
"class"?
> apply(df, 2, class)
> class(df$x)
> class(df$group)
> class(df$y)
> 
> df. <- as.data.frame(xtabs(y ~ x + group, data=df))
> 
> class(df.$x)
> class(df.$group)
> class(df.$Freq)
> 
> ## Question (2): how can I remove the factor structure from x?
> df.$x <- as.numeric(as.character(df.$x)) # seems bulky; note that 

If you do it often you can

unfactor <- function(x) as.numeric(as.character(x))
df.$x <- unfactor(df.$x)

or you can use 
df. <- as.data.frame(xtabs(y ~ x + group, data=df), 
stringsAsFactors=FALSE)
df.$x <- as.numeric(df.$x)

But it seems to me that it is not much less bulkier.

Regards
Petr


> as.numeric(df.$x) is not correct
> class(df.$x)
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Odp: data.frame: How to get the classes of all components and how to remove their factor structure?

2011-06-28 Thread Petr PIKAL
Hi

> Dear expeRts,
> 
> I have two questions concerning data frames:
> (1) How can I apply the class function to each component in a 
data.frame? 
> As you can see below, applying class to each column is not the right 
> approach; applying it to each component seems bulky.
> (2) After transforming the data frame a bit, the classes of certain 
> components change to factor. How can I remove the factor structure?
> 
> Cheers,
> 
> Marius
> 
> x <- c(2004:2010, 2002:2011, 2000:2011)
> df <- data.frame(x=x, group=c(rep("low",7), rep("middle",10), 
rep("high",12)), 
>  y=x+100*runif(length(x))) 
> 
> ## Question (1): why do the following lines do not give the same 
"class"?

from help page
?apply
Arguments
X
an array, including a matrix.

array is not a data frame

> apply(df, 2, class)
> class(df$x)
> class(df$group)
> class(df$y)

sapply(df, class)
x group y 
"integer"  "factor" "numeric" 


> 
> df. <- as.data.frame(xtabs(y ~ x + group, data=df))
> 
> class(df.$x)
> class(df.$group)
> class(df.$Freq)
> 
> ## Question (2): how can I remove the factor structure from x?
> df.$x <- as.numeric(as.character(df.$x)) # seems bulky; note that 
> as.numeric(df.$x) is not correct

Actually it is correct in a sense it behaves as documented

?factor

Warning
The interpretation of a factor depends on both the codes and the "levels" 
attribute. Be careful only to compare factors with the same set of levels 
(in the same order). In particular, as.numeric applied to a factor is 
meaningless, and may happen by implicit coercion. To transform a factor f 
to approximately its original numeric values, as.numeric(levels(f))[f] is 
recommended and slightly more efficient than as.numeric(as.character(f)). 


Regards
Petr

> class(df.$x)





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

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


Re: [R] create a new data frame after comparing two columns of the previous data frame

2011-06-27 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 28.06.2011 02:45:01:

> 
> Right. You forgot the comma!

If you want to resolve this rather cryptic advice see

?"["

Regards
Petr

> 
> -- 
> David.
> 
> On Jun 27, 2011, at 7:10 PM, Nanami wrote:
> 
> > it's a table; I read it from a file; I've tried to make it look 
> > prettier:
> >
> >> head(intra)
> > chr   miRNA   start end   strand  ACC
> > hsa_ID   region region_start region_end
> > chr1 miRNA 1102484 1102578  +   ACC="MI342"; ID="hsa- 
> > mir-200b";
> > exon  11024841102578
> > chr1 miRNA 1103243 1103332  +   ACC="MI737"; ID="hsa- 
> > mir-200a";
> > exon  11032431103332
> > chr1 miRNA 1104385 1104467  +   ACC="MI0001641";  ID="hsa- 
> > mir-429";
> > exon  11043851104467
> > chr1 miRNA 3044539 3044599  +   ACC="MI0015861"; ID="hsa- 
> > mir-4251";
> > exon  30445393044599
> > chr1 miRNA 3477260 3477354  -   ACC="MI0003556"; ID="hsa- 
> > mir-551a";
> > exon  34772603477354
> > chr1 miRNA 6489894 6489956  -   ACC="MI0015864"; ID="hsa- 
> > mir-4252";
> > exon  64898946489956
> >
> >
> > When I changed && with &  I got this error:
> >
> >> new <- intra[(intra$start != intra$region_start )&(intra$end !=
> >> intra$region_end)]
> > Error in `[.data.frame`(intra, (intra$start != intra$region_start) &
> > (intra$end !=  :
> >  undefined columns selected
> >
> > What I would like to do is to create a new table that only contains 
> > the rows
> > for which column start and region_start are not the same.
> >
> >
> >
> > --
> > View this message in context: http://r.789695.n4.nabble.com/create-a-
> new-data-frame-after-comparing-two-columns-of-the-previous-data-frame-
> tp3628981p3629092.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.
> 
> David Winsemius, MD
> West Hartford, CT
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Odp: counting columns that fulfill specific criteria

2011-06-27 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 24.06.2011 16:51:27:

> 
> Thanks for your reply, but that is not quite what I am looking for...I 
do not
> want to add up all the values in the row, I want to get the number of
> columns in each row that meet the criteria and then get that as a
> percentage
> 
> my understanding is that the rowSums function adds up the values does it
> not? I tried your code anyways and it did not work:
> 
> Error in abs(pwdiff) >= t : 
>   comparison (5) is possible only for atomic and list types

That is why some ***reproducible code*** shall be provided from your side

rowSums(USArrests>50)/ncol(USArrests)*100

gives no error and the result tells you percentage of columns for which in 
each row holds that the number is greater than 50. This may be what you 
want.

rowSums(USArrests>50)

simply tells you how many values in each row are greater than specified 
threshold and dividing it by total number of columns gives you percentage.

The error you got means that pwdiff is probably not data frame or t is 
probably not one number. Only you can know that.

For evaluating your objects you can try

str(pwdiff)
str(t)

Besides t is a function or transposing data so you shall find some 
different name for your constant.

Regards
Petr
 

> 
> and when specifying the columns
> (perc[x]<-rowSums(pwdiff[,abs(pwdiff[x,])>=thr], na.rm=T)/ncol(pwdiff)), 
I
> get the following error:
> 
> Error in rowSums(pwdiff[, abs(pwdiff[x, ]) >= thr], na.rm = T) : 
>   'x' must be an array of at least two dimensions
> In addition: There were 30 warnings (use warnings() to see them)
> > warnings()
> Warning messages:
> 1: In perc[x] <- rowSums(pwdiff[, abs(pwdiff[x, ]) >= thr],  ... :
>   number of items to replace is not a multiple of replacement length
> ...
> 
> 
> Ive been trying to sort this out for the past three days and cannot get 
it
> to work for some reason...I can do it SO easily in excel with a simple
> macro, but doing that on a 48x780 table inevitably crashes the
> computer...
> 
> Any more help you can provide would be great, thanks!
> 
> 
> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/counting-
> columns-that-fulfill-specific-criteria-tp3622265p3622711.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] Odp: counting columns that fulfill specific criteria

2011-06-24 Thread Petr PIKAL
Hi


> Hi,
> 
> I have a matrix (pwdiff in the example below) with ~48 rows and 780
> columns.
> For each row, I want to get the percentage of columns that have an 
absolute
> value above a certain threshold "t". I then want to allocate that 
percentage
> to matrix 'perc' in the corresponding row. Below is my attempt at doing
> this, but it does not work: I get 'replacement has length zero'. Any 
help
> would be much appreciated!!
> 
> perc<-matrix(c(1:nrow(pwdiff)))
> for (x in 1:nrow(pwdiff))
> perc[x]<-(((ncol(pwdiff[,abs(pwdiff[x,]>=t)]))/ncol(pwdiff))*100)

As 
> matrix(c(1:nrow(pwdiff)))
Error in nrow(pwdiff) : object 'pwdiff' not found
>

gives an error we cannot directly check your code.

>From what you say it seems to me that you want something like

 rowSums(pwdiff>=t, na.rm=T)/ncol(pwdiff)*100

or maybe

rowSums(abs(pwdiff)>=t, na.rm=T)/ncol(pwdiff)*100

but I can be completely wrong.

Regards
Petr

> 
> I should add that my data has NAs in some rows and not others (but I do 
not
> want to just ignore rows that have NAs)
> 
> Thanks!
> 
> Paul
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/counting-
> columns-that-fulfill-specific-criteria-tp3622265p3622265.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] else problem

2011-06-24 Thread Petr PIKAL
Hi
> 
> Thank you for all your help! I did not know to use "" when searching for 

> help, as ?mean, etc, had always worked for me in the past. 
> It makes perfect sense why 'else' was causing me the trouble the way I 
was
> using it. I think it was working in my other code, despite the same 
> format, because it was part of a function and thus would have been 
> executed completely within the function?

Yes and no

if you made your function like that

fff<-function(x)
if (x>0) print("A")
else print("B")

you would get immediate error

> else {
Error: unexpected 'else' in "else"

So you probably enclosed whole function into brackets like

fff<-function(x) {
if (x>0) print("A")
else print("B")
}

and in that case you did not experienced this else problem not because it 
is a function but because you used those brackets.

Regards
Petr



> Cheers,
> Kara
> 
> From: Bert Gunter [gunter.ber...@gene.com]
> Sent: June 23, 2011 8:27 AM
> To: David Winsemius
> Cc: Kara Przeczek; r-help@r-project.org
> Subject: Re: [R] else problem
> 
> Perhaps some additional clarification...  (???)
> 
> >> if (length(dat2f$year)%%2==0) {
> >>  md <-dat2f[, list(med_year = max(year[which(abs(tot_km3y -
> >> median(tot_km3y)) == min(abs(tot_km3y - median(tot_km3y ]), 
med_TotQ =
> >> median(tot_km3y))]  }
> >> else {
> >
> > If this line is executed at a console session it will fail because the
> > interpreter does not keep a copy of the last condition. If you moved 
the
> > closing curley-brace to just befor the 'else', you should get the 
behavior
> > you expect (if your other code is correct):
> 
> Well, um.. not sure if this is what you meant, but what is happening
> at the console is that when you type , the interpreter checks
> for a syntactically complete statement. If it finds what has been
> given to it **thus far** is, it tries to execute it (if not, it gives
> a continuation character and waits for more input) and, as you said,
> then starts anew to interpret the next line(s) entered, "forgetting"
> all previous. The problem above is that the" if()" statement up to the
> close bracket, "}" is syntactically complete, and so the "else{" that
> follows makes no sense as the beginnig of a new line to  be
> interpreted.
> 
> The simplest and universal solution to this is to simply enclose the
> whole conditional in" { }":
> 
> {if(length ...
> ...
> else {...}
> }
> 
> This forces the interpreter to wait for the last "}" before it will
> interpret and execute.
> 
> Hoping this clarifies rather than obfuscates.
> 
> -- Bert
> 
> 
> 
> >
> > Try instead:
> >
> > if (length(dat2f$year)%%2==0) {
> >  md <-dat2f[, list(med_year = max(year[which(abs(tot_km3y -
> > median(tot_km3y)) == min(abs(tot_km3y - median(tot_km3y ]), 
med_TotQ =
> > median(tot_km3y))]
> > } else {
> >  md <-dat2f[, list(med_year = year[which(tot_km3y == 
median(tot_km3y))],
> > med_TotQ = median(tot_km3y))]
> >  }
> >
> >
> >>  md <-dat2f[, list(med_year = year[which(tot_km3y == 
median(tot_km3y))],
> >> med_TotQ = median(tot_km3y))]
> >>  }
> >>
> >> Each individual piece works perfectly on its own, but together I get 
the
> >> following error:
> >>
> >>> if (length(dat2f$year)%%2==0) {
> >>
> >> +   md <-dat2f[, list(med_year = max(year[which(abs(tot_km3y -
> >> median(tot_km3y)) == min(abs(tot_km3y - median(tot_km3y ]), 
med_TotQ =
> >> median(tot_km3y))] }
> >>>
> >>> else {
> >>
> >> Error: unexpected 'else' in "else"
> >>>
> >>>  md <-dat2f[, list(med_year = year[which(tot_km3y == 
median(tot_km3y))],
> >>> med_TotQ = median(tot_km3y))]
> >>>  }
> >>
> >> Error: unexpected '}' in "  }"
> >>>
> >>
> >> When I tried to look up "else" I got this error:
> >>
> >>> ?else
> >>
> >> Error: unexpected 'else' in "?else"
> >
> > Try instead:
> >
> > ?"else"
> >
> > --
> > David
> >>
> >> I have used exactly the same set up with if...else in other code and 
it
> >> worked fine then. I tried to run it again, and I got the same error 
as
> >> above. What is the problem? I hope it isn't something simple and 
silly!
> >>
> >> I realize that I can use the first line:
> >>
> >>  md <- dat2f[, list(med_year = max(year[which(abs(tot_km3y -
> >> median(tot_km3y)) == min(abs(tot_km3y - median(tot_km3y ]), 
med_TotQ =
> >> median(tot_km3y))]
> >>
> >> for all data sets and it will give me the median for both odd and
> >> even-length data sets, but it is now about the principle; why won't 
the
> >> if...else work?
> >>
> >> Thank you very much for your time!
> >>
> >> Kara
> >
> > David Winsemius, MD
> > West Hartford, CT
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
> 
> 
> 
> --
> "Men by nature long to get on to the ultimate truths, and will often
> be impatient with el

Re: [R] Fastest way of finding if any members of vector x fall in the range of the rows of matrix y

2011-06-24 Thread Petr PIKAL
Hi


> Hi Dimitris,
> Thanks for your reply. But this is not exactly what i am after. I want 
to
> find the probes that falls into certain regions. In your solution it 
will
> ignore the second probe if it falls into the same region as the first 
one.
> Is there any vector trickb uilt in R to find whether probes fall into
> certain regions?
> best,
> salih

Can you explain what is probe and what is region and how Dimitri's code 
failed to do what you wanted?

Only if x is between y values you get one number in check negative and one 
positive and their multiplication is therefore lower than zero.

Regards
Petr


> 
> On Fri, Jun 24, 2011 at 10:23 AM, Dimitris Rizopoulos <
> d.rizopou...@erasmusmc.nl> wrote:
> 
> > One approach is the following:
> >
> > x <- rnorm(5)
> > y <- matrix(rnorm(5*2), 5, 2)
> >
> > check <- y - x
> > check[, 1] * check[, 2] < 0
> >
> >
> > I hope it helps.
> >
> > Best,
> > Dimitris
> >
> >
> >
> > On 6/24/2011 10:57 AM, Salih Tuna wrote:
> >
> >>  Hi All,
> >> What is the fastest way of finding if any members of vector x fall in 
the
> >> range of the rows of matrix y?
> >> I do not want to use two for loops as this will take forever.
> >> Any help will be appreciated,
> >> best,
> >> salih
> >>
> >>[[alternative HTML version deleted]]
> >>
> >> __**
> >> R-help@r-project.org mailing list
> >> https://stat.ethz.ch/mailman/**listinfo/r-help mailman/listinfo/r-help>
> >> PLEASE do read the posting guide http://www.R-project.org/**
> >> posting-guide.html 
> >> and provide commented, minimal, self-contained, reproducible code.
> >>
> >>
> > --
> > Dimitris Rizopoulos
> > Assistant Professor
> > Department of Biostatistics
> > Erasmus University Medical Center
> >
> > Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
> > Tel: +31/(0)10/7043478
> > Fax: +31/(0)10/7043014
> > Web: http://www.erasmusmc.nl/**biostatistiek/ biostatistiek/>
> >
> 
>[[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] strange date problem - May 3, 1992 is NA

2011-06-23 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 22.06.2011 20:40:39:

> On 6/22/2011 1:34 PM, Sarah Goslee wrote:
> > On Wed, Jun 22, 2011 at 2:28 PM, David Winsemius 
 wrote:
> >>
> >> On Jun 22, 2011, at 2:03 PM, Sarah Goslee wrote:
> >>
> >>> Hi,
> >>>
> >>> On Wed, Jun 22, 2011 at 11:40 AM, Alexander Shenkin 

> >>> wrote:
> >
> > is.na(strptime("5/2/1992", format="%m/%d/%Y"))
> 
>  [1] FALSE
> >
> > is.na(strptime("5/3/1992", format="%m/%d/%Y"))
> 
>  [1] TRUE
> >>>
> >>> I can't reproduce your problem on R 2.13.0 on linux:
> >>
> >> I also cannot reproduce it on a Mac with 2.13.0 beta
> > 
> > Which strongly suggests that you should start by upgrading your R
> > installation if at all possible.
> > 
> > I'd also recommend trying it on a default R session, with no extra
> > packages loaded, and no items in your workspace. It's possible that
> > something else is interfering.
> > 
> > On linux, that's achieved by typing R --vanilla at the command line.
> > I'm afraid I don't know how to do it for Windows, but should be
> > similarly straightforward.
> > 
> Thanks Sarah.  Still getting the problem.  I should surely upgrade, but
> still, not a bad idea to get to the bottom of this, or at least have it
> documented as a known issue.  BTW, I'm on Windows 7 Pro x64.
> 

Can not reproduce on Windows 2000 on R2.12.0dev (2.13.0 and 2.14.0dev)


> is.na(strptime("5/3/1992", format="%m/%d/%Y"))
[1] FALSE
> sessionInfo()
R version 2.12.0 Under development (unstable) (2010-05-31 r52164)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=Czech_Czech Republic.1250  LC_CTYPE=Czech_Czech 
Republic.1250 
[3] LC_MONETARY=Czech_Czech Republic.1250 LC_NUMERIC=C  
[5] LC_TIME=Czech_Czech Republic.1250 

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

other attached packages:
[1] lattice_0.18-8 fun_1.0 

loaded via a namespace (and not attached):
[1] grid_2.12.0  tools_2.12.0
> 


So either some problem with your installation or your OS.
Regards
Petr


> (running Rgui.exe --vanilla):
> 
> > is.na(strptime("5/3/1992", format="%m/%d/%Y"))
> [1] TRUE
> 
> > is.na(strptime("5/2/1992", format="%m/%d/%Y"))
> [1] FALSE
> 
> > sessionInfo()
> R version 2.12.1 (2010-12-16)
> Platform: i386-pc-mingw32/i386 (32-bit)
> 
> locale:
> [1] LC_COLLATE=English_United States.1252
> [2] LC_CTYPE=English_United States.1252
> [3] LC_MONETARY=English_United States.1252
> [4] LC_NUMERIC=C
> [5] LC_TIME=English_United States.1252
> 
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods   base
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Odp: Replace selected columns of a dataframe with NA

2011-06-20 Thread Petr PIKAL
Hi

> 
> I am using the following command to replace all the missing values and
> assorted typos in a dataframe with NA:
> 
> mydata[mydata>80]=NA
> 
> The problem is that the first column contains values which should be
> more than 80, so really I want to do it just for
> mydata[,2:length(mydata)]
> 
> I can't seem to re-write the code to fit:
> 
> mydata[,2:length(mydata)>80]=NA # no error message, but doesn't work-
> doesn't do anything, it would seem

mydata[,-1][mydata[,-1]>80]<-NA

shall do what you want

Regards
Petr

> 
> I realise I can just keep the first column somewhere safe and copy it
> back again when I'm done, but I wondered if there was a more elegant
> solution, which would be much more important, if say I just wanted to
> replace the odd columns, or something like that.
> 
> I found this code on the internet too:
> 
> idx <- which(foo>80, arr.ind=TRUE)
> foo[idx[1], idx[2]] <- NA
> 
> But I can't seem to rewrite that either, for the same reason
> 
> Many thanks!
> 
> Chris Beeley
> Institute of Mental Health
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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 get the miminum value in the list

2011-06-20 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 19.06.2011 20:45:04:

> 
> Hi:
> 
> It's just an extra step:
> 
> y <- list(list(c(1,5),c(2,3,4)), list(c(1, 3, 4), c(5, 7)))
> lapply(seq_len(length(y)), function(i) lapply(y[[i]], min))
> [[1]]
> [[1]][[1]]
> [1] 1
> 
> [[1]][[2]]
> [1] 2
> 
> [[2]]
> [[2]][[1]]
> [1] 1
> 
> [[2]][[2]]
> [1] 5
> 
> unlist(lapply(seq_len(length(y)), function(i) lapply(y[[i]], min)))
> [1] 1 2 1 5

Or you can use rapply

rapply(y, min)
[1] 1 2 1 5

Regards

Petr

> 
> HTH,
> Dennis
> 
> On Sun, Jun 19, 2011 at 8:25 AM, jiliguala  wrote:
> >
> > but in my case, the list is a two-variable list, list[[j]][[i]]
> >
> > when i use
> >
> > lapply(list, min)
> >
> > it appears
> > """Error in FUN(X[[1L]], ...) : invalid 'type' (list) of argument"""
> >
> > thanks
> >
> > --
> > View this message in context: 
http://r.789695.n4.nabble.com/how-to-get-
> the-miminum-value-in-the-list-tp3609013p3609433.html
> > Sent from the R help mailing list archive at Nabble.com.
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Replacing values without looping

2011-06-17 Thread Petr PIKAL
Hi

> Hi,
> 
> If you truly have an array, this is option that should be much faster
> than a loop:
> 
> index <- which(is.na(dat))
> dat[index] <- dat[index - 1]
> 
> the only catch is that when there previous value is NA, you may have
> to go through the process a few times to get them all.  One way to
> automate this would be:
> 
> index <- which(is.na(dat))
> 
> while (any(index)) {
>   dat[index] <- dat[index - 1]
>   index <- which(is.na(dat))
> }
> 
> If your dataset has many adjacent missing values, then it would be
> worth it to use a fancier technique that looks for the first previous
> nonmissing value.  There could even be a clever way with indexing that
> I am missing.

Package zoo and function ?na.locf can be used for this type of task.

Regards
Petr


> 
> HTH,
> 
> Josh
> 
> On Thu, Jun 16, 2011 at 5:13 AM, wuffmeister  wrote:
> > I got an array similar to the one below, and want to replace all NAs 
with the
> > previous value.
> > 99 8.2 b
> > NA 8.3 x
> > NA 7.9 x
> > 98 8.1 b
> > NA 7.7 x
> > 99 9.3 b
> > ...
> >
> > i.e. the first two NAs should be replaced to 99, whereas the last one 
should
> > be 98.
> >
> > I would like to apply a function to reach row, checking if the value 
in col
> > 1 is NA, and if it is, set the value to the previous row's col 1 
value.
> >
> > Haven't been able to do this without looping, which gets very slow for 
large
> > datasets...
> >
> > --
> > View this message in context: http://r.789695.n4.nabble.com/Replacing-
> values-without-looping-tp3602247p3602247.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.
> >
> 
> 
> 
> -- 
> Joshua Wiley
> Ph.D. Student, Health Psychology
> University of California, Los Angeles
> http://www.joshuawiley.com/
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] Odp: alphahull: is low level plotting possible?

2011-06-16 Thread Petr PIKAL
Hi
> 
>  Dear R users,
> I am using package alphahull version 0.2-0 with R-2.13.0. Here is my 
problem.
> I have produced a 2-D plot of points and need to draw convex hulls 
around 
> some subsets of these points. So I just need to add the convex hulls to 
> the already existing plot. That is why I cannot use the plot.hull 
> function. So, is there a way to just add the convex hulls to the already 

> existing plot, just as the low level functions "lines" and "points" add 
> lines and points to an already existing plot? I suspect the solution is 
in
> the "arc" function, but I am not sure.

See ?chull and its help page.

Regards
Petr

> 
> Any suggestions will be appreciated.
> 
> Regards,
> 
> Martin
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Odp: problems with plots in loop (corrected Email)

2011-06-15 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 14.06.2011 18:28:42:

> Andreas Betz  
> Odeslal: r-help-boun...@r-project.org
> 
> 14.06.2011 18:28
> 
> Komu
> 
> 
> 
> Kopie
> 
> Předmět
> 
> [R] problems with plots in loop (corrected Email)
> 
> Dear helpers,
> 
> 
> 
> In an attempt to use a loop to generate graphs in a for loop in run into
> a problem. The plan is to fill each page with eight graphs (mfrow =
> c(4,2)) in to two columns. Only the buttom graphs ( meaning every fourth
> graph) have  tick labels on the x  axis to preserve space. I used an if
>  Else statement to achieve that. 
> 
> The problem is that the first eight graphs are skipped when I run the
> loop, the other graphs are fine.  However, all graphs can be generated
> individually. This indicates that the data sets are fine.
> 
> 
> 
> 
> 
> Pulling the results from a nonlinear regression to more than 90 data
> sets from a list (resultslist[[i]])
> 
> Generating the first derivative and multiply it by 100 to adjust for the
> scale. 
> 
> 
> 
> Here is the code. 
> 
> 
> 
> pdf('F:/diffnormal_16001a.pdf')
> par(mfcol = c(4,2))
> for(i in 1: 92){
> fit  <-  NULL
> der <-  NULL
> Zeit  <- NULL
> Zeit <- seq(0,300)
> try(guess <- predict(resultslist_1600[[i]]) )
> if(class(guess) == "try-error") {next}
> fit <- smooth.spline(Zeit, guess)
> der <- 100*(predict(fit, Zeit, deriv = 1))$y
>   if((i/4)%%1 ==0){par(mar =c(4,4,0, 0) + 0.1)}
>   else{par(mar =c(0,4,0, 0) + 0.1)}

Maybe the else just moved due to mailer but it shall be on the same line 
as if statement to be executed. But in that case you would obtain error 
message.

However when I get rid of all I do not have from your code
pdf("test.pdf")
par(mfcol = c(4,2))
for(i in 1: 8){
 fit  <-  NULL
der <-  NULL
 Zeit  <- NULL
 Zeit <- seq(0,300)
   if((i/4)%%1 ==0){par(mar =c(4,4,0, 0) + 0.1)}   else{par(mar =c(0,4,0, 
0) + 0.1)}
   leg = paste("Data_", i,sep = "")
   plot(Zeit, Zeit, pch = 19, cex=3, ylab = "Signal", axes = F)
   if((i/4)%%1 ==0){axis(1, at = seq(0, 360, length = 6), label = c(), 
font = 2)}
   mtext(side = 3, leg, line = -2)}

dev.off()

It seems to me that plotting works as expected.

Regards
Petr

>   leg = paste("Data_", i,sep = "")
>   plot(resultslist_1600[[i]], type = "all", pch = ".", ylab = "Signal",
> log = "", axes = F)
>   lines(Zeit, der)
>   if((i/4)%%1 ==0){axis(1, at = seq(0, 360, length = 6), label = c(),
> font = 2)}
>   axis(2, at =
> pretty(na.omit(eval(parse(text=paste("bleeder1600[,",i,"]",sep =""),
> label = c())
>   mtext(side = 3, leg, line = -2)}
> 
> 
> 
> I understand, that I am supposed to submit working code. However, I deal
> with a fairly comprehensive data set and I have to generate a large list
> using another R package. Thus I explain what it does:
> 
> 
> 
> Generate time points(Zeit <- seq(0,300)
> 
> Pulling the results from a nonlinear regression to more than 90 data
> sets from a list (resultslist_1600[[i]])
> 
> Test if prediction can be done
> 
> try(guess <- predict(resultslist_1600[[i]]) )
> if(class(guess) == "try-error") {next}
> (it turned out it can be done for all data set, as I am able to generate
> the graphs for each data set from the command line individually.
> 
> Generating the first derivative and multiply it by 100 to adjust for the
> scale. 
> 
> fit <- smooth.spline(Zeit, guess)
> 
> der <- 100*(predict(fit, Zeit, deriv = 1))$y
> 
> 
> 
> The problem appears to be hidden in the mfrow statement.
> 
> I spent quite a bit of time on this problem, thus any help or new ideas
> would be very much appreciated.
> 
> 
> 
> Thank you
> 
> 
> 
> Andreas Betz
> 
> Scientist
> 
> andreasbetz@ Dear helpers,
> 
> 
> 
> In an attempt to use a loop to generate graphs in a for loop in run into
> a problem. The plan is to fill each page with eight graphs (mfrow =
> c(4,2)) in to two columns. Only the buttom graphs ( meaning every fourth
> graph) have  tick labels on the x  axis to preserve space. I used an if
>  Else statement to achieve that. 
> 
> The problem is that the first eight graphs are skipped when I run the
> loop, the other graphs are fine.  However, all graphs can be generated
> individually. This indicates that the data sets are fine.
> 
> 
> 
> 
> 
> Pulling the results from a nonlinear regression to more than 90 data
> sets from a list (resultslist[[i]])
> 
> Generating the first derivative and multiply it by 100 to adjust for the
> scale. 
> 
> 
> 
> Here is the code. 
> 
> 
> 
> pdf('F:/diffnormal_16001a.pdf')
> par(mfcol = c(4,2))
> for(i in 1: 92){
> fit  <-  NULL
> der <-  NULL
> Zeit  <- NULL
> Zeit <- seq(0,300)
> try(guess <- predict(resultslist_1600[[i]]) )
> if(class(guess) == "try-error") {next}
> fit <- smooth.spline(Zeit, guess)
> der <- 100*(predict(fit, Zeit, deriv = 1))$y
>   if((i/4)%%1 ==0){par(mar =c(4,4,0, 0) + 0.1)}
>   else{par(mar =c(0,4,0, 0) + 0.1)}
>   leg = paste("Data_", i,sep = "")
>   plot(resu

[R] Odp: log2() and -min() very quick question

2011-06-13 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 13.06.2011 17:59:03:

> Ben Ganzfried  
> Odeslal: r-help-boun...@r-project.org
> 
> 13.06.2011 17:59
> 
> Komu
> 
> r-help@r-project.org
> 
> Kopie
> 
> Předmět
> 
> [R] log2() and -min() very quick question
> 
> I'm looking over good-code a post-doc in my lab wrote and trying to 
learn
> how it works.  I came across the following:
> rel.abundance <- 
as.matrix(read.delim("rel.abundance.csv",row.names=1,as.is
> =TRUE))
> rel.abundance <- log2(rel.abundance-min(rel.abundance)+1)
> 
> I'm not sure what the second line is doing.  I ran each line in R and
> couldn't see a noticeable difference in the output.  I assume log2() 
takes
> the log base 2 of the values?  I'm not clear what -min(rel.abundance) is
> doing either...my hunch would be that it would take the smallest value 
in
> each row?

No. If rel.abundance is matrix min(rel.abundance) is overall minimum

> mat<-matrix(1:12, 3,4)
> min(mat)
[1] 1

so
log2(rel.abundance-min(rel.abundance)+1)

subtract minimum value from all numbers, after that it add 1 do all 
numbers, takes log base 2 from each number and returns matrix with the 
same dimensions as input matrix.

> I'd really like to figure out:
> 1) What's actually going on?
> 2) Is there a good way to run a command over a large dataset in R and 
better
> be able to tell what is going on?  More specifically, when I run each 
line
> in R it looks something like this (w/ dif. values per row):
> Archaea|Euryarchaeota|Methanobacteria|Methanobacteriales|
> 
Methanobacteriaceae|Methanobrevibacter,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
> 
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
> 
0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
> 
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,3,0,0,0,0,0,
> 
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
> 
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,
> 0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,23,0,3,0,0,0
> 
> 
> There are a lot of cells w/ values per row, which is one reason why I 
think
> it is difficult to detect a pattern

there are some summary and structure commands

summary(data) or str(data)

which can tell you some overall information about your data.

Regards
Petr

> 
> Thanks in advance!
> 
> Ben
> 
>[[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] automatically generate the output name of my "for" loops

2011-06-13 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 13.06.2011 17:35:29:

> jiliguala  
> 
> really thanks for helping.
> 
> i just did just like what Petr Pikal said,
> but it appeared some error like this:
> 
> There were 50 or more warnings (use warnings() to see the first 50):
> 
> Warning messages:
> 1: In group[i] <- which(k1$cluster == i) :
>   number of items to replace is not a multiple of replacement length
> 2: In group[i] <- which(k1$cluster == i) :
>   number of items to replace is not a multiple of replacement length
> 3: In group[i] <- which(k1$cluster == i) :
>   number of items to replace is not a multiple of replacement length
> ...
> ...
> ...
> 
> and some solution for that, thanks..

Do you want to mimic some C style programming? If yes you'd rather consult 
some documentation coming with R.

Without knowing much about your code the warning message tells you that 
you want to fill six position egg holder with 10 eggs and R correctly 
tells you a warning that it put 6 eggs in the holder and threw away 
remaining four. 

If this is what you intended, you does not need to worry. If you wanted 
something different you need to reveal some more info to us.

x<-1:5
z<-rep(NA, 4)
z[1:4]<-x
Warning message:
In z[1:4] <- x :
  number of items to replace is not a multiple of replacement length

Regards
Petr

> 
> --
> View this message in context: 
http://r.789695.n4.nabble.com/automatically-
> generate-the-output-name-of-my-for-loops-tp3592160p3594096.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] How to create a numeric data.frame

2011-06-13 Thread Petr PIKAL
Hi
r-help-boun...@r-project.org napsal dne 13.06.2011 17:19:39:

> Patrizio Frederic  
> 
> On Mon, Jun 13, 2011 at 4:45 PM, Barry Rowlingson
>  wrote:
> > On Mon, Jun 13, 2011 at 11:06 AM, Aparna  
wrote:
> >> Hi All
> >>
> >> I am new to R and  I am not sure of how this should be done. I have a 
matrix of
> >> 985x100 values and the class is data.frame.
> >
> >  You don't have a 'matrix' in the R sense of the word. You seem to
> > have a table of numbers which are stored in an object of class
> > 'data.frame'.
> >
> 
> but you could have one:
> 
> a <- data.frame(matrix(rnorm(100),10) # get some data
> class(a) # check for its class
> as.numeric(a) # whoops, won't work
> 
> class(as.matrix(a)) # change class, and
> as.numeric(as.matrix(a)) # bingo, it works

Which results in vector of numbers

str(as.numeric(as.matrix(a)))
 num [1:100] 0.82 -1.339 1.397 0.673 -0.461 ...

data frame is convenient list structure which can contain vectors of 
various nature (numeric, character, factor, logical, ...)
and looks quite similar to Excel table.

matrix is a vector with (2) dimensions but as it is a vector it can not 
consist from objects of different nature (class). Therefore you can have 
numeric or character matrix but not numeric and character columns in your 
matrix.

and vector is vector (numeric, character, logical,  ...) but again you can 
not mix items of different class in one vector.

Regards
Petr

> 
> PF
> 
> 
> -- 
> +---
> | Patrizio Frederic,
> | http://www.economia.unimore.it/frederic_patrizio/
> +---
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Odp: How do I make proper use of the by() function?

2011-06-13 Thread Petr PIKAL
Hi

> [R] How do I make proper use of the by() function?
> 
> Dear list,
> 
> I have a function that uses values from two vectors  and spits out one 
new
> vector  based on all the values of the two original vectors, and with 
the
> same length as them.
> Ok, I would now like to be able to apply that function simply on two 
columns
> in a data frame, divided by the levels of factors in the data frame.
> 
> I'm trying to use by() for this, but the output is too hard to use. What 
I
> am doing is this:
> 
> by(df, list(df$Factor1,df$Factor2),function(x)
> my_function(x$col1,x$col2),simplify=TRUE)

by(df, list(df$Factor1,df$Factor2),function(x) 
my_function(x$col1,x$col2),simplify=TRUE)
Error in df$Factor1 : object of type 'closure' is not subsettable

I get this kind of error which is because I do not have any df object 
other than df function from stats package.

If I understand correctly you want maybe either aggregate or ave

> milan
   pc lot bettongbet  sira vyber betctc
1   1  56   89.95 109.25 3.000 b  88.37
2   2  66   86.87 100.96 3.156 a NA
3   3  84   93.91 101.21 3.120 a NA
4   4  89   89.48 100.00 3.010 a NA
5   5  41  110.15 116.92 3.597 b 106.37
6   6  44   96.53 106.54 3.057 b NA
7   7  47   94.94 104.91 2.857 b NA
8   8  62   90.30 111.05 3.210 b NA
9   9  64   96.41 102.56 3.180 a  90.79
10 10  65   95.04 101.15 3.200 a NA
11 11  57   88.27 104.71 3.060 b NA
12 13  74   91.98 104.93 3.470 a NA

> aggregate(milan[,2:5], list(milan$vyber), sum) 
  Group.1 lot bettongbet   sira
1   a 442  553.69 610.81 19.136
2   b 307  570.14 653.38 18.781

> sapply(milan[,2:5], function(x) ave(x, milan$vyber, "sum"))
   lot  bettong  bet sira
 [1,] 51.16667 95.02333 108.8967 3.130167
 [2,] 73.7 92.28167 101.8017 3.189333
 [3,] 73.7 92.28167 101.8017 3.189333
 [4,] 73.7 92.28167 101.8017 3.189333
 [5,] 51.16667 95.02333 108.8967 3.130167
 [6,] 51.16667 95.02333 108.8967 3.130167
 [7,] 51.16667 95.02333 108.8967 3.130167
 [8,] 51.16667 95.02333 108.8967 3.130167
 [9,] 73.7 92.28167 101.8017 3.189333
[10,] 73.7 92.28167 101.8017 3.189333
[11,] 51.16667 95.02333 108.8967 3.130167
[12,] 73.7 92.28167 101.8017 3.189333

But maybe I am wrong, I still only try to learn mind reading.

> 
> and the output is too complex to be used in a simple way. Actually, I 
just
> want something like a data frame, where the results vectors are placed 
in
> one column and the conditions under which they were produced (i.e. the
> values of the factors according to which the data set were divided) in 
other
> columns.
> 
> This does not seem to be provided by by(), and aggregate only provides 
me
> with the ability to use values from one column, right?
> So, are there other functions I could use?
> 
> Thanks!
> 
> /Fredrik
> 
> -- 
> "Life is like a trumpet - if you don't put anything into it, you don't 
get
> anything out of 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] automatically generate the output name of my "for" loops

2011-06-13 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 13.06.2011 05:21:23:

> Re: [R] automatically generate the output name of my "for" loops
> 
> ?paste
> something like...
> paste (group, i, sep="_")
> 

I believe that better idea is to use list, with which you can work further 
much more efficiently.

lll<- vector("list", 100)

for (i in 1:100) {

lll[i] <- some computation

}

Regards
Petr


> 
> 
> jiliguala wrote:
> > 
> > Hello R users, 
> > 
> > I am new to R and am having difficulty with the output name of my 
"for"
> > loops. 
> > 
> > here is the problem:
> > 
> > 
> > for (i in c(1:100))
> > {
> > the name of the groups <- which(k1$cluster==i)
> > }
> > 
> > how can it automatically generate the name for 100 cluster(just like
> > group_1, group_2...)? what should i put in the bold letter place?
> > really thank you for helping me
> > 
> > Daniel
> > 
> 
> --
> View this message in context: 
http://r.789695.n4.nabble.com/automatically-
> generate-the-output-name-of-my-for-loops-tp3592160p3593123.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] Odp: How to subset based on column name that is a number ?

2011-06-10 Thread Petr PIKAL
Hi
> [R] How to subset based on column name that is a number ?
> 
> Hi,
> 
> I have a data frame with column names "1", "2", "3", ... and I'd like to 
extract 
> a subset based on the values in the first column.  None of the methods I 
tried 
> worked (below).
> 
> 
> x <- subset(dframe, 1 = = "My Text")
> x <- subset(dframe, "1" = = "My Text")
> x <- subset(dframe, names(dframe)[1] = = "My Text")
> Q <- dframe[1 = = "FY11_Q4",]
> Q <- dframe['1'=="FY11_Q4",]
> Q <- dframe[names(dframe)[1]=="FY11_Q4",]
> 

Did you try

dframe[dframe[,"1"]=="My Text",]

Regards
Petr


> 
> Might anyone have a suggestion?
> 
> Many thanks,
> Mauricio
> 
>[[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] Odp: what is the mistake?? the coding still not function. no result display

2011-06-10 Thread Petr PIKAL
Hi
> 
> [R] what is the mistake?? the coding still not function. no result 
display
> 
> #lda.r
> > #
> > #Author:Amsha Nahid, Jairus Bowne, Gerard Murray
> > #Purpose:Perform Linear Discriminant Analysis (LDA)
> > #
> > #Input:Data matrix as specified in Data-matrix-format.pdf
> > #Output:LDA plot
> > #
> > #Notes:Missing values (if any) are replaced by the half of the 
lowest
> > #  value in the entire data matrix.
> > 
> > 
> > #
> > #Load necessary libraries, and install them if they are missing
> > #
> > tryCatch(library(MASS), error=function(err)
> + # if this produces an error:
> + install.packages("MASS",repos="http://cran.ms.unimelb.edu.au/";))
> > 
> > #
> > #Prepare the data matrix
> > #
> > # Read in the .csv file
> > data<-read.csv("C:/Users/nadya/Desktop/praktikal 
UTM/TASK2/new(40data)S2 100 
> >EMS EPI 300-399.csv", sep=",", row.names=1, header=TRUE)
> > # Get groups information
> > groups<-data[,1]
> > # Remove groups for data processing
> > lda_data<-data[,-1]
> > # Replace any missing values (see Notes)
> > lda_data[is.na(lda_data)]<-0.5*(min(lda_data,na.rm=TRUE))
> > 
> > #
> > #Perform the LDA
> > #
> > lda_result<-lda(lda_data,groups)
> Error in lda.default(x, grouping, ...) : 
>   variables  1  3  5  8 10 15 17 20 27 29 34 appear to be constant 
within groups

The problem seems to be with your data, which in some groups are constant.

Try 
split(lda_data, groups) 

or

sapply(split(lda_data, groups), length)

and see your result.

Regards
Petr
> > 
> > #
> > #Generate the figures (on screen)
> > #
> > #Image generation - function definition
> > pic_onscr<-function(matrix, title, cex_val=1)
> + {x11()
> + par(mgp=c(5,2,0),   # axis margins
> + # (title, labels, 
line)
> + mar=c(7,4,4,2), # plot margins 
(b,l,t,r)
> + las=1)  # horizontal labels
> + plot(matrix,# data to plot
> + cex=cex_val,# font size
> + dimen=2 # dimensions to plot
> + )
> + title(main=title)   # title of plot
> + }
> > # Plot LDA scores with sample names
> > pic_onscr(lda_result,"Linear Discriminant Analysis")
> Error in plot(matrix, cex = cex_val, dimen = 2) : 
>   error in evaluating the argument 'x' in selecting a method for 
function 
> 'plot': Error: object 'lda_result' not found
> > # For plotting with larger font size, use a different value of cex:
> > # pic_onscr(lda_result, "LDA Plot", dimen=2, cex=3)
> > 
> > #
> > #Generate figures as image files
> > #
> > #(Uncomment blocks as necessary)
> > 
> > # jpeg #
> > # pic_jpg<-function(filename, matrix, title, cex_val=1)
> > # {# Start jpeg device with basic settings
> > # jpeg(filename,
> > # quality=100,# image quality 
(percent)
> > # bg="white", # background colour
> > # res=300,# image resolution 
(dpi)
> > # units="in", width=8.3, height=5.8   # image dimensions 
(inches)
> > # )
> > # par(mgp=c(5,2,0),   # axis margins 
> > # #  (title, labels, 
line)
> > # mar=c(7,4,4,2), # plot margins 
(b,l,t,r)
> > # las=1   # horizontal labels
> > # )
> > # # Draw the plot
> > # plot(matrix,# data to plot
> > # cex=cex_val,# font size
> > # dimen=2 # dimensions to plot
> > # )
> > # title(main=title)   # title of plot
> > # 
> > # dev.off()
> > # }
> > # pic_jpg("LDA.jpg", lda_result, "Linear Discriminant Analysis")
> > # end jpeg #
> > 
> > # png #
> > # pic_png<-function(filename, matrix, title, cex_val=1)
> > # {# Start png device with basic settings
> > # png(filename,
> > # bg="white", # background colour
> > # res=300,# image resolution 
(dpi)
> > # units="in", width=8.3, height=5.8   # image dimensions 
(inches)
> > # )
> > # par(mgp=c(5,2,0),   # axis margins 
> > # #  (title, labels, 
line)
> > # mar=c(7,4,4,2), # plot margins 
(b,l,t,r)
> > # las=1   # horizontal labels
> > # )
> > # # Draw the plot
> > # plot(matrix,# data to plot
> > # cex=cex_val,# font size
> > 

[R] Odp: Problem using read.xls - Everything converted to factors

2011-06-03 Thread Petr PIKAL
Hi

> 
> [R] Problem using read.xls - Everything converted to factors
> 
> Hallo,
> 
> I would like to use to read.xls function from the gdata package to read 
> data from Microsoft Excel files but I experienced a problem: For example 

> I used the following code:
> 
> testfile<-read.xls("/home/.../wsjecon0603.xls", #file path
> header=F,
> dec=",",
> na.strings="n.a.",
> skip=5,
> sheet=2,
> col.names=c("Name", 
"Firm","GDP1","GDP2","GDP3","GDP4","CPI5",
> 
> "CPI11","UNEMP5","UNEMP11","PROF03","PROF04","STARTS03","STARTS04"),
> nrows=54,
> 
> #colClasses=c
> 
(character,character,numeric,numeric,numeric,numeric,numeric,numeric,numeric,numeric,numeric,numeric,numeric,numeric)
> 
> )
> print(testfile)
> 
> Although the xls file contains numeric values in all the columns except 
> the ones which I named "Name" and "Firm", everything in the data frame 
> has "factor" as class. I tried to use the colClasses option as above and 

> as well with " "'s around each word, but this does not work and I will 

Hm. That shall work. You have got some advice from Gabor but in case 
numeric columns come as non numeric I often find a problem with some kind 
of formating the original values. Numbers like 10 253,52 are treated as 
nonnumeric as there is extra space character between thousands and 
hundereds. Maybe also na.strings are not always marked as n.a. but 
sometimes the value is missing and I suppose this can lead to conversion 
of all column to character vector.

> always receive the following error:
> 
> Fehler in is(object, Class) :
>versuche einen Slot "className" von einem Objekt der einfachen Klasse 

> ("list") ohne Slots anzufordern
> Calls: read.xls -> read.csv -> read.table ->  -> is
> 
> After some hours of reasearch I figured out how I can manually change 
> the classes of the columns:
> 
> testfile$GDP2<-as.numeric(levels(testfile$GDP2))[testfile$GDP2]
> testfile$Name<-as.character(levels(testfile$Name))[testfile$Name] #and 
so on

you can spare some time to use sapply

testfile[,character columns] <- sapply(testfile[,character columns], 
as.numeric)

shall convert all character columns to numeric at once but you will get 
NAs to all values which could not be converted for any reason.

Regards
Petr


> 
> This works, but is a lot of work since I have to import many different 
> data sets. So I was wondering if there is another way to let the classes 

> be recognized correctly.
> 
> Additionally I would like to know if there is any way to import data 
> from different sheets with the same layout at once into one data frame.
> 
> I use Ubuntu 11.04 with Rkward if this is of any importance.
> 
> Thanks in advance for your answers,
> Sebastian
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Odp: RES: Recode numbers

2011-06-03 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 01.06.2011 21:10:23:

> "Filipe Leme Botelho"  
> Odeslal: r-help-boun...@r-project.org
> 
> RES: [R] Recode numbers
> 
> I think this is proper.
> 
> a <- c(1, 2, 3, 3, 4, 4, 5, 6, 1, 2, 2, 3, 1, 2, 1, 2, 3, 3, 4, 5, 1, 2,
> 3, 4)
> b <- c(1, 5, 8, 9, 14, 20, 3, 10, 12, 6, 16, 7, 11, 13, 17, 18, 2, 4,
> 15, 19)
> 
> ref <- 1
> for (i in 2:length(a)) {
>if (a[i]!=a[i-1]) ref <- c(ref, ref[length(ref)]+1)
>if (a[i]==a[i-1]) ref <- c(ref, ref[length(ref)])
>}
> 
> a2 <-b[ref]
> a1 <- c(1, 5, 8, 8, 9, 9, 14, 20, 3, 10, 10, 12, 6, 16, 7, 11, 13, 13,
> 17, 18, 2, 4, 15, 19)

a bit shorter is

a2<-rep(b, rle(a)$lengths)

Regards
Petr

> 
> a1==a2
> 
> 
> -Mensagem original-
> De: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> Em nome de Duncan Murdoch
> Enviada em: quarta-feira, 1 de junho de 2011 15:51
> Para: Lisa
> Cc: r-help@r-project.org
> Assunto: Re: [R] Recode numbers
> 
> (The attributions are a little messed up here:)
> 
> >> I have two sets of numbers that look like
> >>> a<- c(1, 2, 3, 3, 4, 4, 5, 6, 1, 2, 2, 3, 1, 2, 1, 2, 3, 3, 4, 5, 1,
> 2, 3,
> >>> 4)
> >>>
> >>> b<- c(1, 5, 8, 9, 14, 20, 3, 10, 12, 6, 16, 7, 11, 13, 17, 18, 2, 4,
> 15,
> >>> 19)
> >>>
> >>> I just want to use "b" to encode "a" so that "a" looks like
> >>>
> >>> a1<- c(1, 5, 8, 8, 9, 9, 14, 20, 3, 10, 10, 12, 6, 16, 7, 11, 13,
> 13, 17,
> >>> 18, 2, 4, 15, 19)
> >>>
> >>> Does anyone have a suggestion how to deal with this? Thank you in
> advance.
> >>>
> >>
> >> is a1 = b[a] what you are looking for?
> >>
> >> HTH
> >>
> >> Pete
> >
> > Thank you for your help, Pete. I tried b[a], but it is not a1.
> 
> 
> I think you'll need to explain the rule used for a1[9], a1[10], etc.
> 
> Duncan Murdoch
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> "This message and its attachments may contain confidential and/or 
> privileged information. If you are not the addressee, please, advise the 

> sender immediately by replying to the e-mail and delete this message."
> 
> "Este mensaje y sus anexos pueden contener información confidencial o 
> privilegiada. Si ha recibido este e-mail por error por favor bórrelo y 
> envíe un mensaje al remitente."
> 
> "Esta mensagem e seus anexos podem conter informação confidencial ou 
> privilegiada. Caso não seja o destinatário, solicitamos a imediata 
> notificação ao remetente e exclusão da 
> mensagem."__
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Odp: load seven files (named by date) at a time

2011-06-01 Thread Petr PIKAL
Hi

> [R] load seven files (named by date) at a time
> 
> Hello,
> 
> I'm trying to load a weeks worth of files that are each named by the 
> date they were creaded (e.g., 20110601.RData), starting with the day 
> before today so if today is June 1, I would like to load 20110525- 
> 20110531. The script was working until today, and x= 20110593 20110594 
> 20110595 20110596 20110597 20110598 20110599 20110600.
> time=Sys.time()
> t1<- as.numeric(format.Date(time, "%Y%m%d"))
> #date range of data to load
> 
> t1=t1-1
> t0 <-t1-7
> x = t0:t1
> 
> 
> Any solutions?

work with dates not numbers

seq(as.Date(time)-7, as.Date(time)-1, by=1)

Regards
Petr

> 
> Thanks
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Odp: while loop problems

2011-06-01 Thread Petr PIKAL
Hi

Without reproducible example or some code I wonder if anybody can give you 
some advice.

As a wild guess do you use if function correctly i.e. input is "length one 
logical vector" ?

And maybe you do not need loop at all

Regards
Petr

> 
> [R] while loop problems
> 
> Hi , i am trying to get this loop in my r program to work but it is
> not giving me the results that I desire. I am trying to model an
> insurance contract where there are n securities that have a fixed
> likelihood of default vector(data[i,2]) and a payout
> vector(data[i,1]).
> 
> i need to price the value of stop losses at the security level and at
> the portfolio level. to do this i created two while loops for the
> conditional vectors of each level (which will be inputed into the
> function by the user) one while loop to scan through the various
> securities and a final one to model the various scenarios(i.e. monte
> carlo). i tried to Use R's matrix capabilities to help organize the
> results.
> 
> the problem with this code is that the if statement behaves oddly, not
> activating and filtering correctly. this causes the program to be slow
> and provide bad results. it fills the individual protection column
> always rather than conditioning it on the likelihood
> vector(data[i,2]). there is a lot of moving parts but overall it is a
> simple model.
> 
> my end result is to have a vector containing the accumulated values of
> insurance for each type of stop loss(i.e. idiosyncratic and
> aggregate).
> 
> Thanks, Alon.
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Odp: conversion of matrix into list

2011-06-01 Thread Petr PIKAL
Hi
 
> Dear all,
> 
> 
> 
> I have a matrix X which consists of 2 columns. I would like to convert 
this
> matrix into a list where every entry of the list consists of a single 
row of
> the matrix.

e.g.

split(mat, 1:nrow(mat))

Regards
Petr

> 
> Does anyone have a suggestions how to manage this?
> 
> 
> 
> Thank you for your efforts in advance!
> 
> 
> 
> Best,
> 
> 
> 
> Martin
> 
> 
> 
> 
>[[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] Odp: Three sigma rule

2011-05-31 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 28.05.2011 20:12:33:

> "Salil Sharma"  
> Odeslal: r-help-boun...@r-project.org
> Dear Sir,
> 
> 
> 
> I have data, coming from tests, consisting of 300 values. Is there a way 
in
> R with which I can confirm this data to 68-95-99.8 rule or three-sigma 
rule?
> 
> I need to look around percentile ranks and prediction intervals for this
> data. I, however, used SixSigma package and used ss.ci() function, which
> produced 95% confidence intervals. I still am not certain about 
percentile
> ranks conforming to 68-95-99.7 rule for this data.
> 

Not sure what you exactly want but you could look at function quantile.

Or you could compute confidence interval for mean by e.g.

> mean.int
function (x, p = 0.95) 
{
x.na <- na.omit(x)
mu <- mean(x.na)
odch <- sd(x.na)
l <- length(x.na)
alfa <- (1 - p)/2
mu.d <- mu - qt(1 - alfa, l - 1) * odch/sqrt(l)
mu.h <- mu + qt(1 - alfa, l - 1) * odch/sqrt(l)
return(data.frame(mu.d, mu, mu.h))
}

Regards
Petr 


> 
> 
> Thanks and regards,
> Salil Sharma
> 
> 
>[[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] Setting NA to blank

2011-05-09 Thread Petr PIKAL
Hi

> Re: [R] Setting NA to blank
> 
> I asked because I thought it'd solve an issue I had. I was actually 
being
> quite rash in asking this question and for that, I apologize.
> 
> I wanted to know because I was attempting to create a heatmap where the 
NA
> values would not be shown while all the outputs with actual numerical 
value
> will be shown. I had assumed that setting the NA's to blanks would fix 
the
> issue, but it hadn't. I refrained from immediately asking another 
question
> so I that I can look further into this.

If you used heatmap function from stats package I believe that NA values 
are not displayed so they appear as white. So basically you should not 
need any change.

It is usually better then assume what you think the functions are doing to 
learn what they actually do by consulting help page. 

You could also try examples provided at bottom of almost each help page 
and modify it to suit your needs.

Regards
Petr



> 
> I hope that answers your question.
> 
> On Mon, May 9, 2011 at 4:21 PM, Ted Harding 
wrote:
> 
> > John Kane's reply sums it up! (Though you could use "",
> > instead of " ", which would give you an "empty string"
> > instead of the "space" character; but the resulting
> > matrix would still consist entirely of "character"
> > elements).
> >
> > However, the real reason I am following up is to ask
> > why you want the blank instead of the NA.
> >
> > If it is just for printing out or display, then the
> > fact that the matrix has been converted to character
> > probably does not matter.
> >
> > But if it is for compatibility with some other
> > computational software that (e.g.) expects missing
> > values to be represented by a blank, or some "null"
> > representation, then it may not be so straightforward.
> >
> > So, if that might be an issue, please describe for us
> > how you intend to use the result.
> >
> > Ted.
> >
> > On 09-May-11 19:56:39, Dat Mai wrote:
> > > Thank you kind sir!
> > >
> > > On Mon, May 9, 2011 at 3:25 PM, John Kane  
wrote:
> > >
> > >>
> > >> (mat <- matrix(c(1,2,3,NA),2))
> > >> mat[is.na(mat)]   <- " "
> > >> mat
> > >>
> > >> But if you have a numerical matrix it coverts the matrix to 
character.
> > >>
> > >> --- On Mon, 5/9/11, Dat Mai  wrote:
> > >>
> > >> > From: Dat Mai 
> > >> > Subject: [R]  Setting NA to blank
> > >> > To: r-help@r-project.org
> > >> > Received: Monday, May 9, 2011, 2:46 PM
> > >> > Hey All,
> > >> >
> > >> > I have a matrix m, and I wish to set all the NA values to
> > >> > blank. How would I
> > >> > do so?
> > >> >
> > >> > --
> > >> > Best,
> > >> > Dat Mai
> > >> > PhD Rotation Student
> > >> > Albert Einstein College of Medicine
> >
> > 
> > E-Mail: (Ted Harding) 
> > Fax-to-email: +44 (0)870 094 0861
> > Date: 09-May-11   Time: 21:21:07
> > -- XFMail --
> >
> 
> 
> 
> -- 
> Best,
> Dat Mai
> PhD Rotation Student
> Albert Einstein College of Medicine
> 
>[[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] Odp: Using NULL to my data?

2011-05-09 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 09.05.2011 16:07:27:

> Nilza BARROS  
> Odeslal: r-help-boun...@r-project.org
> 
> 09.05.2011 16:07
> 
> 
> Dear R users,
> 
> I am reading data from a file where there are some missing that are
> represented by -.00.
> I am using the command below.
> =My original data ===
> 
> PARM = TMPC;T12X;T12N;DWPC;PALT;SKNT;DRCT;P24M;CLCL
> 
> 
> STNYYMMDD/HHMM  TMPC T12X T12N DWPC PALT
> SKNT
> DRCT P24M CLCL
>  820420110429/1200 22.50 -.0022.4022.20 -.00
> 0.00
> 0.0084.00 4.00
>  820980110429/1200 26.90 -.0023.4024.10  1010.20
> 2.91
>   360.00 2.00 6.00
>  821130110429/1200 24.30 -.0023.3023.70 -.00
> 1.94
>   230.00 3.00 4.00
>  821410110429/1200 24.40 -.0023.7024.20  1011.80
> 2.91
> ===
> 
> dados<-read.table
> ("2011042912_teste.dat",sep='',fill=TRUE,na.strings="-.00",skip=4)
> head(dados)
>   V1  V2   V3 V4   V5   V6 V7   V8 group
> 1 820420 110429/1200 22.5 NA 22.4 22.2 NA 0.00 1
> 2  0   84.00  4.0 NA   NA   NA NA   NA 1
> 3 820980 110429/1200 26.9 NA 23.4 24.1 1010.2 2.91 2
> 43602.00  6.0 NA   NA   NA NA   NA 2
> 5 821130 110429/1200 24.3 NA 23.3 23.7 NA 1.94 3
> 62303.00  4.0 NA   NA   NA NA   NA 3
> =
> After some procedures a have the data as below:
> > head(Alldados)
> 
> 
>   Station_NO   date1 T_2M TMAX_2M TMIN_2M TD_2M PS FF_10M DD_10M
> 1 820420 110429/1200 22.5  NA22.4  22.2 NA   0.00  0
> 2 820980 110429/1200 26.9  NA23.4  24.1 1010.2   2.91360
> 3 821130 110429/1200 24.3  NA23.3  23.7 NA   1.94230
> 4 821410 110429/1200 24.4  NA23.7  24.2 1011.8   2.91270
> 5 821450 110429/1200 28.2  NA21.1  25.8 1008.8   0.00  0
> 6 821810 110429/1200 23.3  NA22.8  22.9 1001.6   0.00  0
>   TOT_PRCP CLCL  date2
> 184.00   NA 2011042912
> 2 2.00   NA 2011042912
> 3 3.00   NA 2011042912
> 412.00   NA 2011042912
> 5 6.00   NA 2011042912
> 638.00   NA 2011042912
> 
> But  I need to feed my database. These missings should be represented by
> NULL.
> I mean, all "NA" should be replaced by "NULL" in my database.
> I am trying the command below to pick up the rows and columns with NA 
but I
> don't know how to fill the original data :
> 
> which(is.na(Alldados),arr.ind=TRUE)
> 
> But I don't know how to replace each NA with NULL. I tried using as.null 
but
> NA is not replace at all.

Why do you want that? NULL is reserved for objects which emerged from 
undefined function results. See its help page.

As such you can not have vector of NULLs.

> rep(NULL, 10)
NULL
> rep(NA, 10)
 [1] NA NA NA NA NA NA NA NA NA NA

Maybe you want to replace NA with zero. If yes 

Alldados[is.na(Alldados)]<-0

could be what you want.

Regards
Petr


> 
> I hope someone could help me.
> 
> Best Wishes,
> Nilza Barros
> 
>[[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] Alter a line in a file.

2011-05-05 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 05.05.2011 15:13:34:

> Joel  
> Odeslal: r-help-boun...@r-project.org
> 
> 05.05.2011 15:13
> 
> 
> jholtman wrote:
> > 
> > a <- readLines(textConnection('setting1="value1"
> > setting2="value2"
> > setting3="value3"
> > setting4="value4"'))
> > closeAllConnections()
> > # change  values
> > ac <- sub('setting4="value4"', 'setting4="value5"', a)
> > writeLines(ac, con='myFile.txt')
> > 
> 
> Problem is that I dont know the value on all the settings that I wanna
> change otherwise that looks like something to continue on.
> 

But in that case how would you like to select the setting?

> 
> 
> Petr Pikal wrote:
> > 
> > What file, what is its structure, is it some R object or separate 
file?
> > What did you try and what went wrong?
> > 
> > Regards
> > Petr 
> > 
> 
> Just a normal textfile nothing fancy
> Ive tried diffrent kind of ways of useing my OS witch is linux by the 
system
> command to do it for me but Im not good enought on regexp to get it to 
work
> properly.

I read the simple text file by read.table

> data
 V1
1 setting1="value1"
2 setting2="value2"
3 setting3="value3"
4 setting4="value4"

> grep("4", data$V1)
[1] 4

Regards
Petr

> 
> --
> View this message in context: 
http://r.789695.n4.nabble.com/Alter-a-line-
> in-a-file-tp3498187p3498316.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] Odp: Alter a line in a file.

2011-05-05 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 05.05.2011 14:16:04:

> Joel  
> Odeslal: r-help-boun...@r-project.org
> 
> 05.05.2011 14:16
> 
> 
> Hi all R users
> 
> Ive got a file that contains diffrent settings in the manor of:

What file, what is its structure, is it some R object or separate file? 
What did you try and what went wrong?

Regards
Petr

> 
> setting1="value1"
> setting2="value2"
> setting3="value3"
> setting4="value4"
> .
> .
> .
> 
> What I want to do is open the file and change the value of a specific
> setting
> like wanna change setting4="value4" -> setting4="value5" and then save 
the
> file again.
> 
> setting1="value1"
> setting2="value2"
> setting3="value3"
> setting4="value5"
> .
> .
> .
> 
> 
> 
> 
> --
> View this message in context: 
http://r.789695.n4.nabble.com/Alter-a-line-
> in-a-file-tp3498187p3498187.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] SAPPLY function XXXX

2011-05-04 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 04.05.2011 22:26:59:

> Erik Iverson  
> Odeslal: r-help-boun...@r-project.org
> 
> 04.05.2011 22:26
> 
> Komu
> 
> Dan Abner 
> 
> 
> > Ultimately, I would like for this to be 1 conponent in a larger 
function
> > that will produce PROC CONTENTS style output. Something like...
> > 
> > data1.contents<-data.frame(Variable=names(data1),
> >  Class=sapply(data1,class),
> >  n.valid=sapply(data1,sum(!is.na)),
> >  n.miss=sapply(data1,sum(is.na)))
> > data1.contents
> 
> Also meant to mention to see ?describe in the Hmisc package:
> 
> E.g.,
> 
>  > describe(c(NA, 1:10))
> 
> There is also a useful method for data.frame objects.

colSums(is.na(data1))
colSums(!is.na(data1))

may also show number of missing and nonmissing values in data frame.

Regards
Petr

> 
> --Erik
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Odp: Is this confict of different versions of R or something else?

2011-05-04 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 04.05.2011 12:44:04:

> TheSavageSam  
> Odeslal: r-help-boun...@r-project.org
> 
> 
> Hello!
> 
> I have had some problems lately with use of R at home and school. At my 
home
> laptop (Ubuntu linux 64bit & R-2.12.0) R works just fine. But when I 
take my
> codes to school(Windows XP 32bit & R-2.10.1 I think) and run those there
> those codes probably won't work. Functions as combinations() didn't work 
and
> expand.grid() worked a bit differently. About expand.grid I just 
couldn't
> pass a dataframe of parametres but I had to pass all the colums 
separately.
> 
> Is this because my university has so old version of R? Or is it because 
I am
> using Linux at home? Or is it because some libraries aren't installed?
> I like R very much, but if there is difference between R in different
> operating systems, then I dislike that.

Hm. Untill now I thought that different versions are for introducing new 
features, properties or enhanced computing. You can not expect that 
everything what works in new version will work in any older version.

There can be slight issues with different operation systems, however I 
believe the biggest problem is old R version in your school PC.

Regards
Petr


> 
> Can you give me some tips how to avoid these problems? Install latest R 
to
> my university PC? I don't want to fall back at Windows users -category
> anymore.
> 
> --
> TheSavageSam
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/Is-this-
> 
confict-of-different-versions-of-R-or-something-else-tp3495104p3495104.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] for loop with global variables

2011-04-28 Thread Petr PIKAL
Hi

Something like
paste("output", i, sep = ".")
shall work
You could consult FAQ
7.34 How can I save the result of each iteration in a loop into a separate 
file

Regards
Petr



r-help-boun...@r-project.org napsal dne 28.04.2011 17:17:48:

> Petr PIKAL  
> Odeslal: r-help-boun...@r-project.org
> 
> 28.04.2011 17:17
> 
> Komu
> 
> ivan 
> 
> Kopie
> 
> r-help@r-project.org
> 
> Předmět
> 
> Re: [R] for loop with global variables
> 
> Hi
> 
> r-help-boun...@r-project.org napsal dne 28.04.2011 16:59:26:
> 
> > ivan  
> > Odeslal: r-help-boun...@r-project.org
> > 
> > 28.04.2011 16:59
> > 
> > Komu
> > 
> > jim holtman 
> > 
> > Kopie
> > 
> > r-help@r-project.org
> > 
> > Předmět
> > 
> > Re: [R] for loop with global variables
> > 
> > Hi,
> > 
> > thank you for the response. What I actually want to do is pick 
> automatically
> > the results of the various outputs (which I have already defined as
> > variables, e.g. output.1,output.2,etc) and insert them into a table. 
The
> > list variable would be redundant since in order to create the data 
frame 
> I
> > would rather type data.frame(results=rbind(output.1,output.2,etc.)). 
If 
> I
> > had 100 outputs, this would be much work. I rather meant something 
like
> > for(i in 1:100) {x=data.frame(results=rbind(output.[[i]]))}, which 
does 
> not
> > work though. It says that object "output." cannot be found.
> > 
> > Kind Regards
> 
> That is the problem. If you used list in the first time you could save 
> yourself much problems. BTW - data frame is also a list with some 
special 
> formating.
> 
> To extend my example
> 
> for(i in 1:3) {
> lll[[i]] <- sample(letters,3)
> names(lll)[i] <- LETTERS[i]
> }
> 
> lll
> $A
> [1] "x" "t" "h"
> $B
> [1] "c" "m" "w"
> $C
> [1] "n" "s" "e"
> 
>  as.data.frame(lll)
>   A B C
> 1 x c n
> 2 t m s
> 3 h w e
> 
> Regards
> Petr
> 
> 
> 
> 
> > 
> > 
> > 
> > On Thu, Apr 28, 2011 at 4:31 PM, jim holtman  
wrote:
> > 
> > > Yes you can, but there is not enough explaination as to what you
> > > really want to do.  I would suggest that you look at using a 'list'
> > > instead of individual objects:
> > >
> > > myList <- list(output.1 = rbind('a','b'), output.2 = rbind('c','d'), 

> ...)
> > >
> > > Then you can use 'lapply' to operation on the elements.
> > >
> > > On Thu, Apr 28, 2011 at 10:16 AM, ivan  wrote:
> > > > Hi,
> > > >
> > > > is there a possibility to use global variables in a for loop. More
> > > > specifically, I want to do the following:
> > > >
> > > > output.1<-rbind("a","b")
> > > > output.2<-rbind("c","d")
> > > > output.3<-rbind("e","f")
> > > > .
> > > > .
> > > > .
> > > > output.n<-rbind(...,...)
> > > >
> > > > next I want to create a data frame with two columns:
> > > >
> > > > Outputs
> > > > Values  output.1 "a","b"  output.2 "c","d"  output.3 "e","f"  .
> > > >  .
> > > >  output.n …,…
> > > > My problem is that I do not how to define a loop over global 
> variables.
> > > > Anybody an idea?
> > > >
> > > > 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.
> > > >
> > > >
> > >
> > >
> > >
> > > --
> > > Jim Holtman
> > > Data Munger Guru
> > >
> > > What is the problem that you are trying to solve?
> > >
> > 
> >[[alternative HTML version deleted]]
> > 
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] for loop with global variables

2011-04-28 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 28.04.2011 16:59:26:

> ivan  
> Odeslal: r-help-boun...@r-project.org
> 
> 28.04.2011 16:59
> 
> Komu
> 
> jim holtman 
> 
> Kopie
> 
> r-help@r-project.org
> 
> Předmět
> 
> Re: [R] for loop with global variables
> 
> Hi,
> 
> thank you for the response. What I actually want to do is pick 
automatically
> the results of the various outputs (which I have already defined as
> variables, e.g. output.1,output.2,etc) and insert them into a table. The
> list variable would be redundant since in order to create the data frame 
I
> would rather type data.frame(results=rbind(output.1,output.2,etc.)). If 
I
> had 100 outputs, this would be much work. I rather meant something like
> for(i in 1:100) {x=data.frame(results=rbind(output.[[i]]))}, which does 
not
> work though. It says that object "output." cannot be found.
> 
> Kind Regards

That is the problem. If you used list in the first time you could save 
yourself much problems. BTW - data frame is also a list with some special 
formating.

To extend my example

for(i in 1:3) {
lll[[i]] <- sample(letters,3)
names(lll)[i] <- LETTERS[i]
}

lll
$A
[1] "x" "t" "h"
$B
[1] "c" "m" "w"
$C
[1] "n" "s" "e"

 as.data.frame(lll)
  A B C
1 x c n
2 t m s
3 h w e

Regards
Petr




> 
> 
> 
> On Thu, Apr 28, 2011 at 4:31 PM, jim holtman  wrote:
> 
> > Yes you can, but there is not enough explaination as to what you
> > really want to do.  I would suggest that you look at using a 'list'
> > instead of individual objects:
> >
> > myList <- list(output.1 = rbind('a','b'), output.2 = rbind('c','d'), 
...)
> >
> > Then you can use 'lapply' to operation on the elements.
> >
> > On Thu, Apr 28, 2011 at 10:16 AM, ivan  wrote:
> > > Hi,
> > >
> > > is there a possibility to use global variables in a for loop. More
> > > specifically, I want to do the following:
> > >
> > > output.1<-rbind("a","b")
> > > output.2<-rbind("c","d")
> > > output.3<-rbind("e","f")
> > > .
> > > .
> > > .
> > > output.n<-rbind(...,...)
> > >
> > > next I want to create a data frame with two columns:
> > >
> > > Outputs
> > > Values  output.1 "a","b"  output.2 "c","d"  output.3 "e","f"  .
> > >  .
> > >  output.n …,…
> > > My problem is that I do not how to define a loop over global 
variables.
> > > Anybody an idea?
> > >
> > > 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.
> > >
> > >
> >
> >
> >
> > --
> > Jim Holtman
> > Data Munger Guru
> >
> > What is the problem that you are trying to solve?
> >
> 
>[[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] Odp: for loop with global variables

2011-04-28 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 28.04.2011 16:16:16:

> ivan  
> Odeslal: r-help-boun...@r-project.org
> 
> 28.04.2011 16:16
> 
> Komu
> 
> r-help@r-project.org
> 
> Kopie
> 
> Předmět
> 
> [R] for loop with global variables
> 
> Hi,
> 
> is there a possibility to use global variables in a for loop. More
> specifically, I want to do the following:
> 
> output.1<-rbind("a","b")
> output.2<-rbind("c","d")
> output.3<-rbind("e","f")
> .
> .
> .
> output.n<-rbind(...,...)
> 
> next I want to create a data frame with two columns:
> 
> Outputs
> Values  output.1 "a","b"  output.2 "c","d"  output.3 "e","f"  .
>  .
>  output.n …,…
> My problem is that I do not how to define a loop over global variables.
> Anybody an idea?

Don't do that. As Jim suggested use list inside a loop.

#declare a list
lll<-vector("list",3)

#do your loop
for(i in 1:3) lll[[i]] <- letters[i]

lll
[[1]]
[1] "a"

[[2]]
[1] "b"

[[3]]
[1] "c"

But I feel that you could maybe achieve desired result without loop in 
more Rish way. If what you want to do is reasonable and frequent I believe 
somebody already made a function which does what you want.

Regards
Petr


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


[R] Odp: read.table: fill=T for header?

2011-04-27 Thread Petr PIKAL
Hi

If I understand correctly you maybe could read a file without header, 
discard last column, read first line of a file and put it as column names.

read.delim(textConnection(infile), header=F, skip=1)
scan(textConnection(infile), nlines=1, sep="\t", what=c("",""))

Regards
Petr


r-help-boun...@r-project.org napsal dne 27.04.2011 14:15:33:

> 
>Dear ExpeRts,t
> 
> I am trying to read tab delimted data produced by somewhat brain dead
> software that seems to think it's a good idea to have an extra tab
> character after the last column - except for the header line. As
> explained in the help page, read.delim now assumes that the first
> column contains the row.names (which is not even wrong) but now and all
> col.names get shiftet by one column. Example:
> 
> infile <- 'sample\tx1\n1\tA\t\n2\tB\t\n3\tA\t'
> read.delim(textConnection(infile))
> sample x1
>   1  A NA
>   2  B NA
>   3  A NA
> 
> So I set row.names to NULL because the man page said "Using
> ‘row.names = NULL’ forces row numbering.". Now the row.names really
> are numbered automatically but I get a "bonus column":
> 
> read.delim(textConnection(infile), row.names=NULL)
> row.names sample x1
>   1 1  A NA
>   2 2  B NA
>   3 3  A NA
> 
> Hm - not what I want. I am also a bit puzzeled why the extra column is
> introduced instead of just using the first col.name. At the moment I
> deal with it by fixing the col.names and dumping the extra column:
> 
> dat <- read.delim(textConnection(infile), row.names=NULL)
> colnames(dat) <- colnames(dat)[-1]
> dat <- dat[-ncol(dat)]
> dat
> sample x1
>   1  1  A
>   2  2  B
>   3  3  A
> 
> I worked my way through ?read.delim but could not find an option to
> deal with these (flawed) files directly. As the opposite situation
> (i.e. more col.names than data) can be fixed with fill=T I was hoping
> something like fill.header=T or fill='header' may exist.  Did I just
> not find it or does it not exist?  And if it doesn't - does anyone
> else think it would be a nice item for the wishlist?
> 
> cu
>Philipp
> 
> 
> -- 
> Dr. Philipp Pagel
> Lehrstuhl für Genomorientierte Bioinformatik
> Technische Universität München
> Wissenschaftszentrum Weihenstephan
> Maximus-von-Imhof-Forum 3
> 85354 Freising, Germany
> http://webclu.bio.wzw.tum.de/~pagel/
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Odp: calculations with vectors of unequal length

2011-04-27 Thread Petr PIKAL
Hi


r-help-boun...@r-project.org napsal dne 27.04.2011 13:30:13:

> Hi there,
> 
> this is probably simple but I can't seem to figure it out by myself...
> 
> I have two dataframes (df.1 and df.2):
> 
> df.1 <- data.frame(year=factor(rep(1:3,3)), level=rep(letters[1:3],3),
> number=c(11:19))
> df.2 <- data.frame(year=factor(c(1:5)), number=c(21:25))
> 
> I would like to create a new variable df.1$new, which is supposed to
> be the sum of each element of df.1$number and those elements of
> df.2$number, where df.2$year equals df.1$year.

merge(df.1,df.2, by.x="year", by.y="year", all.x=T)
  year level number.x number.y
11 a   11   21
21 a   17   21
31 a   14   21

than you can sum last 2 columns. I believe that sqldf package can do what 
you want more efficiently but I do not use it so I do not know exact 
syntax.

Regards
Petr


> 
> What would be the most efficient way of doing this?
> 
> Regards,
> EH
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


<    1   2   3   4   5   6   7   8   9   10   >