Re: [R] Get a percent variable based on group
Hi, Is it this? aggregate(iris$Sepal.Length,by=list(iris$Species),FUN=function(x) sum(x)/sum(iris$Sepal.Length)*100) Group.1 x 1 setosa 28.55676 2 versicolor 33.86195 3 virginica 37.58129 A.K. From: Karine Charlebois karine.charleb...@outlook.com To: arun smartpink...@yahoo.com Sent: Tuesday, January 15, 2013 10:22 PM Subject: RE: [R] Get a percent variable based on group For example, iris$percent - unlist(tapply(iris$Sepal.Length,iris$Species,function(x) x/sum(iris$Sepal.Length, na.rm=TRUE))) aggregate(iris$percent, by=list(iris$Species), FUN=sum, na.rm=TRUE) this last command should return 100% for each specie, not the following values: Group.1 x 1 setosa 0.2855676 2 versicolor 0.3386195 3 virginica 0.3758129 From: karine.charleb...@outlook.com To: smartpink...@yahoo.com Subject: RE: [R] Get a percent variable based on group Date: Tue, 15 Jan 2013 22:13:27 -0500 No, it is not. I need a new column with these values. Karine Date: Tue, 15 Jan 2013 19:11:22 -0800 From: smartpink...@yahoo.com Subject: Re: [R] Get a percent variable based on group To: karine.charleb...@outlook.com CC: r-help@r-project.org HI, Not sure if this is what you meant. tapply(iris$Sepal.Length,iris$Species,FUN=function(x) sum(x)/sum(iris$Sepal.Length)*100) # setosa versicolor virginica # 28.55676 33.86195 37.58129 A.K. - Original Message - From: Karine Charlebois karine.charleb...@outlook.com To: r-help@r-project.org r-help@r-project.org Cc: Sent: Tuesday, January 15, 2013 9:30 PM Subject: [R] Get a percent variable based on group Dear all, I'd like to get a percentage variable based on a group, but without creating a new data frame. For example: data(iris) iris$percent -unlist(tapply(iris$Sepal.Length,iris$Species,function(x) x/sum(x, na.rm=TRUE))) This does not work, I should have only three standard values, respectively for setosa, versicolor, and virginica. How can I do this? MANY THANKS, Karine [[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] matrix manipulation with its rows
Dear R users, I have a question about matrix manipulation with its rows. Plz see the simple example below sample - list(matrix(1:6, nr=2,nc=3), matrix(7:12, nr=2,nc=3), matrix(13:18,nr=2,nc=3)) sample [[1]] [,1] [,2] [,3] [1,]135 [2,]246 [[2]] [,1] [,2] [,3] [1,]79 11 [2,]8 10 12 [[3]] [,1] [,2] [,3] [1,] 13 15 17 [2,] 14 16 18 With this list, I'd like to create this below [[1]] [,1] [,2] [,3] [,4] [,5] [,6] [1,]135 000 [2,]000 246 [[2]] [,1] [,2] [,3] [,4] [,5] [,6] [1,]79 11 000 [2,] 0008 10 12 [[3]] [,1] [,2] [,3] [,4] [,5] [,6] [1,] 13 15 17 000 [2,] 000 14 16 18 Any suggestion will be greatly appreciated. Regards, Kathryn Lord [[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] dendrogram stops!
Dear I am using the 'as.dendrogram' function from the 'stats' library to convert from an hclust object to a dendrogram with a dataset of size ~3 (an example code is below). I need the dendrogram structure to use the dendrapply and attributes functions and to access the child nodes, I do not need any of the plot properties. The problem is that it takes an infinite amount of time to convert and it uses a lot of memory. Could you please let me know which part of the code (the link is below) takes the longest time and if there's a way to make it faster. Is it the recursive part or when applying the attributes to each node (merging, etc) ? If there isn't a way to make it faster, are there similar functions(dendrapply, attributes, accessing of child nodes) that use the hclust object instead? as.dendrogram code: https://svn.r-project.org/R/trunk/src/library/stats/R/dendrogram.R library('stats') library('fastcluster') options(expressions=50) NCols=10 NRows=3 DataB -matrix(runif(NCols*NRows), ncol=NCols) HClust - hclust.vector(DataB ) dhc- as.dendrogram(HClust) #gets stuck here forever| Best RegardsSobh [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] dendrogram stops!
Le mercredi 16 janvier 2013 à 07:29 +0200, Ibrahim Sobh a écrit : Dear I am using the 'as.dendrogram' function from the 'stats' library to convert from an hclust object to a dendrogram with a dataset of size ~3 (an example code is below). I need the dendrogram structure to use the dendrapply and attributes functions and to access the child nodes, I do not need any of the plot properties. Could you be more specific about what you want to do? Maybe you don't need these functions because there are alternate ways of doing the same thing with an hclust object. Cheers The problem is that it takes an infinite amount of time to convert and it uses a lot of memory. Could you please let me know which part of the code (the link is below) takes the longest time and if there's a way to make it faster. Is it the recursive part or when applying the attributes to each node (merging, etc) ? If there isn't a way to make it faster, are there similar functions(dendrapply, attributes, accessing of child nodes) that use the hclust object instead? as.dendrogram code: https://svn.r-project.org/R/trunk/src/library/stats/R/dendrogram.R library('stats') library('fastcluster') options(expressions=50) NCols=10 NRows=3 DataB -matrix(runif(NCols*NRows), ncol=NCols) HClust - hclust.vector(DataB ) dhc- as.dendrogram(HClust) #gets stuck here forever| Best RegardsSobh [[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] Can not load Rcmdr
Le mardi 15 janvier 2013 à 22:49 +, Esformes, Carley M. a écrit : I am getting the error message: library(Rcmdr) Loading required package: car Loading required package: MASS Loading required package: nnet Error : .onAttach failed in attachNamespace() for 'Rcmdr', details: call: structure(.External(dotTclObjv, objv, PACKAGE = tcltk), class = tclObj) error: [tcl] invalid command name image. Error: package/namespace load failed for 'Rcmdr' If I try and load tcltk separately, it loads, but I get a warning. library(tcltk) Loading Tcl/Tk interface ... done Warning message: In fun(libname, pkgname) : couldn't connect to display /tmp/launch-pCcdvk/:0 _X11TransSocketINETConnect() can't get address for /tmp/launch-pCcdvk/:6000: nodename nor servname provided, or not known As you found out yourself, this seems to be a tcltk error, not a Rcmdr one. For starters, what's your operating system? Please post the output of sessionInfo() as requested by the posting guide. Regards I want to run BiodiversityR. Which runs, but ultimately I get an error. library(BiodiversityR) Loading required package: vegan Loading required package: permute This is vegan 2.0-5 BiodiversityRGUI() Loading required package: Rcmdr Error : .onAttach failed in attachNamespace() for 'Rcmdr', details: call: structure(.External(dotTclObjv, objv, PACKAGE = tcltk), class = tclObj) error: [tcl] invalid command name image. Error in BiodiversityRGUI() : needs Rcmdr __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Aligning labels to bars in barplot
Hi, Consider: x=c(2,4,5,10,13,73) names(x)=c(American\nIndian, No\ncategory\nlisted, Hispanic, African-\nAmerican, Asian, White) barplot(x,main=Undergraduate Enrollment by Race, xlab=Race, ylab=Percent, col=rainbow(6)) The labels at the bottom of the bars are aligned at the bottom of the last word in each bar label. How can I code it so that the labels are aligned at the top of the first word in each bar label? Thanks, David. -- View this message in context: http://r.789695.n4.nabble.com/Aligning-labels-to-bars-in-barplot-tp4655701.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] function approx interpolation of time series data sets
Readers, Am trying to use the function 'approx' to interpolate time series data sets: data1: 01:23:40 5 01:23:45 10 01:23:50 12 01:23:55 7 data2: 01:23:42 01:23:47 01:23:51 01:23:54 The objective is to obtain interpolated values of 'data1' column 2 (5, 10, 12, 7) for the times shown in data2. Tried the following command but received the error shown: data3-approx(data1,xout=data2) Error in approx(data1, xout = data2) : (list) object cannot be coerced to type 'double' What is my mistake please? -- r2151 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Aligning labels to bars in barplot
On 01/16/2013 07:48 PM, David Arnold wrote: Hi, Consider: x=c(2,4,5,10,13,73) names(x)=c(American\nIndian, No\ncategory\nlisted, Hispanic, African-\nAmerican, Asian, White) barplot(x,main=Undergraduate Enrollment by Race, xlab=Race, ylab=Percent, col=rainbow(6)) The labels at the bottom of the bars are aligned at the bottom of the last word in each bar label. How can I code it so that the labels are aligned at the top of the first word in each bar label? Hi David, Try this: barpos-barplot(x, main=Undergraduate Enrollment by Race, names.arg=rep(,6), xlab=Race, ylab=Percent, col=rainbow(6)) axis(1,at=barpos,labels=names(x),padj=1) Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] matrix manipulation with its rows
Hi with your specific example you can use remat-function(mat) { mt-t(mat) mt-c(mt[1:3], rep(0,6), mt[4:6]) matrix(mt, 2,6, byrow=TRUE) } lapply(sample, remat) Regards Petr -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Kathryn Lord Sent: Wednesday, January 16, 2013 9:00 AM To: r-help@r-project.org Subject: [R] matrix manipulation with its rows Dear R users, I have a question about matrix manipulation with its rows. Plz see the simple example below sample - list(matrix(1:6, nr=2,nc=3), matrix(7:12, nr=2,nc=3), matrix(13:18,nr=2,nc=3)) sample [[1]] [,1] [,2] [,3] [1,]135 [2,]246 [[2]] [,1] [,2] [,3] [1,]79 11 [2,]8 10 12 [[3]] [,1] [,2] [,3] [1,] 13 15 17 [2,] 14 16 18 With this list, I'd like to create this below [[1]] [,1] [,2] [,3] [,4] [,5] [,6] [1,]135 000 [2,]000 246 [[2]] [,1] [,2] [,3] [,4] [,5] [,6] [1,]79 11 000 [2,] 0008 10 12 [[3]] [,1] [,2] [,3] [,4] [,5] [,6] [1,] 13 15 17 000 [2,] 000 14 16 18 Any suggestion will be greatly appreciated. Regards, Kathryn Lord [[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] matrix manipulation with its rows
Not a great solution, I don't think, but: kronecker(diag(2), matrix(1:6, 2, byrow=TRUE))[c(1,4),] [,1] [,2] [,3] [,4] [,5] [,6] [1,]123000 [2,]000456 So using a function that does this in 'lapply' should solve the problem you state. I'm guessing the real problem might be more complex. Pat On 16/01/2013 07:59, Kathryn Lord wrote: Dear R users, I have a question about matrix manipulation with its rows. Plz see the simple example below sample - list(matrix(1:6, nr=2,nc=3), matrix(7:12, nr=2,nc=3), matrix(13:18,nr=2,nc=3)) sample [[1]] [,1] [,2] [,3] [1,]135 [2,]246 [[2]] [,1] [,2] [,3] [1,]79 11 [2,]8 10 12 [[3]] [,1] [,2] [,3] [1,] 13 15 17 [2,] 14 16 18 With this list, I'd like to create this below [[1]] [,1] [,2] [,3] [,4] [,5] [,6] [1,]135 000 [2,]000 246 [[2]] [,1] [,2] [,3] [,4] [,5] [,6] [1,]79 11 000 [2,] 0008 10 12 [[3]] [,1] [,2] [,3] [,4] [,5] [,6] [1,] 13 15 17 000 [2,] 000 14 16 18 Any suggestion will be greatly appreciated. Regards, Kathryn Lord [[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. -- Patrick Burns pbu...@pburns.seanet.com twitter: @portfolioprobe http://www.portfolioprobe.com/blog http://www.burns-stat.com (home of 'Some hints for the R beginner' and 'The R Inferno') __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Overplotting in GGPLOT
Dear All, I am struggling to jitter the labels in this plot: p-ggplot(centbev,aes(x=bet,y=eig,label=rownames(centbev),colour=res, size=abs(res)))+xlab(Betweenness Centrality)+ylab(Eigenvector Centrality) p+geom_text()+labs(title=Key Actor Analysis AD FD Network) When I try this without jittering I end up with labels that I cannot distinguish, when I try it with, I get a circular spot behind the label which makes it illegible. I want to make the labels (which are numeric) legible. Many thanks for any guidance. Nick __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 approx interpolation of time series data sets
Hello, Like this? data1 - read.table(text = 01:23:40 5 01:23:45 10 01:23:50 12 01:23:55 7 ) data2 - read.table(text = 01:23:42 01:23:47 01:23:51 01:23:54 ) approx(as.POSIXct(data1$V1, format = %H:%M:%S), y = data1$V2, xout = as.POSIXct(data2$V1, format = %H:%M:%S)) Hope this helps, Rui Barradas Em 16-01-2013 08:52, e-letter escreveu: Readers, Am trying to use the function 'approx' to interpolate time series data sets: data1: 01:23:40 5 01:23:45 10 01:23:50 12 01:23:55 7 data2: 01:23:42 01:23:47 01:23:51 01:23:54 The objective is to obtain interpolated values of 'data1' column 2 (5, 10, 12, 7) for the times shown in data2. Tried the following command but received the error shown: data3-approx(data1,xout=data2) Error in approx(data1, xout = data2) : (list) object cannot be coerced to type 'double' What is my mistake please? -- r2151 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] removing loops from code in making data.frame
thanks, it goes a lot faster. Just one thing though, when I apply the code to my data, both data.frames end up differente. Or at least identical(df1, df2) if false however when i do which(df1!=df2) it says 'integer (0)'. Could that be due to the class of the vectors or some thing of the sort? thanks, David Biau De : arun smartpink...@yahoo.com À : Biau David djmb...@yahoo.fr Cc : R help r-help@r-project.org Envoyé le : Mardi 15 janvier 2013 21h54 Objet : Re: [R] removing loops from code in making data.frame Hi, You could also do this: res1-do.call(rbind,lapply(xaulist,function(x) as.numeric(apply(t(mapply(`==`,tata,x)),2,any identical(res1,tutu) #[1] TRUE A.K. - Original Message - From: Biau David djmb...@yahoo.fr To: r help list r-help@r-project.org Cc: Sent: Tuesday, January 15, 2013 2:41 PM Subject: [R] removing loops from code in making data.frame Dear all, I am working on an author network and to do so I have to arrange a data.frame (tutu) crossing author names (rows) per publication number (column). The participation of the author to a study is indicated by a 1 and 0 otherwise. I have a vector (xaulist) of all the names of authors and a data.frame (tata) with all the publications in row and the authors in columns. I have writen a loop to obtain my data.frame but it takes a long time when the number of studies increases. I was looking for a more efficient code. Here is a minimal working example (my code is terrible i know...): #- au1 - c('deb', 'art', 'deb', 'seb', 'deb', 'deb', 'mar', 'mar', 'joy', 'deb') au2 - c('art', 'deb', 'soy', 'deb', 'joy', 'ani', 'deb', 'deb', 'nem', 'mar') au3 - c('mar', 'lio', 'mil', 'mar', 'ani', 'lul', 'nem', 'art', 'deb', 'tat') tata - data.frame(au1, au2, au3) xaulist2 - levels(factor(unlist(tata[,]))) xaulist - levels(as.factor(xaulist2)) tutu - matrix(NA, nrow=length(xaulist), ncol=dim(tata)[1]) # row are authors and col are papers for (i in 1:length(xaulist)) { for (j in 1:dim(tata)[1]) { ifelse('TRUE' %in% as.character(tata[j,]==xaulist[i]), tutu[i,j] - 1, tutu[i,j] - 0) } } tutu[is.na(tutu)] - 0 #- I am looking at some more efficient way to build 'tutu'. Thank you very much, David [[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] read tab delimited file from a certain line
Hi I would like to read table data from a text-files with extra informations in the header (of unknown line count). Example: informations (unknown count of lines) ... and at some point the table -- year month mday value 2013 1 16 0 ... If it was an excel file I could use something like read.xls(..., pattern=year) But it is a simple tab seperated text-file. Is there an easy way to read only the table? (Without dirty things ;)) Thx Christof __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Using table to get frequencies of several factors at once
You could use a variant of apply(), probably sapply For example d - as.data.frame( matrix(sample(0:1, 200, replace=TRUE), ncol=5)) head(d) sapply(d, table) S Ellison -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Pancho Mulongeni Sent: 11 January 2013 11:18 To: R help Subject: [R] Using table to get frequencies of several factors at once Hi, I have a dataframe with n columns, but I am only looking at five of them. And lots of rows, over 700. So I would like to find frequencies for each of the numeric columns (variables) using the table function. However, is there a fast way to produce a frequency table where the 5 rows represent the 5 numeric variables and the columns refer to the values (levels) of the respective numeric variables, which in this case are 0 and 1. The only way I have figured it out is via a for loop: m-seq(218,222,1) #these are columns of the variables in the larger dataframe tm-m[1:5] #I need this for the for loop l.tm-length(tm) B-matrix(nrow=l.tm,ncol=2) #the matrix to hold the freqs for (p in 1:l.tm) { var.num-m[p] B[p,]-table(DATA[,var.num]) } B [,1] [,2] [1,] 6979 [2,] 512 194 [3,] 604 102 [4,] 7006 [5,] 706 706 So the rows represent my five variables (columns) that occupy columns 218 through 222 in the DATA dataframe. So the second column represents my frequencies of the value 1, which is what I am interested in. The last row has a double entry, because there was only one value, 0, with a freq of 706 and so R duplicated in the two columns, but that's ok, I can just ignore it. So is there are better way to do this? Is there a way to use the so called tapply function? I struggle to understand the help doc for this.function. Pancho Mulongeni Research Assistant PharmAccess Foundation 1 Fouché Street Windhoek West Windhoek Namibia Tel: +264 61 419 000 Fax: +264 61 419 001/2 Mob: +264 81 4456 286 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. *** This email and any attachments are confidential. Any use...{{dropped:8}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Codetools Query (repost)
You really don't want to use internals like isBaseVar as there is no guarantee they will continue to exist. Even collectUsage and otehr things mentioned on the same page may need to change if this is reimplemented. The most robust approach is to use findGlobals and omit what you don't want, e.g. omit - ls(package:base, all.names=TRUE) setdiff(findGlobals(moo),omit) [1] y If you do want to use chollectUsage you could use something like funs - new.env() omit - ls(package:base, all.names=TRUE) enter - function(type, v, e, w){ if (! v %in% omit) assign(v, TRUE, funs) } collectUsage(moo, enterGlobal = enter) If %in% is too slow create a hashed envorinment and use exists(). Best, luke On Tue, 15 Jan 2013, Saptarshi Guha wrote: Sorry for reposting, i keep forgetting this should be plain text. Will not make this mistake again Hello, The following code moo - function(a=1){ x=1; x=x+y} funs - new.env() enter - function(type, v, e, w){ assign(v, TRUE, funs) } library(codetools) collectUsage(moo, enterGlobal = enter) adds + to the environment funs i.e. funs: = { + y How can i ignore variables which are present in base, utils, stat environments from being added (equivalently(?) symbols present in R when R is started) I tried funs - new.env() enter - function(type, v, e, w){ if(codetools:::isBaseVar(v, w$env) || codetools:::isStatsVar(v, w$env) || codetools:::isUtilsVar(v, w$env) || v == Quote) return() assign(v, TRUE, funs) } library(codetools) collectUsage(moo, enterGlobal = enter) but this threw Error in exists(v, envir = e, inherits = FALSE, mode = function) : invalid 'envir' argument Cheers __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Luke Tierney Chair, Statistics and Actuarial Science Ralph E. Wareham Professor of Mathematical Sciences University of Iowa Phone: 319-335-3386 Department of Statistics andFax: 319-335-3017 Actuarial Science 241 Schaeffer Hall email: luke-tier...@uiowa.edu Iowa City, IA 52242 WWW: http://www.stat.uiowa.edu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Mean calculation by two variables
Hello All, I have a data frame (dput information below) with food item weight for fish species. I need to calculate the Mean proportion by weight of each food item for each specie, as show in solution data frame (dput information below). I use the ddply function (plyr package) in two steps. First calculate the proportion of weight for each individual: step1 = ddply (example, .(ID), transform, Wi = round (Weight/sum (Weight), 2)) Then, I use lenght (unique (ID)) to calculate the mean of each food item for each specie: step2 = ddply (step1, .(Specie, Food.item), summarise, MWi = sum (Wi)/length (unique(ID))) I do not understand why this didn't work. Someone can help me? Thanks in advanced! *EXAMPLE* structure(list(ID = c(779L, 782L, 1717L, 1717L, 1717L, 1803L, 2650L, 2650L, 2700L, 2700L, 3611L, 3613L, 3647L, 3654L, 3654L, 3683L, 3683L, 3683L, 3685L, 3997L), Site = c(Três Marias, Três Marias, Nova Ponte, Nova Ponte, Nova Ponte, Três Marias, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão), Specie = c(Acestrorhynchus lacustris, Acestrorhynchus lacustris, Acestrorhynchus lacustris, Acestrorhynchus lacustris, Acestrorhynchus lacustris, Acestrorhynchus lacustris, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius), Weight = c(0.06, 0.01, 0.01, 0.33, 0.01, 3.5, 0.01, 0.04, 0.01, 0.01, 0.38, 0.29, 0.04, 0.03, 0.11, 0.04, 0.04, 0.03, 0.01, 0.01), Food.item = c(Fish, Vegetal, Alga, MNI, Sediment, Fish, Alga, MNI, Alga, MNI, Vegetal, Vegetal, Vegetal, Alga, Vegetal, Alga, MNI, Sediment, Sediment, Vegetal)), .Names = c(ID, Site, Specie, Weight, Food.item), row.names = c(1869113L, 2290407L, 56668L, 1485394L, 2126489L, 368143L, 57601L, 1486327L, 57651L, 1486377L, 2348187L, 2348189L, 2293272L, 58605L, 2293279L, 40317L, 1487360L, 2128455L, 2128457L, 2293622L), class = data.frame) *SOLUTION* structure(list(Specie = c(Acestrorhynchus lacustris, Acestrorhynchus lacustris, Acestrorhynchus lacustris, Acestrorhynchus lacustris, Acestrorhynchus lacustris, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius), Food.item = c(Peixe, Vegetal, Alga, MNI, Sedimento, Alga, MNI, Vegetal, Sedimento), MWi = c(0.5, 0.25, 0.0075, 0.235, 0.0075, 0.14111, 0.18444, 0.53222, 0.14111)), .Names = c(Specie, Food.item, MWi), class = data.frame, row.names = c(NA, -9L)) * * sessionInfo() R version 2.15.2 (2012-10-26) Platform: i386-w64-mingw32/i386 (32-bit) Windows XP * * -- Raoni Rosa Rodrigues Research Associate of Fish Transposition Center CTPeixes Universidade Federal de Minas Gerais - UFMG Brasil rodrigues.ra...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Changing frequency values to 1 and 0
Dear list, I'm working with a large data set, where I grouped several species in one group (guild). Then I reshaped my data as shown below. Now, I just want to have Rep only as 1 or 0. I'm not being able to change the values of rep=1 to 1... tried many things and I'm not being successful! melting=melt(occ.data,id.var=c(guild, Site, Rep, Año), measure.var=Pres) y=cast(melting, Site ~ Rep ~ guild ~ Año) Aggregation requires fun.aggregate: length used as default y[1:10,,gui4a,1:2] , , Año = 2003 Rep Site 1 2 3 4 5 1021 0 0 0 0 0 1022 0 0 0 0 0 1023 0 0 0 0 0 1024 0 0 0 0 0 1025 0 0 0 0 0 1026 0 0 0 0 0 * 1051 3 1 2 3 5* * 1052 4 3 5 2 3* * 1053 4 3 3 3 2* * 1054 1 2 1 3 0* , , Año = 2004 Rep Site 1 2 3 4 5 1021 2 5 5 5 4 1022 6 3 2 2 2 1023 4 1 1 2 2 1024 0 1 2 2 0 1025 0 1 0 1 0 1026 2 1 0 0 1 1051 2 1 3 1 2 1052 2 4 1 1 2 1053 2 4 2 2 1 1054 4 3 3 2 3 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] read tab delimited file from a certain line
Hello, Read the file using readLines, then grep ^year. You can then use a textConnection to read.table: x - readLines(con = textConnection( informations (unknown count of lines) ... and at some point the table -- year month mday value 2013 1 16 0 )) # This is it i - grep(^year, x) read.table(textConnection(x[i:length(x)]), header = TRUE) Hope this helps, Rui Barradas Em 16-01-2013 14:17, Christof Kluß escreveu: Hi I would like to read table data from a text-files with extra informations in the header (of unknown line count). Example: informations (unknown count of lines) ... and at some point the table -- year month mday value 2013 1 16 0 ... If it was an excel file I could use something like read.xls(..., pattern=year) But it is a simple tab seperated text-file. Is there an easy way to read only the table? (Without dirty things ;)) Thx Christof __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Mean calculation by two variables
Hello, If you want to calculate the mean weight by Specie and Food.item, you can use ?aggregate. In what follows, I've named your EXAMPLE ex and your SOLUTION sol. Note that the result is different from sol. (No exemplo não há Peixe, é Fish, e os números são outros.) aggregate(Weight ~ Specie + Food.item, data = ex, FUN = mean) Hope this helps, Rui Barradas Em 16-01-2013 15:41, Raoni Rodrigues escreveu: Hello All, I have a data frame (dput information below) with food item weight for fish species. I need to calculate the Mean proportion by weight of each food item for each specie, as show in solution data frame (dput information below). I use the ddply function (plyr package) in two steps. First calculate the proportion of weight for each individual: step1 = ddply (example, .(ID), transform, Wi = round (Weight/sum (Weight), 2)) Then, I use lenght (unique (ID)) to calculate the mean of each food item for each specie: step2 = ddply (step1, .(Specie, Food.item), summarise, MWi = sum (Wi)/length (unique(ID))) I do not understand why this didn't work. Someone can help me? Thanks in advanced! *EXAMPLE* structure(list(ID = c(779L, 782L, 1717L, 1717L, 1717L, 1803L, 2650L, 2650L, 2700L, 2700L, 3611L, 3613L, 3647L, 3654L, 3654L, 3683L, 3683L, 3683L, 3685L, 3997L), Site = c(Três Marias, Três Marias, Nova Ponte, Nova Ponte, Nova Ponte, Três Marias, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão), Specie = c(Acestrorhynchus lacustris, Acestrorhynchus lacustris, Acestrorhynchus lacustris, Acestrorhynchus lacustris, Acestrorhynchus lacustris, Acestrorhynchus lacustris, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius), Weight = c(0.06, 0.01, 0.01, 0.33, 0.01, 3.5, 0.01, 0.04, 0.01, 0.01, 0.38, 0.29, 0.04, 0.03, 0.11, 0.04, 0.04, 0.03, 0.01, 0.01), Food.item = c(Fish, Vegetal, Alga, MNI, Sediment, Fish, Alga, MNI, Alga, MNI, Vegetal, Vegetal, Vegetal, Alga, Vegetal, Alga, MNI, Sediment, Sediment, Vegetal)), .Names = c(ID, Site, Specie, Weight, Food.item), row.names = c(1869113L, 2290407L, 56668L, 1485394L, 2126489L, 368143L, 57601L, 1486327L, 57651L, 1486377L, 2348187L, 2348189L, 2293272L, 58605L, 2293279L, 40317L, 1487360L, 2128455L, 2128457L, 2293622L), class = data.frame) *SOLUTION* structure(list(Specie = c(Acestrorhynchus lacustris, Acestrorhynchus lacustris, Acestrorhynchus lacustris, Acestrorhynchus lacustris, Acestrorhynchus lacustris, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius), Food.item = c(Peixe, Vegetal, Alga, MNI, Sedimento, Alga, MNI, Vegetal, Sedimento), MWi = c(0.5, 0.25, 0.0075, 0.235, 0.0075, 0.14111, 0.18444, 0.53222, 0.14111)), .Names = c(Specie, Food.item, MWi), class = data.frame, row.names = c(NA, -9L)) * * sessionInfo() R version 2.15.2 (2012-10-26) Platform: i386-w64-mingw32/i386 (32-bit) Windows XP * * __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Changing frequency values to 1 and 0
Sorry, but i don't get the problem at all. Could you provide a bit of y by using dput()? Can you provide an example of how you want the data to look like after the transformation? On 16.01.2013, at 16:42, Andrea Goijman wrote: Dear list, I'm working with a large data set, where I grouped several species in one group (guild). Then I reshaped my data as shown below. Now, I just want to have Rep only as 1 or 0. I'm not being able to change the values of rep=1 to 1... tried many things and I'm not being successful! melting=melt(occ.data,id.var=c(guild, Site, Rep, Año), measure.var=Pres) y=cast(melting, Site ~ Rep ~ guild ~ Año) Aggregation requires fun.aggregate: length used as default y[1:10,,gui4a,1:2] , , Año = 2003 Rep Site 1 2 3 4 5 1021 0 0 0 0 0 1022 0 0 0 0 0 1023 0 0 0 0 0 1024 0 0 0 0 0 1025 0 0 0 0 0 1026 0 0 0 0 0 * 1051 3 1 2 3 5* * 1052 4 3 5 2 3* * 1053 4 3 3 3 2* * 1054 1 2 1 3 0* , , Año = 2004 Rep Site 1 2 3 4 5 1021 2 5 5 5 4 1022 6 3 2 2 2 1023 4 1 1 2 2 1024 0 1 2 2 0 1025 0 1 0 1 0 1026 2 1 0 0 1 1051 2 1 3 1 2 1052 2 4 1 1 2 1053 2 4 2 2 1 1054 4 3 3 2 3 [[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] Changing frequency values to 1 and 0
Dear Andrea I may have not understood the question properly, but I guess it has to do with replacing values before and after casting. The molten object ('melting') is a data frame, whilst the cast object ('y') is an array. Crucially, the values of the variable Rep in the 'melting' data frame become the names of the columns in each component within the cast array object. So, if you want to change the values where rep=1 to 1, you have to do that before casting the molten object. If you look at ?cast, you get this example: names(airquality) - tolower(names(airquality)) aqm - melt(airquality, id=c(month, day), na.rm=TRUE) cast(aqm, day ~ month ~ variable) Let's assign the cast result to an object: y=cast(aqm, day ~ month ~ variable) Now let's have a look at the three objects: head(airquality) ozone solar.r wind temp month day 141 190 7.4 67 5 1 236 118 8.0 72 5 2 312 149 12.6 74 5 3 418 313 11.5 62 5 4 5NA NA 14.3 56 5 5 628 NA 14.9 66 5 6 head(aqm) month day variable value 1 5 1ozone41 2 5 2ozone36 3 5 3ozone12 4 5 4ozone18 5 5 6ozone28 6 5 7ozone23 y[1:10,,ozone] month day 5 6 7 8 9 1 41 NA 135 39 96 2 36 NA 49 9 78 3 12 NA 32 16 73 4 18 NA NA 78 91 5 NA NA 64 35 47 6 28 NA 40 66 32 7 23 29 77 122 20 8 19 NA 97 89 23 9 8 71 97 110 21 10 NA 39 85 NA 24 y[1:10,,wind] month day 56789 1 7.4 8.6 4.1 6.9 6.9 2 8.0 9.7 9.2 13.8 5.1 3 12.6 16.1 9.2 7.4 2.8 4 11.5 9.2 10.9 6.9 4.6 5 14.3 8.6 4.6 7.4 7.4 6 14.9 14.3 10.9 4.6 15.5 7 8.6 9.7 5.1 4.0 10.9 8 13.8 6.9 6.3 10.3 10.3 9 20.1 13.8 5.7 8.0 10.9 10 8.6 11.5 7.4 8.6 9.7 Etc. So, if you want to change month5 to 5, you have to do that before casting the aqm dataframe. Once cast, what you get is an array with (in this example) the values for the variable month as column names within each component of the array. Hope this helps, José PS: As an aside, from what I see, there are five Reps (1 to 5), so changing rep=1 to 1 will leave you with only 1 category -namely a vector in the arrays. That's fine but perhaps you meant rep1 rather than rep=1? -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Andrea Goijman Sent: 16 January 2013 15:42 To: R help Subject: [R] Changing frequency values to 1 and 0 Dear list, I'm working with a large data set, where I grouped several species in one group (guild). Then I reshaped my data as shown below. Now, I just want to have Rep only as 1 or 0. I'm not being able to change the values of rep=1 to 1... tried many things and I'm not being successful! melting=melt(occ.data,id.var=c(guild, Site, Rep, Año), measure.var=Pres) y=cast(melting, Site ~ Rep ~ guild ~ Año) Aggregation requires fun.aggregate: length used as default y[1:10,,gui4a,1:2] , , Año = 2003 Rep Site 1 2 3 4 5 1021 0 0 0 0 0 1022 0 0 0 0 0 1023 0 0 0 0 0 1024 0 0 0 0 0 1025 0 0 0 0 0 1026 0 0 0 0 0 * 1051 3 1 2 3 5* * 1052 4 3 5 2 3* * 1053 4 3 3 3 2* * 1054 1 2 1 3 0* , , Año = 2004 Rep Site 1 2 3 4 5 1021 2 5 5 5 4 1022 6 3 2 2 2 1023 4 1 1 2 2 1024 0 1 2 2 0 1025 0 1 0 1 0 1026 2 1 0 0 1 1051 2 1 3 1 2 1052 2 4 1 1 2 1053 2 4 2 2 1 1054 4 3 3 2 3 [[alternative HTML version deleted]] Wrap Up and Run 10k is back! Also, new for 2013 2km intergenerational walks at selected venues. So recruit a buddy, dust off the trainers and beat the winter blues by signing up now: http://www.ageuk.org.uk/10k Milton Keynes | Oxford | Sheffield | Crystal Palace | Exeter | Harewood House, Leeds | Tatton Park, Cheshire | Southampton | Coventry Age UK Improving later life http://www.ageuk.org.uk --- Age UK is a registered charity and company limited by guarantee, (registered charity number 1128267, registered company number 6825798). Registered office: Tavis House, 1-6 Tavistock Square, London WC1H 9NA. For the purposes of promoting Age UK Insurance, Age UK is an Appointed Representative of Age UK Enterprises Limited, Age UK is an Introducer Appointed Representative of JLT Benefit Solutions Limited and Simplyhealth Access for the purposes of introducing potential annuity and health cash plans customers respectively. Age UK Enterprises Limited, JLT Benefit Solutions Limited and Simplyhealth Access are all authorised and regulated by the Financial Services Authority. -- This email and any files transmitted with it are
Re: [R] Changing frequency values to 1 and 0
Sure! Although I'm not sure how to use dput() Here is more detail and some data what I want is that the repetitions in Y (at the end) only have 1 or 0... library(reshape) library(car) ###Read in the occurence data occ.data - read.table(Occ_short.csv, header=TRUE,sep=,,na.strings=TRUE) #occ data from 2007-2008 occ.data[1:30,] Año Punto Especie Pres Ruta_com Point Site Rep 1 201230TYSA1 10830 1086 5 2 201226VACH1 10826 1086 1 3 201227VACH1 10827 1086 2 4 201226ZEAU1 10826 1086 1 5 201227ZEAU1 10827 1086 2 6 201228ZEAU1 10828 1086 3 7 201230ZEAU1 10830 1086 5 8 2012 7TYSA1 111 7 1112 2 9 2012 6ZEAU1 111 6 1112 1 10 201210ZEAU1 11110 1112 5 11 201224TYSA1 11124 1115 4 12 201223VACH1 11123 1115 3 13 201221ZEAU1 11121 1115 1 14 201223ZEAU1 11123 1115 3 15 201224ZEAU1 11124 1115 4 16 201225ZEAU1 11125 1115 5 17 201228AMHU1 11128 1116 3 18 201229AMHU1 11129 1116 4 19 201230AMHU1 11130 1116 5 20 201227TYSA1 11127 1116 2 21 201226VACH1 11126 1116 1 22 201227VACH1 11127 1116 2 23 201226ZEAU1 11126 1116 1 24 201227ZEAU1 11127 1116 2 25 201229ZEAU1 11129 1116 4 26 201228ZOCA1 11128 1116 3 27 201229ZOCA1 11129 1116 4 28 201230ZOCA1 11130 1116 5 29 2012 5AMHU1 205 5 2051 5 30 2012 3SILU1 205 3 2051 3 ## RECODE SPECIES INTO GUILDS # occ.data$guild- recode(occ.data$Especie, c('AMHU','SILU','ZOCA')='gui4b';else='OTHER') occ.data[1:30,] Año Punto Especie Pres Ruta_com Point Site Rep guild 1 201230TYSA1 10830 1086 5 OTHER 2 201226VACH1 10826 1086 1 OTHER 3 201227VACH1 10827 1086 2 OTHER 4 201226ZEAU1 10826 1086 1 OTHER 5 201227ZEAU1 10827 1086 2 OTHER 6 201228ZEAU1 10828 1086 3 OTHER 7 201230ZEAU1 10830 1086 5 OTHER 8 2012 7TYSA1 111 7 1112 2 OTHER 9 2012 6ZEAU1 111 6 1112 1 OTHER 10 201210ZEAU1 11110 1112 5 OTHER 11 201224TYSA1 11124 1115 4 OTHER 12 201223VACH1 11123 1115 3 OTHER 13 201221ZEAU1 11121 1115 1 OTHER 14 201223ZEAU1 11123 1115 3 OTHER 15 201224ZEAU1 11124 1115 4 OTHER 16 201225ZEAU1 11125 1115 5 OTHER 17 201228AMHU1 11128 1116 3 gui4b 18 201229AMHU1 11129 1116 4 gui4b 19 201230AMHU1 11130 1116 5 gui4b 20 201227TYSA1 11127 1116 2 OTHER 21 201226VACH1 11126 1116 1 OTHER 22 201227VACH1 11127 1116 2 OTHER 23 201226ZEAU1 11126 1116 1 OTHER 24 201227ZEAU1 11127 1116 2 OTHER 25 201229ZEAU1 11129 1116 4 OTHER 26 201228ZOCA1 11128 1116 3 gui4b 27 201229ZOCA1 11129 1116 4 gui4b 28 201230ZOCA1 11130 1116 5 gui4b 29 2012 5AMHU1 205 5 2051 5 gui4b 30 2012 3SILU1 205 3 2051 3 gui4b # The detection/non-detection data is reshaped into a four dimensional #array y where the first dimension, j, is the point; the second #dimension, k, is the rep; the third dimension, i, is the guild; and the last #dimension t, is the year junk.melt=melt(occ.data,id.var=c(guild, Site, Rep, Año), measure.var=Pres) y=cast(junk.melt, Site ~ Rep ~ guild ~ Año) Aggregation requires fun.aggregate: length used as default y , , guild = gui4b, Año = 2012 Rep Site 1 2 3 4 5 1086 0 0 0 0 0 1112 0 0 0 0 0 1115 0 0 0 0 0 1116 0 0 2 2 2 2051 1 0 1 1 3 2055 1 0 0 3 2 2056 0 1 1 0 0 , , guild = OTHER, Año = 2012 Rep Site 1 2 3 4 5 1086 2 2 1 0 2 1112 1 1 0 0 1 1115 1 0 2 2 1 1116 2 3 0 1 0 2051 2 3 1 1 3 2055 1 2 2 1 0 2056 1 2 1 1 0 [[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
Re: [R] Recursive file Download from FTP
I want to download and unzip many files from the FTP and create variables for year, month, and day for each file based on the naming mechanism. I am stack with the following lines and any help will be appreciated. library(RCurl) # Download the files for 1985. url = ftp://ftp.cpc.ncep.noaa.gov/fews/AFR_CLIM/ARC2/DATA/1985/; filenames = getURL(url, ftp://ftp.use.epsv/ = FALSE, dirlistonly = TRUE) crlf = TRUE Peter Maclean Department of Economics UDSM [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] removing loops from code in making data.frame
Hi, In my first solution, you would get FALSE for identical(res,tutu) if you don't convert `res` columns to numeric. Both res1, and tutu were matrix. You can check the column class by: apply(res1,2,class) Also try: all.equal(res1,tutu) #[1] TRUE A.K. From: Biau David djmb...@yahoo.fr To: arun smartpink...@yahoo.com Cc: R help r-help@r-project.org Sent: Wednesday, January 16, 2013 7:37 AM Subject: Re: [R] removing loops from code in making data.frame thanks, it goes a lot faster. Just one thing though, when I apply the code to my data, both data.frames end up differente. Or at least identical(df1, df2) if false however when i do which(df1!=df2) it says 'integer (0)'. Could that be due to the class of the vectors or some thing of the sort? thanks, David Biau De : arun smartpink...@yahoo.com À : Biau David djmb...@yahoo.fr Cc : R help r-help@r-project.org Envoyé le : Mardi 15 janvier 2013 21h54 Objet : Re: [R] removing loops from code in making data.frame Hi, You could also do this: res1-do.call(rbind,lapply(xaulist,function(x) as.numeric(apply(t(mapply(`==`,tata,x)),2,any identical(res1,tutu) #[1] TRUE A.K. - Original Message - From: Biau David djmb...@yahoo.fr To: r help list r-help@r-project.org Cc: Sent: Tuesday, January 15, 2013 2:41 PM Subject: [R] removing loops from code in making data.frame Dear all, I am working on an author network and to do so I have to arrange a data.frame (tutu) crossing author names (rows) per publication number (column). The participation of the author to a study is indicated by a 1 and 0 otherwise. I have a vector (xaulist) of all the names of authors and a data.frame (tata) with all the publications in row and the authors in columns. I have writen a loop to obtain my data.frame but it takes a long time when the number of studies increases. I was looking for a more efficient code. Here is a minimal working example (my code is terrible i know...): #- au1 - c('deb', 'art', 'deb', 'seb', 'deb', 'deb', 'mar', 'mar', 'joy', 'deb') au2 - c('art', 'deb', 'soy', 'deb', 'joy', 'ani', 'deb', 'deb', 'nem', 'mar') au3 - c('mar', 'lio', 'mil', 'mar', 'ani', 'lul', 'nem', 'art', 'deb', 'tat') tata - data.frame(au1, au2, au3) xaulist2 - levels(factor(unlist(tata[,]))) xaulist - levels(as.factor(xaulist2)) tutu - matrix(NA, nrow=length(xaulist), ncol=dim(tata)[1]) # row are authors and col are papers for (i in 1:length(xaulist)) { for (j in 1:dim(tata)[1]) { ifelse('TRUE' %in% as.character(tata[j,]==xaulist[i]), tutu[i,j] - 1, tutu[i,j] - 0) } } tutu[is.na(tutu)] - 0 #- I am looking at some more efficient way to build 'tutu'. Thank you very much, David [[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] How to change levels?
Hello! I have got a dataframe with 10 columns and 100 rows. The seventh column consists of a lot of country names. When I use newdata=subset(data, data[, 7]==United Kingdom|data[, 7]==Germany) I get just the rows where the country name is UK or Germany. But the level information doesn`t change. That means if I use levels(newdata[,7]), I get: [1] Austria Belgium [3] Denmark Finland [5] France Germany [7] SpainSweden [9] Switzerland The Netherlands [11] United Kingdom United States of America That leads to problems in the further data processing . How can I change the level information to the real levels of newdata? Thanking you in anticipation Claudia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] matrix manipulation with its rows
HI, You could also do this: lapply(sample1,function(x) {mat1-cbind(matrix(0,nrow=2,ncol=3),x); mat1[cbind(rep(1,3),1:3)]- mat1[cbind(rep(1,3),4:6)]; mat1[cbind(rep(1,3),4:6)]-0; mat1}) A.K. - Original Message - From: Kathryn Lord kathryn.lord2...@gmail.com To: r-help@r-project.org Cc: Sent: Wednesday, January 16, 2013 2:59 AM Subject: [R] matrix manipulation with its rows Dear R users, I have a question about matrix manipulation with its rows. Plz see the simple example below sample - list(matrix(1:6, nr=2,nc=3), matrix(7:12, nr=2,nc=3), matrix(13:18,nr=2,nc=3)) sample [[1]] [,1] [,2] [,3] [1,] 1 3 5 [2,] 2 4 6 [[2]] [,1] [,2] [,3] [1,] 7 9 11 [2,] 8 10 12 [[3]] [,1] [,2] [,3] [1,] 13 15 17 [2,] 14 16 18 With this list, I'd like to create this below [[1]] [,1] [,2] [,3] [,4] [,5] [,6] [1,] 1 3 5 0 0 0 [2,] 0 0 0 2 4 6 [[2]] [,1] [,2] [,3] [,4] [,5] [,6] [1,] 7 9 11 0 0 0 [2,] 0 0 0 8 10 12 [[3]] [,1] [,2] [,3] [,4] [,5] [,6] [1,] 13 15 17 0 0 0 [2,] 0 0 0 14 16 18 Any suggestion will be greatly appreciated. Regards, Kathryn Lord [[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] random effects model
Hi I tried removing the missing values and installing plyr. Still error message appears with ggplot2 Btw, did you get the attachments with my earlier mail? Ta. On Wed, Jan 16, 2013 at 3:16 AM, arun kirshna [via R] ml-node+s789695n4655612...@n4.nabble.com wrote: Hi, Check these links: http://comments.gmane.org/gmane.comp.lang.r.ggplot2/6527 https://groups.google.com/forum/#!msg/ggplot2/nfVjxL0DXnY/5zf50zCeZuMJ A.K. From: Usha Gurunathan [hidden email]http://user/SendEmail.jtp?type=nodenode=4655612i=0 To: arun [hidden email]http://user/SendEmail.jtp?type=nodenode=4655612i=1 Cc: R help [hidden email]http://user/SendEmail.jtp?type=nodenode=4655612i=2 Sent: Tuesday, January 15, 2013 6:31 AM Subject: Re: [R] random effects model Hi AK Got an error message with library(ggplot2) ggplot(BP.stack1,aes(x=factor(HiBP),fill=Obese))+geom_bar(position=fill) Error in rename(x, .base_to_ggplot, warn_missing = FALSE) : could not find function revalue ggplot(BP.stack1,aes(x=factor(HiBP),fill=Overweight))+geom_bar(position=fill) Error in rename(x, .base_to_ggplot, warn_missing = FALSE) : could not find function revalue I got the dot plot, thanks for that. I have attached some plots, not sure how to interpret, they had unusual patterns.Is it because of missing data? I tried removing the missing data too. They still appeared the same. Do I need to transform the data? Thanks in advance. On Tue, Jan 15, 2013 at 8:54 AM, arun [hidden email]http://user/SendEmail.jtp?type=nodenode=4655612i=3 wrote: HI, BP_2b-read.csv(BP_2b.csv,sep=\t) BP_2bNM-na.omit(BP_2b) BP.stack3 - reshape(BP_2bNM,idvar=CODEA,timevar=time,sep=,varying=list(c(Obese14,Obese21),c(Overweight14,Overweight21),c(hibp14,hibp21)),v.names=c(Obese,Overweight,HiBP),times=factor(c(1,2)),direction=long) library(car) BP.stack3$Obese- recode(BP.stack3$Obese,1='Obese';0='Not Obese') BP.stack3$Overweight- recode(BP.stack3$Overweight,1='Overweight';0='Not Overweight') library(ggplot2) ggplot(BP.stack3,aes(x=factor(HiBP),fill=Obese))+geom_bar(position=fill) ggplot(BP.stack3,aes(x=factor(HiBP),fill=Overweight))+geom_bar(position=fill) You could try lmer() from lme4. library(lme4) fm1-lmer(HiBP~time+(1|CODEA), family=binomial,data=BP.stack3) #check codes, not sure print(dotplot(ranef(fm1,post=TRUE), scales = list(x = list(relation = free)))[[1]]) qmt1- qqmath(ranef(fm1, postVar=TRUE)) print(qmt1[[1]]) A.K. From: Usha Gurunathan [hidden email]http://user/SendEmail.jtp?type=nodenode=4655612i=4 To: arun [hidden email]http://user/SendEmail.jtp?type=nodenode=4655612i=5 Cc: R help [hidden email]http://user/SendEmail.jtp?type=nodenode=4655612i=6 Sent: Monday, January 14, 2013 6:32 AM Subject: Re: [R] random effects model Hi AK I have been trying to create some plots. All being categorical variables, I am not getting any luck with plots. The few ones that have worked are below: barchart(~table(HiBP)|Obese,data=BP.sub3) ## BP.sub3 is the stacked data without missing values barchart(~table(HiBP)|Overweight,data=BP.sub3) plot(jitter(hibp14,factor=2)~jitter(Obese14,factor=2),col=gray,cex=0.7, data=Copy.of.BP_2) ## Copy.of.BP_2 is the original wide format ## not producing any good plots with mixed models as well. summary(lme.3 - lme(HiBP~time, data=BP.sub3,random=~1|CODEA, na.action=na.omit)) anova(lme.3) head(ranef(lme.3)) print(plot(ranef(lme.3))) ## Thanks for any help. On Mon, Jan 14, 2013 at 4:33 AM, arun [hidden email]http://user/SendEmail.jtp?type=nodenode=4655612i=7 wrote: HI, I think I mentioned to you before that when you reshape the columns excluding the response variable, response variable gets repeated (in this case hibp14 or hibp21) and creates the error I run your code, there are obvious problems in the code so I didn't reach up to BP.gee BP_2b-read.csv(BP_2b.csv,sep=\t) BP.stack3 - reshape(BP_2b,idvar=CODEA,timevar=time,sep=_,varying=list(c(Obese14,Obese21),c(Overweight14,Overweight21)),v.names=c(Obese,Overweight),times=factor(c(1,2)),direction=long) BP.stack3 - transform(BP.stack3,CODEA=factor(CODEA),Sex=factor(Sex,labels=c(Male,Female)),MaternalAge=factor(MaternalAge,labels=c(39years or less,40-49 years,50 years or older)),Education=factor(Education,labels=c(Primary/special,Started secondary,Completed grade10, Completed grade12, College,University)),Birthplace=factor(Birthplace,labels=c(Australia,Other English-speaking,Other))) BP.stack3$Sex - factor(BP.stack3$Sex,levels=levels(BP.stack3$Sex)[c(2,1)]) BP.sub3a - subset(BP.stack3,subset=!(is.na(Sex)| is.na(Education)| is.na(Birthplace)|is.na(Education)|is.na(hibp14)| is.na(hibp21))) nrow(BP.sub3a) #[1] 3364 BP.sub5a - BP.sub3a[order(BP.sub3a$CODEA),] # your code was BP.sub5a - BP.sub3a[order(BP.sub5a$CODEA),] ^ was
[R] setting the legend scale in contour plots
Hi, I'd like to compare SST data for year 2000 with SST for year 2001. I managed to get filled contour plots showing monthly SST for both years (12 plots for each year, 24 plots in total). In order to compare year 2000 and year 2001, however, I'd need to have the same legend scale (same color bar) in both years plots. Thus, my question is: is there a way to set the legend scale in contour plots? Considering only year 2000, this is my script: for (t in 1:12) { SSTt[,,t]-t(SST[,,t]) filled.contour( x=seq(-180,180, length.out=nrow(SSTt[,,t])), y=seq(-90,90, length.out=ncol(SSTt[,,t])), SSTt[,,t], xlim=range(seq(-180,180, length.out=nrow(SSTt[,,t])), finite=TRUE), ylim=range(seq(-90,90, length.out=ncol(SSTt[,,t])), finite=TRUE), zlim=range(SSTt[,,t], finite=TRUE), levels=pretty(range(SSTt[,,t], finite=TRUE), nlevels), nlevels=25, color.palette=heat.colors, col=color.palette(length(pretty(range(SSTt[,,t], finite=TRUE), nlevels), nlevels=25)-1), ) } When I try to run it, I get this error: Error in n[1L] : object of type 'closure' is not subsettable Could you please tell me what's wrong? Cheers Sarah [[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 with a parallel process
Hi R-Core, i am using nnet and DEoptim, Xcc=matrix(rnorm(100,0.5,0.08),50,2) Ycr=matrix(rnorm(50,0.2,0.05),50,1) pred_regm1 - function(A) { A1=A[1] A2=A[2] A3=A[3] regm1 - nnet(Xcc,Ycr,entropy=T,size=A1,decay=A2,maxit=2000,trace=F,Hess=T,rang=A3,skip=T) dif=sum((predict(regm1,Xcc)-Ycr)^2) return(dif) } somar=DEoptim(pred_regm1,c(1,0.1,0.01), c(25,0.999,0.95), control = DEoptim.control(steptol=25,trace = FALSE,itermax=500,parallelType=1)) but implemented parallel process, i have next error: Error en checkForRemoteErrors(val) : 4 nodes produced errors; first error: could not find function nnet how I can solve my mistake? Thanks and kind regards -- David Zamora Ávila (I.C.) Estudiante de la Maestría en Hidrosistemas Pontificia Universidad Javeriana Bogota, Colombia Ed. José Gabriel Maldonado Tel.: 3 20 83 20 Ext.: 5259 [[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] Problems regarding the package BRugs
Respected Sir, With reference to my mail to you dated 8th January,2013, and the reply by you dated 9th January, 2013, I am sending this mail to you. I had a problem regarding running a program in the latest version of the BRugs package in R 2.15.1 and 2.15.2. I want to mention here that this program runs well to others, who are running it using the earlier version of this package. sir, I am running the program line by line. It seems that there is an error in the function samplesSample(). when I used the command involving the function, the error was like below: model has probably not yet been updated model has probably not yet been updated Is there any problem with the function, or the input of the function, in the latest version of the BRugs package? Can you please help me in this problem. Thanking you. Moumita Chatterjee. Research Scholar Department Of Statistics University Of Calcutta [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to cut the time format short
Hello all, I have a time format looks like 31JAN2002:00:00:00.000 How could I cut it to 31JAN2002 ? I tried with format() but not work. Thanks, Rebecca -- This message, and any attachments, is for the intended r...{{dropped:5}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R and Windows 8
Hello: I'd like to know if R will run under Windows 8? Thank you, CJO [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R and Windows 8
On 13-01-16 11:06 AM, Claire Oswald wrote: Hello: I'd like to know if R will run under Windows 8? As far as I know, it has not been tested there. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to change levels?
Hi, see ?droplevels and/or the stringsAsFactors section of ?options Best, Ista On Wed, Jan 16, 2013 at 4:56 AM, paladini palad...@beuth-hochschule.de wrote: Hello! I have got a dataframe with 10 columns and 100 rows. The seventh column consists of a lot of country names. When I use newdata=subset(data, data[, 7]==United Kingdom|data[, 7]==Germany) I get just the rows where the country name is UK or Germany. But the level information doesn`t change. That means if I use levels(newdata[,7]), I get: [1] Austria Belgium [3] Denmark Finland [5] France Germany [7] SpainSweden [9] Switzerland The Netherlands [11] United Kingdom United States of America That leads to problems in the further data processing . How can I change the level information to the real levels of newdata? Thanking you in anticipation Claudia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] R and Windows 8
On Wed, Jan 16, 2013 at 11:06 AM, Claire Oswald claire.j.osw...@gmail.com wrote: Hello: I'd like to know if R will run under Windows 8? I am running R on Windows 8 with no apparent problems. -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Aligning labels to bars in barplot
Nice, worked very well. But because of the realignment, I now need to lower by xlab a bit. Any suggestions? David. -- View this message in context: http://r.789695.n4.nabble.com/Aligning-labels-to-bars-in-barplot-tp4655701p4655749.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] read tab delimited file from a certain line
Lines1 - readLines(con = textConnection( informations (unknown count of lines) ... and at some point the table -- year month mday value 2013 1 16 0 )) indx-seq(match(regmatches(Lines1,regexpr(^year.*,Lines1)),Lines1),length(Lines1)) read.table(text=Lines1[indx],sep=,header=TRUE) # year month mday value #1 2013 1 16 0 A.K. - Original Message - From: Christof Kluß ckl...@email.uni-kiel.de To: r-h...@stat.math.ethz.ch Cc: Sent: Wednesday, January 16, 2013 9:17 AM Subject: [R] read tab delimited file from a certain line Hi I would like to read table data from a text-files with extra informations in the header (of unknown line count). Example: informations (unknown count of lines) ... and at some point the table -- year month mday value 2013 1 16 0 ... If it was an excel file I could use something like read.xls(..., pattern=year) But it is a simple tab seperated text-file. Is there an easy way to read only the table? (Without dirty things ;)) Thx Christof __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Changing frequency values to 1 and 0
Hi, May be this helps you. source(Andreadata.txt) head(occ.data) melting- melt(occ.data,id.var=c(Point, Site, Rep, Año),measure.var=Pres) y-cast(melting,Site~Rep~Point~Año) dim(y) #[1] 10 5 25 6 y[,,25,6] # Rep #Site 1 2 3 4 5 # 1021 0 0 0 0 0 # 1022 0 0 0 0 0 # 1051 0 0 0 0 0 # 2073 0 0 0 0 0 # 2194 0 0 0 0 0 # 2195 0 0 0 0 0 # 3055 0 0 0 0 7 # 4072 0 0 0 0 0 # 4073 0 0 0 0 0 # 6202 0 0 0 0 0 library(plyr) y1-aaply(y,1,function(x) {x[x1]-1;x}) dim(y1) #[1] 10 5 25 6 y1[,,25,6] # Rep #Site 1 2 3 4 5 # 1021 0 0 0 0 0 # 1022 0 0 0 0 0 # 1051 0 0 0 0 0 # 2073 0 0 0 0 0 # 2194 0 0 0 0 0 # 2195 0 0 0 0 0 # 3055 0 0 0 0 1 # 4072 0 0 0 0 0 # 4073 0 0 0 0 0 # 6202 0 0 0 0 0 A.K. - Original Message - From: Andrea Goijman agoij...@cnia.inta.gov.ar To: R help r-help@r-project.org Cc: Sent: Wednesday, January 16, 2013 10:42 AM Subject: [R] Changing frequency values to 1 and 0 Dear list, I'm working with a large data set, where I grouped several species in one group (guild). Then I reshaped my data as shown below. Now, I just want to have Rep only as 1 or 0. I'm not being able to change the values of rep=1 to 1... tried many things and I'm not being successful! melting=melt(occ.data,id.var=c(guild, Site, Rep, Año), measure.var=Pres) y=cast(melting, Site ~ Rep ~ guild ~ Año) Aggregation requires fun.aggregate: length used as default y[1:10,,gui4a,1:2] , , Año = 2003 Rep Site 1 2 3 4 5 1021 0 0 0 0 0 1022 0 0 0 0 0 1023 0 0 0 0 0 1024 0 0 0 0 0 1025 0 0 0 0 0 1026 0 0 0 0 0 * 1051 3 1 2 3 5* * 1052 4 3 5 2 3* * 1053 4 3 3 3 2* * 1054 1 2 1 3 0* , , Año = 2004 Rep Site 1 2 3 4 5 1021 2 5 5 5 4 1022 6 3 2 2 2 1023 4 1 1 2 2 1024 0 1 2 2 0 1025 0 1 0 1 0 1026 2 1 0 0 1 1051 2 1 3 1 2 1052 2 4 1 1 2 1053 2 4 2 2 1 1054 4 3 3 2 3 [[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] Changing frequency values to 1 and 0
Thanks!! that should work!! On Wed, Jan 16, 2013 at 1:03 PM, arun smartpink...@yahoo.com wrote: HI, Saw ur post in Nabble. occ.data-read.table(text= Año Punto Especie Pres Ruta_com Point Site Rep guild 1 201230TYSA1 10830 1086 5 OTHER 2 201226VACH1 10826 1086 1 OTHER 3 201227VACH1 10827 1086 2 OTHER 4 201226ZEAU1 10826 1086 1 OTHER 5 201227ZEAU1 10827 1086 2 OTHER 6 201228ZEAU1 10828 1086 3 OTHER 7 201230ZEAU1 10830 1086 5 OTHER 8 2012 7TYSA1 111 7 1112 2 OTHER 9 2012 6ZEAU1 111 6 1112 1 OTHER 10 201210ZEAU1 11110 1112 5 OTHER 11 201224TYSA1 11124 1115 4 OTHER 12 201223VACH1 11123 1115 3 OTHER 13 201221ZEAU1 11121 1115 1 OTHER 14 201223ZEAU1 11123 1115 3 OTHER 15 201224ZEAU1 11124 1115 4 OTHER 16 201225ZEAU1 11125 1115 5 OTHER 17 201228AMHU1 11128 1116 3 gui4b 18 201229AMHU1 11129 1116 4 gui4b 19 201230AMHU1 11130 1116 5 gui4b 20 201227TYSA1 11127 1116 2 OTHER 21 201226VACH1 11126 1116 1 OTHER 22 201227VACH1 11127 1116 2 OTHER 23 201226ZEAU1 11126 1116 1 OTHER 24 201227ZEAU1 11127 1116 2 OTHER 25 201229ZEAU1 11129 1116 4 OTHER 26 201228ZOCA1 11128 1116 3 gui4b 27 201229ZOCA1 11129 1116 4 gui4b 28 201230ZOCA1 11130 1116 5 gui4b 29 2012 5AMHU1 205 5 2051 5 gui4b 30 2012 3SILU1 205 3 2051 3 gui4b ,sep=,header=TRUE,stringsAsFactors=FALSE) junk.melt- melt(occ.data,id.var=c(guild, Site, Rep, Año), measure.var=Pres) y-cast(junk.melt, Site ~ Rep ~ guild ~ Año) y #, , guild = gui4b, Año = 2012 # # Rep #Site 1 2 3 4 5 # 1086 0 0 0 0 0 # 1112 0 0 0 0 0 # 1115 0 0 0 0 0 # 1116 0 0 2 2 2 # 2051 0 0 1 0 1 #, , guild = OTHER, Año = 2012 # # Rep #Site 1 2 3 4 5 # 1086 2 2 1 0 2 # 1112 1 1 0 0 1 # 1115 1 0 2 2 1 # 1116 2 3 0 1 0 2051 0 0 0 0 0 library(plyr) aaply(y,1,function(x) {x[x1]-1;x}) #, , guild = gui4b # # Rep #Site 1 2 3 4 5 # 1086 0 0 0 0 0 # 1112 0 0 0 0 0 # 1115 0 0 0 0 0 # 1116 0 0 1 1 1 # 2051 0 0 1 0 1 #, , guild = OTHER # # Rep #Site 1 2 3 4 5 # 1086 1 1 1 0 1 # 1112 1 1 0 0 1 # 1115 1 0 1 1 1 # 1116 1 1 0 1 0 # 2051 0 0 0 0 0 A.K. - Original Message - From: Andrea Goijman agoij...@cnia.inta.gov.ar To: R help r-help@r-project.org Cc: Sent: Wednesday, January 16, 2013 10:42 AM Subject: [R] Changing frequency values to 1 and 0 Dear list, I'm working with a large data set, where I grouped several species in one group (guild). Then I reshaped my data as shown below. Now, I just want to have Rep only as 1 or 0. I'm not being able to change the values of rep=1 to 1... tried many things and I'm not being successful! melting=melt(occ.data,id.var=c(guild, Site, Rep, Año), measure.var=Pres) y=cast(melting, Site ~ Rep ~ guild ~ Año) Aggregation requires fun.aggregate: length used as default y[1:10,,gui4a,1:2] , , Año = 2003 Rep Site 1 2 3 4 5 1021 0 0 0 0 0 1022 0 0 0 0 0 1023 0 0 0 0 0 1024 0 0 0 0 0 1025 0 0 0 0 0 1026 0 0 0 0 0 * 1051 3 1 2 3 5* * 1052 4 3 5 2 3* * 1053 4 3 3 3 2* * 1054 1 2 1 3 0* , , Año = 2004 Rep Site 1 2 3 4 5 1021 2 5 5 5 4 1022 6 3 2 2 2 1023 4 1 1 2 2 1024 0 1 2 2 0 1025 0 1 0 1 0 1026 2 1 0 0 1 1051 2 1 3 1 2 1052 2 4 1 1 2 1053 2 4 2 2 1 1054 4 3 3 2 3 [[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. -- --- Lic. Andrea Paula Goijman Grupo Ecología y Gestión Ambiental de la Biodiversidad IRB - INTA Castelar, Argentina agoij...@cnia.inta.gov.ar http://inta.gob.ar/personas/goijman.andrea/ http://inta.gob.ar/personas/goijman.andrea/ PhD Candidate Georgia Cooperative Fish and Wildlife Research Unit D.B. Warnell School of Forestry and Natural Resources University of Georgia Athens, GA 30602 USA Tel. +706.206.4805 andre...@uga.edu [[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
Re: [R] Changing frequency values to 1 and 0
HI, Saw ur post in Nabble. occ.data-read.table(text= Año Punto Especie Pres Ruta_com Point Site Rep guild 1 2012 30 TYSA 1 108 30 1086 5 OTHER 2 2012 26 VACH 1 108 26 1086 1 OTHER 3 2012 27 VACH 1 108 27 1086 2 OTHER 4 2012 26 ZEAU 1 108 26 1086 1 OTHER 5 2012 27 ZEAU 1 108 27 1086 2 OTHER 6 2012 28 ZEAU 1 108 28 1086 3 OTHER 7 2012 30 ZEAU 1 108 30 1086 5 OTHER 8 2012 7 TYSA 1 111 7 1112 2 OTHER 9 2012 6 ZEAU 1 111 6 1112 1 OTHER 10 2012 10 ZEAU 1 111 10 1112 5 OTHER 11 2012 24 TYSA 1 111 24 1115 4 OTHER 12 2012 23 VACH 1 111 23 1115 3 OTHER 13 2012 21 ZEAU 1 111 21 1115 1 OTHER 14 2012 23 ZEAU 1 111 23 1115 3 OTHER 15 2012 24 ZEAU 1 111 24 1115 4 OTHER 16 2012 25 ZEAU 1 111 25 1115 5 OTHER 17 2012 28 AMHU 1 111 28 1116 3 gui4b 18 2012 29 AMHU 1 111 29 1116 4 gui4b 19 2012 30 AMHU 1 111 30 1116 5 gui4b 20 2012 27 TYSA 1 111 27 1116 2 OTHER 21 2012 26 VACH 1 111 26 1116 1 OTHER 22 2012 27 VACH 1 111 27 1116 2 OTHER 23 2012 26 ZEAU 1 111 26 1116 1 OTHER 24 2012 27 ZEAU 1 111 27 1116 2 OTHER 25 2012 29 ZEAU 1 111 29 1116 4 OTHER 26 2012 28 ZOCA 1 111 28 1116 3 gui4b 27 2012 29 ZOCA 1 111 29 1116 4 gui4b 28 2012 30 ZOCA 1 111 30 1116 5 gui4b 29 2012 5 AMHU 1 205 5 2051 5 gui4b 30 2012 3 SILU 1 205 3 2051 3 gui4b ,sep=,header=TRUE,stringsAsFactors=FALSE) junk.melt- melt(occ.data,id.var=c(guild, Site, Rep, Año), measure.var=Pres) y-cast(junk.melt, Site ~ Rep ~ guild ~ Año) y #, , guild = gui4b, Año = 2012 # # Rep #Site 1 2 3 4 5 # 1086 0 0 0 0 0 # 1112 0 0 0 0 0 # 1115 0 0 0 0 0 # 1116 0 0 2 2 2 # 2051 0 0 1 0 1 #, , guild = OTHER, Año = 2012 # # Rep #Site 1 2 3 4 5 # 1086 2 2 1 0 2 # 1112 1 1 0 0 1 # 1115 1 0 2 2 1 # 1116 2 3 0 1 0 2051 0 0 0 0 0 library(plyr) aaply(y,1,function(x) {x[x1]-1;x}) #, , guild = gui4b # # Rep #Site 1 2 3 4 5 # 1086 0 0 0 0 0 # 1112 0 0 0 0 0 # 1115 0 0 0 0 0 # 1116 0 0 1 1 1 # 2051 0 0 1 0 1 #, , guild = OTHER # # Rep #Site 1 2 3 4 5 # 1086 1 1 1 0 1 # 1112 1 1 0 0 1 # 1115 1 0 1 1 1 # 1116 1 1 0 1 0 # 2051 0 0 0 0 0 A.K. - Original Message - From: Andrea Goijman agoij...@cnia.inta.gov.ar To: R help r-help@r-project.org Cc: Sent: Wednesday, January 16, 2013 10:42 AM Subject: [R] Changing frequency values to 1 and 0 Dear list, I'm working with a large data set, where I grouped several species in one group (guild). Then I reshaped my data as shown below. Now, I just want to have Rep only as 1 or 0. I'm not being able to change the values of rep=1 to 1... tried many things and I'm not being successful! melting=melt(occ.data,id.var=c(guild, Site, Rep, Año), measure.var=Pres) y=cast(melting, Site ~ Rep ~ guild ~ Año) Aggregation requires fun.aggregate: length used as default y[1:10,,gui4a,1:2] , , Año = 2003 Rep Site 1 2 3 4 5 1021 0 0 0 0 0 1022 0 0 0 0 0 1023 0 0 0 0 0 1024 0 0 0 0 0 1025 0 0 0 0 0 1026 0 0 0 0 0 * 1051 3 1 2 3 5* * 1052 4 3 5 2 3* * 1053 4 3 3 3 2* * 1054 1 2 1 3 0* , , Año = 2004 Rep Site 1 2 3 4 5 1021 2 5 5 5 4 1022 6 3 2 2 2 1023 4 1 1 2 2 1024 0 1 2 2 0 1025 0 1 0 1 0 1026 2 1 0 0 1 1051 2 1 3 1 2 1052 2 4 1 1 2 1053 2 4 2 2 1 1054 4 3 3 2 3 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to cut the time format short
I have a time format looks like 31JAN2002:00:00:00.000 How could I cut it to 31JAN2002 You have several options depending on what form the data are in. Assuming it is character data, you could use substr: substr(31JAN2002:00:00:00.000, 1, 9) or gsub: gsub((.{9}).+, \\1, 31JAN2002:00:00:00.000) or you could convert to date and reprint: d - as.Date(31JAN2002:00:00:00.000, format=%d%b%Y) format(d, %d%b%Y) #albeit with lowecase month All of those should work on vectors. Some will work on factors but to be safe, wrap the factors in as.character() S Ellison *** This email and any attachments are confidential. Any use...{{dropped:8}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R and Windows 8
On 16/01/2013 16:06, Claire Oswald wrote: Hello: I'd like to know if R will run under Windows 8? We have students running it under Windows 8, 32- and 64-bit OS. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Log scale on y axis of parallel coordinate plot (lattice)
On Mon, 07-Jan-2013 at 10:21PM +1100, Roland Seubert wrote: | Hello all, | | I would like to make a parallel coordinate plot with lattice. The | plot should have vertical log scale axes, and should in principle | look like this one (I put less chemical elements in my example | below): | | http://www.geokem.com/images/scans/epr-and-N_Chile_Ridge.gif | | The data I am trying to plot are chemical analyses of rock samples | (data frame df). The data needs to be normalised against a | reference sample (vector norm), to get the actual data to be | plotted (data frame df_n). Here is a simplified example: | | df - data.frame(La = c(3.0, 2.9, 2.7), Eu = c(0.86, 0.76, 0.66), | Lu = c(0.07, 0.04, 0.04), row.names = c(sample1, sample2, | sample3)) | norm - c(0.237, 0.0563, 0.0246) | df_n - df / norm | df_n |LaEuLu | sample1 12.65823 3.628692 0.2953586 | sample2 51.50977 13.499112 0.7104796 | sample3 109.75610 26.829268 1.6260163 | | The plot needs the same scale for all axes, so my simple panel | function would be: | | panel.myplot - function(..., common.scale) {panel.parallel(..., | common.scale = TRUE)} | | I tried to plot the data with the following command to get vertical | axes with a log scale: | | parallelplot(~ df_n, panel = panel.myplot, horizontal.axis = | FALSE, scales = list(y = list(log = 10))) | | The problem is that lattice simply ignores the log scale and gives | me the following warning: | | Warning message: | In parallelplot.formula(~df_n, panel = panel.spiderplot, | horizontal.axis = FALSE, : | cannot have log y-scale Check out how to use the scales list in the help for xyplot(). You might need to brush up on how the help for axis() to see which parameters you need to set. HTH -- ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. ___Patrick Connolly {~._.~} Great minds discuss ideas _( Y )_ Average minds discuss events (:_~*~_:) Small minds discuss people (_)-(_) . Eleanor Roosevelt ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] R and Windows 8
I'm using R 64 in Win8 64 without problems. Only the StatET plugin for eclipse is not working. 2013/1/16 Prof Brian Ripley rip...@stats.ox.ac.uk On 16/01/2013 16:06, Claire Oswald wrote: Hello: I'd like to know if R will run under Windows 8? We have students running it under Windows 8, 32- and 64-bit OS. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~**ripley/http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to cut the time format short
Hello Ellison, Thanks very much! I use the substr() and it works! Have a great day! Cheers, Rebecca -Original Message- From: S Ellison [mailto:s.elli...@lgcgroup.com] Sent: Wednesday, January 16, 2013 1:35 PM To: Yuan, Rebecca; R help Subject: RE: How to cut the time format short I have a time format looks like 31JAN2002:00:00:00.000 How could I cut it to 31JAN2002 You have several options depending on what form the data are in. Assuming it is character data, you could use substr: substr(31JAN2002:00:00:00.000, 1, 9) or gsub: gsub((.{9}).+, \\1, 31JAN2002:00:00:00.000) or you could convert to date and reprint: d - as.Date(31JAN2002:00:00:00.000, format=%d%b%Y) format(d, %d%b%Y) #albeit with lowecase month All of those should work on vectors. Some will work on factors but to be safe, wrap the factors in as.character() S Ellison *** This email and any attachments are confidential. Any use...{{dropped:7}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Problems regarding the package BRugs
On 16.01.2013 12:13, moumita chatterjee wrote: Respected Sir, With reference to my mail to you dated 8th January,2013, and the reply by you dated 9th January, 2013, I am sending this mail to you. I had a problem regarding running a program in the latest version of the BRugs package in R 2.15.1 and 2.15.2. I want to mention here that this program runs well to others, who are running it using the earlier version of this package. sir, I am running the program line by line. It seems that there is an error in the function samplesSample(). when I used the command involving the function, the error was like below: model has probably not yet been updated model has probably not yet been updated And you have updated? Where is the reproducible code we ask for on this mailing list? Best, Uwe Ligges Is there any problem with the function, or the input of the function, in the latest version of the BRugs package? Can you please help me in this problem. Thanking you. Moumita Chatterjee. Research Scholar Department Of Statistics University Of Calcutta [[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] configure/build R on Windows
On 15.01.2013 22:24, Beto . wrote: Hello, Does anyone knows if there is a Documentation or any wiki that could help me to configure and build R using cygwin with the Intel Compilers on Windows? No, cygwin is an unsupported platform. Best, Uwe Ligges Thanks, Humberto. [[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 a parallel process
On 16.01.2013 17:13, David Zamora Ávila wrote: Hi R-Core, i am using nnet and DEoptim, Xcc=matrix(rnorm(100,0.5,0.08),50,2) Ycr=matrix(rnorm(50,0.2,0.05),50,1) pred_regm1 - function(A) { A1=A[1] A2=A[2] A3=A[3] regm1 - nnet(Xcc,Ycr,entropy=T,size=A1,decay=A2,maxit=2000,trace=F,Hess=T,rang=A3,skip=T) dif=sum((predict(regm1,Xcc)-Ycr)^2) return(dif) } somar=DEoptim(pred_regm1,c(1,0.1,0.01), c(25,0.999,0.95), control = DEoptim.control(steptol=25,trace = FALSE,itermax=500,parallelType=1)) but implemented parallel process, i have next error: Error en checkForRemoteErrors(val) : 4 nodes produced errors; first error: could not find function nnet how I can solve my mistake? Load nnet on all the nodes, not only on the master. Best, Uwe Ligges Thanks and kind regards __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 the legend scale in contour plots
On 16.01.2013 12:00, Sarah Magozzi wrote: Hi, I'd like to compare SST data for year 2000 with SST for year 2001. I managed to get filled contour plots showing monthly SST for both years (12 plots for each year, 24 plots in total). In order to compare year 2000 and year 2001, however, I'd need to have the same legend scale (same color bar) in both years plots. Thus, my question is: is there a way to set the legend scale in contour plots? Considering only year 2000, this is my script: for (t in 1:12) { SSTt[,,t]-t(SST[,,t]) filled.contour( x=seq(-180,180, length.out=nrow(SSTt[,,t])), y=seq(-90,90, length.out=ncol(SSTt[,,t])), SSTt[,,t], xlim=range(seq(-180,180, length.out=nrow(SSTt[,,t])), finite=TRUE), ylim=range(seq(-90,90, length.out=ncol(SSTt[,,t])), finite=TRUE), zlim=range(SSTt[,,t], finite=TRUE), levels=pretty(range(SSTt[,,t], finite=TRUE), nlevels), nlevels=25, color.palette=heat.colors, col=color.palette(length(pretty(range(SSTt[,,t], finite=TRUE), nlevels), nlevels=25)-1), ) } When I try to run it, I get this error: Error in n[1L] : object of type 'closure' is not subsettable Could you please tell me what's wrong? Not likely anybody starts to create a reproducible example to check what is going on. The reproducible exampelm is what you should provide. See the posting guide. Best, Uwe Ligges Cheers Sarah [[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] configure/build R on Windows
On Jan 16, 2013, at 20:24 , Uwe Ligges wrote: On 15.01.2013 22:24, Beto . wrote: Hello, Does anyone knows if there is a Documentation or any wiki that could help me to configure and build R using cygwin with the Intel Compilers on Windows? No, cygwin is an unsupported platform. Let me clarify that a bit: We're not forbidding people to try, or help each other with trying. It's just that R Core members have tried and failed to make a satisfactorily working build and at some point decided not to even try any more. So you're on your own. (I seem to recall that there is some lurking nastiness. If you manage to get something running, make very sure that R passes its make check-all self-tests before you release it on unsuspecting users!) -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Log scale on y axis of parallel coordinate plot (lattice)
On Wed, Jan 16, 2013 at 12:05 PM, Patrick Connolly p_conno...@slingshot.co.nz wrote: On Mon, 07-Jan-2013 at 10:21PM +1100, Roland Seubert wrote: | Hello all, | | I would like to make a parallel coordinate plot with lattice. The | plot should have vertical log scale axes, and should in principle | look like this one (I put less chemical elements in my example | below): | | http://www.geokem.com/images/scans/epr-and-N_Chile_Ridge.gif | | The data I am trying to plot are chemical analyses of rock samples | (data frame df). The data needs to be normalised against a | reference sample (vector norm), to get the actual data to be | plotted (data frame df_n). Here is a simplified example: | | df - data.frame(La = c(3.0, 2.9, 2.7), Eu = c(0.86, 0.76, 0.66), | Lu = c(0.07, 0.04, 0.04), row.names = c(sample1, sample2, | sample3)) | norm - c(0.237, 0.0563, 0.0246) | df_n - df / norm | df_n |LaEuLu | sample1 12.65823 3.628692 0.2953586 | sample2 51.50977 13.499112 0.7104796 | sample3 109.75610 26.829268 1.6260163 | | The plot needs the same scale for all axes, so my simple panel | function would be: | | panel.myplot - function(..., common.scale) {panel.parallel(..., | common.scale = TRUE)} | | I tried to plot the data with the following command to get vertical | axes with a log scale: | | parallelplot(~ df_n, panel = panel.myplot, horizontal.axis = | FALSE, scales = list(y = list(log = 10))) | | The problem is that lattice simply ignores the log scale and gives | me the following warning: | | Warning message: | In parallelplot.formula(~df_n, panel = panel.spiderplot, | horizontal.axis = FALSE, : | cannot have log y-scale Check out how to use the scales list in the help for xyplot(). You might need to brush up on how the help for axis() to see which parameters you need to set. Actually I don't think that's the OP's problem. My guess the attempt to set the scale for y was because horizontal.axis = FALSE, which makes intuitive sense but unfortunately is wrong for parallelplot (which uses y.scales for annotation of the categories regardless of direction). OP, try c(parallelplot(~ df_n, horizontal.axis = FALSE, scales=list(x = list(log = TRUE))) , parallelplot(~ df_n, horizontal.axis = FALSE)) Cheers HTH -- ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. ___Patrick Connolly {~._.~} Great minds discuss ideas _( Y )_ Average minds discuss events (:_~*~_:) Small minds discuss people (_)-(_) . Eleanor Roosevelt ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] configure/build R on Windows
On 16.01.2013 20:44, peter dalgaard wrote: On Jan 16, 2013, at 20:24 , Uwe Ligges wrote: On 15.01.2013 22:24, Beto . wrote: Hello, Does anyone knows if there is a Documentation or any wiki that could help me to configure and build R using cygwin with the Intel Compilers on Windows? No, cygwin is an unsupported platform. Let me clarify that a bit: We're not forbidding people to try, or help each other with trying. It's just that R Core members have tried and failed to make a satisfactorily working build and at some point decided not to even try any more. So you're on your own. (I seem to recall that there is some lurking nastiness. If you manage to get something running, make very sure that R passes its make check-all self-tests before you release it on unsuspecting users!) Yes, same is true when using the other set of compilers. Best, Uwe __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Log scale on y axis of parallel coordinate plot (lattice)
On Wed, Jan 16, 2013 at 12:46 PM, ilai ke...@math.montana.edu wrote: Oops... That's require(latticeExtra) c(parallelplot(~ df_n, horizontal.axis = FALSE, scales=list(x = list(log = TRUE))) , parallelplot(~ df_n, horizontal.axis = FALSE)) or you'll get the full printout of the two objects. Sorry HTH -- ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. ___Patrick Connolly {~._.~} Great minds discuss ideas _( Y )_ Average minds discuss events (:_~*~_:) Small minds discuss people (_)-(_) . Eleanor Roosevelt ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Rscript on Mac : specify R64 over R (32-bit version)
Hi, I have both R and R64 installed on Mac OSX 10.8 Mountain Lion (64-bit). When I run the command sessionInfo() from within Rscript, I get: R version 2.15.2 (2012-10-26) Platform: i386-apple-darwin9.8.0/i386 (32-bit) Is there a way to make Rscript point at the R64 rather than R (32-bit)? Thanks, Matt [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Read.dta and Write.dta Binary Data Error
We have the same problem. And we reported as bug: https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=15166 Hope someone can help Orvalho On Wed, Jan 16, 2013 at 8:05 PM, voldermatt matt.pece...@gmail.com wrote: Thanks in advance. I pass data sets between R and Stata and think dta files would be the best files for this. To do this I can use package foreign or package memisc. I mostly use foreign, although have used memisc and this problem mostly didn't happen, but created errors at other times. I have a csv data set (and created a test case) with with at least one column completely missing. This eventually creates the error. My list of commands are: data - read.csv(file, colClasses = character) write.dta(data, newFile) read.dta(newFile) Error in read.dta(newFile) : a binary read error occurred The colClasses specificiation is important. This causes the error. Stata 10 and Stata 11 can read the file. Stata 12 is completely lost looking at the dataset. I know this is an R forum, but the data set acts very strangely in Stata so I will continue. For my larger data set if I drop one of my variables, all variables that are all missing are dropped. Either there is an issue with how the data sets are being saved/stored, or I am doing something incorrectly by specifying the character option in read.csv. I run R version 2.15.1. Matt -- View this message in context: http://r.789695.n4.nabble.com/Read-dta-and-Write-dta-Binary-Data-Error-tp4655754.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Rscript on Mac : specify R64 over R (32-bit version)
On 16/01/2013 20:16, Matthew Pettis wrote: Hi, I have both R and R64 installed on Mac OSX 10.8 Mountain Lion (64-bit). When I run the command sessionInfo() from within Rscript, I get: R version 2.15.2 (2012-10-26) Platform: i386-apple-darwin9.8.0/i386 (32-bit) Is there a way to make Rscript point at the R64 rather than R (32-bit)? Yes, but it is much better to ask this on R-sig-mac. The main issue is why it has not done so by default. You can always use Rscript --arch-x86_64 Ah: this is 2.15.2 whose installer did not know about Mountain Lion: please update to R-patched from http://r.research.att.com/. Thanks, Matt [[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. As the posting guide asked. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Codetools Query (repost)
thanks much. Saptarshi __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] equivalent code that doesn't return same results?
I need to automate changing the reference value for factors in analysis, and it is my understanding that the following two sets of code should produce identical results, but they do not: 1)dataset$method 2)eval(parse(text=paste(dataset,IVcat[k],sep=$)))(in this case I have IVcat[k]=method, which is why they are equal) I even tested them in R, which says that these two objects are identical: identical(dataset$method,eval(parse(text=paste(dataset,IVcat[k],sep=$ [1] TRUE However, when I write the following code, which is the same in both cases (except that the first case uses expression (1) above and the second case uses expression (2)), it works in the first case but returns an error code in the second: dataset$method-relevel(dataset$method,ref=online) This code properly changes the reference level as desired. eval(parse(text=paste(dataset,IVcat[k],sep=$)))-relevel(eval(parse(text=paste(dataset,IVcat[k],sep=$))),ref=online) This code returns the following error: Error in eval(parse(text = paste(dataset, IVcat[k], sep = $))) - relevel(eval(parse(text = paste(dataset, : target of assignment expands to non-language object I'm new to R, so maybe I'm making a stupid mistake here (maybe because I'm still not understanding the relevel function properly?), but I've been banging my head against this for most of the day, and I'm out of ideas... Thanks for taking the time to read my post, and thanks in advance for any help! -- View this message in context: http://r.789695.n4.nabble.com/equivalent-code-that-doesn-t-return-same-results-tp4655788.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] equivalent code that doesn't return same results?
eval(parse(text=paste(dataset,IVcat[k],sep=$)))-relevel(eval(parse(text=paste(dataset,IVcat[k],sep=$))),ref=online) This code returns the following error: Error in eval(parse(text = paste(dataset, IVcat[k], sep = $))) - relevel(eval(parse(text = paste(dataset, : target of assignment expands to non-language object Replace eval(parse(text=paste(dataset, IVcat[k], sep=$))) with dataset[[ IVcat[k] ]] everywhere. This works because object$componentName is the same as object[[ componentName ]] and the [[ version lets you use a variable for the name of the component. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of cwladis Sent: Wednesday, January 16, 2013 1:12 PM To: r-help@r-project.org Subject: [R] equivalent code that doesn't return same results? I need to automate changing the reference value for factors in analysis, and it is my understanding that the following two sets of code should produce identical results, but they do not: 1)dataset$method 2)eval(parse(text=paste(dataset,IVcat[k],sep=$)))(in this case I have IVcat[k]=method, which is why they are equal) I even tested them in R, which says that these two objects are identical: identical(dataset$method,eval(parse(text=paste(dataset,IVcat[k],sep=$ [1] TRUE However, when I write the following code, which is the same in both cases (except that the first case uses expression (1) above and the second case uses expression (2)), it works in the first case but returns an error code in the second: dataset$method-relevel(dataset$method,ref=online) This code properly changes the reference level as desired. eval(parse(text=paste(dataset,IVcat[k],sep=$)))- relevel(eval(parse(text=paste(dataset,IVcat[k],sep=$))),ref=online) This code returns the following error: Error in eval(parse(text = paste(dataset, IVcat[k], sep = $))) - relevel(eval(parse(text = paste(dataset, : target of assignment expands to non-language object I'm new to R, so maybe I'm making a stupid mistake here (maybe because I'm still not understanding the relevel function properly?), but I've been banging my head against this for most of the day, and I'm out of ideas... Thanks for taking the time to read my post, and thanks in advance for any help! -- View this message in context: http://r.789695.n4.nabble.com/equivalent-code-that- doesn-t-return-same-results-tp4655788.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] Recursive file Download from FTP
I want to download and unzip many files from the FTP and create variables for year, month, and day for each file based on the naming mechanism. I am stack with the following lines and any help will be highly appreciated. I want to create a spreadsheet file with lat lon and estimate as headers. library(RCurl) # Download the files for 1985. url = ftp://ftp.cpc.ncep.noaa.gov/fews/AFR_CLIM/ARC2/DATA/1985/; filenames = getURL(url, ftp://ftp.use.epsv/ = FALSE, dirlistonly = TRUE) crlf = TRUE Peter Maclean Department of Economics UDSM [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Recursive file Download from FTP
Hello, You have an extra argument to getURL that is _not_ an argument: ftp://ftp.use.epsv/ To get the list of files just do url - ftp://ftp.cpc.ncep.noaa.gov/fews/AFR_CLIM/ARC2/DATA/1985/; filenames - getURL(url, dirlistonly = TRUE) fn - unlist(strsplit(filenames, \r\n)) # To download the files destdir - C:/Rui/Temp/ # Adapt to your system lapply(fn, function(x) download.file(paste0(url, x), paste0(destdir, x))) Hope this helps, Rui Barradas Em 16-01-2013 22:41, Peter Maclean escreveu: I want to download and unzip many files from the FTP and create variables for year, month, and day for each file based on the naming mechanism. I am stack with the following lines and any help will be highly appreciated. I want to create a spreadsheet file with lat lon and estimate as headers. library(RCurl) # Download the files for 1985. url = ftp://ftp.cpc.ncep.noaa.gov/fews/AFR_CLIM/ARC2/DATA/1985/; filenames = getURL(url, ftp://ftp.use.epsv/ = FALSE, dirlistonly = TRUE) crlf = TRUE Peter Maclean Department of Economics UDSM [[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] Equivalent of box() in grid graphics
Paul Murell's article What's in a Name in The R Journal Vol 4/2 gives an interesting example of editing a stacked barplot of the barley data. Using the method described in that article, it's easy to do something along the lines of grid.edit(plot_01.border.strip.1, grep=TRUE, global=TRUE, gp=gpar(col = red)) That changes more than I'd like to change. I'd like to change only the bottom line of the rectangle. How would I overwrite the unwanted red lines along the lines of what box() would do with base graphics? TIA Patrick __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] error installing KEGGSOAP
Hi, I am new to bioconductor, trying to install KEGGSOAP package, but got warnings() when installing and error message when trying to load the package, can anyone suggest what went wrong? many thanks John source(http://bioconductor.org/biocLite.R;) Bioconductor version 2.11 (BiocInstaller 1.8.3), ?biocLite for help biocLite(KEGGSOAP) BioC_mirror: http://bioconductor.org Using Bioconductor version 2.11 (BiocInstaller 1.8.3), R version 2.15. Installing package(s) 'KEGGSOAP' trying URL 'http://bioconductor.org/packages/2.11/bioc/bin/windows/contrib/2.15/KEGGSOAP_1.32.0.zip' Content type 'application/zip' length 69037 bytes (67 Kb) opened URL downloaded 67 Kb package âKEGGSOAPâ successfully unpacked and MD5 sums checked The downloaded binary packages are in        C:\Users\yzhang\AppData\Local\Temp\RtmpawAjwx\downloaded_packages Warning message: installed directory not writable, cannot update packages 'acepack', 'actuar', 'ada', 'ade4', 'ade4TkGUI',  'agricolae', 'akima', 'ape', 'aplpack', 'arules', 'bitops', 'boot', 'Cairo', 'car', 'caTools', 'cba',  'chron', 'class', 'clue', 'cluster', 'coda', 'colorspace', 'CompQuadForm', 'corpcor', 'DAAG', 'date',  'deldir', 'descr', 'deSolve', 'devtools', 'digest', 'diptest', 'doBy', 'DoE.wrapper', 'e1071', 'effects',  'ENmisc', 'epiR', 'eRm', 'evaluate', 'evd', 'FactoMineR', 'fArma', 'fAssets', 'fBasics', 'fdrtool',  'fExoticOptions', 'fExtremes', 'fGarch', 'fields', 'flexclust', 'fMultivar', 'fNonlinear', 'fOptions',  'forecast', 'foreign', 'fpc', 'fracdiff', 'fRegression', 'FrF2', 'FrF2.catlg128', 'fTrading',  'fUnitRoots', 'gamlss', 'gamlss.data', 'gamlss.dist', 'gclus', 'gdata', 'geoR', 'GGally', 'ggm',  'ggplot2', 'gmodels', 'gridBase', 'gWidgets', 'gWidgetstcltk', 'HH', 'Hmisc', 'httr', 'igraph',  'igraph0', 'inline', 'ipred', 'isa2', 'JavaGD', 'JGR', 'kernlab', 'KernSmoot [... truncated] library(KEGGSOAP) Loading required package: BiocGenerics Attaching package: âBiocGenericsâ The following object(s) are masked from âpackage:statsâ:    xtabs The following object(s) are masked from âpackage:baseâ:    anyDuplicated, cbind, colnames, duplicated, eval, Filter, Find, get, intersect, lapply, Map, mapply, mget, order, paste,    pmax, pmax.int, pmin, pmin.int, Position, rbind, Reduce, rep.int, rownames, sapply, setdiff, table, tapply, union, unique failed to load HTTP resource Error : .onLoad failed in loadNamespace() for 'KEGGSOAP', details:  call: NULL  error: 1: failed to load HTTP resource Error: package/namespace load failed for âKEGGSOAPâ sessionInfo() R version 2.15.1 (2012-06-22) Platform: x86_64-pc-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252  [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                         [5] LC_TIME=English_United States.1252   attached base packages: [1] stats    graphics grDevices datasets utils    methods  base    other attached packages: [1] BiocGenerics_0.4.0 BiocInstaller_1.8.3 loaded via a namespace (and not attached): [1] codetools_0.2-8 RCurl_1.91-1.1 SSOAP_0.8-0    tools_2.15.1   XML_3.9-4.1    XMLSchema_0.7-2 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] error installing KEGGSOAP
What went wrong? You cross-posted. Don't ask about bioconductor packages on R-help. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. array chip arrayprof...@yahoo.com wrote: Hi, I am new to bioconductor, trying to install KEGGSOAP package, but got warnings() when installing and error message when trying to load the package, can anyone suggest what went wrong? many thanks John source(http://bioconductor.org/biocLite.R;) Bioconductor version 2.11 (BiocInstaller 1.8.3), ?biocLite for help biocLite(KEGGSOAP) BioC_mirror: http://bioconductor.org Using Bioconductor version 2.11 (BiocInstaller 1.8.3), R version 2.15. Installing package(s) 'KEGGSOAP' trying URL 'http://bioconductor.org/packages/2.11/bioc/bin/windows/contrib/2.15/KEGGSOAP_1.32.0.zip' Content type 'application/zip' length 69037 bytes (67 Kb) opened URL downloaded 67 Kb package ���KEGGSOAP��� successfully unpacked and MD5 sums checked The downloaded binary packages are in �� C:\Users\yzhang\AppData\Local\Temp\RtmpawAjwx\downloaded_packages Warning message: installed directory not writable, cannot update packages 'acepack', 'actuar', 'ada', 'ade4', 'ade4TkGUI', �� 'agricolae', 'akima', 'ape', 'aplpack', 'arules', 'bitops', 'boot', 'Cairo', 'car', 'caTools', 'cba', �� 'chron', 'class', 'clue', 'cluster', 'coda', 'colorspace', 'CompQuadForm', 'corpcor', 'DAAG', 'date', �� 'deldir', 'descr', 'deSolve', 'devtools', 'digest', 'diptest', 'doBy', 'DoE.wrapper', 'e1071', 'effects', �� 'ENmisc', 'epiR', 'eRm', 'evaluate', 'evd', 'FactoMineR', 'fArma', 'fAssets', 'fBasics', 'fdrtool', �� 'fExoticOptions', 'fExtremes', 'fGarch', 'fields', 'flexclust', 'fMultivar', 'fNonlinear', 'fOptions', �� 'forecast', 'foreign', 'fpc', 'fracdiff', 'fRegression', 'FrF2', 'FrF2.catlg128', 'fTrading', �� 'fUnitRoots', 'gamlss', 'gamlss.data', 'gamlss.dist', 'gclus', 'gdata', 'geoR', 'GGally', 'ggm', �� 'ggplot2', 'gmodels', 'gridBase', 'gWidgets', 'gWidgetstcltk', 'HH', 'Hmisc', 'httr', 'igraph', �� 'igraph0', 'inline', 'ipred', 'isa2', 'JavaGD', 'JGR', 'kernlab', 'KernSmoot [... truncated] library(KEGGSOAP) Loading required package: BiocGenerics Attaching package: ���BiocGenerics��� The following object(s) are masked from ���package:stats���: �� xtabs The following object(s) are masked from ���package:base���: �� anyDuplicated, cbind, colnames, duplicated, eval, Filter, Find, get, intersect, lapply, Map, mapply, mget, order, paste, �� pmax, pmax.int, pmin, pmin.int, Position, rbind, Reduce, rep.int, rownames, sapply, setdiff, table, tapply, union, unique failed to load HTTP resource Error : .onLoad failed in loadNamespace() for 'KEGGSOAP', details: �� call: NULL �� error: 1: failed to load HTTP resource Error: package/namespace load failed for ���KEGGSOAP��� sessionInfo() R version 2.15.1 (2012-06-22) Platform: x86_64-pc-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=English_United States.1252�� LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C�� [5] LC_TIME=English_United States.1252�� attached base packages: [1] stats graphics�� grDevices datasets�� utils methods base other attached packages: [1] BiocGenerics_0.4.0�� BiocInstaller_1.8.3 loaded via a namespace (and not attached): [1] codetools_0.2-8 RCurl_1.91-1.1�� SSOAP_0.8-0 tools_2.15.1�� XML_3.9-4.1 XMLSchema_0.7-2 [[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] create block diagonal with each rows
Hi Kathryn, take a look at the kronecker function. Cheers Andrew On Thu, Jan 17, 2013 at 1:11 PM, Kathryn Lord kathryn.lord2...@gmail.comwrote: Dear R users, I'd like to create a block diagonal matrix with each rows in a matrix. Here is a simple example. (In fact, the matrix is big) x - matrix(1:20, 4,5) x [,1] [,2] [,3] [,4] [,5] [1,]159 13 17 [2,]26 10 14 18 [3,]37 11 15 19 [4,]48 12 16 20 With each rows in matrix x, I'd like to make the matrix below. [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9][,10] [,11][,12][,13][,14][,15][,16][,17][,18][,19][,20] [1,]159 13 17 00000 000 00 00000 [2,]0000026 10 14 18 000 00 00000 [3,]0000000000 37 11 15 19 00000 [4,]0000000000 000 00 48 12 16 20 Any suggestion will be greatly appreciated. Best, Kathryn Lord [[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. -- Andrew Robinson Director (A/g), ACERA Senior Lecturer in Applied Statistics Tel: +61-3-8344-6410 Department of Mathematics and StatisticsFax: +61-3-8344 4599 University of Melbourne, VIC 3010 Australia Email: a.robin...@ms.unimelb.edu.auWebsite: http://www.ms.unimelb.edu.au FAwR: http://www.ms.unimelb.edu.au/~andrewpr/FAwR/ SPuR: http://www.ms.unimelb.edu.au/spuRs/ [[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] exporting simulated data
Dear All, I wrote a function datagen to simulate a dataset. I would like to generate 1000 datasets and export them with file names from data0001.dat to data1000.dat. Would anybody please provide some useful codes on this? Thank you very much. Best Regards, Ray [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] create block diagonal with each rows
Hi, May be this helps: library(Matrix) res1-lapply(split(x,1:nrow(x)),function(y) sparseMatrix(i=rep(1:4,each=5),j=1:(4*5),x=y)) do.call(rbind,lapply(seq_along(res1),function(i) res1[[i]][i,])) # [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] #[1,] 1 5 9 13 17 0 0 0 0 0 0 0 0 0 #[2,] 0 0 0 0 0 2 6 10 14 18 0 0 0 0 #[3,] 0 0 0 0 0 0 0 0 0 0 3 7 11 15 #[4,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 # [,15] [,16] [,17] [,18] [,19] [,20] #[1,] 0 0 0 0 0 0 #[2,] 0 0 0 0 0 0 #[3,] 19 0 0 0 0 0 #[4,] 0 4 8 12 16 20 A.K. - Original Message - From: Kathryn Lord kathryn.lord2...@gmail.com To: r-help r-help@r-project.org Cc: Sent: Wednesday, January 16, 2013 9:11 PM Subject: [R] create block diagonal with each rows Dear R users, I'd like to create a block diagonal matrix with each rows in a matrix. Here is a simple example. (In fact, the matrix is big) x - matrix(1:20, 4,5) x [,1] [,2] [,3] [,4] [,5] [1,] 1 5 9 13 17 [2,] 2 6 10 14 18 [3,] 3 7 11 15 19 [4,] 4 8 12 16 20 With each rows in matrix x, I'd like to make the matrix below. [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9][,10] [,11][,12][,13][,14][,15][,16][,17][,18][,19][,20] [1,] 1 5 9 13 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [2,] 0 0 0 0 0 2 6 10 14 18 0 0 0 0 0 0 0 0 0 0 [3,] 0 0 0 0 0 0 0 0 0 0 3 7 11 15 19 0 0 0 0 0 [4,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 8 12 16 20 Any suggestion will be greatly appreciated. Best, Kathryn Lord [[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] random effects model
HI, In the same link at the bottom of the page, All is well now after updating all packages with the following: update.packages() It may or may not solve your problem. I got your attachments. You should post those questions in (r-sig-mixed-mod...@r-project.org). I suggest you to read lme4 book (http://lme4.r-forge.r-project.org/lMMwR/) #lrgprt.pdf A.K. - Original Message - From: rex2013 usha.nat...@gmail.com To: r-help@r-project.org Cc: Sent: Wednesday, January 16, 2013 5:06 AM Subject: Re: [R] random effects model Hi I tried removing the missing values and installing plyr. Still error message appears with ggplot2 Btw, did you get the attachments with my earlier mail? Ta. On Wed, Jan 16, 2013 at 3:16 AM, arun kirshna [via R] ml-node+s789695n4655612...@n4.nabble.com wrote: Hi, Check these links: http://comments.gmane.org/gmane.comp.lang.r.ggplot2/6527 https://groups.google.com/forum/#!msg/ggplot2/nfVjxL0DXnY/5zf50zCeZuMJ A.K. From: Usha Gurunathan [hidden email]http://user/SendEmail.jtp?type=nodenode=4655612i=0 To: arun [hidden email]http://user/SendEmail.jtp?type=nodenode=4655612i=1 Cc: R help [hidden email]http://user/SendEmail.jtp?type=nodenode=4655612i=2 Sent: Tuesday, January 15, 2013 6:31 AM Subject: Re: [R] random effects model Hi AK Got an error message with library(ggplot2) ggplot(BP.stack1,aes(x=factor(HiBP),fill=Obese))+geom_bar(position=fill) Error in rename(x, .base_to_ggplot, warn_missing = FALSE) : could not find function revalue ggplot(BP.stack1,aes(x=factor(HiBP),fill=Overweight))+geom_bar(position=fill) Error in rename(x, .base_to_ggplot, warn_missing = FALSE) : could not find function revalue I got the dot plot, thanks for that. I have attached some plots, not sure how to interpret, they had unusual patterns.Is it because of missing data? I tried removing the missing data too. They still appeared the same. Do I need to transform the data? Thanks in advance. On Tue, Jan 15, 2013 at 8:54 AM, arun [hidden email]http://user/SendEmail.jtp?type=nodenode=4655612i=3 wrote: HI, BP_2b-read.csv(BP_2b.csv,sep=\t) BP_2bNM-na.omit(BP_2b) BP.stack3 - reshape(BP_2bNM,idvar=CODEA,timevar=time,sep=,varying=list(c(Obese14,Obese21),c(Overweight14,Overweight21),c(hibp14,hibp21)),v.names=c(Obese,Overweight,HiBP),times=factor(c(1,2)),direction=long) library(car) BP.stack3$Obese- recode(BP.stack3$Obese,1='Obese';0='Not Obese') BP.stack3$Overweight- recode(BP.stack3$Overweight,1='Overweight';0='Not Overweight') library(ggplot2) ggplot(BP.stack3,aes(x=factor(HiBP),fill=Obese))+geom_bar(position=fill) ggplot(BP.stack3,aes(x=factor(HiBP),fill=Overweight))+geom_bar(position=fill) You could try lmer() from lme4. library(lme4) fm1-lmer(HiBP~time+(1|CODEA), family=binomial,data=BP.stack3) #check codes, not sure print(dotplot(ranef(fm1,post=TRUE), scales = list(x = list(relation = free)))[[1]]) qmt1- qqmath(ranef(fm1, postVar=TRUE)) print(qmt1[[1]]) A.K. From: Usha Gurunathan [hidden email]http://user/SendEmail.jtp?type=nodenode=4655612i=4 To: arun [hidden email]http://user/SendEmail.jtp?type=nodenode=4655612i=5 Cc: R help [hidden email]http://user/SendEmail.jtp?type=nodenode=4655612i=6 Sent: Monday, January 14, 2013 6:32 AM Subject: Re: [R] random effects model Hi AK I have been trying to create some plots. All being categorical variables, I am not getting any luck with plots. The few ones that have worked are below: barchart(~table(HiBP)|Obese,data=BP.sub3) ## BP.sub3 is the stacked data without missing values barchart(~table(HiBP)|Overweight,data=BP.sub3) plot(jitter(hibp14,factor=2)~jitter(Obese14,factor=2),col=gray,cex=0.7, data=Copy.of.BP_2) ## Copy.of.BP_2 is the original wide format ## not producing any good plots with mixed models as well. summary(lme.3 - lme(HiBP~time, data=BP.sub3,random=~1|CODEA, na.action=na.omit)) anova(lme.3) head(ranef(lme.3)) print(plot(ranef(lme.3))) ## Thanks for any help. On Mon, Jan 14, 2013 at 4:33 AM, arun [hidden email]http://user/SendEmail.jtp?type=nodenode=4655612i=7 wrote: HI, I think I mentioned to you before that when you reshape the columns excluding the response variable, response variable gets repeated (in this case hibp14 or hibp21) and creates the error I run your code, there are obvious problems in the code so I didn't reach up to BP.gee BP_2b-read.csv(BP_2b.csv,sep=\t) BP.stack3 - reshape(BP_2b,idvar=CODEA,timevar=time,sep=_,varying=list(c(Obese14,Obese21),c(Overweight14,Overweight21)),v.names=c(Obese,Overweight),times=factor(c(1,2)),direction=long) BP.stack3 - transform(BP.stack3,CODEA=factor(CODEA),Sex=factor(Sex,labels=c(Male,Female)),MaternalAge=factor(MaternalAge,labels=c(39years or less,40-49 years,50 years or
[R] How to plot this simple step function?
Hi everyone, I am trying to graph a step function in R Studio. I just learned about R today and decided to try it! The following is what I want it to look like. I graphed it using x - 0:5 y - c(0, .2, .3, .6, .9, 1.0) plot(x, y, type = s) And used Microsoft Paint to get it to how I wanted it to look, but I want to do it in R Studio completely. http://r.789695.n4.nabble.com/file/n4655792/plot.png How can I replicate this image? Also, when do I use the window above the Console? Any incredibly easy tutorials out there to get me started? -- View this message in context: http://r.789695.n4.nabble.com/How-to-plot-this-simple-step-function-tp4655792.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Mean calculation by two variables
Hello Rui! Thanks a lot for your help! Sorry for make mistake with the factor's name, was inattention during data preparation for the asking mail. Unfortunately, it not simple mean calculation, because same individual could have more than one row, if it eat more than a food item. In example data, Acestrorhynchus lacustris are represent by six rows and just four individuals (ID 1717 repeats three times). Because that I tried use lenght (unique(ID)). After calculate the proportion for each individual (step1), I have to sum same food item and divide by four for Acestrorhynchus and by nine for Schizodon (that have 14 row of data). Because that is not simply calculate the mean. Could you please give me some idea? I'm sending again exemple and solution data, now with correct factor's name. Thanks again for your attention and time, Raoni *Example:* structure(list(ID = c(779L, 782L, 1717L, 1717L, 1717L, 1803L, 2650L, 2650L, 2700L, 2700L, 3611L, 3613L, 3647L, 3654L, 3654L, 3683L, 3683L, 3683L, 3685L, 3997L), Site = c(Três Marias, Três Marias, Nova Ponte, Nova Ponte, Nova Ponte, Três Marias, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão), Specie = c(Acestrorhynchus lacustris, Acestrorhynchus lacustris, Acestrorhynchus lacustris, Acestrorhynchus lacustris, Acestrorhynchus lacustris, Acestrorhynchus lacustris, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius), Weight = c(0.06, 0.01, 0.01, 0.33, 0.01, 3.5, 0.01, 0.04, 0.01, 0.01, 0.38, 0.29, 0.04, 0.03, 0.11, 0.04, 0.04, 0.03, 0.01, 0.01), Food.item = c(Fish, Vegetal, Alga, MNI, Sediment, Fish, Alga, MNI, Alga, MNI, Vegetal, Vegetal, Vegetal, Alga, Vegetal, Alga, MNI, Sediment, Sediment, Vegetal)), .Names = c(ID, Site, Specie, Weight, Food.item), row.names = c(1869113L, 2290407L, 56668L, 1485394L, 2126489L, 368143L, 57601L, 1486327L, 57651L, 1486377L, 2348187L, 2348189L, 2293272L, 58605L, 2293279L, 40317L, 1487360L, 2128455L, 2128457L, 2293622L), class = data.frame) *Solution:* structure(list(Specie = c(Acestrorhynchus lacustris, Acestrorhynchus lacustris, Acestrorhynchus lacustris, Acestrorhynchus lacustris, Acestrorhynchus lacustris, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius), Food.item = c(Peixe, Vegetal, Alga, MNI, Sedimento, Alga, MNI, Vegetal, Sedimento), MWi = c(0.5, 0.25, 0.0075, 0.235, 0.0075, 0.14111, 0.18444, 0.53222, 0.14111)), .Names = c(Specie, Food.item, MWi), row.names = c(NA, -9L), class = data.frame) 2013/1/16 Rui Barradas ruipbarra...@sapo.pt Hello, If you want to calculate the mean weight by Specie and Food.item, you can use ?aggregate. In what follows, I've named your EXAMPLE ex and your SOLUTION sol. Note that the result is different from sol. (No exemplo não há Peixe, é Fish, e os números são outros.) aggregate(Weight ~ Specie + Food.item, data = ex, FUN = mean) Hope this helps, Rui Barradas Em 16-01-2013 15:41, Raoni Rodrigues escreveu: Hello All, I have a data frame (dput information below) with food item weight for fish species. I need to calculate the Mean proportion by weight of each food item for each specie, as show in solution data frame (dput information below). I use the ddply function (plyr package) in two steps. First calculate the proportion of weight for each individual: step1 = ddply (example, .(ID), transform, Wi = round (Weight/sum (Weight), 2)) Then, I use lenght (unique (ID)) to calculate the mean of each food item for each specie: step2 = ddply (step1, .(Specie, Food.item), summarise, MWi = sum (Wi)/length (unique(ID))) I do not understand why this didn't work. Someone can help me? Thanks in advanced! *EXAMPLE* structure(list(ID = c(779L, 782L, 1717L, 1717L, 1717L, 1803L, 2650L, 2650L, 2700L, 2700L, 3611L, 3613L, 3647L, 3654L, 3654L, 3683L, 3683L, 3683L, 3685L, 3997L), Site = c(Três Marias, Três Marias, Nova Ponte, Nova Ponte, Nova Ponte, Três Marias, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão), Specie = c(Acestrorhynchus lacustris, Acestrorhynchus lacustris, Acestrorhynchus lacustris, Acestrorhynchus lacustris, Acestrorhynchus lacustris, Acestrorhynchus lacustris, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius), Weight = c(0.06, 0.01, 0.01,
[R] How to change R file in stats?
Dear I have changed some code in R file inside the stats package (dendrogram.R). Now I wan to test and run the stats package with the new updated code, what should I do in detail? RegardsIbrahim Sobh [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to change R file in stats?
On 17 January 2013 07:03, Ibrahim Sobh im_s...@hotmail.com wrote: Dear I have changed some code in R file inside the stats package (dendrogram.R). Now I wan to test and run the stats package with the new updated code, what should I do in detail? For testing the simplest thing you can do is to ?source the file in your session. But R-core is very well maintained, why would you need to change the core code? It will only bring you maintenance chaos. If you need additional feature, maybe you can have a look on CRAN if it is implemented. Best, -m __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] [BioC] error installing KEGGSOAP
On 01/16/2013 05:58 PM, array chip wrote: Hi, I am new to bioconductor, trying to install KEGGSOAP package, but got warnings() when installing and error message when trying to load the package, can anyone suggest what went wrong? many thanks John source(http://bioconductor.org/biocLite.R;) Bioconductor version 2.11 (BiocInstaller 1.8.3), ?biocLite for help biocLite(KEGGSOAP) BioC_mirror: http://bioconductor.org Using Bioconductor version 2.11 (BiocInstaller 1.8.3), R version 2.15. Installing package(s) 'KEGGSOAP' trying URL 'http://bioconductor.org/packages/2.11/bioc/bin/windows/contrib/2.15/KEGGSOAP_1.32.0.zip' Content type 'application/zip' length 69037 bytes (67 Kb) opened URL downloaded 67 Kb package ‘KEGGSOAP’ successfully unpacked and MD5 sums checked The downloaded binary packages are in        C:\Users\yzhang\AppData\Local\Temp\RtmpawAjwx\downloaded_packages Warning message: installed directory not writable, cannot update packages 'acepack', 'actuar', 'ada', 'ade4', 'ade4TkGUI',  'agricolae', 'akima', 'ape', 'aplpack', 'arules', 'bitops', 'boot', 'Cairo', 'car', 'caTools', 'cba',  'chron', 'class', 'clue', 'cluster', 'coda', 'colorspace', 'CompQuadForm', 'corpcor', 'DAAG', 'date',  'deldir', 'descr', 'deSolve', 'devtools', 'digest', 'diptest', 'doBy', 'DoE.wrapper', 'e1071', 'effects',  'ENmisc', 'epiR', 'eRm', 'evaluate', 'evd', 'FactoMineR', 'fArma', 'fAssets', 'fBasics', 'fdrtool',  'fExoticOptions', 'fExtremes', 'fGarch', 'fields', 'flexclust', 'fMultivar', 'fNonlinear', 'fOptions',  'forecast', 'foreign', 'fpc', 'fracdiff', 'fRegression', 'FrF2', 'FrF2.catlg128', 'fTrading',  'fUnitRoots', 'gamlss', 'gamlss.data', 'gamlss.dist', 'gclus', 'gdata', 'geoR', 'GGally', 'ggm',  'ggplot2', 'gmodels', 'gridBase', 'gWidgets', 'gWidgetstcltk', 'HH', 'Hmisc', 'httr', 'igraph',  'igraph0', 'inline', 'ipred', 'isa2', 'JavaGD', 'JGR', 'kernlab', 'KernSmoot [... truncated] library(KEGGSOAP) Loading required package: BiocGenerics Attaching package: ‘BiocGenerics’ The following object(s) are masked from ‘package:stats’:    xtabs The following object(s) are masked from ‘package:base’:    anyDuplicated, cbind, colnames, duplicated, eval, Filter, Find, get, intersect, lapply, Map, mapply, mget, order, paste,    pmax, pmax.int, pmin, pmin.int, Position, rbind, Reduce, rep.int, rownames, sapply, setdiff, table, tapply, union, unique failed to load HTTP resource Error : .onLoad failed in loadNamespace() for 'KEGGSOAP', details:  call: NULL  error: 1: failed to load HTTP resource Error: package/namespace load failed for ‘KEGGSOAP’ KEGG's SOAP service has been discontinued; the package has been replaced by KEGGREST, but KEGGREST is only available if using the 'devel' version of R, e.g., http://cran.fhcrc.org/bin/windows/base/rdevel.html Martin sessionInfo() R version 2.15.1 (2012-06-22) Platform: x86_64-pc-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252  [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                         [5] LC_TIME=English_United States.1252   attached base packages: [1] stats    graphics grDevices datasets utils    methods  base    other attached packages: [1] BiocGenerics_0.4.0 BiocInstaller_1.8.3 loaded via a namespace (and not attached): [1] codetools_0.2-8 RCurl_1.91-1.1 SSOAP_0.8-0    tools_2.15.1   XML_3.9-4.1    XMLSchema_0.7-2 [[alternative HTML version deleted]] ___ Bioconductor mailing list bioconduc...@r-project.org https://stat.ethz.ch/mailman/listinfo/bioconductor Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor -- Computational Biology / Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: Arnold Building M1 B861 Phone: (206) 667-2793 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 plot this simple step function?
Base Graphics: plot(x,y,type=n) segments(x[-length(x)],y[-length(x)],x[-1],y[-length(x)]) points(x[-length(x)],y[-length(x)],pch=16) points(x[-1],y[-length(x)],pch=1) Ggplot graphics: library(ggplot2) dta - data.frame( x= x[-length(x)],y=y[-length(x)], xend=x[-1], yend=y[-length(x)] ) ggplot( dta, aes( x=x, y=y, xend=xend, yend=yend )) + geom_segment()+ geom_point( shape=16, size=4 ) + geom_point( aes( x=xend, y=yend, shape=1, size=4 ) There is also lattice graphics, but I don't feel like putting that example together right now. As for how to use RStudio, please understand that RStudio has its own support forums. Please direct questions regarding that user interface there, and remember that the people answering questions here may be using completely different tools and operating systems than you are. I strongly recommend reading the R-help posting guide and reading other people's questions here to get the flavor of the kinds of question and answer format is preferred around here. Hint: this is a mailing list, not Nabble. Easy tutorials? There are lots of them, but they don't necessarily get you where you want to go. I recommend reading the Introduction to R document that comes with R, with particular focus on vectors, lists, matrices, data frames, and indexing. The apply family of functions will also be useful, but vectors and indexing are first priority. They all work together to make a very powerful combination, and learning those fundamentals will pay off in helping you decipher examples such as that ones above. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Bornin1992 i...@mcparland.ca wrote: Hi everyone, I am trying to graph a step function in R Studio. I just learned about R today and decided to try it! The following is what I want it to look like. I graphed it using x - 0:5 y - c(0, .2, .3, .6, .9, 1.0) plot(x, y, type = s) And used Microsoft Paint to get it to how I wanted it to look, but I want to do it in R Studio completely. http://r.789695.n4.nabble.com/file/n4655792/plot.png How can I replicate this image? Also, when do I use the window above the Console? Any incredibly easy tutorials out there to get me started? -- View this message in context: http://r.789695.n4.nabble.com/How-to-plot-this-simple-step-function-tp4655792.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 change R file in stats?
Sorry, this is not the place for a detailed answer to this question. For testing you can load modified R functions into an R session by loading the original package using the library function and then pasting the new function definition at the command line. When R goes looking for that function it will find your global version before it finds the one from the package. For rebuilding the package, please read the Writing R Extensions documentation. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Ibrahim Sobh im_s...@hotmail.com wrote: Dear I have changed some code in R file inside the stats package (dendrogram.R). Now I wan to test and run the stats package with the new updated code, what should I do in detail? RegardsIbrahim Sobh [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to change levels?
Hi or you can just call factor function after subsetting newdata[,7] - factor (newdata[,7]) Regards Petr -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Ista Zahn Sent: Wednesday, January 16, 2013 6:36 PM To: paladini Cc: r-help@r-project.org Subject: Re: [R] How to change levels? Hi, see ?droplevels and/or the stringsAsFactors section of ?options Best, Ista On Wed, Jan 16, 2013 at 4:56 AM, paladini paladini@beuth- hochschule.de wrote: Hello! I have got a dataframe with 10 columns and 100 rows. The seventh column consists of a lot of country names. When I use newdata=subset(data, data[, 7]==United Kingdom|data[, 7]==Germany) I get just the rows where the country name is UK or Germany. But the level information doesn`t change. That means if I use levels(newdata[,7]), I get: [1] Austria Belgium [3] Denmark Finland [5] France Germany [7] SpainSweden [9] Switzerland The Netherlands [11] United Kingdom United States of America That leads to problems in the further data processing . How can I change the level information to the real levels of newdata? Thanking you in anticipation Claudia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] How to plot this simple step function?
Sorry, missed a parenthesis: ggplot( dta, aes( x=x, y=y, xend=xend, yend=yend )) + geom_segment()+ geom_point( shape=16, size=4 ) + geom_point( aes( x=xend, y=yend ), shape=1, size=4 ) If you have questions about base graphics or lattice, this forum is good. If you have questions about ggplot2, the ggplot2 Google group is probably a better bet than here. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Jeff Newmiller jdnew...@dcn.davis.ca.us wrote: Base Graphics: plot(x,y,type=n) segments(x[-length(x)],y[-length(x)],x[-1],y[-length(x)]) points(x[-length(x)],y[-length(x)],pch=16) points(x[-1],y[-length(x)],pch=1) Ggplot graphics: library(ggplot2) dta - data.frame( x= x[-length(x)],y=y[-length(x)], xend=x[-1], yend=y[-length(x)] ) ggplot( dta, aes( x=x, y=y, xend=xend, yend=yend )) + geom_segment()+ geom_point( shape=16, size=4 ) + geom_point( aes( x=xend, y=yend, shape=1, size=4 ) There is also lattice graphics, but I don't feel like putting that example together right now. As for how to use RStudio, please understand that RStudio has its own support forums. Please direct questions regarding that user interface there, and remember that the people answering questions here may be using completely different tools and operating systems than you are. I strongly recommend reading the R-help posting guide and reading other people's questions here to get the flavor of the kinds of question and answer format is preferred around here. Hint: this is a mailing list, not Nabble. Easy tutorials? There are lots of them, but they don't necessarily get you where you want to go. I recommend reading the Introduction to R document that comes with R, with particular focus on vectors, lists, matrices, data frames, and indexing. The apply family of functions will also be useful, but vectors and indexing are first priority. They all work together to make a very powerful combination, and learning those fundamentals will pay off in helping you decipher examples such as that ones above. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Bornin1992 i...@mcparland.ca wrote: Hi everyone, I am trying to graph a step function in R Studio. I just learned about R today and decided to try it! The following is what I want it to look like. I graphed it using x - 0:5 y - c(0, .2, .3, .6, .9, 1.0) plot(x, y, type = s) And used Microsoft Paint to get it to how I wanted it to look, but I want to do it in R Studio completely. http://r.789695.n4.nabble.com/file/n4655792/plot.png How can I replicate this image? Also, when do I use the window above the Console? Any incredibly easy tutorials out there to get me started? -- View this message in context: http://r.789695.n4.nabble.com/How-to-plot-this-simple-step-function-tp4655792.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.
[R] RESOLVED: Using table to get frequencies of several factors at once
Thanks, I hereby declare this thread as resolved. -Original Message- From: S Ellison [mailto:s.elli...@lgcgroup.com] Sent: Wednesday, January 16, 2013 4:27 PM To: Pancho Mulongeni; R help Subject: RE: Using table to get frequencies of several factors at once You could use a variant of apply(), probably sapply For example d - as.data.frame( matrix(sample(0:1, 200, replace=TRUE), ncol=5)) head(d) sapply(d, table) S Ellison -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Pancho Mulongeni Sent: 11 January 2013 11:18 To: R help Subject: [R] Using table to get frequencies of several factors at once Hi, I have a dataframe with n columns, but I am only looking at five of them. And lots of rows, over 700. So I would like to find frequencies for each of the numeric columns (variables) using the table function. However, is there a fast way to produce a frequency table where the 5 rows represent the 5 numeric variables and the columns refer to the values (levels) of the respective numeric variables, which in this case are 0 and 1. The only way I have figured it out is via a for loop: m-seq(218,222,1) #these are columns of the variables in the larger dataframe tm-m[1:5] #I need this for the for loop l.tm-length(tm) B-matrix(nrow=l.tm,ncol=2) #the matrix to hold the freqs for (p in 1:l.tm) { var.num-m[p] B[p,]-table(DATA[,var.num]) } B [,1] [,2] [1,] 6979 [2,] 512 194 [3,] 604 102 [4,] 7006 [5,] 706 706 So the rows represent my five variables (columns) that occupy columns 218 through 222 in the DATA dataframe. So the second column represents my frequencies of the value 1, which is what I am interested in. The last row has a double entry, because there was only one value, 0, with a freq of 706 and so R duplicated in the two columns, but that's ok, I can just ignore it. So is there are better way to do this? Is there a way to use the so called tapply function? I struggle to understand the help doc for this.function. Pancho Mulongeni Research Assistant PharmAccess Foundation 1 Fouché Street Windhoek West Windhoek Namibia Tel: +264 61 419 000 Fax: +264 61 419 001/2 Mob: +264 81 4456 286 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. *** This email and any attachments are confidential. Any use...{{dropped:9}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.