Re: [R] Using apply to get group means

2009-03-31 Thread Domenico Vistocco
Sorry, there was a mistake in the previous mail: Domenico Vistocco wrote: A different solution (using aggregate for the table of means and merge for adding it to the dataframe): x1<-rep(c("A","B","C"),3) x2<-c(rep(1,3),rep(2,3),1,2,1) x3<-c(1,2,3,4,5

Re: [R] Using apply to get group means

2009-03-31 Thread Domenico Vistocco
A different solution (using aggregate for the table of means and merge for adding it to the dataframe): x1<-rep(c("A","B","C"),3) x2<-c(rep(1,3),rep(2,3),1,2,1) x3<-c(1,2,3,4,5,6,2,6,4) x<-data.frame(x1,x2,x3) #here using data.frame the x1 variable is directly converted to factor x3means <-

Re: [R] binary AND operators in R

2009-03-29 Thread Domenico Vistocco
You should find the functions: bitAnd, bitOr and bitXor in the bitops package. Ciao, domenico mau...@alice.it wrote: I cannot find any R function or operator that performs a binary AND operation, as performed by Fortran built-in function "iand". Ideally either R operator "&" or "&&" should d

Re: [R] How to select randomly from a matrix?

2009-03-09 Thread Domenico Vistocco
WXE83 wrote: Dear all, I got one problem here and hoping someone can help me on this. Say I have a 50 by 2 matrix and I don't know how to randomly select: data <- matrix(1:25, 50, 2) 1. a pair of observations from the last 10th of the 50 observation from the matrix. data[sample(41:50, 1

Re: [R] merge data frames with same column names of different lengths and missing values

2009-03-07 Thread Domenico Vistocco
Steven Lubitz wrote: Hello, I'm switching over from SAS to R and am having trouble merging data frames. The data frames have several columns with the same name, and each has a different number of rows. Some of the values are missing from cells with the same column names in each data frame. I h

Re: [R] Download and Import xls files in R

2009-03-07 Thread Domenico Vistocco
Jacopo Anselmi wrote: Dear List, I am trying to solve a problem: I have approximately 100 Excel spreadsheets each with approximately 4 sheet each that I would like to download and import in R for analysis. Unfortunately i realized (i also sent an email to the author or xlsReadWrite() ) that the

Re: [R] Summary grouped by factor

2009-03-06 Thread Domenico Vistocco
soeren.vo...@eawag.ch wrote: ### example:start v <- sample(rnorm(200), 100, replace=T) k <- rep.int(c("locA", "locB", "locC", "locD"), 25) tapply(v, k, summary) ### example:end This one is better: do.call(cbind, tapply(v,k,summary)) Ciao, domenico ... (hopefully) produces 4 summaries of v acc

Re: [R] Summary grouped by factor

2009-03-06 Thread Domenico Vistocco
soeren.vo...@eawag.ch wrote: ### example:start v <- sample(rnorm(200), 100, replace=T) k <- rep.int(c("locA", "locB", "locC", "locD"), 25) tapply(v, k, summary) ### example:end Maybe this could be a solution: t1 <- tapply(v, k, summary) t2 <- sapply(t1, cbind) rownames(t2) <- names(t1[[1]]) t2

Re: [R] How to apply a function to slices of multidimensional arrays, and not just iterating through single elements

2009-03-06 Thread Domenico Vistocco
If I well understand, maybe you have still apply at your disposal: arrayA <- 1:60 dim(arrayA) <- c(3,4,5) apply(arrayA, 2, sum) You have the same result of: res<-numeric(4);for (i in 1:4) res[i]<-sum(arrayA[,i,]) Ciao, domenico PS: have a look at plyr package for more "slicing" and "applying"

Re: [R] Something similar to data.frame, but allows variables with unique lengths?

2009-02-26 Thread Domenico Vistocco
Jason Rupert wrote: I have a tightly coupled collection of variables with different lengths and types (some characters and others numerics). I looked at the documentation for data.frame, but indicates that it expects all variables to have the same length, i.e. number of elements. I think you

Re: [R] understanding how R determines numbers and characters when creating a data frame

2009-02-18 Thread Domenico Vistocco
Alan Smith wrote: Hello R Users and Developers, I have a basic question about how R works. Over the past few years I have struggled when I try to generate a new data frame that I believe should contain numeric data in some columns and character data in others only to find everything converted t

Re: [R] Adding greek letters to plot title

2009-02-18 Thread Domenico Vistocco
gina patel wrote: I would like to add the greek letter mu to replace u in my title shown below. main="R=[0.001uM]:A=[750uM]" i tried using main=expression(R=[0.001~mu~M]:A=[750~mu~M]) plot(1:3, main=expression(paste("R=[0.001~",mu,"~M]:A=[750~",mu,"~M]"))) Ciao, domenico but this is not work

Re: [R] RcolorBrewer

2009-02-18 Thread Domenico Vistocco
Alina Sheyman wrote: I've downloaded the RcolorBrewer package, but when I try to run mypalette<-brewer.pal(7,"Greens") (or any other command with brewer.pal) I get the following error message - Error: could not find function "brewer.pal" Does anyone know why that's happening? Is there smth els

Re: [R] Creating several txt outputs

2009-02-18 Thread Domenico Vistocco
diego Diego wrote: Dear R experts: I have a list (a very long one) and I need to create successively txt outputs (on diferent files ideally) for the data of each component of the list. How can I do this? Maybe this could help you: list2Files <- list(1:3, letters[1:10], matrix(1:15, 5, 3))

Re: [R] lineplot in ggplot2 with different colour and linetype

2009-02-18 Thread Domenico Vistocco
Harsh wrote: Hi list, I would like to use ggplot2 in creating a line plot with 4 lines (groups), 2 of which I want in colour and the remaining two as dotted lines. ### R code ### library(ggplot2) ### create data vals <- rnorm(400) div<- c(rep("A",100),rep("B",100),rep("C",100),rep("D",100

[R] how to add points/lines to a surface plot

2009-02-10 Thread Domenico Vistocco
Dear All, is there a way to superimpose points and/or lines on a surface plot? Below I try to explain my problem. Suppose I have the following surface plot (likelikood for the normal variable when both parameters are unknown): ---

Re: [R] counting run lengths

2008-10-27 Thread Domenico Vistocco
Try this: unSpells[tail(Atr,1)==0] <- apply(Atr,2,function(x)sum(x==0))[tail(Atr,1)==0] Or (if you don't have to preserve the value in the unSpells vector): unSpells <- apply(Atr,2,function(x)sum(x==0)) But in this case you have 0 instead of 1 in the second and fourth position. Ciao, domenico

[R] two questions on Sweave (help in the output + warnings in the output)

2008-09-19 Thread Domenico Vistocco
Dear All, I am working on some slides using LaTeX/Beamer and R/Sweave. I have the two questions below (sorry if they are stupid or already solved but I didn't find solutions on the web). 1) Using the following code: \begin{frame}[containsverbatim] <>= help('dim') @ \end{frame} I have only: > h

Re: [R] Expert systems

2008-01-29 Thread Domenico Vistocco
I know that there are packages implementings the probabilistic expert systems (the so-called probabilistic networks or bayesian networks). You find (at least) the following packages: bnlearn (bayesian network structure learning) deal (learning bayesian networks with mixed variables) G1DBN (for dy

Re: [R] How to fill bar plot with textile rather than color

2008-01-28 Thread Domenico Vistocco
If you type > example(barplot) you will find an example. Ciao, domenico CHENYS wrote: > Hi, I'm looking for a tool which can fill bar chart with dash, skewed line, > or grids, rather than pure color. Any one have the idea how to do that in R? > Or maybe in Matlab will also be helpful. > > Than

Re: [R] two histograms in the same graph

2008-01-25 Thread Domenico Vistocco
You could use ggplot2: library(ggplot2) x=rnorm(100) y=rnorm(100) df=melt(data.frame(x,y)) #for "vertical" histogram ggplot(data=df,aes(x=value))+geom_histogram()+facet_grid(.~variable) #for "horizontal" histogram ggplot(data=df,aes(x=value))+geom_histogram()+facet_grid(.~variable) + coord_flip

Re: [R] How to do more advanced cross tabulation in R?

2008-01-23 Thread Domenico Vistocco
You could have a look at the reshape package. Ciao, domenico tom soyer wrote: > Hi, > > I am trying to reproduce some functionalities of Excel pivot table in R, > sadly, I couldn't figure out how to do it. I am wondering if this is even > possible in R. Does anyone know? > > Here is an example: >

Re: [R] contingency table on data frame

2008-01-22 Thread Domenico Vistocco
Karin Lagesen wrote: > I am sorry if this is a faq or tutorial somewhere, but I am unable to > solve this one. > > What I am looking for is a count of how many different > categories(numbers in this case) that appears for a given factor. > > Example: > > >> l <- c("Yes", "No", "Perhaps") >> x <-

Re: [R] Multivariable barplot

2008-01-22 Thread Domenico Vistocco
Domenico Vistocco wrote: > Pilar Loren wrote: > >> Hi, is it possible to do a multivariable barplot with ggplot2? >> >> I have something like that: >> >> >> >>> df >>> >>> >>LENGTH

Re: [R] Multivariable barplot

2008-01-22 Thread Domenico Vistocco
Pilar Loren wrote: > Hi, is it possible to do a multivariable barplot with ggplot2? > > I have something like that: > > >> df >> >LENGTH LAT > 091639 10.002 42.26282 > 091640 30.808 42.26834 > 091641 21.591 42.31689 > 091642 22.030 41.53246 > 091643 22.744 42

Re: [R] Converting plots to ggplot2

2008-01-17 Thread Domenico Vistocco
Thompson, David (MNR) wrote: > Hello Hadley, > > I am trying to reproduce the following with ggplot: > a <- seq(0, 360, 5)*pi/180 ; a > ac <- sin(a + (45*pi/180)) + 1 ; ac > plot(a, ac, type='b', xaxt = "n") > axis(1, at=seq(0,6,1), labels=round(seq(0,6,1)*180/pi),1) > abline(v=

Re: [R] side by side plots

2008-01-07 Thread Domenico Vistocco
[EMAIL PROTECTED] wrote: > Hello everyone, > > I have an overlay plot it's nice but you can't see all the data. I would > like to know if there is a way to get a plot that gives a side by side > plot so that each plot would be next to each other. The two plots have > the same data are of different

Re: [R] Plot only a subset of all factors in dataframe

2008-01-04 Thread Domenico Vistocco
?subset The select argument allows to select the columns and the subset argument the rows. domenico Laura Hollink wrote: > Hi all, > I have a dataframe called 'table' in which both factors and numerical > values are stored. > > > dim(table) > [1] 990 6 > > The fist 10 lines of table, to get

Re: [R] question about scale() function

2008-01-03 Thread Domenico Vistocco
tom soyer wrote: > oops, it should be: rms=(sum((x-mean(x))^2)/(length(x)-1))^(1/2) > sd(x) does the same thing. domenico > On 1/3/08, tom soyer <[EMAIL PROTECTED]> wrote: > >> Thanks Jim. Yes it does... but I calculated the root mean square (rms), >> and couldn't reproduce the result withou

Re: [R] if statement problem

2008-01-01 Thread Domenico Vistocco
You should look for your answer using the help for the if statement (?"if"). The cond argument should be a scalar (otherwise only the first element is used). ?"if" . cond: A length-one logical vector that is not 'NA'. Conditions of length greater than one are accepted with a warnin

Re: [R] gplot function - error

2007-12-28 Thread Domenico Vistocco
You changed the intial letter: the function is qplot and not gplot. domenico Ricardo Perrone wrote: > Hi all, > > i installed the ggplot2 package via install.packages(), but the gplot > function was not recognized in R console command. Is there any paths to > configure? The error message report

Re: [R] Diagonal matrix with off diagonal elements

2007-12-21 Thread Domenico Vistocco
Jonas Malmros wrote: > Hi, everyone > > I wonder if there is a function in R with which I can create a square > matrix with elements off main diagonal (for example one diagonal below > the main diagonal). > > Thanks in advance! > > You could combine rbind, diag and cbind: rbind(rep(0,3),cbind(d

Re: [R] Using boxplot in a daily time series

2007-12-15 Thread Domenico Vistocco
From your post it is not clear how the data are organized. Supposing they are in a data frame you could use the ~ sintax. For example: timeColumn=as.Date("01-01-1970") + 1:500 timeSeries=rnorm(500) df=data.frame(time=timeColumn, index=timeSeries) > > head(df) > time index > 1 1-01-20 -

Re: [R] Array dimnames

2007-12-15 Thread Domenico Vistocco
Sorry, there were mistakes in variable names... (I realized only after pressed the send button) Domenico Vistocco wrote: > dave mitchell wrote: > >> Dear all, >> Possibly a rudimentary question, however any help is greatly appreciated. I >> am sorting a large matrix

Re: [R] Array dimnames

2007-12-15 Thread Domenico Vistocco
dave mitchell wrote: > Dear all, > Possibly a rudimentary question, however any help is greatly appreciated. I > am sorting a large matrix into an array of dim(p(i),q,3). I put each entry > into a corresponding matrix (1 of the 3) based on some criteria. I figure > this will assist me in condens

Re: [R] what does cut(data, breaks=n) actually do?

2007-12-13 Thread Domenico Vistocco
cut(data, breaks=n) splits the data in n bins of (approximately) the same size. The used size is obtained by: max(data) - min(data) n > x=rnorm(x) > cut(x,breaks=3) [1] (1.79,9.97] (-6.39,1.79] (9.97,18.2] (9.97,18.2] (-6.39,1.79] [6] (

Re: [R] problem applying a conditional formula to each element of a matrix

2007-12-12 Thread Domenico Vistocco
The conditional have to be a single element: > ?"if" cond: A length-one logical vector that is not 'NA'. Conditions of length greater than one are accepted with a warning, but only the first element is used. Other types are coerced to logical if possible, ignoring

Re: [R] R and Excel Interface

2007-12-12 Thread Domenico Vistocco
[EMAIL PROTECTED] wrote: > Hello everyone, > > I'll to request some input on what is available for use as an R/Excel > interface; any help will be appreciated. > > Tony. > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing

Re: [R] Measure of agreement??

2007-12-12 Thread Domenico Vistocco
There is an agreement plot (and a relative measure) in the vcd package. Maybe it could be useful. domenico Ioannis Dimakos wrote: > Patrik, > > >> help.search("kappa") >> > > is a good place to start. Alternatively, > > >> RSiteSearch("measure of agreement") >> > > provides helpf

Re: [R] Importing Large Dataset into Excel

2007-12-12 Thread Domenico Vistocco
If you are using a windows system you could take a look at the xlsReadWrite packages (there are functions for reading xls files). domenico jim holtman wrote: > ?count.fields > > count.fields will tell you how many items are in each line. As you > said, they should all be the same, but this will

Re: [R] simple problems

2007-12-06 Thread Domenico Vistocco
marciarr wrote: > Hello R users, > I have been looking through Help files and Nabble list for the answers for > these simple questions, but it seems to be fruitless. > 1- in a data frame with two columns, x and y, how do I get the corresponding > value of x to, let's say, the minimum value of the y

Re: [R] R2HTML how to pair graphic.png and table

2007-12-06 Thread Domenico Vistocco
You could use a table with one row and two columns: HTML("",file=HTMLoutput) HTML(tab,file=HTMLoutput) HTML("",file=HTMLoutput) HTMLInsertGraph(graf,file=HTMLoutput,caption="Esempio di grafico") HTML("",file=HTMLoutput) domenico PS: You could create a function if this is a common operation: tab

Re: [R] colour coded points in biplot

2007-12-06 Thread Domenico Vistocco
If you are using correspondence analysis you could see the plot.ca function in the ca library. Petr PIKAL wrote: > Dear all > > I tried to make a biplot with color coded labels but I was not successful. > Searching archives I found that it is probably not so simple. > I found > http://tolstoy.ne

Re: [R] Conjoint Analysis in R??

2007-12-06 Thread Domenico Vistocco
http://tolstoy.newcastle.edu.au/R/help/05/06/6104.html http://tolstoy.newcastle.edu.au/R/help/05/06/6103.html domenico faisal afzal siddiqui wrote: > Pls advise how I can use R in conjoint analysis?? > > regds > Faisal Afzal Siddiqui > Karachi, Pakistan > > > >

Re: [R] correlation coefficient from qq plot

2007-12-06 Thread Domenico Vistocco
You could use the qqnorm function to obtain the correlation, as: > qqp=qqnorm(rstudent(regrname)) > cor(qqp$x,qqp$y) If you do not want see the plot (as the qq.plot is richer): > qqp=qqnorm(rstudent(regrname), plot.it=F) domenico vistocco Tom Fitzhugh wrote: > Hi, > &

Re: [R] newbie lapply question

2007-12-05 Thread Domenico Vistocco
> class(fff(x)) [1] "Date" Perhaps your function use a different input (not a vector of dates but a dataframe)? domenico vistocco Ranjan Bagchi wrote: > On Wed, 5 Dec 2007, Prof Brian Ripley wrote: > >> [...] >> > > Thanks I'll read it more car

Re: [R] Multiple stacked barplots on the same graph?

2007-12-05 Thread Domenico Vistocco
This command works: qplot(x=Categorie,y=Total,data=mydata,geom="bar",fill=Part) for your data. domenico vistocco Stéphane CRUVEILLER wrote: > Hi, > > the same error message is displayed with geom="bar" as parameter. > here is the output of dput: > > >

Re: [R] Inserting a subsequence between values of a vector

2007-12-04 Thread Domenico Vistocco
library(R.utils) pos=which(diff(x)==1)+1 insert(x,ats=pos,rep(list(rep(0,3)),length(pos))) domenico vistocco Serguei Kaniovski wrote: > Hallo, > > suppose I have a vector: > > x <- c(1,1,1,2,2,3,3,3,3,3,4) > > How can I generate a vector/sequence in which a fixed numbe

Re: [R] Multiple stacked barplots on the same graph?

2007-12-04 Thread Domenico Vistocco
4,sep="") > library(ggplot2) > dfm=melt(x) > qplot(as.factor(x=X1),y=value,geom="histogram",data=dfm,fill=X2) domenico vistocco Stéphane CRUVEILLER wrote: > Dear R-Users, > > I would like to know whether it is possible to draw several >

Re: [R] reduce the code used by "for"

2007-12-04 Thread Domenico Vistocco
n to set the missing in the third row to 0: > y[3,,][which(is.na(y[3,,]))]=0 and to set the missing in the other rows to 1: > y[-3,,][which(is.na(y[-3,,]))]=1 domenico vistocco Luis Ridao Cruz wrote: > R-help, > > I have a 3-way array: > > >> dim(bugvinP) >

Re: [R] ggplot2: Choosing colours

2007-12-04 Thread Domenico Vistocco
qplot(data=dataset, x, y, colour=z) ONKELINX, Thierry wrote: > Dear useRs, > > I'm trying to specify the colour of a factor with ggplot2. The example > below gets me close to what I want, but it's missing a legend. > > Any ideas? > > Thanks, > > Thierry > > library(ggplot2) > dataset <- data.frame

Re: [R] ggplot2: Choosing colours

2007-12-03 Thread Domenico Vistocco
qplot(data=dataset, x, y, colour=z) ONKELINX, Thierry wrote: > Dear useRs, > > I'm trying to specify the colour of a factor with ggplot2. The example > below gets me close to what I want, but it's missing a legend. > > Any ideas? > > Thanks, > > Thierry > > library(ggplot2) > dataset <- data.frame