Re: [R] date calculation
On Fri, Oct 29, 2010 at 11:02 PM, Shi, Tao wrote: > Hi Ben, > > That must be the case! In fact if I do: > >> difftime(strptime("24NOV2004", format="%d%b%Y"), >> strptime("13MAY2004",format="%d%b%Y"), units="days", tz="GMT") > Time difference of 195 days > > > which supports your claim. > > Can someone from the R development team confirm this? Combining empirical results with the documentation (you can read more details about how timezones and dates are handled at ?DateTimeClasses ) which states that dst is used for relevant timezones (although this behavior can be OS dependent), this is not really necessary. For example, note that if one goes to a time before daylight savings: > difftime(strptime("24NOV1902", format="%d%b%Y"), > strptime("13MAY1902",format="%d%b%Y"), units="days") Time difference of 195 days and that the hours match exactly what one would expect given dst. > difftime(strptime("24NOV2004", format="%d%b%Y"), > strptime("13MAY2004",format="%d%b%Y"), units="hours") Time difference of 4681 hours > 195 * 24 + 1 [1] 4681 In short, difftime() is performing as stated and documented (if slightly unexpected at first glance). Cheers, Josh > > Thanks! > > ...Tao > > > > > > - Original Message - >> From:Ben Bolker >> To:r-h...@stat.math.ethz.ch >> Cc: >> Sent:Friday, October 29, 2010 7:54:53 PM >> Subject:Re: [R] date calculation >> >> >> Shi, Tao >> href="http://yahoo.com";>yahoo.com> writes: > >> Could someone >> explain to me why the following result is not a integer? >> >> > >> difftime(strptime("24NOV2004", format="%d%b%Y"), strptime("13MAY2004", >> >> >format="%d%b%Y"), units="days") >> Time difference of 195.0417 >> days > > Presumably because this goes across a daylight-savings >> time > adjustment? 0.0417=1/24 days is 1 hour ... > > Ben >> Bolker > > __ > >> ymailto="mailto:R-help@r-project.org"; >> href="mailto:R-help@r-project.org";>R-help@r-project.org mailing list > >> href="https://stat.ethz.ch/mailman/listinfo/r-help"; target=_blank >> >https://stat.ethz.ch/mailman/listinfo/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. > -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] date calculation
Hi Ben, That must be the case! In fact if I do: > difftime(strptime("24NOV2004", format="%d%b%Y"), > strptime("13MAY2004",format="%d%b%Y"), units="days", tz="GMT") Time difference of 195 days which supports your claim. Can someone from the R development team confirm this? Thanks! ...Tao - Original Message - > From:Ben Bolker > To:r-h...@stat.math.ethz.ch > Cc: > Sent:Friday, October 29, 2010 7:54:53 PM > Subject:Re: [R] date calculation > > > Shi, Tao > href="http://yahoo.com";>yahoo.com> writes: > Could someone > explain to me why the following result is not a integer? > > > > difftime(strptime("24NOV2004", format="%d%b%Y"), strptime("13MAY2004", > > >format="%d%b%Y"), units="days") > Time difference of 195.0417 > days Presumably because this goes across a daylight-savings > time adjustment? 0.0417=1/24 days is 1 hour ... Ben > Bolker __ > ymailto="mailto:R-help@r-project.org"; > href="mailto:R-help@r-project.org";>R-help@r-project.org mailing list > href="https://stat.ethz.ch/mailman/listinfo/r-help"; target=_blank > >https://stat.ethz.ch/mailman/listinfo/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] date calculation
Hi Phil, Thanks for the reply, but I don't think you have explained where the decimal part is coming from ...Tao - Original Message - > From:Phil Spector > To:"Shi, Tao" > Cc:r-h...@stat.math.ethz.ch > Sent:Friday, October 29, 2010 5:04:23 PM > Subject:Re: [R] date calculation > > > Tao - The documentation for the difftime function > says: Function ‘difftime’ calculates a difference of two > date/time objects and returns an object of class > ‘"difftime"’ with an attribute indicating the > units. So that answers your question. If you want it to be an > integer, you're certainly free to make it one: > > as.integer(difftime(strptime("24NOV2004", format="%d%b%Y"), + > > strptime("13MAY2004",format="%d%b%Y"), units="days")) [1] 195 > > - Phil Spector > Statistical Computing > Facility > Department of Statistics > > UC Berkeley > > ymailto="mailto:spec...@stat.berkeley.edu"; > href="mailto:spec...@stat.berkeley.edu";>spec...@stat.berkeley.edu On > Fri, 29 Oct 2010, Shi, Tao wrote: > Hi list, > > Could > someone explain to me why the following result is not a > integer? > > >> difftime(strptime("24NOV2004", > format="%d%b%Y"), strptime("13MAY2004", >> format="%d%b%Y"), > units="days") > Time difference of 195.0417 days > > I'm using > R2.12.0 on WinXP. > > Thanks! > > ...Tao > > > __ > > ymailto="mailto:R-help@r-project.org"; > href="mailto:R-help@r-project.org";>R-help@r-project.org mailing list > > > >https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the > posting guide http://www.R-project.org/posting-guide.html > and provide > commented, minimal, self-contained, reproducible code. > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Chrooted R + Rserve
I am trying to reproduce this setting, but it does not seem to work anymore. I keep getting the error: execve failed: No such file or directory. One of the reasons is that /usr/local/bin/Rserve is no longer a standalone executable, and is now initiated using R CMD Rserve. However, after making the appropriate changes to the .ini, I still get the same error. Anyone successfully reproduced this setting with a recent R/Rserve/Jailkit? -- View this message in context: http://r.789695.n4.nabble.com/Chrooted-R-Rserve-tp845917p3020014.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] Trouble installing gsl wrapper
Hi, I'm trying to install the gsl wrapper source code (http://cran.r-project.org/src/contrib/gsl_1.9-8.tar.gz) on a Linux system (OpenSuse 11.1), but encountering the following problem. I've already installed 'gsl' version 1.14 (ftp://ftp.gnu.org/gnu/gsl/gsl-1.14.tar.gz) on the system. What's missing? Thanks a lot... > R CMD INSTALL gsl * installing to library ‘/usr/lib64/R/library’ * installing *source* package ‘gsl’ ... checking for gsl-config... /usr/local/bin/gsl-config checking if GSL version >= 1.12... checking for gcc... gcc checking for C compiler default output file name... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed yes configure: creating ./config.status config.status: creating src/Makevars ** libs make: Nothing to be done for `all'. installing to /usr/lib64/R/library/gsl/libs ** R ** inst ** preparing package for lazy loading ** help *** installing help indices ** building package indices ... ** testing if installed package can be loaded Error in dyn.load(file, DLLpath = DLLpath, ...) : unable to load shared object '/usr/lib64/R/library/gsl/libs/gsl.so': libgsl.so.0: cannot open shared object file: No such file or directory ERROR: loading failed * removing ‘/usr/lib64/R/library/gsl’ > sessionInfo() R version 2.12.0 (2010-10-15) Platform: x86_64-unknown-linux-gnu (64-bit) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Differenciate numbers from reference for rows
Hi: x <- matrix(20:35, ncol = 1) u <- c(1, 4, 5, 6, 11) # 'x values' m <- c(1, 3, 1, 1, 0.5) # Function to compute the inner product of the multipliers with the extracted # elements of x determined by u f <- function(mat, inputs, mults) crossprod(mat[inputs], mults) f(x, u, mults = c(1, 3, 1, 1, 0.5)) [,1] [1,] 153 20 + 23 * 3 + 24 + 25 + 30 * 0.5 [1] 153 The function is flexible enough to allow you to play with the input matrix (although a vector would also work), the 'observation vector' inputs and the set of multipliers. Here's one way (not necessarily the most efficient): uv <- matrix(sample(1:15, 25, replace = TRUE), ncol = 5) uv # like an X matrix, where each row provides the input values of the vars [,1] [,2] [,3] [,4] [,5] [1,] 128 11 10 15 [2,] 15 11 14 148 [3,]484 10 12 [4,] 105217 [5,] 11491 11 # Apply the function f to each row of uv: apply(uv, 1, function(y) f(x, y, mults = c(1, 3, 1, 1, 0.5))) [1] 188.0 203.5 171.5 155.0 162.0 The direct matrix version: crossprod(t(matrix(x[uv], ncol = 5)), c(1, 3, 1, 1, 0.5)) [,1] [1,] 188.0 [2,] 203.5 [3,] 171.5 [4,] 155.0 [5,] 162.0 Notice that the apply() call returns a vector whereas crossprod() returns a matrix. x[uv] selects the x values associated with the indices in uv and returns a vector in column-major order. The crossprod() call transposes the reshaped x[uv] and then 'matrix' multiplies it by the vector c(1, 3, 1, 1, 0.5). HTH, Dennis On Fri, Oct 29, 2010 at 3:54 PM, M.Ribeiro wrote: > > So, I am having a tricky reference file to extract information from. > > The format of the file is > > x 1 + 4 * 3 + 5 + 6 + 11 * 0.5 > > So, the elements that are not being multiplied (1, 5 and 6) and the > elements > before the multiplication sign (4 and 11) means actually the reference for > the row in a matrix where I need to extract the element from. > > The numbers after the multiplication sign are regular numbers > Ex: > > > x<-matrix(20:35) > > x > [,1] > [1,] 20 > [2,] 21 > [3,] 22 > [4,] 23 > [5,] 24 > [6,] 25 > [7,] 26 > [8,] 27 > [9,] 28 > [10,] 29 > [11,] 30 > [12,] 31 > [13,] 32 > [14,] 33 > [15,] 34 > [16,] 35 > > I would like to read the rows 1,4,5,6 and 11 and sum then. However the > numbers in the elements row 4 and 11 are multiplied by 3 and 0.5 > > So it would be > 20 + 23 * 3 + 24 + 25 + 30 * 0.5. > > And I have this format in different files so I can't do all by hand. > Can anybody help me with a script that can differentiate this? > Thanks > -- > View this message in context: > http://r.789695.n4.nabble.com/Differenciate-numbers-from-reference-for-rows-tp3019853p3019853.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. > [[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] date calculation
Shi, Tao yahoo.com> writes: > Could someone explain to me why the following result is not a integer? > > > difftime(strptime("24NOV2004", format="%d%b%Y"), strptime("13MAY2004", > >format="%d%b%Y"), units="days") > Time difference of 195.0417 days Presumably because this goes across a daylight-savings time adjustment? 0.0417=1/24 days is 1 hour ... Ben Bolker __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] grouping question
Hello Jorge, Thank you for the reply. I tried a few different things with if/else but couldn't get them to go. I really appreciate your feedback. I learned something new from this Will -- View this message in context: http://r.789695.n4.nabble.com/grouping-question-tp3019922p3019952.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] grouping question
Hello Jim Wow. I tried cut but i see you have an interim step with labels a,b,c but levels night and day. i was really close to this. i have labels night,day,night and it wouldn't let me duplicate labels. I am very greatful for your input Will -- View this message in context: http://r.789695.n4.nabble.com/grouping-question-tp3019922p3019950.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] grouping question
Hi Will, One way would be: > x [1] 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 > factor(ifelse(x>6 & x<18, 'day', 'night')) [1] night night night night night night night day day day day day day day day [16] day day day night night night night night night night Levels: day night HTH, Jorge On Fri, Oct 29, 2010 at 8:56 PM, will phillips <> wrote: > > Hello > > I have what is probably a very simple grouping question however, given my > limited exposure to R, I have not found a solution yet despite my research > efforts and wild attempts at what I thought "might" produce some sort of > result. > > I have a very simple list of integers that range between 1 and 24. These > correspond to hours of the day. > > I am trying to create a grouping of Day and Night with > Day = 6 to 17.99 > Night = 1 to 5.59 and 18 to 24 > > Using the Cut command I can create the segments but I have not found a > "combine" type of command to merger the two "night" segments. No luck with > if/else either. > > Any help would be greatly appreciated > > Thank you > > Will > > > -- > View this message in context: > http://r.789695.n4.nabble.com/grouping-question-tp3019922p3019922.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. > [[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] grouping question
try this: > x [1] 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 > y <- cut(x, breaks=c(-Inf,6,18, Inf), labels=c('a','b','c')) > levels(y) <- c('night','day','night') > y [1] night night night night night night night day day day day day day day day day day day [19] day night night night night night night Levels: night day > On Fri, Oct 29, 2010 at 8:56 PM, will phillips wrote: > > Hello > > I have what is probably a very simple grouping question however, given my > limited exposure to R, I have not found a solution yet despite my research > efforts and wild attempts at what I thought "might" produce some sort of > result. > > I have a very simple list of integers that range between 1 and 24. These > correspond to hours of the day. > > I am trying to create a grouping of Day and Night with > Day = 6 to 17.99 > Night = 1 to 5.59 and 18 to 24 > > Using the Cut command I can create the segments but I have not found a > "combine" type of command to merger the two "night" segments. No luck with > if/else either. > > Any help would be greatly appreciated > > Thank you > > Will > > > -- > View this message in context: > http://r.789695.n4.nabble.com/grouping-question-tp3019922p3019922.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. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] grouping question
Hello I have what is probably a very simple grouping question however, given my limited exposure to R, I have not found a solution yet despite my research efforts and wild attempts at what I thought "might" produce some sort of result. I have a very simple list of integers that range between 1 and 24. These correspond to hours of the day. I am trying to create a grouping of Day and Night with Day = 6 to 17.99 Night = 1 to 5.59 and 18 to 24 Using the Cut command I can create the segments but I have not found a "combine" type of command to merger the two "night" segments. No luck with if/else either. Any help would be greatly appreciated Thank you Will -- View this message in context: http://r.789695.n4.nabble.com/grouping-question-tp3019922p3019922.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] plot pdf
Hi Mary, I am not sure off hand why savePlot() is not doing what you expect, but hopefully my inline comments answer your other questions and at least get you the graphs you want. Cheers, Josh On Fri, Oct 29, 2010 at 3:18 PM, wrote: > > > I want to plot the unstadardized version of a normal plot. Can you explain > why that is not working? > Dev.set(1) > xcrit=-1.645 > cord.x <- c(-3,seq(-3,xcrit,0.01),xcrit) > cord.y <- c(0,dnorm(seq(-3,xcrit,0.01)),0) # what does final 0 do here? You are creating *coordinates* to draw a polygon. That is, (x, y). The 0s just match with -3 and xcrit and serve to define the perimeter of the polygon. Please read the documentation for ?polygon for more details. > curve(dnorm(x,0,1),xlim=c(-3,3),main='Normal PDF') This makes your nice curve based on the density function for the normal distribution with a range from -3 to +3. This part works fine for me. > polygon(cord.x,cord.y,col='orange') This does the coloring, the coordinates define the polygon, which is closed by connecting the first and last points. This also seems to work. I end up with the lower region of the graph filled orange. > savePlot(filename="c:\\ssl_z.emf",type="emf") #unable to create > metafile? why? hard for me to say right now (I'm on a linux box). It might help though if you reported sessionInfo() > x=seq(80,200,1) > plot(x,dnorm(x,140,15),type="l",ylab="Probability") This seems fine to me also. > dev.set(4) > xcrit=135.9 > cord.x <- c(80,seq(80,xcrit,.1),xcrit) > cord.y <- c(0,dnorm(seq(80,xcrit,.1)),0) #final 0 needs to be > changed but to what? Why does the final zero need to be changed? What do you want it to be? I suspect you do need to change dnorm() though. You are creating y coordinates based on a normal distribution with mean 0 and sd = 1, but then you plot a curve for a mean of 140 and sd = 15. I would adjust your code to: cord.y <- c(0, dnorm(seq(80, xcrit, .1), 140, 15), 0) which gives the results I *think* you are after. > curve(dnorm(x,140,15),xlim=c(80,200),main='Normal PDF',ylab="Probability") > polygon(cord.x,cord.y,col='orange') Using the adjustment I showed above, I now get a graph that is filled orange from 80 to xcrit (under the normal curve). > savePlot(filename="c:\\ssl_z.emf",type="emf") #unable to create > metafile? why? > > > Sincerely, > > Mary A. Marion > > > [[alternative HTML version deleted]] I manually removed spaces in my reply. In the future it nice if you could send plain text emails (since the html ones are scrubbed). > > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] vertical list sum
Hi Duncan, If vectors of unequal length is the problem, one way to go, using your example, would be: # your example x <- list(c(9, 5, 7, 2, 14, 4, 4, 3), c(3, 6, 25, 2, 14, 3, 3, 4), c(28, 4, 14, 3, 14, 2, 4, 5), 28) x # maximum number of components k <- max(sapply(x, length)) k # expanding each list of x to have k elements lapply(x, function(l) l[1:k]) # average as requested by Greg colMeans(do.call(rbind, lapply(x, function(l) l[1:k])), na.rm = TRUE) HTH, Jorge On Fri, Oct 29, 2010 at 7:37 PM, Duncan Mackay <> wrote: > Hi Jorge > > I tried your methods for all (which work for complete rows) and then I > remove the first value of $y and repeated; both fail because of the unequal > numbers > The problem is when there are unequal numbers in the rows and trying to > make a matrix of them. > > I was trying some things with Greg's vaules. > x <- list() > x[[1]] <- c(9,5,7,2, 14, 4, 4, 3) > x[[2]] <- c(3, 6, 25, 2, 14, 3, 3 , 4) > x[[3]] <- c(28, 4 ,14, 3, 14, 2 ,4 , 5) > x[4] <- list(28 , 4 ,14 , 3, 14, 2 , 4 ) > > x.av <- list() > for(j in seq_along(1:max(sapply(x,length))) ) x.av[j] <- > mean(sapply(x,"[",j),na.rm=T) > unlist(x.av) # if you want a vector > > which Greg may have used first > > Regards > > Duncan > > Duncan Mackay > Department of Agronomy and Soil Science > University of New England > ARMIDALE NSW 2351 > Email home: mac...@northnet.com.au > > > At 08:53 30/10/2010, you wrote: > >> Hi Greg, >> >> Here are two ways of doing it: >> >> > mylist <- list(x = rpois(10, 10), y = rpois(10, 20), z = rpois(10, 5)) >> > mylist >> $x >> [1] 3 13 14 16 10 7 3 5 12 14 >> >> $y >> [1] 17 16 26 13 23 24 16 28 23 12 >> >> $z >> [1] 2 6 5 5 5 1 9 11 6 4 >> >> > >> > colMeans(do.call(rbind, mylist), na.rm = TRUE) >> [1] 7.33 11.67 15.00 11.33 12.67 10.67 9.33 >> 14.67 13.67 >> [10] 10.00 >> > >> > Reduce("+", mylist)/length(mylist) >> [1] 7.33 11.67 15.00 11.33 12.67 10.67 9.33 >> 14.67 13.67 >> [10] 10.00 >> >> >> HTH, >> Jorge >> >> >> On Fri, Oct 29, 2010 at 6:46 PM, Gregory Ryslik <> wrote: >> >> > Hi Everyone, >> > >> > I have a list of vectors like this (in this case it's 3 vectors but >> assume >> > the vector count and the length of each vector is not known): >> > >> > [[1]] >> > [1] 9 5 7 2 14 4 4 3 >> > >> > [[2]] >> > [1] 3 6 25 2 14 3 3 4 >> > >> > [[3]] >> > [1] 28 4 14 3 14 2 4 5 >> > >> > What I want to do is take the average vertically. Thus I want to do >> 9+3+28 >> > /3, 5+6+4 /3, etc... and then have it return a vector. I'm assuming that >> if >> > I can sum it, I can count it to so summing this would be just as >> helpful. >> > >> > I understand I can first go through each element of the list, get a >> vector, >> > cbind into matrix and sum across but I was hoping to avoid that... I >> tried >> > getting it to work with mapply but am having difficulties... >> > >> > Thanks! >> > >> > Kind regards, >> > Greg >> > __ >> > R-help@r-project.org mailing list >> > https://stat.ethz.ch/mailman/listinfo/r-help >> > PLEASE do read the posting guide >> > http://www.R-project.org/posting-guide.html >> > and provide commented, minimal, self-contained, reproducible code. >> > >> >>[[alternative HTML version deleted]] >> >> >> __ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[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 Matlab
Hi. On Fri, Oct 29, 2010 at 3:31 AM, Claudia Beleites wrote: > Dear Henrik, > > sorry for bothering you with a report hastily pasted together and not > particularly nice for you as I used my toy data flu from a non-standard > package. I should have better used e.g. the iris. > > I'm aware that writeMat doesn't deal with S4 objects. In fact, if I'd > overlook the error message, there's the 2nd chance to see that the file size > is 0B. Yes, it is an unfortunate side effect that if there is an error while writing the MAT file, it gives a corrupt *.mat file. I'll put it on the "to do in the future" list to write to a temporary file (e.g. *.mat.tmp) which is only renamed to *.mat when writeMat() returns successfully. I use that "trick" elsewhere and it has saved us a few times. > In fact the attempt to save flu directly was a classical "autopilot" error, > that's why I tried to save the x afterwards. > > So the problem here was the unnamed storing of x. > >> I intentionally do not try to "infer" the name "x" from >> writeMat("flu.mat", x), basically because I think using substitute() >> should be avoided as far as possible, but also because it is unclear >> what the name should be in cases such as writeMat("flu.mat", 1:10). > > I was just going to suggest a patch that assigns the names of type Vnumber > to the unnamed objects - but when I wanted to get the source I realized your > version with the warning is already out. > > I think, however, you may forgot a nchar?: any (nchar (names) == 0) Thanks for spotting that; a merge of (nchar (names) == 0) and (names == "") incorrectly became (names == 0). Corrected in the next release. > > So here's my suggestion for l. 775-777 of writeMat.R: > > if (is.null(names) || any (nchar (names) == 0L)) { > names [nchar (names) == 0L] <- paste ("V", which (nchar (names) == 0L), > sep = "") > names (args) <- names > warning("All objects written have to be named, e.g. use writeMat(..., > x=a, y=y) and not writeMat(..., x=a, y): ", deparse(sys.call()), "\nDummy > names have been assigned."); > } I did think about that, however, it may introduce other ambiguities. For instance, consider writeMat("foo.mat", V2=1, 2); Then there will be two "V2" names. The analogue to read.table() or data.frame() is to add ".1" etc when there is a clash, e.g. "V2" and "V2.1". However, "V2.1" is not a valid name in Matlab. What should then be done? Of course, you can try to make sure you generate valid Matlab names. On a related matter, today you can do writeMat("foo.mat", V2=1, "V2.1"=2) and there is no warning/error given by writeMat() and it reads correctly by readMat(). However, in Matlab you get >> load('foo.mat') ??? Error using ==> load Invalid field name: 'V2.1'. If anyone knows a regular expression for testing the validity of names such that they are valid Matlab variable/field names, please let me know and I can add additional sanity checks in writeMat(). Also, as your initial example indicates that it could be surprising that writeMat("foo.mat", x) would become writeMat("foo.mat", V1=x) and not writeMat("foo.mat", x=x). After further investigation, I actually think that although Matlab indeed can read non-named objects using data=load('foo.mat') I don't think they are accessible. So I was wrong. Because of this, I have bumped up the warning to be an error, preventing non-named objects to be written. Will be the case in the next release of the package. I will postpone adding any bells and whistles trying to make writeMat() smart such as adding names. As soon as you do that you introduce other issues and expectations and have to worry about backward compatibilities if it turns out to be a bad idea. My strategy for now is to have writeMat() assert that only valid MAT files are written, and give errors otherwise. /Henrik > > > After all, e.g. data.frame () will also rather create dummy names for > unnamed columns. And, I think, a warning should make the user aware that > he's doing something that _may_ not work out as intendet. But here I think > it is _most likely_ not working as intended. > > >> MISCELLANEOUS: >> Note that writeMat() cannot write compressed MAT files. It is >> documented in help("readMat"), and will be so in help("writeMat") in >> the next release. Package Rcompression, loaded or not, has no effect >> on writeMat(). It is only readMat() that can read them, if >> Rcompression is installed. You do not have to load it >> explicitly/yourself - if readMat() detects a compress MAT file, it >> will automatically try to load it; > > OK, good to know. > > Thanks a lot for your explanation in spite of my bad report. > > Claudia > > > -- > Claudia Beleites > Dipartimento dei Materiali e delle Risorse Naturali > Università degli Studi di Trieste > Via Alfonso Valerio 6/a > I-34127 Trieste > > phone: +39 0 40 5 58-37 68 > email: cbelei...@units.it > > __ > R-help@r-project.org mailing list > https://s
Re: [R] vertical list sum
Hi, Ah! Thanks for your help! I have even seen Reduce before but for some reason just didn't make the connection. This helps a ton! Thanks again. Kind regards, Greg On Oct 29, 2010, at 6:53 PM, Jorge Ivan Velez wrote: > Hi Greg, > > Here are two ways of doing it: > > > mylist <- list(x = rpois(10, 10), y = rpois(10, 20), z = rpois(10, 5)) > > mylist > $x > [1] 3 13 14 16 10 7 3 5 12 14 > > $y > [1] 17 16 26 13 23 24 16 28 23 12 > > $z > [1] 2 6 5 5 5 1 9 11 6 4 > > > > > colMeans(do.call(rbind, mylist), na.rm = TRUE) > [1] 7.33 11.67 15.00 11.33 12.67 10.67 9.33 > 14.67 13.67 > [10] 10.00 > > > > Reduce("+", mylist)/length(mylist) > [1] 7.33 11.67 15.00 11.33 12.67 10.67 9.33 > 14.67 13.67 > [10] 10.00 > > > HTH, > Jorge > > > On Fri, Oct 29, 2010 at 6:46 PM, Gregory Ryslik <> wrote: > Hi Everyone, > > I have a list of vectors like this (in this case it's 3 vectors but assume > the vector count and the length of each vector is not known): > > [[1]] > [1] 9 5 7 2 14 4 4 3 > > [[2]] > [1] 3 6 25 2 14 3 3 4 > > [[3]] > [1] 28 4 14 3 14 2 4 5 > > What I want to do is take the average vertically. Thus I want to do 9+3+28 > /3, 5+6+4 /3, etc... and then have it return a vector. I'm assuming that if I > can sum it, I can count it to so summing this would be just as helpful. > > I understand I can first go through each element of the list, get a vector, > cbind into matrix and sum across but I was hoping to avoid that... I tried > getting it to work with mapply but am having difficulties... > > Thanks! > > Kind regards, > Greg > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/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] date calculation
Tao - The documentation for the difftime function says: Function ‘difftime’ calculates a difference of two date/time objects and returns an object of class ‘"difftime"’ with an attribute indicating the units. So that answers your question. If you want it to be an integer, you're certainly free to make it one: as.integer(difftime(strptime("24NOV2004", format="%d%b%Y"), + strptime("13MAY2004",format="%d%b%Y"), units="days")) [1] 195 - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec...@stat.berkeley.edu On Fri, 29 Oct 2010, Shi, Tao wrote: Hi list, Could someone explain to me why the following result is not a integer? difftime(strptime("24NOV2004", format="%d%b%Y"), strptime("13MAY2004", format="%d%b%Y"), units="days") Time difference of 195.0417 days I'm using R2.12.0 on WinXP. Thanks! ...Tao __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] date calculation
Hi list, Could someone explain to me why the following result is not a integer? > difftime(strptime("24NOV2004", format="%d%b%Y"), strptime("13MAY2004", >format="%d%b%Y"), units="days") Time difference of 195.0417 days I'm using R2.12.0 on WinXP. Thanks! ...Tao __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 scan df from a specific word?
On Fri, Oct 29, 2010 at 6:34 PM, M.Ribeiro wrote: > > Hi R-helpers, > > I need to read some file with different lines (I don't know the number of > lines to skip) and I would like to find a way to start reading the > data.frame from the word "source". > > ex: > > djhsafk > asdfhkjash > shdfjkash > asfhjkash #those lines contain numbers and words, I want to skip > then but they have different sizes > asdfhjkash > asdfhjksa > > source > tret 2 > res 3 > Here is a one line solution but it does make use of the external utility, gawk. If you using Linux you probably have it on your system already. You can also get gawk for Windows or if you download Duncan's Rtools distribution its included there too -- gawk.exe is just a single file so just make sure you put it somewhere on your PATH. > read.table(pipe('gawk "/Analysis of Variance/ {exit}; /Source/ {i++}; i" > myfile.dat'), header = TRUE, fill = TRUE) Source Model termsGamma Component Comp.SE X. C 1Residual 8383 8367 NANA NA NA 2 at(type,1).Nfam6262 10.1131 10.11311.81 0 P 3 at(type,2).Nfam6262 28.1153 28.11532.16 0 P 4rep.iblk 768 768 63.2919 63.2919 10.94 0 P 5 at(type,1).Nfemale4444 29.9049 29.90492.93 0 P 6 at(type,1).Nclone 2689 2689 109.5600 109.5600 12.66 0 P 7 at(type,2).Nfemale4444 14.0305 14.03051.68 0 P 8Variance 0 0 479.0400 479.0400 36.23 0 P 9Variance 0 0 490.5800 490.5800 17.51 0 P 10 Variance 0 0 469.9320 469.9320 36.51 0 P 11 Variance 0 0 544.6540 544.6540 17.86 0 P -- 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] vertical list sum
Aplogies to the original poster - I got names wrong in a cut and paste Hi Jorge I tried your methods for all (which work for complete rows) and then I remove the first value of $y and repeated; both fail because of the unequal numbers The problem is when there are unequal numbers in the rows and trying to make a matrix of them. I was trying some things with Greg's vaules. x <- list() x[[1]] <- c(9,5,7,2, 14, 4, 4, 3) x[[2]] <- c(3, 6, 25, 2, 14, 3, 3 , 4) x[[3]] <- c(28, 4 ,14, 3, 14, 2 ,4 , 5) x[4] <- list(28 , 4 ,14 , 3, 14, 2 , 4 ) x.av <- list() for(j in seq_along(1:max(sapply(x,length))) ) x.av[j] <- mean(sapply(x,"[",j),na.rm=T) unlist(x.av) # if you want a vector which Greg may have used first Regards Duncan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] vertical list sum
Hi Jorge I tried your methods for all (which work for complete rows) and then I remove the first value of $y and repeated; both fail because of the unequal numbers The problem is when there are unequal numbers in the rows and trying to make a matrix of them. I was trying some things with Greg's vaules. x <- list() x[[1]] <- c(9,5,7,2, 14, 4, 4, 3) x[[2]] <- c(3, 6, 25, 2, 14, 3, 3 , 4) x[[3]] <- c(28, 4 ,14, 3, 14, 2 ,4 , 5) x[4] <- list(28 , 4 ,14 , 3, 14, 2 , 4 ) x.av <- list() for(j in seq_along(1:max(sapply(x,length))) ) x.av[j] <- mean(sapply(x,"[",j),na.rm=T) unlist(x.av) # if you want a vector which Greg may have used first Regards Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England ARMIDALE NSW 2351 Email home: mac...@northnet.com.au At 08:53 30/10/2010, you wrote: Hi Greg, Here are two ways of doing it: > mylist <- list(x = rpois(10, 10), y = rpois(10, 20), z = rpois(10, 5)) > mylist $x [1] 3 13 14 16 10 7 3 5 12 14 $y [1] 17 16 26 13 23 24 16 28 23 12 $z [1] 2 6 5 5 5 1 9 11 6 4 > > colMeans(do.call(rbind, mylist), na.rm = TRUE) [1] 7.33 11.67 15.00 11.33 12.67 10.67 9.33 14.67 13.67 [10] 10.00 > > Reduce("+", mylist)/length(mylist) [1] 7.33 11.67 15.00 11.33 12.67 10.67 9.33 14.67 13.67 [10] 10.00 HTH, Jorge On Fri, Oct 29, 2010 at 6:46 PM, Gregory Ryslik <> wrote: > Hi Everyone, > > I have a list of vectors like this (in this case it's 3 vectors but assume > the vector count and the length of each vector is not known): > > [[1]] > [1] 9 5 7 2 14 4 4 3 > > [[2]] > [1] 3 6 25 2 14 3 3 4 > > [[3]] > [1] 28 4 14 3 14 2 4 5 > > What I want to do is take the average vertically. Thus I want to do 9+3+28 > /3, 5+6+4 /3, etc... and then have it return a vector. I'm assuming that if > I can sum it, I can count it to so summing this would be just as helpful. > > I understand I can first go through each element of the list, get a vector, > cbind into matrix and sum across but I was hoping to avoid that... I tried > getting it to work with mapply but am having difficulties... > > Thanks! > > Kind regards, > Greg > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to scan df from a specific word?
Sorry, this isn't really an R solution, but here it goes anyway. You can isolate the block from Source to the first following blank line by the following unix/linux/cygwin command, assuming inFile is your input file and outFile is the output file: cat inFile | grep -A 100 Source | grep -m 1 -B 100 ^$ > outFile (in this command the number of lines in the Source block is limited to about 100-2=98, you can safely increase the number if necessary) You will probably still have the problem of successive spaces in the block you are interested in. This can also be handled on the command line, for example by adding | sed 's/ */\t/g' (note there are 3 spaces between the first / and the *) between the $ and > characters in the command above. The last bit will replace all occurrences of 2 or more spaces by a tab, so you can read the file as tab-separated. Equivalently, you could do the line filtering in R as Phil suggested. Peter On Fri, Oct 29, 2010 at 3:39 PM, M.Ribeiro wrote: > > Sorry, the explanation wasn't very good...just to explain better. > > I am writing a loop to read and process every time a different file in the > same script. > And what I want to load into a variable each time is a data.frame that is > bellow the word source in all of my files. > > So I would like to recognize the word Source in the text fileand read > the table bellow source until the next blank line (the file has more written > stuff bellow the data frame that I want to read too) > > Here is an example of the file. I want the df to read from source until the > blank line right above the words "Analysis of Variance > > Notice: 37 singularities detected in design matrix. > 1 LogL=-2664.01 S2= 1. 8367 df : 2 components > constrained > 2 LogL=-2269.45 S2= 1. 8367 df > 3 LogL=-1698.47 S2= 1. 8367 df > 4 LogL=-1252.72 S2= 1. 8367 df > 5 LogL=-1013.52 S2= 1. 8367 df > 6 LogL=-957.409 S2= 1. 8367 df > 7 LogL=-944.252 S2= 1. 8367 df > 8 LogL=-939.976 S2= 1. 8367 df > 9 LogL=-938.908 S2= 1. 8367 df > 10 LogL=-938.798 S2= 1. 8367 df > 11 LogL=-938.795 S2= 1. 8367 df > 12 LogL=-938.795 S2= 1. 8367 df > > Source Model terms Gamma Component Comp/SE % C > Residual 8383 8367 > at(type,1).Nfam 62 62 10.1131 10.1131 1.81 0 P > at(type,2).Nfam 62 62 28.1153 28.1153 2.16 0 P > rep.iblk 768 768 63.2919 63.2919 10.94 0 P > at(type,1).Nfemale 44 44 29.9049 29.9049 2.93 0 P > at(type,1).Nclone 2689 2689 109.560 109.560 12.66 0 P > at(type,2).Nfemale 44 44 14.0305 14.0305 1.68 0 P > Variance 0 0 479.040 479.040 36.23 0 P > Variance 0 0 490.580 490.580 17.51 0 P > Variance 0 0 469.932 469.932 36.51 0 P > Variance 0 0 544.654 544.654 17.86 0 P > > Analysis of Variance NumDF F_inc > 27 mu 1 5860.84 > > 12 culture 1 0.07 > 10 type 1 29.59 > 28 culture.rep 6 14.06 > 30 culture.rep.type 7 2.17 > 36 at(type,1).Nfam 62 effects fitted > -- > View this message in context: > http://r.789695.n4.nabble.com/How-to-scan-df-from-a-specific-word-tp3019841p3019846.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 scan df from a specific word?
It might be easier to preprocess the file before passing it to R, but you an do what you want using a connection: f = file('s.dat','r') while(1){ + txt = readLines(f,1) + if(length(grep('Source',txt)))break; + } while(1){ + more = readLines(f,1) + if(nchar(more) == 0)break; + txt = paste(txt,more,sep='\n') + } try = read.table(textConnection(txt),header=TRUE,fill=TRUE) try Source Model termsGamma Component Comp.SE X. C 1Residual 8383 8367 NANA NA NA 2 at(type,1).Nfam6262 10.1131 10.11311.81 0 P 3 at(type,2).Nfam6262 28.1153 28.11532.16 0 P 4rep.iblk 768 768 63.2919 63.2919 10.94 0 P 5 at(type,1).Nfemale4444 29.9049 29.90492.93 0 P 6 at(type,1).Nclone 2689 2689 109.5600 109.5600 12.66 0 P 7 at(type,2).Nfemale4444 14.0305 14.03051.68 0 P 8Variance 0 0 479.0400 479.0400 36.23 0 P 9Variance 0 0 490.5800 490.5800 17.51 0 P 10 Variance 0 0 469.9320 469.9320 36.51 0 P 11 Variance 0 0 544.6540 544.6540 17.86 0 P The first loop reads up until the word "Source" appears in the line, and the second loop builds a text representation of what you want so that you can read it using textConnection. Hope this helps. - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec...@stat.berkeley.edu On Fri, 29 Oct 2010, M.Ribeiro wrote: Sorry, the explanation wasn't very good...just to explain better. I am writing a loop to read and process every time a different file in the same script. And what I want to load into a variable each time is a data.frame that is bellow the word source in all of my files. So I would like to recognize the word Source in the text fileand read the table bellow source until the next blank line (the file has more written stuff bellow the data frame that I want to read too) Here is an example of the file. I want the df to read from source until the blank line right above the words "Analysis of Variance Notice: 37 singularities detected in design matrix. 1 LogL=-2664.01 S2= 1. 8367 df: 2 components constrained 2 LogL=-2269.45 S2= 1. 8367 df 3 LogL=-1698.47 S2= 1. 8367 df 4 LogL=-1252.72 S2= 1. 8367 df 5 LogL=-1013.52 S2= 1. 8367 df 6 LogL=-957.409 S2= 1. 8367 df 7 LogL=-944.252 S2= 1. 8367 df 8 LogL=-939.976 S2= 1. 8367 df 9 LogL=-938.908 S2= 1. 8367 df 10 LogL=-938.798 S2= 1. 8367 df 11 LogL=-938.795 S2= 1. 8367 df 12 LogL=-938.795 S2= 1. 8367 df SourceModel terms Gamma ComponentComp/SE % C Residual 8383 8367 at(type,1).Nfam 62 62 10.1131 10.1131 1.81 0 P at(type,2).Nfam 62 62 28.1153 28.1153 2.16 0 P rep.iblk768768 63.2919 63.2919 10.94 0 P at(type,1).Nfemale 44 44 29.9049 29.9049 2.93 0 P at(type,1).Nclone 2689 2689 109.560 109.560 12.66 0 P at(type,2).Nfemale 44 44 14.0305 14.0305 1.68 0 P Variance 0 0 479.040 479.040 36.23 0 P Variance 0 0 490.580 490.580 17.51 0 P Variance 0 0 469.932 469.932 36.51 0 P Variance 0 0 544.654 544.654 17.86 0 P Analysis of Variance NumDF F_inc 27 mu15860.84 12 culture 1 0.07 10 type 1 29.59 28 culture.rep 6 14.06 30 culture.rep.type 7 2.17 36 at(type,1).Nfam 62 effects fitted -- View this message in context: http://r.789695.n4.nabble.com/How-to-scan-df-from-a-specific-word-tp3019841p3019846.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, sel
Re: [R] vertical list sum
Hi Greg, Here are two ways of doing it: > mylist <- list(x = rpois(10, 10), y = rpois(10, 20), z = rpois(10, 5)) > mylist $x [1] 3 13 14 16 10 7 3 5 12 14 $y [1] 17 16 26 13 23 24 16 28 23 12 $z [1] 2 6 5 5 5 1 9 11 6 4 > > colMeans(do.call(rbind, mylist), na.rm = TRUE) [1] 7.33 11.67 15.00 11.33 12.67 10.67 9.33 14.67 13.67 [10] 10.00 > > Reduce("+", mylist)/length(mylist) [1] 7.33 11.67 15.00 11.33 12.67 10.67 9.33 14.67 13.67 [10] 10.00 HTH, Jorge On Fri, Oct 29, 2010 at 6:46 PM, Gregory Ryslik <> wrote: > Hi Everyone, > > I have a list of vectors like this (in this case it's 3 vectors but assume > the vector count and the length of each vector is not known): > > [[1]] > [1] 9 5 7 2 14 4 4 3 > > [[2]] > [1] 3 6 25 2 14 3 3 4 > > [[3]] > [1] 28 4 14 3 14 2 4 5 > > What I want to do is take the average vertically. Thus I want to do 9+3+28 > /3, 5+6+4 /3, etc... and then have it return a vector. I'm assuming that if > I can sum it, I can count it to so summing this would be just as helpful. > > I understand I can first go through each element of the list, get a vector, > cbind into matrix and sum across but I was hoping to avoid that... I tried > getting it to work with mapply but am having difficulties... > > Thanks! > > Kind regards, > Greg > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/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] Differenciate numbers from reference for rows
So, I am having a tricky reference file to extract information from. The format of the file is x 1 + 4 * 3 + 5 + 6 + 11 * 0.5 So, the elements that are not being multiplied (1, 5 and 6) and the elements before the multiplication sign (4 and 11) means actually the reference for the row in a matrix where I need to extract the element from. The numbers after the multiplication sign are regular numbers Ex: > x<-matrix(20:35) > x [,1] [1,] 20 [2,] 21 [3,] 22 [4,] 23 [5,] 24 [6,] 25 [7,] 26 [8,] 27 [9,] 28 [10,] 29 [11,] 30 [12,] 31 [13,] 32 [14,] 33 [15,] 34 [16,] 35 I would like to read the rows 1,4,5,6 and 11 and sum then. However the numbers in the elements row 4 and 11 are multiplied by 3 and 0.5 So it would be 20 + 23 * 3 + 24 + 25 + 30 * 0.5. And I have this format in different files so I can't do all by hand. Can anybody help me with a script that can differentiate this? Thanks -- View this message in context: http://r.789695.n4.nabble.com/Differenciate-numbers-from-reference-for-rows-tp3019853p3019853.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] vertical list sum
Hi Everyone, I have a list of vectors like this (in this case it's 3 vectors but assume the vector count and the length of each vector is not known): [[1]] [1] 9 5 7 2 14 4 4 3 [[2]] [1] 3 6 25 2 14 3 3 4 [[3]] [1] 28 4 14 3 14 2 4 5 What I want to do is take the average vertically. Thus I want to do 9+3+28 /3, 5+6+4 /3, etc... and then have it return a vector. I'm assuming that if I can sum it, I can count it to so summing this would be just as helpful. I understand I can first go through each element of the list, get a vector, cbind into matrix and sum across but I was hoping to avoid that... I tried getting it to work with mapply but am having difficulties... Thanks! Kind regards, Greg __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 scan df from a specific word?
Sorry, the explanation wasn't very good...just to explain better. I am writing a loop to read and process every time a different file in the same script. And what I want to load into a variable each time is a data.frame that is bellow the word source in all of my files. So I would like to recognize the word Source in the text fileand read the table bellow source until the next blank line (the file has more written stuff bellow the data frame that I want to read too) Here is an example of the file. I want the df to read from source until the blank line right above the words "Analysis of Variance Notice: 37 singularities detected in design matrix. 1 LogL=-2664.01 S2= 1. 8367 df: 2 components constrained 2 LogL=-2269.45 S2= 1. 8367 df 3 LogL=-1698.47 S2= 1. 8367 df 4 LogL=-1252.72 S2= 1. 8367 df 5 LogL=-1013.52 S2= 1. 8367 df 6 LogL=-957.409 S2= 1. 8367 df 7 LogL=-944.252 S2= 1. 8367 df 8 LogL=-939.976 S2= 1. 8367 df 9 LogL=-938.908 S2= 1. 8367 df 10 LogL=-938.798 S2= 1. 8367 df 11 LogL=-938.795 S2= 1. 8367 df 12 LogL=-938.795 S2= 1. 8367 df SourceModel terms Gamma ComponentComp/SE % C Residual 8383 8367 at(type,1).Nfam 62 62 10.1131 10.1131 1.81 0 P at(type,2).Nfam 62 62 28.1153 28.1153 2.16 0 P rep.iblk768768 63.2919 63.2919 10.94 0 P at(type,1).Nfemale 44 44 29.9049 29.9049 2.93 0 P at(type,1).Nclone 2689 2689 109.560 109.560 12.66 0 P at(type,2).Nfemale 44 44 14.0305 14.0305 1.68 0 P Variance 0 0 479.040 479.040 36.23 0 P Variance 0 0 490.580 490.580 17.51 0 P Variance 0 0 469.932 469.932 36.51 0 P Variance 0 0 544.654 544.654 17.86 0 P Analysis of Variance NumDF F_inc 27 mu15860.84 12 culture 1 0.07 10 type 1 29.59 28 culture.rep 6 14.06 30 culture.rep.type 7 2.17 36 at(type,1).Nfam 62 effects fitted -- View this message in context: http://r.789695.n4.nabble.com/How-to-scan-df-from-a-specific-word-tp3019841p3019846.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] How to scan df from a specific word?
Sorry, the explanation wasn't very good...just to explain better. I am writing a loop to read and process different files in the same script. And what I want to load into a variable is a data.frame that is above the word source in all of my files. So I would like to recognize the word Source in the text fileand read the table bellow source until the next blank line (the file has more written stuff bellow the data frame that I want to read too) Here is an example of the file. I want the df to read from source until the blank line right above the words "Analysis of Variance Notice: 37 singularities detected in design matrix. 1 LogL=-2664.01 S2= 1. 8367 df: 2 components constrained 2 LogL=-2269.45 S2= 1. 8367 df 3 LogL=-1698.47 S2= 1. 8367 df 4 LogL=-1252.72 S2= 1. 8367 df 5 LogL=-1013.52 S2= 1. 8367 df 6 LogL=-957.409 S2= 1. 8367 df 7 LogL=-944.252 S2= 1. 8367 df 8 LogL=-939.976 S2= 1. 8367 df 9 LogL=-938.908 S2= 1. 8367 df 10 LogL=-938.798 S2= 1. 8367 df 11 LogL=-938.795 S2= 1. 8367 df 12 LogL=-938.795 S2= 1. 8367 df SourceModel terms Gamma ComponentComp/SE % C Residual 8383 8367 at(type,1).Nfam 62 62 10.1131 10.1131 1.81 0 P at(type,2).Nfam 62 62 28.1153 28.1153 2.16 0 P rep.iblk768768 63.2919 63.2919 10.94 0 P at(type,1).Nfemale 44 44 29.9049 29.9049 2.93 0 P at(type,1).Nclone 2689 2689 109.560 109.560 12.66 0 P at(type,2).Nfemale 44 44 14.0305 14.0305 1.68 0 P Variance 0 0 479.040 479.040 36.23 0 P Variance 0 0 490.580 490.580 17.51 0 P Variance 0 0 469.932 469.932 36.51 0 P Variance 0 0 544.654 544.654 17.86 0 P Analysis of Variance NumDF F_inc 27 mu15860.84 12 culture 1 0.07 10 type 1 29.59 28 culture.rep 6 14.06 30 culture.rep.type 7 2.17 36 at(type,1).Nfam 62 effects fitted -- View this message in context: http://r.789695.n4.nabble.com/How-to-scan-df-from-a-specific-word-tp3019841p3019844.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] How to scan df from a specific word?
Hi R-helpers, I need to read some file with different lines (I don't know the number of lines to skip) and I would like to find a way to start reading the data.frame from the word "source". ex: djhsafk asdfhkjash shdfjkash asfhjkash #those lines contain numbers and words, I want to skip then but they have different sizes asdfhjkash asdfhjksa source tret 2 res 3 Can anybody help? Thanks -- View this message in context: http://r.789695.n4.nabble.com/How-to-scan-df-from-a-specific-word-tp3019841p3019841.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] plot pdf
I want to plot the unstadardized version of a normal plot. Can you explain why that is not working? Dev.set(1) xcrit=-1.645 cord.x <- c(-3,seq(-3,xcrit,0.01),xcrit) cord.y <- c(0,dnorm(seq(-3,xcrit,0.01)),0)           # what does final 0 do here? curve(dnorm(x,0,1),xlim=c(-3,3),main='Normal PDF') polygon(cord.x,cord.y,col='orange') savePlot(filename="c:\\ssl_z.emf",type="emf")          #unable to create metafile? why?  x=seq(80,200,1) plot(x,dnorm(x,140,15),type="l",ylab="Probability")  dev.set(4) xcrit=135.9 cord.x <- c(80,seq(80,xcrit,.1),xcrit) cord.y <- c(0,dnorm(seq(80,xcrit,.1)),0)              #final 0 needs to be changed but to what? curve(dnorm(x,140,15),xlim=c(80,200),main='Normal PDF',ylab="Probability") polygon(cord.x,cord.y,col='orange') savePlot(filename="c:\\ssl_z.emf",type="emf")        #unable to create metafile? why?   Sincerely, Mary A. Marion [[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 debug (mtrace) a function defined inside a function?
On 29/10/2010 5:19 PM, Andre Zege wrote: Hi, everyone. I am using a fair amount of closures in my code. Problem i am experiencing is i cannot figure out how to mtrace functions defined within a function. There must be some way to name such function for mtrace to see it and let me step into it. For example, say i have code mymodel<-function(){ data<-numeric(0) build<-function(){ data<<-1 } m<-list() m$build<-build m } How do I mtrace build function defined inside mymodel function so that i can step into build? I don't use mtrace, but you can use setBreakpoint() to set a breakpoint by line number, and presumably you could set the action to whatever will trigger mtrace. It will modify the source of mymodel so that every time it creates a new build(), it creates it with a breakpoint within. See ?setBreakpoint and ?trace. 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] R version 2-12.0 - running as 32 or as 64 bit?
Actually, Berwin - you are right. I also did get 2 shortcuts. I just thought that one of them was old - from my previous R installations. And indeed the 4th line tells what version is running. Great! Thank you! Dimitri On Fri, Oct 29, 2010 at 5:02 PM, Berwin A Turlach wrote: > G'day Dimitri, > > On Fri, 29 Oct 2010 16:45:00 -0400 > Dimitri Liakhovitski wrote: > >> Question: I installed R verison 2-12.0 on my Windows 7 (64 bit) PC. >> When I was installing it, it did not ask me anything about 32 vs. 64 >> bit. So, if I run R now - is it running as a 32-bit or a 64-bit? > > Well, when I did the same, I got two shortcuts installed on my desktop, > one named R 2.12.0 and the other named R x64 2.12.0. If I had any > doubts which version of R these shortcuts would start, then the fourth > line of the start-up message would put them to rest. Missing that > message, you can always issue the command > >> .Machine$sizeof.pointer > > if the answer is 4, you are running 32bit, if the answer is 8, then you > are running 64 bit. > > HTH. > > Cheers, > > Berwin > > == Full address > Berwin A Turlach Tel.: +61 (8) 6488 3338 (secr) > School of Maths and Stats (M019) +61 (8) 6488 3383 (self) > The University of Western Australia FAX : +61 (8) 6488 1028 > 35 Stirling Highway > Crawley WA 6009 e-mail: ber...@maths.uwa.edu.au > Australia http://www.maths.uwa.edu.au/~berwin > -- Dimitri Liakhovitski Ninah Consulting www.ninah.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] how to debug (mtrace) a function defined inside a function?
Hi, everyone. I am using a fair amount of closures in my code. Problem i am experiencing is i cannot figure out how to mtrace functions defined within a function. There must be some way to name such function for mtrace to see it and let me step into it. For example, say i have code mymodel<-function(){ data<-numeric(0) build<-function(){ data<<-1 } m<-list() m$build<-build m } How do I mtrace build function defined inside mymodel function so that i can step into build? -- View this message in context: http://r.789695.n4.nabble.com/how-to-debug-mtrace-a-function-defined-inside-a-function-tp3019781p3019781.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] SARIMA simulation using time series history
Thank you for your suggestion, Juan. However, I have tried to specify the innovations and this doesn't seem to solve the problem. Are there really no opportunities to simulate from a (S)ARIMA model using past observations in R, besides to make the whole script from the ground? Knut Siterer Juan Pablo Calle : Hi Knut, The arima.sim function, in the stats package, has an argument innov="YourSerie" for the innovations, you should try something like: arima.sim(list(order=c(p,d,q), ar=c(ar coefficients), ma=c(ma coefficients), seasonal=list(order=c(P,D,Q), period=NA)), n=N, innov=YourSerie) I'm not sure, but maybe this help you. Salute. Juan. On 2010-10-28, at 8:08 PM, Knut Erik Vedahl wrote: Hi, I'm currently working with a SARIMA model from which I want to make simulations. As I understand, neither sarima.Sim nor the functions in the gsarima package use historic realizations of the time series to simulate future values. However, I want to use historic values as input and simulate future values based on the history. Anyone who know whether such a function is available in the libaries or anywhere else? Thanks for any help! Knut __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Memory use in R
On 29/10/2010 12:46 PM, DM2010 wrote: Dear R Users I have two questions about how R makes use of memory on a Windows computer. On my machine certain R jobs seem to stop with messages such as... "Error: cannot allocate vector of size 215.0 Mb" ...when, according to Windows Task Manager, there are still hundreds of megabytes of physical memory available. These jobs usually stop when the peak commit charge is around 2.6GB (in Windows-speak the "commit charge" is all the memory allocated by system, drivers, applications etc.). Machine characteristics Processor: Pentium-D 4GB of installed memory (Task Manager reports 3584MB = 4GB - 512MB total memory) Windows booted with /3GB switch R started with --max-mem-size=3071M memory.limit() as reported by R: 3071 My questions are: 1. When it starts, does R ask the system to allocate memory for it in a single chunk? No, it can handle fragmented allocations. 2. Can R allocate memory either side of the system-preallocated memory in the middle of address space? I think so. However, when it asks for 215 Mb, it needs to get that allocation in a single block of contiguous addresses, and it won't move things around to make space. When all you've got is 3 GB to play in and you've allocated 2.6 GB, there's a good chance that the remaining space is spread out in small pieces and no available unused address ranges are big enough. If you run R in a 64 bit OS you'll find it handles this situation better, because the OS can assign the physical memory to whatever address it likes, and you'll have lots of big open ranges. On the other hand, with bigger pointers everything takes a bit more space, so you might run out sooner. Duncan Murdoch Best wishes David Max __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 version 2-12.0 - running as 32 or as 64 bit?
On 29/10/2010 4:45 PM, Dimitri Liakhovitski wrote: Question: I installed R verison 2-12.0 on my Windows 7 (64 bit) PC. When I was installing it, it did not ask me anything about 32 vs. 64 bit. So, if I run R now - is it running as a 32-bit or a 64-bit? If it didn't ask you about it, then it probably thinks your machine can't run 64 bits. Any ideas why it might think that? Can you give details about what Windows says about itself in Help | About Windows (accessible from Explorer)? 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.
[R] NetWorkSpace from REvolution; Distributed Computing setup questions
***Summary:*** I'm setting up a cluster using netWorkSpace, and I'm having issues with the sleigh initialization. My R function to initialize the sleigh succeeds and the sleigh appears to be ready, but I get apparently conflicting information from "status(s)", "rankCount(s)", and "s"; and basic sleigh functions cause the sleigh to hang indefinitely. Also, the log file contains an error that indicates that the script is trying to find a file in a nonexistent directory: "/usr/local/lib/R/site-library/nws/bin/RNWSSleighWorker.sh: 37: /Library/Frameworks/R.framework/Resources/bin/R: not found" (see section 4). I've spent quite a bit of time trying to debug this, and I've gathered here all the information that I think may be pertinent to solving the problem. The following is therefore a bit lengthy, but I think complete (as far as I'm able to tell from the existing documentation). It's organized into sections roughly by the topic tested. So if you're familiar with the workings of netWorkSpaces, I would be very grateful if you would take a look at my diagnostics below and tell me if you can identify the problem. ***Details:*** ***Section 1*** Currently my setup is: MASTER: MacBook Pro running OS X 10.6.4 R-2.11.1, Python 2.6.1, and NWSserver-2.0.0. WORKER: Optiplex GX620 running Ubuntu 10.10 (64bit), R-2.11.1, Python 2.6.6, NWSserver-2.0.0, and NWS-2.0.0.3 (client) R and Python are in the PATH on both machines; I can start them from the worker's command line by typing "R" or "python". The client is able to find the "RNWSSleighWorker.sh" file. (Note 1: I put the server software on the client because I was getting an message saying: "No nws server found" each time I tried to install the client software. I don't know if this is needed) (Note 2: I plan to set up many more machines if I can get this working) (Note 3: Originally I was trying this on Windows machines with Cygwin, but I encountered the same error and figured I could at least rule out a possible cause by setting it up on a linux machine. Ultimately I would like to get this working in Windows/Cygwin.) ***Section 2*** The function I used to start the sleigh is: s=sleigh( + nwsHost="172.30.xx.xx", + nwsPort=8765, + launch=sshcmd, + nodeList=c("10.85.xxx.xxx"), + scriptExec=envcmd, + scriptDir="/usr/local/lib/R/site-library/nws/bin", + scriptName="RNWSSleighWorker.sh", + workingDir='~/tmp/', + logDir='~/tmp/', + outfile="outfileTest", + user="tj") This function returns the message below and then clear command prompt: Executing command: '/Library/Frameworks/R.framework/Resources/library/nws/bin/SleighWorkerWrapper.sh' 'ssh' '-f' '-x' '-l' 'tj' '10.85.101.109' 'env' 'RSleighName=10.85.101.109' 'RSleighNwsName=sleigh_ride_0450__nwssNGG4LF' 'RSleighUserNwsName=sleigh_user_0452__nwssNGG4LF' 'RSleighID=1' 'RSleighWorkerCount=1' 'RSleighScriptDir=/usr/local/lib/R/site-library/nws/bin' 'RSleighNwsHost=172.30.34.71' 'RSleighNwsPort=8765' 'RSleighWorkingDir=~/tmp/' 'RProg=/Library/Frameworks/R.framework/Resources/bin/R' 'RSleighWorkerOut=sleigh_ride_0450__nwssNGG4LF_0001.txt' 'RSleighLogDir=~/tmp/' '/usr/local/lib/R/site-library/nws/bin/RNWSSleighWorker.sh' If I type the name of the sleigh "s" as below, I get information that makes it look like the sleigh is ready to receive commands: > s NWS Sleigh Object NWS Host: 172.30.xx.xx:8765 Workspace Name: sleigh_ride_0446__nwssNGG4LF 1 Worker Nodes: 10.85.xxx.xxx Likewise, if I send a simple ssh command to the worker I get a response: > system('ssh t...@10.85.101.109 date') Fri Oct 29 15:15:10 EDT 2010 I can also communicate values between the two machines using the NWS web server and the nwsStore() and nwsFetch() functions. However, if I check the status of the sleigh using "status(s)" or "rankCount(s)", I get less encouraging information: > status(s) $numWorkers [1] 0 $closed [1] 0 > rankCount(s6) [1] 0 ***Section 3*** I can access the NWS server through "localhost:8766" and see that sleighs are being created. There are two entries: a sleigh_ride and a sleigh_user; but the worker count in the sleigh_ride is also zero. If I execute either of the following test sleigh functions, the sleigh will hang indefinitely (though the R terminal will not hang, since I used blocking=false): eachWorker(s5, Sys.info, eo=list(blocking=FALSE)) eachWorker(s, function() library(nws), eo=list(blocking=FALSE)) ***Section 4*** ***CRUX OF THE ISSUE (probably):*** Finally, three files get created in the "~/tmp" directory that I specified as the logDir and workingDir, named: "outfileTest", "RSleighSentinelLog_1000_1" , and "sleigh_ride_0450__nwssNGG4LF_0001.txt". All three contain exactly the same information: "/usr/local/lib/R/site-library/nws/bin/RNWSSleighWorker.sh: 37: /Library/Frameworks/R.framework/Resources/bin/R: not found" Whats puzzling is the "Library/Frameworks/R.framework/Resources/bin/R" part. That looks like an OS X-style path rather tha
Re: [R] One-class SVM
Hi, On Fri, Oct 29, 2010 at 4:24 PM, ANJAN PURKAYASTHA wrote: > Does any R package support one-class SVM? > I'm trying to develop an application to detect anomalies in genome > sequencing. I'm pretty sure kernlab supports this: http://cran.r-project.org/web/packages/kernlab/index.html And: http://www.jstatsoft.org/v11/i09/paper -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R version 2-12.0 - running as 32 or as 64 bit?
G'day Dimitri, On Fri, 29 Oct 2010 16:45:00 -0400 Dimitri Liakhovitski wrote: > Question: I installed R verison 2-12.0 on my Windows 7 (64 bit) PC. > When I was installing it, it did not ask me anything about 32 vs. 64 > bit. So, if I run R now - is it running as a 32-bit or a 64-bit? Well, when I did the same, I got two shortcuts installed on my desktop, one named R 2.12.0 and the other named R x64 2.12.0. If I had any doubts which version of R these shortcuts would start, then the fourth line of the start-up message would put them to rest. Missing that message, you can always issue the command > .Machine$sizeof.pointer if the answer is 4, you are running 32bit, if the answer is 8, then you are running 64 bit. HTH. Cheers, Berwin == Full address Berwin A Turlach Tel.: +61 (8) 6488 3338 (secr) School of Maths and Stats (M019)+61 (8) 6488 3383 (self) The University of Western Australia FAX : +61 (8) 6488 1028 35 Stirling Highway Crawley WA 6009e-mail: ber...@maths.uwa.edu.au Australiahttp://www.maths.uwa.edu.au/~berwin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 version 2-12.0 - running as 32 or as 64 bit?
Question: I installed R verison 2-12.0 on my Windows 7 (64 bit) PC. When I was installing it, it did not ask me anything about 32 vs. 64 bit. So, if I run R now - is it running as a 32-bit or a 64-bit? thank you! -- Dimitri Liakhovitski Ninah Consulting www.ninah.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help pages do not open
Hi Dimitri, The help pages should be loaded from a local server (which is corroborated by the 127...ip), so the internet connection should not matter. I would check whether IE is the default application for .html extensions, and you could also try running R as an admin (though I do not really think that should matter here). Cheers, Josh On Fri, Oct 29, 2010 at 1:20 PM, Dimitri Liakhovitski wrote: > I tried one more thing - I uninstalled R again, and this time > installed it under: > C:\Users\Myname\R\R-2.12.0 > And again - am gettting the same error: > Error in shell.exec(url) : > access to 'http://127.0.0.1:30111/library/stats/html/lm.html' denied > > Any help is greatly appreciated! > Dimitri > > On Fri, Oct 29, 2010 at 9:22 AM, Dimitri Liakhovitski > wrote: >> I have just installed R-2.12 >> I have Windows 7, 64-bit verison. >> I currently have IE as my default browser. The internet connection is very >> good. >> >> Whenever I try to run a help command (?lm, for example), I get this error: >> Error in shell.exec(url) : access to >> 'http://127.0.0.1:20271/library/stats/html/lm.html' denied >> >> I first got this message when Google Chrome was my default browser. >> For some reason, Google Chrome stopped opening web pages. At the same >> time R11 stopped showing help pages. Then, I uninstalled Google Chrome >> and defined IE as my default browser. Then, I uninstalled R11 and >> installed R12 instead. But I am getting the same error. >> >> Any advice? >> >> >> -- >> Dimitri Liakhovitski >> Ninah Consulting >> www.ninah.com >> > > > > -- > Dimitri Liakhovitski > Ninah Consulting > www.ninah.com > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help pages do not open
Problem solved. It turned out I had to reset my IE as my default browser for all extentions (like .html). Now, R help is working! Dimitri On Fri, Oct 29, 2010 at 4:20 PM, Dimitri Liakhovitski wrote: > I tried one more thing - I uninstalled R again, and this time > installed it under: > C:\Users\Myname\R\R-2.12.0 > And again - am gettting the same error: > Error in shell.exec(url) : > access to 'http://127.0.0.1:30111/library/stats/html/lm.html' denied > > Any help is greatly appreciated! > Dimitri > > On Fri, Oct 29, 2010 at 9:22 AM, Dimitri Liakhovitski > wrote: >> I have just installed R-2.12 >> I have Windows 7, 64-bit verison. >> I currently have IE as my default browser. The internet connection is very >> good. >> >> Whenever I try to run a help command (?lm, for example), I get this error: >> Error in shell.exec(url) : access to >> 'http://127.0.0.1:20271/library/stats/html/lm.html' denied >> >> I first got this message when Google Chrome was my default browser. >> For some reason, Google Chrome stopped opening web pages. At the same >> time R11 stopped showing help pages. Then, I uninstalled Google Chrome >> and defined IE as my default browser. Then, I uninstalled R11 and >> installed R12 instead. But I am getting the same error. >> >> Any advice? >> >> >> -- >> Dimitri Liakhovitski >> Ninah Consulting >> www.ninah.com >> > > > > -- > Dimitri Liakhovitski > Ninah Consulting > www.ninah.com > -- Dimitri Liakhovitski Ninah Consulting www.ninah.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] One-class SVM
Does any R package support one-class SVM? I'm trying to develop an application to detect anomalies in genome sequencing. Thanks in advance. Anjan -- === anjan purkayastha, phd. research associate fas center for systems biology, harvard university 52 oxford street cambridge ma 02138 phone-703.740.6939 === [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help pages do not open
I tried one more thing - I uninstalled R again, and this time installed it under: C:\Users\Myname\R\R-2.12.0 And again - am gettting the same error: Error in shell.exec(url) : access to 'http://127.0.0.1:30111/library/stats/html/lm.html' denied Any help is greatly appreciated! Dimitri On Fri, Oct 29, 2010 at 9:22 AM, Dimitri Liakhovitski wrote: > I have just installed R-2.12 > I have Windows 7, 64-bit verison. > I currently have IE as my default browser. The internet connection is very > good. > > Whenever I try to run a help command (?lm, for example), I get this error: > Error in shell.exec(url) : access to > 'http://127.0.0.1:20271/library/stats/html/lm.html' denied > > I first got this message when Google Chrome was my default browser. > For some reason, Google Chrome stopped opening web pages. At the same > time R11 stopped showing help pages. Then, I uninstalled Google Chrome > and defined IE as my default browser. Then, I uninstalled R11 and > installed R12 instead. But I am getting the same error. > > Any advice? > > > -- > Dimitri Liakhovitski > Ninah Consulting > www.ninah.com > -- Dimitri Liakhovitski Ninah Consulting www.ninah.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] Memory use in R
Dear R Users I have two questions about how R makes use of memory on a Windows computer. On my machine certain R jobs seem to stop with messages such as... "Error: cannot allocate vector of size 215.0 Mb" ...when, according to Windows Task Manager, there are still hundreds of megabytes of physical memory available. These jobs usually stop when the peak commit charge is around 2.6GB (in Windows-speak the "commit charge" is all the memory allocated by system, drivers, applications etc.). Machine characteristics Processor: Pentium-D 4GB of installed memory (Task Manager reports 3584MB = 4GB - 512MB total memory) Windows booted with /3GB switch R started with --max-mem-size=3071M memory.limit() as reported by R: 3071 My questions are: 1. When it starts, does R ask the system to allocate memory for it in a single chunk? 2. Can R allocate memory either side of the system-preallocated memory in the middle of address space? Best wishes David Max -- View this message in context: http://r.789695.n4.nabble.com/Memory-use-in-R-tp3019447p3019447.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] Tukey post hoc comparison (glht?) after 3factorial mixed model (lmer)
Hello, dear R-community. This is a question about TukeyHSD between factor combinations of a Three-Way ANOVA, which is - since it is a multi measure ANOVA - not a simple ANOVA but a Generalised Linear Mixed Model (GLMM), calculated with "lmer". > growth <- groupedData(length~meas|box_id,outer=~spec*comp*water,data=all.spec) > model <- lmer(length~spec*comp*water+(meas|box_id),data=growth) > summary(model) This works fine. But now, I would like to calculate Tukey HSD among certain factor combinations. Formerly (before version 1.0), Tukey contrasts including all levels of interactions could be calculated with the multcomp package more or less automatically like this: > summary (glht (model, linfct = mcp (spec*comp*water = "Tukey"))) Now, Mr Hothorn et al. have changed the function and it is "suggestet to the users that they write out, manually, the set of contrasts they want". I think that is not a bad idea, but I got problems with the syntax in my case. And I would really grateful if anybody could help me. So far I tried: > K <- cbind(0,diag(length(fixef(model))-1)) > rownames(K) <- names(fixef(model))[-1] > model_glht <- glht(model,linfct=K) > summary(model_glht) # but actually this is not what I want I'm rather looking for a Tukey output like this specSt:compControl - specSt:compRoot p that they are equal < 0.05 specSt:compControl - specSt:compShoot specSt:compControl - specSt:compFull specSt:compRoot - specSt:compShoot specSt:compRoot - specSt:compFull specSt:compShoot - specSt:compFull and that for each of the 3 studied species, i.e. compare all-pairwise combinations of the levels of the second factor within each level of the first factor. We are not interested in the third factor, so data can be averaged over that. THANKS A LOT FOR ANY ADVICE, Sincerely Anna Radtke -> model output: Linear mixed model fit by REML Formula: length ~ spec * comp * water + (meas | box_id) Data: growth AIC BIC logLik deviance REMLdev 4800 4909 -2372 49884744 Random effects: Groups NameVariance Std.Dev. Corr box_id (Intercept) 0.0 0.000 meas222484.2 471.682NaN Residual 9439.4 97.157 Number of obs: 360, groups: box_id, 120 Fixed effects: Estimate Std. Error t value (Intercept) -353.554 65.777 -5.375 specSt -103.111 93.023 -1.108 specSv-4.485 93.023 -0.048 comproot -41.686 93.023 -0.448 compshoot241.847 93.023 2.600 compxfull316.849 93.023 3.406 watermoist -48.620 93.023 -0.523 specSt:comproot 97.168131.554 0.739 specSv:comproot 54.849131.554 0.417 specSt:compshoot 10.416131.554 0.079 specSv:compshoot 6.584131.554 0.050 specSt:compxfull 90.949131.554 0.691 specSv:compxfull 43.284131.554 0.329 specSt:watermoist 9.222131.554 0.070 specSv:watermoist104.229131.554 0.792 comproot:watermoist 15.931131.554 0.121 compshoot:watermoist 28.999131.554 0.220 compxfull:watermoist 39.363131.554 0.299 specSt:comproot:watermoist45.513186.046 0.245 specSv:comproot:watermoist -24.350186.046 -0.131 specSt:compshoot:watermoist 46.027186.046 0.247 specSv:compshoot:watermoist1.232186.046 0.007 specSt:compxfull:watermoist 23.749186.046 0.128 specSv:compxfull:watermoist -57.109186.046 -0.307 "meas" "spec" "comp" "water" "box_id" "sprouts" "leaves" "length" "long.sprout" "81" 1 "Sf" "xfull" "moist" 81 6.8 13.6 150.4 43.8 "82" 1 "Sf" "root" "moist" 82 6.5 18.5 104.25 25.75 "83" 1 "Sf" "control" "moist" 83 9.25 29 146 27 "84" 1 "Sf" "control" "moist" 84 6.8 31.4 163.8 46.6 "85" 1 "Sf" "shoot" "moist" 85 4.8 19.8 127.6 32.8 "86" 1 "Sf" "control" "moist" 86 8.2 30.6 144.4 31.6 "87" 1 "Sf" "root" "moist" 87 7.8 32.8 174 38.8 "88" 1 "Sf" "shoot" "moist" 88 5 8.5 54 22.25 "89" 1 "Sf" "xfull" "moist" 89 2.25 7 54.25 27 "90" 1 "Sf" "control" "moist" 90 5.6 21.2 103 30 "91" 1 "Sf" "shoot" "moist" 91 4.25 18 84.25 29.25 "92" 1 "Sf" "root" "moist" 92 5.8 26.4 133.2 33 "93" 1 "Sf" "shoot" "moist" 93 11.25 35.25 215 44.25 "94" 1 "Sf" "root" "moist" 94 6 17. 90.6667 19. "95" 1 "Sf" "root" "moist" 95 4.7 5.3 33.6667 9.3 "96" 1 "Sf" "shoot" "moist" 96 6.5 11.5 88.25 25.5 "97" 1 "Sf" "xfull" "moist" 97 9.8 13 184.4 40.2 "98" 1 "Sf" "xfull" "moist" 98 5.8 15.2 156.6 41.6 "99" 1 "Sf" "control" "moist" 99 7.5 26.5 140.75 36.5 "100" 1 "Sf" "xfull" "moist" 100 4.2 10.4 91 41.2 "101" 1 "Sf" "control" "awater-logged" 101 9 35.8 222.2 43.6 "102" 1 "Sf" "shoot" "awater-logged" 102 10.8 40.6 245.4 47.6 "103" 1 "Sf" "xfull" "awater-logged" 103 4.6 10.6 134.6 47 "104" 1 "Sf" "shoot" "awate
Re: [R] doubt in climate variability analysis in R! - code included!
the following code was used library(akima) library(clim.pact) nc.1 <- "RF_80-05.nc" nc.rf.in <- open.ncdf(nc.1) x1 <- retrieve.nc(nc.1, v.nam="Rainfall",l.scale=FALSE, x.rng=c(70, 80), y.rng=c(10, 13.5)) #dimension is checked for the subset. (lon, lat, time) is changed as (time, lat, lon) >dim(x1$dat) #[1] 2192 8 20 My question is - how can i convert this array into a dataframe so that i have "lat", "lon", "precipitation values" in 3 different columns (note, I will have it for just a single day). So, my expected dataframe will have rainfall values for each given pair of "lon" and "lat". Or is there any other better way to do my spatial variogram analysis for a single day given the above dataset? here is the link for the dataset. HTTP://WWW.4SHARED.COM/FILE/4ZV0G3JR/RF_80-85.HTML -- Regards, Mahalakshmi Graduate Student #20, Department of Geography Michigan State University East Lansing, MI 48824 Quoting govin...@msu.edu: > > > Hello all, > > I am trying to use "clim.pact" package for my work, but since this > is the beginning for me to use gridded datasets in "R", I am having > some trouble. > > I want to do seasonal analyses like trends, anomalies, variograms, > EOF and probably kriging too to downscale my 1 degree gridded data > to 0.5. So, as a first step, I compiled my entire dataset (with 25 > yeears of daily dataset which were present as 25 files) into a > single netcdf file. > > Then, I downloaded clim.pact to do further analysis, which works but > seems to change dataset's original dimensions' order for > "retrieve.nc" function (i.e. original lon, lat, time order was > changed to time, lat, lon after using this function to get a > subset). I am not sure as to why this happened and not able to get > any plots such as box plot (showing trend in "lon", "lat", > "time"), variogram (or variance), correlation analysis done > because of this conversion problem. > > Further, basic "R" functions seem to work well with objects such as > dataframe, matrix ..etc with time in a separate column, and the > data values (precipitation, or temperature) in a separate coulmn > with corresponding station values (lon/lat). So, now I have very > little idea about what I have to do. Can anyone suggest me a better > (probably more refined way) way than what I am currently doing to > analyze these data? > > > > -- > Regards, > Mahalakshmi > Graduate Student > #20, Department of Geography > Michigan State University > East Lansing, MI 48824 [[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] Plotting 2 Lines on the Same Chart
On Fri, Oct 29, 2010 at 2:30 PM, Jason Kwok wrote: > Thanks. 1 more question. > > When I use > > Plot(series1) > lines(series2) > > The graph will use the y axis scaling for series 1 so some of series 2 is > cut off. How do I control the y axis scaling? > Plot them together as a multivariate series as in the examples already pointed to. -- 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] Plotting 2 Lines on the Same Chart
Thanks. 1 more question. When I use Plot(series1) lines(series2) The graph will use the y axis scaling for series 1 so some of series 2 is cut off. How do I control the y axis scaling? Thanks, Jason On Fri, Oct 29, 2010 at 2:10 PM, Gabor Grothendieck wrote: > On Fri, Oct 29, 2010 at 1:41 PM, Jason Kwok wrote: > > How do I plot two time series plots on the same chart? > > > > Try this: > > example(plot.ts) > example(ts.plot) > > library(zoo) > example(plot.zoo) > library(lattice) > example(xyplot.zoo) > > -- > Statistics & Software Consulting > GKX Group, GKX Associates Inc. > tel: 1-877-GKX-GROUP > email: ggrothendieck at 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.
Re: [R] Plotting 2 Lines on the Same Chart
On Fri, Oct 29, 2010 at 1:41 PM, Jason Kwok wrote: > How do I plot two time series plots on the same chart? > Try this: example(plot.ts) example(ts.plot) library(zoo) example(plot.zoo) library(lattice) example(xyplot.zoo) -- 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] Dickey Fuller Test
Thanks a lot for your answers, Dennis and Bernhard! -- View this message in context: http://r.789695.n4.nabble.com/Dickey-Fuller-Test-tp3018408p3019544.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] Plotting 2 Lines on the Same Chart
How do I plot two time series plots on the same chart? Thanks, Jason [[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] doubt in climate variability analysis in R!
> -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] > On Behalf Of govin...@msu.edu > Sent: Friday, October 29, 2010 8:33 AM > To: r-help@r-project.org > Subject: [R] doubt in climate variability analysis in R! > > > > Hello all, > > I am trying to use "clim.pact" package for my work, but since this is > the beginning for me to use gridded datasets in "R", I am having some > trouble. > > I want to do seasonal analyses like trends, anomalies, variograms, EOF > and probably kriging too to downscale my 1 degree gridded data to 0.5. > So, as a first step, I compiled my entire dataset (with 25 yeears of > daily dataset which were present as 25 files) into a single netcdf file. > > Then, I downloaded clim.pact to do further analysis, which works but > seems to change dataset's original dimensions' order for "retrieve.nc" > function (i.e. original lon, lat, time order was changed to time, lat, > lon after using this function to get a subset). I am not sure as to why > this happened and not able to get any plots such as box plot (showing > trend in "lon", "lat", "time"), variogram (or variance), correlation > analysis done because of this conversion problem. > > Further, basic "R" functions seem to work well with objects such as > dataframe, matrix ..etc with time in a separate column, and the data > values (precipitation, or temperature) in a separate coulmn with > corresponding station values (lon/lat). So, now I have very little idea > about what I have to do. Can anyone suggest me a better (probably more > refined way) way than what I am currently doing to analyze these data? > > > > -- > Regards, > Mahalakshmi > Graduate Student > #20, Department of Geography > Michigan State University > East Lansing, MI 48824 > [[alternative HTML version deleted]] You should read the posing guide referenced at the bottom of every email. It will tell you how to ask questions and what information you need to provide in order to get useful help. At a minimum, we need a self-contained reproducible example that demonstrates the problem you are having. Provide say 10 observations and the code you used to subset the data, and maybe someone can help you with a solution. Dan Daniel Nordlund Bothell, WA USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Repeated Measures MANOVA
Dear Chris, See the examples in ?Anova in the car package (but it works with a model fit by lm). I hope this helps, John John Fox Senator William McMaster Professor of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada web: socserv.mcmaster.ca/jfox > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf Of Christopher Kurby > Sent: October-29-10 12:24 PM > To: r-help@r-project.org > Subject: [R] Repeated Measures MANOVA > > Hello all, > > Is there an r function that exists that will perform repeated measures > MANOVAs? For example, let's say I have 3 DVs, one between-subjects IV, and > one within-subjects IV. Based on the documentation for the manova command, a > function like that below is not appropriate because it cannot take Error > arguments. > > manova(cbind(DV1,DV2,DV3) ~ BetweenSubjectsIV * WithinSubjectsIV + > Error(SubjNum/WithinSubjectsIV), data=dat) > > Do you know of any functions that would allow me to perform such an analysis? > I realize that I could turn the DVs into levels of a new IV, and then perform > a standard repeated measures ANOVA. But, I do not feel that would be > appropriate in this case. > > Thanks so much for your time, > Chris > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/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] scatterplot3d; scaling point symbols to depth of graph
I had a look: I fixed it 5 months ago and forgot to make a new release. The version on R-forge contains the fix already. New release on its way to CRAN. Best wishes; Uwe On 28.10.2010 11:28, John Coulthard wrote: Hi I'm trying to scale the point symbols on a 3d plot so that the ones at the front are larger than the ones at the back. I'm trying to give the image some perspective. Given this code... library(scatterplot3d) data=array(c(0,5,9), c(3,3)) scatterplot3d(data, pch=19, cex.symbols=10-data[,2], color=c("red","blue","black")); data [,1] [,2] [,3] [1,]000 [2,]555 [3,]999 which gives a vector for cex.symbols as 10-data[,2] [1] 10 5 1 I would expect the largest point to be the red one at the origin but the image I get has the black symbol at co-ords 9,9,9 as the largest and red at 0,0,0 the smallest. Then if I do... data=array(c(0,9,5), c(3,3)) data [,1] [,2] [,3] [1,]000 [2,]999 [3,]555 scatterplot3d(data, pch=19, cex.symbols=10-data[,2], color=c("red","blue","black")); 10-data[,2] [1] 10 1 5 I'd expect the position and size of the points to be the same but the colour of blue and black to be exchanged. But the size of the points also changes such that the red point at 0,0,0 is the medium size and the black at 5,5,5 is the smallest. So is it possible to get the points described by each row in data to be scaled by the values in data[,2]? Many thanks John sessionInfo() R version 2.11.1 (2010-05-31) i386-redhat-linux-gnu locale: [1] LC_CTYPE=en_US.utf8 LC_NUMERIC=C [3] LC_TIME=en_US.utf8LC_COLLATE=en_US.utf8 [5] LC_MONETARY=C LC_MESSAGES=en_US.utf8 [7] LC_PAPER=en_US.utf8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] scatterplot3d_0.3-30 loaded via a namespace (and not attached): [1] tools_2.11.1 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Repeated Measures MANOVA
Hello all, Is there an r function that exists that will perform repeated measures MANOVAs? For example, let's say I have 3 DVs, one between-subjects IV, and one within-subjects IV. Based on the documentation for the manova command, a function like that below is not appropriate because it cannot take Error arguments. manova(cbind(DV1,DV2,DV3) ~ BetweenSubjectsIV * WithinSubjectsIV + Error(SubjNum/WithinSubjectsIV), data=dat) Do you know of any functions that would allow me to perform such an analysis? I realize that I could turn the DVs into levels of a new IV, and then perform a standard repeated measures ANOVA. But, I do not feel that would be appropriate in this case. Thanks so much for your time, Chris __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Clustering
On Oct 29, 2010, at 12:08 PM, David Winsemius wrote: On Oct 29, 2010, at 11:37 AM, dpender wrote: Apologies for being vague, The structure of the output is as follows: Still no code? $ cluster1 : Named num [1:131] 3.05 2.71 3.26 2.91 2.88 3.11 3.21 -1 2.97 3.39 ... ..- attr(*, "names")= chr [1:131] "6667" "6668" "6669" "6670" ... With 613 clusters. What I require is abstracting the first and last value of - attr(*, "names")= chr [1:131] "6667" "6668" "6669" "6670" Those values are in an attribute: Corrections: ? attribute ?attributes ? attr Your specific request may (perhaps) be addressed by something like: attrnames <- attr(objname["cluster1"], "names") ^ ^ should be doubled square- brackets attrnames[c(1, length(attrnames)] ^ missing right-paren Might work: attrnames <- attr(clusobj[["cluster1"]], "names") attrnames[c(1, length(attrnames))] -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Tukey post hoc comparison (glht?) after 3factorial mixed model (lmer)
Hello, dear R-community. This is a question about TukeyHSD between factor combinations of a Three-Way ANOVA, which is - since it is a multi measure ANOVA - not a simple ANOVA but a Generalised Linear Mixed Model (GLMM), calculated with "lmer". > growth <- groupedData(length~meas|box_id,outer=~spec*comp*water,data=all.spec) > model <- lmer(length~spec*comp*water+(meas|box_id),data=growth) > summary(model) This works fine. But now, I would like to calculate Tukey HSD among certain factor combinations. Formerly (before version 1.0), Tukey contrasts including all levels of interactions could be calculated with the multcomp package more or less automatically like this: > summary (glht (model, linfct = mcp (spec*comp*water = "Tukey"))) Now, Mr Hothorn et al. have changed the function and it is "suggestet to the users that they write out, manually, the set of contrasts they want". I think that is not a bad idea, but I got problems with the syntax in my case. And I would really grateful if anybody could help me. So far I tried: > K <- cbind(0,diag(length(fixef(model))-1)) > rownames(K) <- names(fixef(model))[-1] > model_glht <- glht(model,linfct=K) > summary(model_glht) # but actually this is not what I want I'm rather looking for a Tukey output like this specSt:compControl - specSt:compRoot p that they are equal < 0.05 specSt:compControl - specSt:compShoot specSt:compControl - specSt:compFull specSt:compRoot - specSt:compShoot specSt:compRoot - specSt:compFull specSt:compShoot - specSt:compFull and that for each of the 3 studied species, i.e. compare all-pairwise combinations of the levels of the second factor within each level of the first factor. We are not interested in the third factor, so data can be averaged over that. THANKS A LOT FOR ANY ADVICE, Sincerely Anna Radtke -> model output: Linear mixed model fit by REML Formula: length ~ spec * comp * water + (meas | box_id) Data: growth AIC BIC logLik deviance REMLdev 4800 4909 -2372 49884744 Random effects: Groups NameVariance Std.Dev. Corr box_id (Intercept) 0.0 0.000 meas222484.2 471.682NaN Residual 9439.4 97.157 Number of obs: 360, groups: box_id, 120 Fixed effects: Estimate Std. Error t value (Intercept) -353.554 65.777 -5.375 specSt -103.111 93.023 -1.108 specSv-4.485 93.023 -0.048 comproot -41.686 93.023 -0.448 compshoot241.847 93.023 2.600 compxfull316.849 93.023 3.406 watermoist -48.620 93.023 -0.523 specSt:comproot 97.168131.554 0.739 specSv:comproot 54.849131.554 0.417 specSt:compshoot 10.416131.554 0.079 specSv:compshoot 6.584131.554 0.050 specSt:compxfull 90.949131.554 0.691 specSv:compxfull 43.284131.554 0.329 specSt:watermoist 9.222131.554 0.070 specSv:watermoist104.229131.554 0.792 comproot:watermoist 15.931131.554 0.121 compshoot:watermoist 28.999131.554 0.220 compxfull:watermoist 39.363131.554 0.299 specSt:comproot:watermoist45.513186.046 0.245 specSv:comproot:watermoist -24.350186.046 -0.131 specSt:compshoot:watermoist 46.027186.046 0.247 specSv:compshoot:watermoist1.232186.046 0.007 specSt:compxfull:watermoist 23.749186.046 0.128 specSv:compxfull:watermoist -57.109186.046 -0.307 "meas" "spec" "comp" "water" "box_id" "sprouts" "leaves" "length" "long.sprout" "81" 1 "Sf" "xfull" "moist" 81 6.8 13.6 150.4 43.8 "82" 1 "Sf" "root" "moist" 82 6.5 18.5 104.25 25.75 "83" 1 "Sf" "control" "moist" 83 9.25 29 146 27 "84" 1 "Sf" "control" "moist" 84 6.8 31.4 163.8 46.6 "85" 1 "Sf" "shoot" "moist" 85 4.8 19.8 127.6 32.8 "86" 1 "Sf" "control" "moist" 86 8.2 30.6 144.4 31.6 "87" 1 "Sf" "root" "moist" 87 7.8 32.8 174 38.8 "88" 1 "Sf" "shoot" "moist" 88 5 8.5 54 22.25 "89" 1 "Sf" "xfull" "moist" 89 2.25 7 54.25 27 "90" 1 "Sf" "control" "moist" 90 5.6 21.2 103 30 "91" 1 "Sf" "shoot" "moist" 91 4.25 18 84.25 29.25 "92" 1 "Sf" "root" "moist" 92 5.8 26.4 133.2 33 "93" 1 "Sf" "shoot" "moist" 93 11.25 35.25 215 44.25 "94" 1 "Sf" "root" "moist" 94 6 17. 90.6667 19. "95" 1 "Sf" "root" "moist" 95 4.7 5.3 33.6667 9.3 "96" 1 "Sf" "shoot" "moist" 96 6.5 11.5 88.25 25.5 "97" 1 "Sf" "xfull" "moist" 97 9.8 13 184.4 40.2 "98" 1 "Sf" "xfull" "moist" 98 5.8 15.2 156.6 41.6 "99" 1 "Sf" "control" "moist" 99 7.5 26.5 140.75 36.5 "100" 1 "Sf" "xfull" "moist" 100 4.2 10.4 91 41.2 "101" 1 "Sf" "control" "awater-logged" 101 9 35.8 222.2 43.6 "102" 1 "Sf" "shoot" "awater-logged" 102 10.8 40.6 245.4 47.6 "103" 1 "Sf" "xfull" "awater-logged" 103 4.6 10.6 134.6 47 "104" 1 "Sf" "shoot" "awate
Re: [R] Clustering
On Oct 29, 2010, at 11:37 AM, dpender wrote: Apologies for being vague, The structure of the output is as follows: Still no code? $ cluster1 : Named num [1:131] 3.05 2.71 3.26 2.91 2.88 3.11 3.21 -1 2.97 3.39 ... ..- attr(*, "names")= chr [1:131] "6667" "6668" "6669" "6670" ... With 613 clusters. What I require is abstracting the first and last value of - attr(*, "names")= chr [1:131] "6667" "6668" "6669" "6670" Those values are in an attribute: ? attribute ? attr Your specific request may (perhaps) be addressed by something like: attrnames <- attr(objname["cluster1"], "names") attrnames[c(1, length(attrnames)] I don't really think this is optimal. For one thing it won't generalize to the rest of the clusters. Generally when data are put into an attribute, the programmer also provides an extraction function. Since Nabble posters are prone to not retaining thread context, the name of your function and package are probably elsewhere further up the thread but not available as I read this on a mail- client. Perhaps if you read more of the documentation? (Just a guess.) This will give a start and end point of the cluster and allow for the spacing to be determined. Those would be character values and, if you want to do calculations, would obviously need to be coerced to numeric. Thanks, Doug -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] draw path diagram using dot
Dear John, Thank you very much for your help! I appreciate it. eshi -- View this message in context: http://r.789695.n4.nabble.com/draw-path-diagram-using-dot-tp3017987p3019359.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] Cox Proportional Models and Haplotypes
You could do a weighted cox ph model, with possible haplotype configurations for each subject weighted by their posterior probabilities given genotype data. Are your markers SNPs? If so you can use a utility function from the hapassoc package to get started. For example, if your data is in a dataframe dat, with nsnp SNPs in the last nsnps columns, you could create an augmented data frame (augmented by pseudo-individuals for each subject with ambiguous phase) with library(hapassoc) ph<-pre.hapassoc(dat,nsnps) augdat<-cbind(ph$nonHaploDM,ph$haploDM) wts<-ph$wt and then use coxph with augdat as the data frme and wts as the weights. See ?pre.hapassoc for details on accepted formats for the SNP data. Brad -- Brad McNeney Statistics and Actuarial Science Simon Fraser University On Tue, Oct 26, 2010 at 12:01 PM, David Winsemius wrote: > > On Oct 26, 2010, at 8:57 AM, sr500 wrote: > >> >> Hello, >> >> I was wondering if anyone knew of a function that fits haplotype data into >> a >> cox proportional hazard model. I have computed my Haplotype frequencies >> using the haplo.stats package. I have also been using the haplo.glm >> function >> but this is a linear regression and is not quite what I am looking for… >> > > I think you need to describe your data situation more completely and ideally > would include a small extract of your data to allow testing and > illustration. Cox proportional hazards models are typically used to analyze > time to event data and you have not alluded to any "events". > > -- > David. > >> Thank you very much, >> SR >> >> -- >> View this message in context: >> http://r.789695.n4.nabble.com/Cox-Proportional-Models-and-Haplotypes-tp3013989p3013989.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] Please help me about Monte Carlo Permutation
Hi dear Mi³ego dnia, I am sorry I got lost here. May be it it sound if I write you about what I am going to do. "To test such null hypotheses we used the Monte Carlo test, i.e. we chose randomly (5000 times) a value for the current dependent characteristic (richness or actual species pool) in the interval 0 to the maximum possible value of the dependent variable for each observed value of the current independent variable. The maximum observed value was either the calculated size of the regional pool, or the measured size of the actual pool. Each time, we calculated the correlation coefficient r between the independent and dependent variables in order to achieve the empirical distribution of r for the null hypothesis conditions. The empirical probability of cases with a correlation between the two studied variables positive and stronger than that observed in the real data, served as an estimate of the significance level for rejecting the null hypotheses. Thus, by saying that there exists a significant relationship, we mean that the relationship is significantly stronger than expected from our null model". I hope I can get all necessary R code for analyses. Chitra -- View this message in context: http://r.789695.n4.nabble.com/Please-help-me-about-Monte-Carlo-Permutation-tp3017131p3019329.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] Clustering
Apologies for being vague, The structure of the output is as follows: $ cluster1 : Named num [1:131] 3.05 2.71 3.26 2.91 2.88 3.11 3.21 -1 2.97 3.39 ... ..- attr(*, "names")= chr [1:131] "6667" "6668" "6669" "6670" ... With 613 clusters. What I require is abstracting the first and last value of - attr(*, "names")= chr [1:131] "6667" "6668" "6669" "6670" This will give a start and end point of the cluster and allow for the spacing to be determined. Thanks, Doug -- View this message in context: http://r.789695.n4.nabble.com/Clustering-tp3017056p3019323.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] I got lot in the permutation
Thanks for your help. May be I can not make clear by my writing. The statement which I am going to do is like this "To test such null hypotheses we used the Monte Carlo test, i.e. we chose randomly (5000 times) a value for the current dependent characteristic (richness or actual species pool) in the interval 0 to the maximum possible value of the dependent variable for each observed value of the current independent variable. The maximum observed value was either the calculated size of the regional pool, or the measured size of the actual pool. Each time, we calculated the correlation coefficient r between the independent and dependent variables in order to achieve the empirical distribution of r for the null hypothesis conditions. The empirical probability of cases with a correlation between the two studied variables positive and stronger than that observed in the real data, served as an estimate of the significance level for rejecting the null hypotheses. Thus, by saying that there exists a significant relationship, we mean that the relationship is significantly stronger than expected from our null model". I hope you will figure out and provide me all code for analyses. Thanks. Chitra __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] doubt in climate variability analysis in R!
Hello all, I am trying to use "clim.pact" package for my work, but since this is the beginning for me to use gridded datasets in "R", I am having some trouble. I want to do seasonal analyses like trends, anomalies, variograms, EOF and probably kriging too to downscale my 1 degree gridded data to 0.5. So, as a first step, I compiled my entire dataset (with 25 yeears of daily dataset which were present as 25 files) into a single netcdf file. Then, I downloaded clim.pact to do further analysis, which works but seems to change dataset's original dimensions' order for "retrieve.nc" function (i.e. original lon, lat, time order was changed to time, lat, lon after using this function to get a subset). I am not sure as to why this happened and not able to get any plots such as box plot (showing trend in "lon", "lat", "time"), variogram (or variance), correlation analysis done because of this conversion problem. Further, basic "R" functions seem to work well with objects such as dataframe, matrix ..etc with time in a separate column, and the data values (precipitation, or temperature) in a separate coulmn with corresponding station values (lon/lat). So, now I have very little idea about what I have to do. Can anyone suggest me a better (probably more refined way) way than what I am currently doing to analyze these data? -- Regards, Mahalakshmi Graduate Student #20, Department of Geography Michigan State University East Lansing, MI 48824 [[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] Contract programming position at Merck (NJ, USA)
Job: Scientific programmer at Merck, Biostatistics, Rahway, NJ, USA [Job Description] This position works closely with statisticians to process and analyze ultrasound, MRI, and radiotelemetry longitudinal studies using a series of programs developed in R and Mathworks/Matlab. This position provides support for the analysis of several pre-clinical and clinical functional MRI studies by preprocessing and processing data using the software FSL. Qualified candidates must have a proficiency and experience with statistical software and technical computing packages including Matlab, R, SAS, and S-Plus as well as familiarity with medical image concepts (e.g., functional MRI) and an understanding of analysis tools for fMRI (FSL, SPM). This is contract position for an ongoing need in Biometrics Research. It is a term contract position (1 year) with the possibility to extend up to 2 years in length based on continued business need and available budget. If you are interested, please contact: amy_gilles...@merck.com Notice: This e-mail message, together with any attachme...{{dropped:14}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Reading multiple .csv-files and assigning them to variable names
On Fri, Oct 29, 2010 at 5:16 AM, Sarah Moens wrote: > Hi all, > > I've been trying to find a solution for the problem of reading > multiple files and storing them in a variable that contains the names > by which I want to call the datasets later on. > > For example (5 filenames): > > - The filenames are stored in one variable: > filenames = paste(paste('name', '_', 1:5, sep = ''), '.csv', sep = '') > > - Subsequently I have a variable just containing the meaningful names > for the dataset > meaningfulnames = c('name1','name2'...,'name5') > > - I want to link each of these names to the data that is read > > for (i in 1:5) > { > meaningfulnames[i] = read.csv(filenames[i], header = TRUE, sep = ',') > } > > > I need to read in quite a lot of datafiles. I have a code doing this > one at a time, but since the number of datafiles I need to read will > increase in the future, I want to make sure I have a more flexible > solution for this. > Try this: filenames <- sprintf("%s_%d.csv", "name", 1:5) L <- sapply(filenames, read.csv, simplify = FALSE) L will be a list with the data frames as components and the file names as the component names. If you wish to change the names from the filenames to some other names you can do this: names(L) <- vector.of.other.names If the data frames all have the same number of columns and the same names in the same order then you could also put them into a single data frame like this: do.call("rbind", L) or if you want to retain the knowledge of which each came from: library(lattice) do.call("make.groups", L) -- 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] Printing data.frame data: alternatives to print?
I think that'll work... thanks! matt On Fri, Oct 29, 2010 at 9:45 AM, jim holtman wrote: > Is this what you want: > >> df > f1 f2 > 1 Maj I Minor A > 2 Maj I Minor A > 3 Maj I Minor A > 4 Maj II Minor A > 5 Maj II Minor B > 6 Maj II Minor B > 7 Maj III Minor B > 8 Maj III Minor C > 9 Maj III Minor C >> df[!duplicated(df),] > f1 f2 > 1 Maj I Minor A > 4 Maj II Minor A > 5 Maj II Minor B > 7 Maj III Minor B > 8 Maj III Minor C >> > > > On Fri, Oct 29, 2010 at 9:53 AM, Matthew Pettis > wrote: >> Hi, >> >> I have a data frame with two factors (well, more, but 2 for simple >> consideration), and I want to display the different combinations of >> the them that actually occur in the data. In reality, there are too >> many of them to do to do a 'table' call and have one col vertical and >> one col horizontal (I don't want any of the factors listed >> horizontally). Before I try to write a function to do this for me, I >> was wondering if there were alternate printing styles for data that >> already exist, and if someone could direct me to them? Inclded is a >> sample code and 2 possibilities (others welcome for consideration) of >> how I want to display some data. >> >> Thanks, >> Matt >> >> - >> >> df <- data.frame( >> f1=rep(c("Maj I", "Maj II", "Maj III"), each=3), >> f2=c("Minor A", "Minor A", "Minor A", "Minor A", "Minor B", "Minor >> B", "Minor B", "Minor C", "Minor C") >> ) >> >> - >> >> What I want printed is something like: >> >> --- >> f1 f2 >> Maj I Minor A >> >> Maj II Minor A >> Minor B >> >> Maj III Minor B >> Minor C >> --- >> >> or >> >> --- >> f1 f2 >> Maj I Minor A >> >> Maj II Minor A >> Maj II Minor B >> >> Maj III Minor B >> Maj III Minor C >> >> __ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > > > -- > Jim Holtman > Cincinnati, OH > +1 513 646 9390 > > What is the problem that you are trying to solve? > -- Seven Deadly Sins (Gandhi): - Wealth without work - Politics without principle - Pleasure without conscience - Commerce without morality - Science without humanity - Worship without sacrifice - Knowledge without character __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] strftime vs strptime ??
On Oct 29, 2010, at 6:55 AM, skan wrote: Hello Could anyone explain me the difference between strftime vs strptime, please ? I've read the help but it's a little bit cionfusing for me. You should focus on the "Value" section of the help page. They return vectors of different classes. -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Printing data.frame data: alternatives to print?
Is this what you want: > df f1 f2 1 Maj I Minor A 2 Maj I Minor A 3 Maj I Minor A 4 Maj II Minor A 5 Maj II Minor B 6 Maj II Minor B 7 Maj III Minor B 8 Maj III Minor C 9 Maj III Minor C > df[!duplicated(df),] f1 f2 1 Maj I Minor A 4 Maj II Minor A 5 Maj II Minor B 7 Maj III Minor B 8 Maj III Minor C > On Fri, Oct 29, 2010 at 9:53 AM, Matthew Pettis wrote: > Hi, > > I have a data frame with two factors (well, more, but 2 for simple > consideration), and I want to display the different combinations of > the them that actually occur in the data. In reality, there are too > many of them to do to do a 'table' call and have one col vertical and > one col horizontal (I don't want any of the factors listed > horizontally). Before I try to write a function to do this for me, I > was wondering if there were alternate printing styles for data that > already exist, and if someone could direct me to them? Inclded is a > sample code and 2 possibilities (others welcome for consideration) of > how I want to display some data. > > Thanks, > Matt > > - > > df <- data.frame( > f1=rep(c("Maj I", "Maj II", "Maj III"), each=3), > f2=c("Minor A", "Minor A", "Minor A", "Minor A", "Minor B", "Minor > B", "Minor B", "Minor C", "Minor C") > ) > > - > > What I want printed is something like: > > --- > f1 f2 > Maj I Minor A > > Maj II Minor A > Minor B > > Maj III Minor B > Minor C > --- > > or > > --- > f1 f2 > Maj I Minor A > > Maj II Minor A > Maj II Minor B > > Maj III Minor B > Maj III Minor C > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] strftime vs strptime ??
strptime() takes a character vector and makes a date-time object. That is input. strftime() takes a date-time object and makes an character vector. That is output, and it is normally called via format() or print(). Let's see what the help says (slightly edited to refer just to these two): Date-time Conversion Functions to and from Character (One is 'to' and one is 'from.) Functions to convert between character representations and objects of classes ‘"POSIXlt"’ and ‘"POSIXct"’ representing calendar dates and times. ‘strftime’ converts objects from the class ‘"POSIXlt"’ to character vectors. ‘strptime’ converts character vectors to class ‘"POSIXlt"’ On Fri, 29 Oct 2010, skan wrote: Hello Could anyone explain me the difference between strftime vs strptime, please ? I've read the help but it's a little bit cionfusing for me. cheers -- View this message in context: http://r.789695.n4.nabble.com/strftime-vs-strptime-tp3018865p3018865.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. -- 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] Checking existance of a directory
On Fri, 29 Oct 2010, Ron Michael wrote: Hi all, I am wondering is there any way to check whether some Directory exists or not, given the parent path of that directory? After searching for a while I found that there is a function dir.create() to create some directory. However I need to know whether such directory already exists or not, otherwise I will create that. Well, as others have also pointed out, you don't need to do that (and I created dir.create() deliberately so you don't). But see ?file_test and op = "-d" if you actually need to in some other application. (This is linked from ?file.exists which is linked from ?dir.create.) ? Thanks, -- 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] Clustering
On Oct 29, 2010, at 5:14 AM, dpender wrote: That's helpful but the reason I'm using clusters in evd is that I need to specify a time condition to ensure independence. I believe this is the first we heard about any particular function or package. I therefore have an output We would need to know the code that produced that output and either the data to which that code was applied or the structure of the output. (Use the str() function) in the form Cluster[[i]][j-k] where i is the cluster number and j-k is the range of values above the threshold taking account of the time condition. Unless you find someone who uses that package in the manner you have, you will need to explain in much greater detail than you have so far. From this I can get durations easily enough but the spacing is proving quite difficult. There are quite possibly methods using rle() or possibly something like rollapply() from the zoo package, but you need to provide a specific and richer test case. The data is for ocean waves and therefore it may be possible that the wave height drops below the threshold for a short period but should still be considered part of the same event, hence the time conditon. Hope this clarifies the problem. It clarifies it to the extent that it show how much more you will need to further clarify. -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Reading multiple .csv-files and assigning them to variable names
Read them into a list; much easier to handle: myList <- lapply(filenames, read.csv) On Fri, Oct 29, 2010 at 5:16 AM, Sarah Moens wrote: > Hi all, > > I've been trying to find a solution for the problem of reading > multiple files and storing them in a variable that contains the names > by which I want to call the datasets later on. > > For example (5 filenames): > > - The filenames are stored in one variable: > filenames = paste(paste('name', '_', 1:5, sep = ''), '.csv', sep = '') > > - Subsequently I have a variable just containing the meaningful names > for the dataset > meaningfulnames = c('name1','name2'...,'name5') > > - I want to link each of these names to the data that is read > > for (i in 1:5) > { > meaningfulnames[i] = read.csv(filenames[i], header = TRUE, sep = ',') > } > > > I need to read in quite a lot of datafiles. I have a code doing this > one at a time, but since the number of datafiles I need to read will > increase in the future, I want to make sure I have a more flexible > solution for this. > > Thanks a lot for your help. I have tried to look in the help pages and > also came across dbfread, but I can't seem to find something I can use > or understand at this point. > > > Sarah > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] ksvm problem
Hi to all! When I use the example from kernlab::ksvm this works fine.. Give me the result… > filter <- > ksvm(type~.,data=spamtrain,kernel="rbfdot",kpar=list(sigma=0.05),C=5,cross=3) But as soon as I change the type data as follows > type_train<-spamtrain[,ncol(spamtrain)] > filter <- > ksvm(type_train,data=spamtrain,kernel="rbfdot",kpar=list(sigma=0.05),C=5,cross=3) Error: evaluation nested too deeply: infinite recursion / options(expressions=)? This gives me error. I don’t know why? I have also tried changing the expression values but it still doesn’t work… > .Options$expressions [1] 5000 > options(expressions=1) > .Options$expressions [1] 1 > filter <- > ksvm(type_train,data=spamtrain,kernel="rbfdot",kpar=list(sigma=0.05),C=5,cross=3) Error: evaluation nested too deeply: infinite recursion / options(expressions=)? Why am I getting this error? And how to resolve it? thank you .. -- View this message in context: http://r.789695.n4.nabble.com/ksvm-problem-tp3019212p3019212.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] Reading multiple .csv-files and assigning them to variable names
Hi all, I've been trying to find a solution for the problem of reading multiple files and storing them in a variable that contains the names by which I want to call the datasets later on. For example (5 filenames): - The filenames are stored in one variable: filenames = paste(paste('name', '_', 1:5, sep = ''), '.csv', sep = '') - Subsequently I have a variable just containing the meaningful names for the dataset meaningfulnames = c('name1','name2'...,'name5') - I want to link each of these names to the data that is read for (i in 1:5) { meaningfulnames[i] = read.csv(filenames[i], header = TRUE, sep = ',') } I need to read in quite a lot of datafiles. I have a code doing this one at a time, but since the number of datafiles I need to read will increase in the future, I want to make sure I have a more flexible solution for this. Thanks a lot for your help. I have tried to look in the help pages and also came across dbfread, but I can't seem to find something I can use or understand at this point. Sarah __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] quiry on paste() function
Perhaps, the following construct does what you need: paste(c("a", "b", "c"), c(",", ":", ""), sep="",collapse="") Regards, Jan On 29-10-2010 10:49, Ron Michael wrote: Hi all, I want to club different objects (character type) to a single one and using paste() function that can be done happily. However the problem with paste function is the separator field is unique for all underlying objects. If I put separator as "-" then this will come in between all underlying objects which are to be clubbed. Therefore I am wondering whether there is any mechanism to put different separators for different places. Trivially this can be done by applying paste() function repeatedly. However I feel there must be some single mechanism for doing that. Here is one example, where I apply paste() function twice to incorporate 2 different separators: paste(paste("a", "b", sep=","), "c", sep=":") [1] "a,b:c" Can the same thing be done using paste() function once? something like: paste("a", "b", "c", sep=c(",", ":")) # this put 1st separator everywhere which is not intended Thanks, [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Printing data.frame data: alternatives to print?
Matt, Below are three (of the probably many more) possible ways of doing this: aggregate(1:nrow(df), df, length) ftable(1 ~ f1 + f2, data=df) library(plyr) ddply(df, .(f1,f2), nrow) Regards, Jan On 29-10-2010 15:53, Matthew Pettis wrote: Hi, I have a data frame with two factors (well, more, but 2 for simple consideration), and I want to display the different combinations of the them that actually occur in the data. In reality, there are too many of them to do to do a 'table' call and have one col vertical and one col horizontal (I don't want any of the factors listed horizontally). Before I try to write a function to do this for me, I was wondering if there were alternate printing styles for data that already exist, and if someone could direct me to them? Inclded is a sample code and 2 possibilities (others welcome for consideration) of how I want to display some data. Thanks, Matt - df<- data.frame( f1=rep(c("Maj I", "Maj II", "Maj III"), each=3), f2=c("Minor A", "Minor A", "Minor A", "Minor A", "Minor B", "Minor B", "Minor B", "Minor C", "Minor C") ) - What I want printed is something like: --- f1 f2 Maj I Minor A Maj II Minor A Minor B Maj III Minor B Minor C --- or --- f1 f2 Maj I Minor A Maj II Minor A Maj II Minor B Maj III Minor B Maj III Minor C __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Simulating data, loop
Hi Sarah, There is one thing you need to think about: how do you choose which values should not be removed if you have more than 20 and which should be if you have less than 20. In my code, I've just done it with sample(), which might not be what you need. Here is what I have: if (length(which(ynew==0))>20) { y <- y[c(which(ynew==1), sample(which(ynew==0),20-length(which(ynew==1] } else { y <- y[sample(which(ynew==1),20)] } Does it make what you're looking for? HTH, Ivan Le 10/29/2010 14:46, Sarah a écrit : Hello, I would like to run a script in which a loop is included. Since I'm new to R, I cannot manage the following problem. I really hope someone could help me out. Data in the variable Y should be removed from the simulated data set with probability 0.50 if the variable X has a value below zero, and with probability 0.10 if X has a value above zero (see script). However, the total number of removed values from Y should be 20 when X< 0, and 4 when X>0. Whenever the total number of removed values is less than 20 (when X<0), R should remove more values from Y at random (until a total of 20 values has been removed). When R has removed more than 20 values from Y, R should restore some removed values such that a maximum of 20 values has been removed from variable Y. How can I tell R to put some removed values back in the data set, or to remove more values until a maximum number of removed values has been reached? y<- rnorm(40,1,3) x<- 1+2*y1+ rnorm(40,0,5) #Remove values in Y dependent on X: ynew<- rep(NA,40) for (j in 1:40) { if (x[j]< 0){ynew[j]<- rbinom(1,1,0.50)} if (x[j]> 0){ynew[j]<- rbinom(1,1,0.10)} } -- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. Säugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calan...@uni-hamburg.de ** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Printing data.frame data: alternatives to print?
Hi, I have a data frame with two factors (well, more, but 2 for simple consideration), and I want to display the different combinations of the them that actually occur in the data. In reality, there are too many of them to do to do a 'table' call and have one col vertical and one col horizontal (I don't want any of the factors listed horizontally). Before I try to write a function to do this for me, I was wondering if there were alternate printing styles for data that already exist, and if someone could direct me to them? Inclded is a sample code and 2 possibilities (others welcome for consideration) of how I want to display some data. Thanks, Matt - df <- data.frame( f1=rep(c("Maj I", "Maj II", "Maj III"), each=3), f2=c("Minor A", "Minor A", "Minor A", "Minor A", "Minor B", "Minor B", "Minor B", "Minor C", "Minor C") ) - What I want printed is something like: --- f1 f2 Maj I Minor A Maj II Minor A Minor B Maj III Minor B Minor C --- or --- f1 f2 Maj I Minor A Maj II Minor A Maj II Minor B Maj III Minor B Maj III Minor C __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 pages do not open
I have just installed R 12. I have Windows 7, 64-bit verison. I currently have IE as my default browser. The internet connection is very good. Whenever I try to run a help command (?lm, for example), I get this error: Error in shell.exec(url) : access to 'http://127.0.0.1:20271/library/stats/html/lm.html' denied I first got this message when Google Chrome was my default browser. For some reason, Google Chrome stopped opening web pages. At the same time R11 stopped showing help pages. Then, I uninstalled Google Chrome and defined IE as my default browser. Then, I uninstalled R11 and installed R12 instead. But I am getting the same error. Any advice? -- Dimitri Liakhovitski Ninah Consulting www.ninah.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] Simulating data, loop
Hello, I would like to run a script in which a loop is included. Since I'm new to R, I cannot manage the following problem. I really hope someone could help me out. Data in the variable Y should be removed from the simulated data set with probability 0.50 if the variable X has a value below zero, and with probability 0.10 if X has a value above zero (see script). However, the total number of removed values from Y should be 20 when X < 0, and 4 when X>0. Whenever the total number of removed values is less than 20 (when X<0), R should remove more values from Y at random (until a total of 20 values has been removed). When R has removed more than 20 values from Y, R should restore some removed values such that a maximum of 20 values has been removed from variable Y. How can I tell R to put some removed values back in the data set, or to remove more values until a maximum number of removed values has been reached? y <- rnorm(40,1,3) x <- 1+2*y1+ rnorm(40,0,5) #Remove values in Y dependent on X: ynew <- rep(NA,40) for (j in 1:40) { if (x[j] < 0){ynew[j] <- rbinom(1,1,0.50)} if (x[j] > 0){ynew[j] <- rbinom(1,1,0.10)} } -- View this message in context: http://r.789695.n4.nabble.com/Simulating-data-loop-tp3019044p3019044.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] relsurv package
Hello, I have a question about relsurv package particularly rsadd function: Rsadd(Surv(time,cens)~sex+ratetable(age=age*365.24,sex=sex,year=year),data=,=ratetable=,int=5,method=”max.lik”). In the tutorial, it is indicated that "the age and year must be given in the date format, i.e. in number of days since 01.01.1960". Nethertheless, in Pohar’s article, http://ibmi.mf.uni-lj.si/ibmi/biostat-center/predtiski/CMPB_Pohar_Stare_relsurv.pdf, there is no indication about that. What is the true way to use this function. Thanks for your help, Laurence -- View this message in context: http://r.789695.n4.nabble.com/Re-relsurv-package-tp867129p3019040.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] make many barplot into one plot
Dear R users I would like to group my barplot graph (see example on the R help link). The proposed R code, adding individual bars to the plot, looks really overwhelming. My specific dataset just consists of five groups and three different levels within each groups (the individual bars). The .txt file is read as matrix (horizontal: group, vertical: levels). The R trellis barchart (function group="") is an easy function, but unfortunately the upper plot part look much different from other graphs. I would therefore prefer barplot to stansdardize my plots within the manuscript. It would be very helpful for me to know if anyone else has worked on the barplot group function. Thanks Sibylle http://onertipaday.blogspot.com/2007/05/make-many-barplot-into-one-plot.html R code from the link ## I have 4 tables like this:satu <- array(c(5,15,20,68,29,54,84,119), dim=c(2,4), dimnames=list(c("Negative", "Positive"), c("Black", "Brown", "Red", "Blond")))dua <- array(c(50,105,30,8,29,25,84,9), dim=c(2,4), dimnames=list(c("Negative", "Positive"), c("Black", "Brown", "Red", "Blond")))tiga <- array(c(9,16,26,68,12,4,84,12), dim=c(2,4), dimnames=list(c("Negative", "Positive"), c("Black", "Brown", "Red", "Blond")))empat <- array(c(25,13,50,78,19,34,84,101), dim=c(2,4), dimnames=list(c("Negative", "Positive"), c("Black", "Brown", "Red", "Blond")))# rbind() the tables togetherTAB <- rbind(satu, dua, tiga, empat)# Do the barplot and save the bar midpointsmp <- barplot(TAB, beside = TRUE, axisnames = FALSE)# Add the individual bar labelsmtext(1, at = mp, text = c("N", "P"),line = 0, cex = 0.5)# Get the midpoints of each sequential pair of bars# within each of the four groupsat <- t(sapply(seq(1, nrow(TAB), by = 2),function(x) colMeans(mp[c(x, x+1), ])))# Add the group labels ! for each pairmtext(1, at = at, text = rep(c("satu", "dua", "tiga", "empat"), 4),line = 1, cex = 0.75)# Add the color labels for each groupmtext(1, at = colMeans(mp), text = c("Black", "Brown", "Red", "Blond"), line = 2) -- Sicherer, schneller und einfacher. Die aktuellen Internet-Browser - jetzt kostenlos herunterladen! http://portal.gmx.net/de/go/chbrowser __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] check RAM usage
?memory.size use before/after a sequence of commands to get an idea of the memory usage. On Fri, Oct 29, 2010 at 5:21 AM, Joel wrote: > > Hi > > Is there any way to check an certain command or procedure's RAM usage? > > Im after something similar to system.time(bla) that gives me the time the > command took to preform but for RAM usage. > > Hope you understand what i mean. > > Best regards > Joel > -- > View this message in context: > http://r.789695.n4.nabble.com/check-RAM-usage-tp3018753p3018753.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. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] quiry on paste() function
On Fri, Oct 29, 2010 at 4:49 AM, Ron Michael wrote: > Hi all, I want to club different objects (character type) to a single one and > using paste() function that can be done happily. However the problem with > paste function is the separator field is unique for all underlying objects. > If I put separator as "-" then this will come in between all underlying > objects which are to be clubbed. > > Therefore I am wondering whether there is any mechanism to put different > separators for different places. Trivially this can be done by applying > paste() function repeatedly. However I feel there must be some single > mechanism for doing that. > > Here is one example, where I apply paste() function twice to incorporate 2 > different separators: >> paste(paste("a", "b", sep=","), "c", sep=":") > [1] "a,b:c" > > Can the same thing be done using paste() function once? something like: > paste("a", "b", "c", sep=c(",", ":")) # this put 1st separator everywhere > which is not intended > Try sprintf instead: sprintf("%s,%s:%s", "a", "b", "c") -- 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] Checking existance of a directory
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 29/10/10 13:08, Ron Michael wrote: > Hi all, I am wondering is there any way to check whether some Directory > exists or not, given the parent path of that directory? After searching for a > while I found that there is a function dir.create() to create some directory. > However I need to know whether such directory already exists or not, > otherwise I will create that. Just use dir.create(showWarnings=FALSE) This will create the directory if it does not exist, and do nothing if it does. If showWarnings=TRUE, it will give you a warning that the directory exists. Cheers, Rainer > > Thanks, > > > [[alternative HTML version deleted]] > > > > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. - -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Natural Sciences Building Office Suite 2039 Stellenbosch University Main Campus, Merriman Avenue Stellenbosch South Africa Tel:+33 - (0)9 53 10 27 44 Cell: +27 - (0)8 39 47 90 42 Fax (SA): +27 - (0)8 65 16 27 82 Fax (D) : +49 - (0)3 21 21 25 22 44 Fax (FR): +33 - (0)9 58 10 27 44 email: rai...@krugs.de Skype: RMkrug -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkzKtV0ACgkQoYgNqgF2egpRSACgiB498c+M0ICsoJMZxS051lkw k4UAn0XAI52H1LtRZAJSUQcB6haK8xWO =66jA -END PGP SIGNATURE- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Checking existance of a directory
Try this: if(!file.info('myfolder')$isdir) dir.create('myfolder') On Fri, Oct 29, 2010 at 9:08 AM, Ron Michael wrote: > Hi all, I am wondering is there any way to check whether some Directory > exists or not, given the parent path of that directory? After searching for > a while I found that there is a function dir.create() to create some > directory. However I need to know whether such directory already exists or > not, otherwise I will create that. > > Thanks, > > >[[alternative HTML version deleted]] > > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[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] Checking existance of a directory
Hi, something like this perhaps, if("myfolder"%in%dir()==FALSE) dir.create("myfolder") Command dir.create() is not overwriting an existing folder. Best regards, Andris On Fri, Oct 29, 2010 at 12:08 PM, Ron Michael wrote: > Hi all, I am wondering is there any way to check whether some Directory > exists or not, given the parent path of that directory? After searching for a > while I found that there is a function dir.create() to create some directory. > However I need to know whether such directory already exists or not, > otherwise I will create that. > > Thanks, > > > [[alternative HTML version deleted]] > > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] quiry on paste() function
Perhaps the following construct does what you need: paste(c("a", "b", "c"), c(",", ":", ""), sep="",collapse="") Regards, Jan On 29-10-2010 10:49, Ron Michael wrote: > Hi all, I want to club different objects (character type) to a single one and > using paste() function that can be done happily. However the problem with > paste function is the separator field is unique for all underlying objects. > If I put separator as "-" then this will come in between all underlying > objects which are to be clubbed. > > Therefore I am wondering whether there is any mechanism to put different > separators for different places. Trivially this can be done by applying > paste() function repeatedly. However I feel there must be some single > mechanism for doing that. > > Here is one example, where I apply paste() function twice to incorporate 2 > different separators: >> paste(paste("a", "b", sep=","), "c", sep=":") > [1] "a,b:c" > > Can the same thing be done using paste() function once? something like: > paste("a", "b", "c", sep=c(",", ":")) # this put 1st separator everywhere > which is not intended > > Thanks, > > > [[alternative HTML version deleted]] > > > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. [[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] true time series lags behind fitted values in arima model
Hi I am fitting an arima model to some time series X. When I was comparing the fitted values of the model to the true time series I realized that the true time series lags one time step behind the fitted values of the arima model. And this is the case for any model. When I did a simple linear regression using lm to check, I also find the same results, that the true series lags behind the fitted values. I don't understand this, what am I doing wrong? Below I copied some of the code to demonstrate the issue. ## Analysis using arima() X<-c(6.841067, 6.978443, 6.984755, 7.007225, 7.161198, 7.169790, 7.251534, # the true time series 7.336429, 7.356600, 7.413271, 7.404165, 7.480869, 7.498686, 7.429809, 7.302747, 7.168251, 7.124798, 7.094881, 7.119132, 7.049250, 6.961049, 7.013442, 6.915243, 6.758036, 6.665078, 6.730523, 6.702005, 6.905522, 7.005191, 7.308986) model100<-arima(X,order=c(1,0,0),include.mean=T,method="ML") # the arima model resid100<-residuals(model100) Xfit100<-X-resid100 # the fitted values ts.plot(cbind(Xfit100,X),col=c(2,4),main="ARIMA(1,0,0)") # plot the true ts vs the fitted values legend(20,7.5,c("true values","fitted values"),pch=c(16,16),col=c("blue","red")) ## Same analysis using lm() Y<-X[2:30] # create X(t)-> a time series without the first value X1<-X[1:29] # create the X(t-1) time<-seq(1978,2006) model1<-lm(Y~X1) summary(model1) arima.intercept<-model1[[1]][[1]]/(1-model1[[1]][[2]]);arima.intercept model100[[1]][[2]] plot(Y~time,type="b") # plot the two series points(fitted(model1)~time,type="b",col="green") legend(1995,7.5,c("true values","fitted values"),pch=c(16,16),col=c("black","green")) Thank you very much for the help best wishes Benedikt __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Checking existance of a directory
Hi all, I am wondering is there any way to check whether some Directory exists or not, given the parent path of that directory? After searching for a while I found that there is a function dir.create() to create some directory. However I need to know whether such directory already exists or not, otherwise I will create that. Thanks, [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] multiple weights in MANOVA
Hi all I have 7 responses that I want to fit with MANOVA. I have accumulated the responses into a matrix Y and each response has a weight vector associated with it, so I have accumulated the weights into a matrix WT of the same dimensions as Y. When I try fit <- manova( Y ~ X1 + X2 + X3, weights = WT ) I get the following message: Error in lm.wfit(x, y, w, offset = offset, singular.ok = singular.ok, : incompatible dimensions Does this mean I have used manova() wrongly or does it not handle a matrix of weights as required here? Thanks in advance and please CC replies to me Michael Hopkins Algorithm and Statistical Modelling Expert Upstream 23 Old Bond Street London W1S 4PZ [[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] strftime vs strptime ??
Hello Could anyone explain me the difference between strftime vs strptime, please ? I've read the help but it's a little bit cionfusing for me. cheers -- View this message in context: http://r.789695.n4.nabble.com/strftime-vs-strptime-tp3018865p3018865.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] what´s wrong with this code?
G'day Jose, On Fri, 29 Oct 2010 11:25:05 +0200 José Manuel Gavilán Ruiz wrote: > Hello, I want to maximize a likelihood function expressed as an > integral that can not be symbolically evaluated. I expose my problem > in a reduced form. > > g<- function(x){ > integrand<-function(y) {exp(-x^2)*y} > g<-integrate(integrand,0,1) > } > h<-function(x) log((g(x))) > > g is an object of the class function, but g(2) is a integrate object, > I can print(g(2)) an get a result, but > if I try h(2) R says is a nonnumeric argument for a mathematical > function. My goal is to maximize h. Which can be done without R quite trivially. The result of g(x) is exp(-x^2)/2. So h(x) is -x^2-log(2), which is maximised at x=0. Cheers, Berwin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 Matlab
Dear Henrik, sorry for bothering you with a report hastily pasted together and not particularly nice for you as I used my toy data flu from a non-standard package. I should have better used e.g. the iris. I'm aware that writeMat doesn't deal with S4 objects. In fact, if I'd overlook the error message, there's the 2nd chance to see that the file size is 0B. In fact the attempt to save flu directly was a classical "autopilot" error, that's why I tried to save the x afterwards. So the problem here was the unnamed storing of x. I intentionally do not try to "infer" the name "x" from writeMat("flu.mat", x), basically because I think using substitute() should be avoided as far as possible, but also because it is unclear what the name should be in cases such as writeMat("flu.mat", 1:10). I was just going to suggest a patch that assigns the names of type Vnumber to the unnamed objects - but when I wanted to get the source I realized your version with the warning is already out. I think, however, you may forgot a nchar?: any (nchar (names) == 0) So here's my suggestion for l. 775-777 of writeMat.R: if (is.null(names) || any (nchar (names) == 0L)) { names [nchar (names) == 0L] <- paste ("V", which (nchar (names) == 0L), sep = "") names (args) <- names warning("All objects written have to be named, e.g. use writeMat(..., x=a, y=y) and not writeMat(..., x=a, y): ", deparse(sys.call()), "\nDummy names have been assigned."); } After all, e.g. data.frame () will also rather create dummy names for unnamed columns. And, I think, a warning should make the user aware that he's doing something that _may_ not work out as intendet. But here I think it is _most likely_ not working as intended. MISCELLANEOUS: Note that writeMat() cannot write compressed MAT files. It is documented in help("readMat"), and will be so in help("writeMat") in the next release. Package Rcompression, loaded or not, has no effect on writeMat(). It is only readMat() that can read them, if Rcompression is installed. You do not have to load it explicitly/yourself - if readMat() detects a compress MAT file, it will automatically try to load it; OK, good to know. Thanks a lot for your explanation in spite of my bad report. Claudia -- Claudia Beleites Dipartimento dei Materiali e delle Risorse Naturali Università degli Studi di Trieste Via Alfonso Valerio 6/a I-34127 Trieste phone: +39 0 40 5 58-37 68 email: cbelei...@units.it __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] what´s wrong with this code?
G'day Jose, On Fri, 29 Oct 2010 11:25:05 +0200 José Manuel Gavilán Ruiz wrote: > Hello, I want to maximize a likelihood function expressed as an > integral that can not be symbolically evaluated. I expose my problem > in a reduced form. > > g<- function(x){ > integrand<-function(y) {exp(-x^2)*y} > g<-integrate(integrand,0,1) > } > h<-function(x) log((g(x))) > > g is an object of the class function, but g(2) is a integrate object, > I can print(g(2)) an get a result, but > if I try h(2) R says is a nonnumeric argument for a mathematical > function. R> print(g(2)) 0.00915782 with absolute error < 1.0e-16 Indeed print(g(2)) gives an output, but it is obviously not just a numeric number but something formatted, presumably based on the class of the returned object from g(2) and the values that this object contains. (You may want to read up on R's way(s) to object oriented programming). So what does g() return? R> str(g(2)) List of 5 $ value : num 0.00916 $ abs.error : num 1.02e-16 $ subdivisions: int 1 $ message : chr "OK" $ call: language integrate(f = integrand, lower = 0, upper = 1) - attr(*, "class")= chr "integrate" The object is a list with several values, and class "integrate". > My goal is to maximize h. what´s wrong? I guess you want to pass only the component value to h(). R> g <- function(x){ + integrand <- function(y) {exp(-x^2)*y} + integrate(integrand, 0, 1)$value} R> g(2) [1] 0.00915782 R> h(g(2)) [1] -0.693231 HTH, Cheers, Berwin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Rsolnp examples
Jan Theodore Galkowski acm.org> writes: > > I'm interested in the Rsolnp package. For their primary function > "solnp", one example is given, and there is a reference to "unit > tests". Anyone know where these can be found? Also, Rsolnp is > used in a few other packages (e.g., depmixS4), but I cannot seem > to find source illustrating its call sequence, and the precise > definition of the functions passed. When you download the source package, test functions are in the "Rsolnp/R/benchmarks.R" file. And you will find the original manual describing these tests in "Rsolnp/inst/doc" (Matlab version). Calling 'solnp' is easy; what exactly is your problem? Hans Werner > Can anyone help? > > Thanks, > > - Jan > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] what´s wrong with this code?
Hello, I want to maximize a likelihood function expressed as an integral that can not be symbolically evaluated. I expose my problem in a reduced form. g<- function(x){ integrand<-function(y) {exp(-x^2)*y} g<-integrate(integrand,0,1) } h<-function(x) log((g(x))) g is an object of the class function, but g(2) is a integrate object, I can print(g(2)) an get a result, but if I try h(2) R says is a nonnumeric argument for a mathematical function. My goal is to maximize h. what´s wrong? thanks __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] check RAM usage
Hi Is there any way to check an certain command or procedure's RAM usage? Im after something similar to system.time(bla) that gives me the time the command took to preform but for RAM usage. Hope you understand what i mean. Best regards Joel -- View this message in context: http://r.789695.n4.nabble.com/check-RAM-usage-tp3018753p3018753.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.