[R] Recommended way of requiring packages of a certain version?
What is the recommended way of requiring a certain version when loading a package (or, indeed, from R itself)? Perl has the require module version use module version require version use version constructs which is kind of what I am looking for (especially 'use' which is evaluated at compile time), but R seems to have lost the version= argument to require(). The best I have been able to come up with are constructs of the form if ( utils::compareVersion(utils::packageDescription(data.table, fields=Version), 1.5) 0 ) stop(Need data.table version 1.5 or later) if ( utils::compareVersion(as.character(getRversion()), 2.11) = 0 ) stop(Does not work yet with latest R.) But this is tedious and error prone. I have created my own require() function to automate this (it takes a vector of versions and a vector of comparisons and only load the package if they are all met), but it is non-standard and just that much harder for my colleagues to maintain. Somebody must already have done this? Allan PS: Shouldn't utils::compareVersion(2.11.0, 2.11) return zero instead of one? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] aggregate(...) with multiple functions
Hi r-help-boun...@r-project.org napsal dne 16.07.2010 05:02:52: On Thu, Jul 15, 2010 at 10:45 PM, Murat Tasan mmu...@gmail.com wrote: hi all - i'm just wondering what sort of code people write to essentially performa an aggregate call, but with different functions being applied to the various columns. for example, if i have a data frame x and would like to marginalize by a factor f for the rows, but apply mean() to col1 and median() to col2. if i wanted to apply mean() to both columns, i would call: aggregate(x, list(f), mean) but to get the mean of col1 and the median of col2, i have to write separate tapply calls, then wrap back into a data frame: data.frame(tapply(x$col1, f, mean), tapply(x$col2, f, mean)) this is a somewhat inelegant solution for data frames with potentially many columns. what i would like is for aggregate to take a list of functions for columns, something like: aggregate(x, list(f), list(mean, median)) i'm just curious how others get around this limitation in aggregate(). do most simply make the individual tapply() calls separately, then possibly wrap them back up (as done in the example above), or is there a more elegant solution using some function of R that i might be unaware of? If you want to use aggregate wrap data to cbind aggregate(data, list(y), function(x) cbind(mean(x), median(x))) Regards Petr Using sqldf we can write: library(sqldf) sqldf(select Treatment, avg(conc), median(uptake) from CO2 group by Treatment) Treatment avg(conc) median(uptake) 1chilled 435 19.7 2 nonchilled 435 31.3 See http://sqldf.googlecode.com for more info. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] FW: coeficient of determination
Try RSiteSearch(coefficient of determination) which seems to list some promising candidates. Allan On 15/07/10 16:47, Alireza Ehsani wrote: Hello there how can i calculate coefficient of determination with R? Kind regards Ali Reza Ehsani Ph.d. student [[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] Recommended way of requiring packages of a certain version?
Hi Allan, When you create an R package you can specify in the DESCRIPTION file that your package depends on a certain R version and versions of packages. For example: Package: automap Version: 1.0-7 Date: 2010/05/04 Title: Automatic interpolation package Author: Paul Hiemstra p.hiems...@geo.uu.nl Maintainer: Paul Hiemstra p.hiems...@geo.uu.nl Description: This package performs an automatic interpolation by automatically estimating the variogram and then calling gstat. Depends: R (= 2.7.0), methods, sp (= 0.9-4), gstat (= 0.9-58) Imports: lattice License: GPL So distributing code to other people is preferably done using R packages, which gives you this option. regards, Paul On 07/16/2010 09:06 AM, Allan Engelhardt wrote: What is the recommended way of requiring a certain version when loading a package (or, indeed, from R itself)? Perl has the require module version use module version require version use version constructs which is kind of what I am looking for (especially 'use' which is evaluated at compile time), but R seems to have lost the version= argument to require(). The best I have been able to come up with are constructs of the form if ( utils::compareVersion(utils::packageDescription(data.table, fields=Version), 1.5) 0 ) stop(Need data.table version 1.5 or later) if ( utils::compareVersion(as.character(getRversion()), 2.11) = 0 ) stop(Does not work yet with latest R.) But this is tedious and error prone. I have created my own require() function to automate this (it takes a vector of versions and a vector of comparisons and only load the package if they are all met), but it is non-standard and just that much harder for my colleagues to maintain. Somebody must already have done this? Allan PS: Shouldn't utils::compareVersion(2.11.0, 2.11) return zero instead of one? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +3130 253 5773 http://intamap.geo.uu.nl/~paul http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] loess line predicting number where the line crosses zero twice
On Fri, 2010-07-16 at 14:25 +1200, Peter Alspach wrote: Tena koe Stephen You'll need to use loess(w[,bkf_depths]~w[,measure])) and predict with a sufficiently dense sequence of w[,'measure'] to interpolate to an 'accuracy' that meets your requirements. Actually, if I understand your data correctly, it could be that simple linear interpolation (i.e., without loess) would be sufficient (even better). HTH Peter Alspach If Stephen is going to use a predict method, then it would probably be wise to stop abusing the formula interface that many R model functions have. Doing this: loess(w[,bkf_depths]~w[,measure]) is a recipe for much head scratching when predict() won't work on your fitted model with new data. Also, the above model call is somewhat obfuscated by the way it is written. This is much better: loess(bkf_depths ~ measure, data = w) Much easier to read, plus prediction works!: pdat - with(w, data.frame(measure = seq(min(measure), max(measure), length = 100))) mod - loess(w[,bkf_depths]~w[,measure]) predict(mod, pdat) ## Whoops, this fails [1] 0.11928879 0.33733102 0.53497599 0.71073264 0.86711027 1.00276470 [7] 1.00276470 1.11816623 1.21681583 1.29127522 1.33860899 1.36907242 [13] 1.39292078 1.40297664 1.39390373 1.37871901 1.37043942 1.38674537 [19] 1.42032404 1.44670249 1.44140783 1.41272292 1.37328779 1.30516530 [25] 1.19041829 1.03514669 1.03514669 1.00074242 0.84832562 0.62322528 [31] 0.36293723 0.06856913 -0.05847241 Warning message: 'newdata' had 100 rows but variable(s) found have 33 rows mod2 - loess(bkf_depths ~ measure, data = w) head(p - predict(mod2, pdat)) [1] 0.1192888 0.1836197 0.2465784 0.3080418 0.3678864 0.4259892 length(p) [1] 100 Stephen, see ?approx if you want to give the interpolation a go. Either way, you'll need a reasonably fine grid (of points in measure) if you want to constrain the 0 depth locations well. wapp - with(w, approx(measure, bkf_depths, xout = seq(5, max(measure), length = 200))) i.e. we focus on the area where we want to find 0 depth with 200 locations spread across this region. I think the line below will then find the point on the tape that is closest to 0 without being out of the water with(wapp, x[which.min(y[y 0])]) [1] 5.560402 HTH G -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of stephen sefick Sent: Friday, 16 July 2010 11:33 a.m. To: r-help@r-project.org Subject: [R] loess line predicting number where the line crosses zero twice These data represent stream channel cross-sectional surveys. I would like to be able to find the measurement on the tape (measure) where the Bank Full Depth (bkf_depths) is 0. This will happen twice because the channel has two sides. I thought fitting a loess line to these data and then predicting the measurment number would do it. I was wrong. Below is my failed attempt. My naive thought is this - I would like to run my finger along this line and when it hits zero I would like to pick out the value of measure. This should happen twice. Any help would be greatly appreciated! w - (structure(list(measure = c(0, 0.2, 0.4, 0.6, 0.8, 1, 1, 1.2, 1.4, 1.6, 1.8, 2, 2.2, 2.4, 2.6, 2.8, 3, 3.2, 3.4, 3.6, 3.8, 4, 4.2, 4.4, 4.6, 4.8, 4.8, 4.84, 5, 5.2, 5.4, 5.6, 5.68), bkf_depths = c(0, 0.44, 0.46, 0.66, 0.9, 1.1, 1.1, 1.2, 1.3, 1.33, 1.36, 1.36, 1.36, 1.38, 1.38, 1.36, 1.36, 1.38, 1.37, 1.37, 1.34, 1.32, 1.36, 1.35, 1.36, 1.4, 1.4, 1.3, 0.7, 0.57, 0.21, -0.05, -0.12)), .Names = c(measure, bkf_depths), row.names = c(32L, 1L, 2L, 3L, 4L, 5L, 29L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 31L, 24L, 30L, 25L, 26L, 27L, 28L, 33L), class = data.frame) ) plot(w[,bkf_depths]~w[,measure]) lines(loess(w[,bkf_depths]~w[,measure])) #this is what I tried and there should be two 0s one at the left side of the graph and one at the right side predict(loess(w[,measure]~w[,bkf_depths]), 0) kindest regards, -- Stephen Sefick | Auburn University | | Department of Biological Sciences | | 331 Funchess Hall | | Auburn, Alabama | | 36849| |___| | sas0...@auburn.edu | | http://www.auburn.edu/~sas0025 | |___| Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis
Re: [R] Weighted densityplot?
On Thu, Jul 15, 2010 at 5:51 PM, Farley, Robert farl...@metro.net wrote: I'm trying to plot a series of densities using/comparing differing weights. I see the reference to weights and subscripts, but I don't understand how to implement that. My data are of the form: I, J, Actual, Distance, Subset, Weight1, Weight2, ... I'm trying to see the effect of the distance distribution (Actual by Distance) compared to the various weighted distributions (Subset*WeightX by Distance) I presume I and J are the subscripts to the weight Variable in densityplot. If anyone has a code snippet of densityplot using weights, I could get started I'm not sure what I and J are in your data, or what you want exactly. But here is an example using 'weights': faithful$dummy - gl(2, 1, nrow(faithful)) p1 - densityplot(~eruptions | dummy, faithful, main = unweighted) p2 - densityplot(~eruptions | dummy, faithful, weights = 1/waiting, main = weighted) plot(p1, split = c(1, 1, 1, 2)) plot(p2, split = c(1, 2, 1, 2), newpage = FALSE) -Deepayan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Creating functions of many arguments
Your specific example can just use 'prod'. The 'prod' function uses the '...' construct which I think is what you are looking for. However, in concurrence with a previous answer, it is almost surely going to be a good idea to change your way of thinking about the problem. One word in the R world to search for is: vectorization On 16/07/2010 02:32, Axel Urbiz wrote: Dear users, My apologies for the simple question. I'd like to create a function where the number of arguments is as big as the size of my data set. Supose I have n observations in my data, how can I write a function like fun- function (x1,x2,,xn) {x1*x2*...*xn} Thanks in advance for your help! Axel. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Patrick Burns pbu...@pburns.seanet.com http://www.burns-stat.com (home of 'Some hints for the R beginner' and 'The R Inferno') __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] discrepancy matrix
Hi! I want to create a discrepancy matrix. I have got a data.frame Q: number colour date 2 343b1503 3 678 g 1701 4 347b1904 5 345b2001 6 123 g 1809 Now i want to create a matrix, whose entries are the total differences between the ranks of number and date for each pair ( a pair is a combination , made of different colours (zB. 2,3 or 2,6)). (343-678)+(1503-1701) = -533 ( if my explanation is too bad, you can look up for a equivalent example on this page:http://www.stat.lsa.umich.edu/~bbh/optmatch/doc/optmatch.pdf ( on page 5)) I tried this code: plantdist-round(outer(rank(' date')[as.logical('colour')],rank(' date')[!as.logical('colour')], FUN = function(X, Y) { abs(X - Y) }) + outer(rank( 'number ')[as.logical('colour')], rank( 'number ')[!as.logical('colour')], FUN = function(X, Y) { abs(X - Y) })) With the result: NA And im over this problem since two days, i´m sure, that the answer is not so difficult...bit i can´t find it ... So i hoped , that you could help me=) -- View this message in context: http://r.789695.n4.nabble.com/discrepancy-matrix-tp2291126p2291126.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] Recommended way of requiring packages of a certain version?
So distributing code to other people is preferably done using R packages, which gives you this option. However (as far as I am aware), note that this option is checked at package build time, not at load time. Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Recommended way of requiring packages of a certain version?
On 16/07/10 09:32, Paul Hiemstra wrote: Hi Allan, When you create an R package you can specify in the DESCRIPTION file that your package depends on a certain R version and versions of packages. For example: [...] Depends: R (= 2.7.0), methods, sp (= 0.9-4), gstat (= 0.9-58) Thanks Paul, this is helpful. It doesn't quite do what I want because support for operators other than `=` is erratic (the documentation at [1] seems to suggest that R CMD INSTALL supports any operator while install.packages() only supports `=`). Also I am not sure if it is checked on every package load? [...] So distributing code to other people is preferably done using R packages, which gives you this option. Agreed in principle (and that is kind of what I am developing), but sometimes you just want to send a piece of analysis you are working on. But thanks for the pointer. Allan [1] http://cran.r-project.org/doc/manuals/R-exts.html#fn-2 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] a very particular plot
On Wed, Jul 14, 2010 at 1:32 AM, Ian Bentley ian.bent...@gmail.com wrote: I've got a couple of more changes that I want to make to my plot, and I can't figure things out. Thanks for all the help. I'm using this R script library(ggplot2) library(lattice) # Generate 50 data sets of size 100 and assign them to a list object low - 1 n - 50 #Load data from file for(i in low:n) assign(paste('df', i, sep = ''), read.table(paste(tot-LinkedList,i*100,query.log,sep=''), header=TRUE)) dnames - paste('df', low:n, sep = '') l - vector('list', n) for(i in seq_along(dnames)) l[[i]] - with(get(dnames[i]), Send + Receive) ml - melt(l) dsum - ddply(ml, 'L1', summarise, mins = min(value), meds = median(value), maxs = max(value)) p - ggplot(ml, aes(x = L1*100, y = value)) + geom_point(alpha = 0.2) + geom_point(data = dsum, aes(y = mins), shape = 1, size = 3, solid=TRUE, colour='blue') + geom_point(data = dsum, aes(y = meds), shape = 2, size = 3, solid=TRUE, colour='blue') + geom_point(data = dsum, aes(y = maxs), shape = 3, size = 3, solid=TRUE, colour='blue') + geom_smooth(data = dsum, aes(y = mins)) + geom_smooth(data = dsum, aes(y = meds)) + geom_smooth(data = dsum, aes(y = maxs)) + opts(axis.text.x = theme_text(size = 7, angle = 90, hjust = 1), title = 'Linked List Query Costs Increasing Network Size') + xlab('Network Complexity (nodes)') + ylab('Battery Cost (uJ)') + --END-- And this works great, except that I think that I am not being very R'y, since now I want to add a legend saying that circle (i.e. shape 1) is the minimum, and shape 2 is the med, and shape 3 is max. I'd also like to be able to move the legend to the top left part of the plot since that area is empty anyways. Is there any way that I can do it easily? Yes, but it's difficult to show you how without a simple reproducible example... Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Two Dimensional Transformation
Hi - I am trying to map a two dimensional area A to another two dimensional area B using a function. For instance A = {(x,y), 0x1, 0y1}, and the function is u = x+y and v = x/y. 2-D area is defined by (u,v). Is there a way I can do this in R? Thanks Ravi [[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] Two Dimensional Transformation
Unless I am missing something this should do it a- cbind(runif(10),runif(10)) b - cbind(a[,1]+a[,2], a[,1]/a[,2]) On Jul 16, 2010, at 7:00 AM, Ravi Ramaswamy wrote: Hi - I am trying to map a two dimensional area A to another two dimensional area B using a function. For instance A = {(x,y), 0x1, 0y1}, and the function is u = x+y and v = x/y. 2-D area is defined by (u,v). Is there a way I can do this in R? Thanks Ravi [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to transform: 4 columns into two columns stacked
I have the following data structure: n=5 mydata - data.frame(id=1:n, x=rnorm(n), y=rnorm(n), id=1:n, x=rnorm(n), y=rnorm(n)) print(mydata) producing the following represention id x y id.1 x.1y.1 1 1 0.5326855 -2.076337031 0.7930274 -1.0530558 2 2 0.7888909 0.633546932 0.5908323 -1.3543282 3 3 0.5350803 -0.201089313 2.5079242 -0.4657274 4 4 -1.3041960 -0.251951294 1.6294046 -1.4094830 5 5 0.3109767 -0.023059815 0.5183756 1.3084776 however I need to transform this data into this form: id x y 1 1 0.5326855 -2.07633703 2 2 0.7888909 0.63354693 3 3 0.5350803 -0.20108931 4 4 -1.3041960 -0.25195129 5 5 0.3109767 -0.02305981 6 1 0.7930274 -1.0530558 7 2 0.5908323 -1.3543282 8 3 2.5079242 -0.4657274 9 4 1.6294046 -1.4094830 10 5 0.5183756 1.3084776 what is the simplest way to do that? Thanks a lot in advance! Ralf __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 transform: 4 columns into two columns stacked
On 16-Jul-10 11:27:18, Ralf B wrote: I have the following data structure: n=5 mydata - data.frame(id=1:n, x=rnorm(n), y=rnorm(n), id=1:n, x=rnorm(n), y=rnorm(n)) print(mydata) producing the following represention id x y id.1 x.1y.1 1 1 0.5326855 -2.076337031 0.7930274 -1.0530558 2 2 0.7888909 0.633546932 0.5908323 -1.3543282 3 3 0.5350803 -0.201089313 2.5079242 -0.4657274 4 4 -1.3041960 -0.251951294 1.6294046 -1.4094830 5 5 0.3109767 -0.023059815 0.5183756 1.3084776 however I need to transform this data into this form: id x y 1 1 0.5326855 -2.07633703 2 2 0.7888909 0.63354693 3 3 0.5350803 -0.20108931 4 4 -1.3041960 -0.25195129 5 5 0.3109767 -0.02305981 6 1 0.7930274 -1.0530558 7 2 0.5908323 -1.3543282 8 3 2.5079242 -0.4657274 9 4 1.6294046 -1.4094830 10 5 0.5183756 1.3084776 what is the simplest way to do that? Thanks a lot in advance! Ralf Something on the lines of dataframe(id = c(mydata$id, mydata$id1), x = c(mydata$x , mydata$x1 ), y = c(mydata$y , mydata$y1 ) Ted. E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 16-Jul-10 Time: 12:56:48 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 transform: 4 columns into two columns stacked
its maybe not as simple as Teds solution but points to a more general approach reshape(mydata,direction=long,varying=names(mydata),v.names=c(id,x,y)) Am 16.07.2010 13:27, schrieb Ralf B: I have the following data structure: n=5 mydata - data.frame(id=1:n, x=rnorm(n), y=rnorm(n), id=1:n, x=rnorm(n), y=rnorm(n)) print(mydata) producing the following represention id x y id.1 x.1y.1 1 1 0.5326855 -2.076337031 0.7930274 -1.0530558 2 2 0.7888909 0.633546932 0.5908323 -1.3543282 3 3 0.5350803 -0.201089313 2.5079242 -0.4657274 4 4 -1.3041960 -0.251951294 1.6294046 -1.4094830 5 5 0.3109767 -0.023059815 0.5183756 1.3084776 however I need to transform this data into this form: id x y 1 1 0.5326855 -2.07633703 2 2 0.7888909 0.63354693 3 3 0.5350803 -0.20108931 4 4 -1.3041960 -0.25195129 5 5 0.3109767 -0.02305981 6 1 0.7930274 -1.0530558 7 2 0.5908323 -1.3543282 8 3 2.5079242 -0.4657274 9 4 1.6294046 -1.4094830 10 5 0.5183756 1.3084776 what is the simplest way to do that? Thanks a lot in advance! Ralf __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Eik Vettorazzi Institut für Medizinische Biometrie und Epidemiologie Universitätsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/7410-58243 F ++49/40/7410-57790 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Creating Enumerated Variables
I think this is simpler but still not all that clean. === xx - structure(list(ID = 1:9, Age = c(10L, 10L, 10L, 11L, 11L, 11L, 10L, 10L, 11L), School = c(1L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 2L ), Grade = c(98L, 97L, 92L, 90L, 80L, 70L, 80L, 79L, 70L)), .Names = c(ID, Age, School, Grade), class = data.frame, row.names = c(NA, -9L)) library(reshape) (rr - cast(xx, Age + School ~ ., length)) mylist - NULL for(i in 1:length(rr[,3])) { mylist[[i]] - seq(rr[i,3]) } ecount - unlist(mylist) cbind(xx[order(xx[,3]),], ecount) --- On Thu, 7/15/10, Dennis Murphy djmu...@gmail.com wrote: From: Dennis Murphy djmu...@gmail.com Subject: Re: [R] Creating Enumerated Variables To: jdellava jdell...@vcuhi.edu Cc: r-help@r-project.org Received: Thursday, July 15, 2010, 5:08 PM Hi: I sincerely hope there's an easier way, but one method to get this is as follows, with d as the data frame name of your test data: d - d[order(with(d, Age, School, rev(Grade))), ] d$Count - do.call(c, mapply(seq, 1, as.vector(t(with(d, table(Age, School)) d d ID Age School Grade Count 1 1 10 1 98 1 3 3 10 1 92 2 7 7 10 1 80 3 8 8 10 1 79 4 2 2 10 2 97 1 4 4 11 1 90 1 5 5 11 1 80 2 6 6 11 2 70 1 9 9 11 2 70 2 The code to get the count is a little convoluted: - first, find the frequency table of Age and School, transpose it and then unlist into a vector - use mapply to generate a sequence for each group from 1 up to its group count; mapply() is necessary to use the counts as a vector argument. This returns a list of sequences. - do.call() applies a function (here, c) to an input list, yielding the vector of groupwise indices we wanted. Basically, it flattens the list. This is what we assign to d$Count. Side note: I didn't get the correct ordering the first time, but I did the second time (2.11.1 64bit, Windows 7). HTH, Dennis On Thu, Jul 15, 2010 at 7:45 AM, jdellava jdell...@vcu.edu wrote: Hi, I am trying to create a variable counting the number of individuals based on two variables. I am able to do it or one variable, but not two. In SAS I was able to sort by two variables and use a first. statement to create the counts based on both. Here is an example: What I have ID Age School Grade 1 10 1 98 2 10 2 97 3 10 1 92 4 11 1 90 5 11 1 80 6 11 2 70 7 10 1 80 8 10 1 79 9 11 2 70 What I need ID Age School Grade School Count 1 10 1 98 1 3 10 1 92 2 7 10 1 80 3 8 10 1 79 4 2 10 2 97 1 4 11 1 90 1 5 11 1 80 2 6 11 2 70 1 9 11 2 70 2 I want to create counts of individuals age 10 in school 1 then age 10 in school two (the what I need set) Anyway to do this? Thank you. -- View this message in context: http://r.789695.n4.nabble.com/Creating-Enumerated-Variables-tp2290262p2290262.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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented,
Re: [R] send out put to file in R
On Thu, Jul 15, 2010 at 6:38 PM, chakri_amateur chakri2...@yahoo.co.in wrote: [...] I want to extract the largest connected component (alias sub-graph) of the network. My input network is a large network of 1000 vertices and 15000 arcs. From this, I want to take out only the largest cluster. If you decompose a graph to components, you get a list of graphs; Yes. But I want only the largest sub-graph. It is first in the list sub-graphs generated. Am I right ? I tried with 10 files, and all the time the largest sub-graph is shown first in the list. (i.e i=1, in compo[[i]]) No, this is not right. It is just a coincidence. The components are not ordered. In fact, the first component in the list is the one that has the first (well, zeroth) vertex. Check the sizes of the components and explicitly choose the largest one: compo[[ which.max(sapply(compo, vcount)) ]] Best, Gabor for (i in seq_along(compo)) { write.graph(compo[[i]], file=paste(sep=, new-, i, .net), format=pajek) } It worked. I Just had to give entire file path instead of just new ! for (i in seq_along(compo)) { write.graph(compo[[i]], file=paste(sep=, F://new-, i, .net), pajek) } or For the first component write.graph(compo[[1]], F://new.net, pajek) Chakri Second, -- View this message in context: http://r.789695.n4.nabble.com/send-out-put-to-file-in-R-tp2288515p2290393.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. -- Gabor Csardi gabor.csa...@unil.ch UNIL DGM __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Creating Enumerated Variables
On Thu, Jul 15, 2010 at 11:08 PM, Dennis Murphy djmu...@gmail.com wrote: Hi: I sincerely hope there's an easier way, but one method to get this is as follows, with d as the data frame name of your test data: d - d[order(with(d, Age, School, rev(Grade))), ] d$Count - do.call(c, mapply(seq, 1, as.vector(t(with(d, table(Age, School)) It's easier if you use plyr ;) library(plyr) ddply(d, c(Age, School), transform, school_count = seq_along(ID)) Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] CART with a circular response
Could anyone advise me how can I implement classification and regression tree analyses for a circular response (angles)? Rpart allows for user-defined splitting rules. You need to define a function which is given y and an ordered x, and returns the 'goodness of split' for each split point. You need to decide how to define goodness. Terry Therneau __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] threshold in plot
Hi I want to draw a plot from observed and predicted data and also shows threshold and data before threshold are identified with different color from data after threshold. Suppose: abserved data are 0 or 1 predicted data= 0 to 1 threshold=0.5 Thanks alot [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Standard Error for individual patient survival with survfit and summary.survfit
Can anyone tell me what is the difference between these two standard errors and how should I interpret the confidence intervals and std.err given these differences? help(survfit.object) will give you the answer. The std in the object is for the cumulative hazard, the printout uses a Taylor series argument to compute the se of the survival. (The are several reasons for this choice, including that se(survival) is not well defined by the standard formulas when S=0). Terry Therneau __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Packages built before R 2.10.0
Dear list, I am running R2.11.1 on 32 bit windows. I am receiving messages as follows ... require(car) Loading required package: car Error: package 'car' was built before R 2.10.0: please re-install it The package kohonen was another example. This failure appears to be fatal and not only affects the package concerned, but also all its dependents. Is there anything I can do at my end, or do I have to wait for the packages to be re-built, Thanks, Philip This message should be regarded as confidential. If you have received this email in error please notify the sender and destroy it immediately. Statements of intent shall only become binding when confirmed in hard copy by an authorised signatory. The contents of this email may relate to dealings with other companies within the Detica Limited group of companies. Detica Limited is registered in England under No: 1337451. Registered offices: Surrey Research Park, Guildford, Surrey, GU2 7YP, England. [[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] Question about KLdiv and large datasets
Hi all, when running KL on a small data set, everything is fine: require(flexmix) n - 20 a - rnorm(n) b - rnorm(n) mydata - cbind(a,b) KLdiv(mydata) however, when this dataset increases require(flexmix) n - 1000 a - rnorm(n) b - rnorm(n) mydata - cbind(a,b) KLdiv(mydata) KL seems to be not defined. Can somebody explain what is going on? Thanks, Ralf __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] filtered back-projection
Hi List, Does R have a package that will do filtered back-projection? I'm a medical physicist trying to produce an image of a dose cloud within a phantom using software other than Matlab and wondered if R has this capability. I looked through the imaging pages on the project site but didn't see anything specific about back-projection. 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.
Re: [R] Packages built before R 2.10.0
On 16/07/2010 9:50 AM, Philip Whittall wrote: Dear list, I am running R2.11.1 on 32 bit windows. I am receiving messages as follows ... require(car) Loading required package: car Error: package 'car' was built before R 2.10.0: please re-install it The package kohonen was another example. This failure appears to be fatal and not only affects the package concerned, but also all its dependents. Is there anything I can do at my end, or do I have to wait for the packages to be re-built, Just follow the instructions: re-install the packages and they will be fine. They've already been rebuilt for 2.11.x long ago. Duncan Murdoch Thanks, Philip This message should be regarded as confidential. If you have received this email in error please notify the sender and destroy it immediately. Statements of intent shall only become binding when confirmed in hard copy by an authorised signatory. The contents of this email may relate to dealings with other companies within the Detica Limited group of companies. Detica Limited is registered in England under No: 1337451. Registered offices: Surrey Research Park, Guildford, Surrey, GU2 7YP, England. [[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] Packages built before R 2.10.0
Hi Duncan, Many thanks for the response. I did indeed re-install car and this is what occurred ... utils:::menuInstallLocal() package 'car' successfully unpacked and MD5 sums checked require(candisc) Loading required package: candisc Loading required package: car Error: package 'car' was built before R 2.10.0: please re-install it utils:::menuInstallLocal() package 'candisc' successfully unpacked and MD5 sums checked require(candisc) Loading required package: candisc Loading required package: car Error: package 'car' was built before R 2.10.0: please re-install it require(car) Loading required package: car Error: package 'car' was built before R 2.10.0: please re-install it I had checked the .zip files on the CRAN site ahd I do have the current ones I had also run update.packages() both as a command and from the console pull down menu. I have probably missed something obvious, Thanks, Philip -Original Message- From: Duncan Murdoch [mailto:murdoch.dun...@gmail.com] Sent: 16 July 2010 15:24 To: Philip Whittall Cc: r-help@r-project.org Subject: Re: [R] Packages built before R 2.10.0 On 16/07/2010 9:50 AM, Philip Whittall wrote: Dear list, I am running R2.11.1 on 32 bit windows. I am receiving messages as follows ... require(car) Loading required package: car Error: package 'car' was built before R 2.10.0: please re-install it The package kohonen was another example. This failure appears to be fatal and not only affects the package concerned, but also all its dependents. Is there anything I can do at my end, or do I have to wait for the packages to be re-built, Just follow the instructions: re-install the packages and they will be fine. They've already been rebuilt for 2.11.x long ago. Duncan Murdoch Thanks, Philip This message should be regarded as confidential. If you have received this email in error please notify the sender and destroy it immediately. Statements of intent shall only become binding when confirmed in hard copy by an authorised signatory. The contents of this email may relate to dealings with other companies within the Detica Limited group of companies. Detica Limited is registered in England under No: 1337451. Registered offices: Surrey Research Park, Guildford, Surrey, GU2 7YP, England. [[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. This message should be regarded as confidential. If you have received this email in error please notify the sender and destroy it immediately. Statements of intent shall only become binding when confirmed in hard copy by an authorised signatory. The contents of this email may relate to dealings with other companies within the Detica Limited group of companies. Detica Limited is registered in England under No: 1337451. Registered offices: Surrey Research Park, Guildford, Surrey, GU2 7YP, England. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Question about KLdiv and large datasets
On 2010-07-16 7:56, Ralf B wrote: Hi all, when running KL on a small data set, everything is fine: require(flexmix) n- 20 a- rnorm(n) b- rnorm(n) mydata- cbind(a,b) KLdiv(mydata) however, when this dataset increases require(flexmix) n- 1000 a- rnorm(n) b- rnorm(n) mydata- cbind(a,b) KLdiv(mydata) KL seems to be not defined. Can somebody explain what is going on? Thanks, Ralf Ralf, You can adjust the 'eps=' argument. But I don't know what this will do to the reliability of the results. KLdiv(mydata, eps = 1e-7) -Peter Ehlers __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Packages built before R 2.10.0
On 16/07/2010 10:41 AM, Philip Whittall wrote: Hi Duncan, Many thanks for the response. I did indeed re-install car and this is what occurred ... utils:::menuInstallLocal() package 'car' successfully unpacked and MD5 sums checked require(candisc) Loading required package: candisc Loading required package: car Error: package 'car' was built before R 2.10.0: please re-install it utils:::menuInstallLocal() package 'candisc' successfully unpacked and MD5 sums checked require(candisc) Loading required package: candisc Loading required package: car Error: package 'car' was built before R 2.10.0: please re-install it require(car) Loading required package: car Error: package 'car' was built before R 2.10.0: please re-install it I had checked the .zip files on the CRAN site ahd I do have the current ones I had also run update.packages() both as a command and from the console pull down menu. I have probably missed something obvious, I would guess you need to use a more up-to-date mirror. It's also possible that you have somehow messed up the path to your library and are installing to one place but loading from another, but normally new installs go into the first search position, so I don't see how that could be the cause. Duncan Murdoch Thanks, Philip -Original Message- From: Duncan Murdoch [mailto:murdoch.dun...@gmail.com] Sent: 16 July 2010 15:24 To: Philip Whittall Cc: r-help@r-project.org Subject: Re: [R] Packages built before R 2.10.0 On 16/07/2010 9:50 AM, Philip Whittall wrote: Dear list, I am running R2.11.1 on 32 bit windows. I am receiving messages as follows ... require(car) Loading required package: car Error: package 'car' was built before R 2.10.0: please re-install it The package kohonen was another example. This failure appears to be fatal and not only affects the package concerned, but also all its dependents. Is there anything I can do at my end, or do I have to wait for the packages to be re-built, Just follow the instructions: re-install the packages and they will be fine. They've already been rebuilt for 2.11.x long ago. Duncan Murdoch Thanks, Philip This message should be regarded as confidential. If you have received this email in error please notify the sender and destroy it immediately. Statements of intent shall only become binding when confirmed in hard copy by an authorised signatory. The contents of this email may relate to dealings with other companies within the Detica Limited group of companies. Detica Limited is registered in England under No: 1337451. Registered offices: Surrey Research Park, Guildford, Surrey, GU2 7YP, England. [[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. This message should be regarded as confidential. If you have received this email in error please notify the sender and destroy it immediately. Statements of intent shall only become binding when confirmed in hard copy by an authorised signatory. The contents of this email may relate to dealings with other companies within the Detica Limited group of companies. Detica Limited is registered in England under No: 1337451. Registered offices: Surrey Research Park, Guildford, Surrey, GU2 7YP, England. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Packages built before R 2.10.0
I should have added that this problem is not serious under 2.10 as you only get a Warning and everything works require(candisc) Loading required package: candisc Loading required package: car Loading required package: heplots Warning message: package 'car' was built under R version 2.9.2 and help will not work correctly Please re-install it require(car) require(candisc) I am using the mirror from Imperial College London and a check on the \library\car subdirectory of my R-2.11.1 installation show that it was updated at the expected time, Thanks, Philip -Original Message- From: Duncan Murdoch [mailto:murdoch.dun...@gmail.com] Sent: 16 July 2010 15:45 To: Philip Whittall Cc: r-help@r-project.org Subject: Re: [R] Packages built before R 2.10.0 On 16/07/2010 10:41 AM, Philip Whittall wrote: Hi Duncan, Many thanks for the response. I did indeed re-install car and this is what occurred ... utils:::menuInstallLocal() package 'car' successfully unpacked and MD5 sums checked require(candisc) Loading required package: candisc Loading required package: car Error: package 'car' was built before R 2.10.0: please re-install it utils:::menuInstallLocal() package 'candisc' successfully unpacked and MD5 sums checked require(candisc) Loading required package: candisc Loading required package: car Error: package 'car' was built before R 2.10.0: please re-install it require(car) Loading required package: car Error: package 'car' was built before R 2.10.0: please re-install it I had checked the .zip files on the CRAN site ahd I do have the current ones I had also run update.packages() both as a command and from the console pull down menu. I have probably missed something obvious, I would guess you need to use a more up-to-date mirror. It's also possible that you have somehow messed up the path to your library and are installing to one place but loading from another, but normally new installs go into the first search position, so I don't see how that could be the cause. Duncan Murdoch Thanks, Philip -Original Message- From: Duncan Murdoch [mailto:murdoch.dun...@gmail.com] Sent: 16 July 2010 15:24 To: Philip Whittall Cc: r-help@r-project.org Subject: Re: [R] Packages built before R 2.10.0 On 16/07/2010 9:50 AM, Philip Whittall wrote: Dear list, I am running R2.11.1 on 32 bit windows. I am receiving messages as follows ... require(car) Loading required package: car Error: package 'car' was built before R 2.10.0: please re-install it The package kohonen was another example. This failure appears to be fatal and not only affects the package concerned, but also all its dependents. Is there anything I can do at my end, or do I have to wait for the packages to be re-built, Just follow the instructions: re-install the packages and they will be fine. They've already been rebuilt for 2.11.x long ago. Duncan Murdoch Thanks, Philip This message should be regarded as confidential. If you have received this email in error please notify the sender and destroy it immediately. Statements of intent shall only become binding when confirmed in hard copy by an authorised signatory. The contents of this email may relate to dealings with other companies within the Detica Limited group of companies. Detica Limited is registered in England under No: 1337451. Registered offices: Surrey Research Park, Guildford, Surrey, GU2 7YP, England. [[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. This message should be regarded as confidential. If you have received this email in error please notify the sender and destroy it immediately. Statements of intent shall only become binding when confirmed in hard copy by an authorised signatory. The contents of this email may relate to dealings with other companies within the Detica Limited group of companies. Detica Limited is registered in England under No: 1337451. Registered offices: Surrey Research Park, Guildford, Surrey, GU2 7YP, England. This message should be regarded as confidential. If you have received this email in error please notify the sender and destroy it immediately. Statements of intent shall only become binding when confirmed in hard copy by an authorised signatory. The contents of this email may relate to dealings with other companies within the Detica Limited group of companies. Detica Limited is registered in England under No: 1337451. Registered offices: Surrey Research Park, Guildford, Surrey, GU2 7YP, England. __ R-help@r-project.org mailing list
[R] read.table input array
Hello to all! I am new with R and I need your help. I'm trying to read a file which contests are similar to this: ABCTLengths 14.00.001525878918c(1,2,3) 11.00.001716613824c(1,1,4) So all the columns are numeric values, except Lengths, which is supposed to be an variable length array of integers. How can I make R read them as arrays of integers? Or otherwise, convert the character array to an array of integers. When I read the file, I do it like this t1 = read.table(file=paste(./borrar.dat,sep=), header=T, colClasses=c(numeric, numeric, numeric, numeric, array)) But the 5th column is treated as an array of characters, and when trying to convert it to another class of data, I either get two strings c(1,2,3) and c(1,1,4) or using a toRaw converter, I get the corresponding ASCII ¿? values. Should the input be modified in order to be able to read it as an array of integers? Thank you for your help. Balpo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] assign
Hi. I am a beginner. What is the difference between: x-2 and x=2 Thanks. Linda __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Packages built before R 2.10.0
On 16/07/2010 10:51 AM, Philip Whittall wrote: I should have added that this problem is not serious under 2.10 as you only get a Warning and everything works require(candisc) Loading required package: candisc Loading required package: car Loading required package: heplots Warning message: package 'car' was built under R version 2.9.2 and help will not work correctly Please re-install it require(car) require(candisc) I am using the mirror from Imperial College London and a check on the \library\car subdirectory of my R-2.11.1 installation show that it was updated at the expected time, I just did an install from the UK (London) mirror (the same one?) and it works fine. So I've got no idea what's going wrong for you. I'd suggest deleting the directory holding the problem package (i.e. \library\car) and confirming that the error changes to Error in library(car) : there is no package called 'car'. Then do an install using install.packages(car) and see if that fixes things. Duncan Murdoch Thanks, Philip -Original Message- From: Duncan Murdoch [mailto:murdoch.dun...@gmail.com] Sent: 16 July 2010 15:45 To: Philip Whittall Cc: r-help@r-project.org Subject: Re: [R] Packages built before R 2.10.0 On 16/07/2010 10:41 AM, Philip Whittall wrote: Hi Duncan, Many thanks for the response. I did indeed re-install car and this is what occurred ... utils:::menuInstallLocal() package 'car' successfully unpacked and MD5 sums checked require(candisc) Loading required package: candisc Loading required package: car Error: package 'car' was built before R 2.10.0: please re-install it utils:::menuInstallLocal() package 'candisc' successfully unpacked and MD5 sums checked require(candisc) Loading required package: candisc Loading required package: car Error: package 'car' was built before R 2.10.0: please re-install it require(car) Loading required package: car Error: package 'car' was built before R 2.10.0: please re-install it I had checked the .zip files on the CRAN site ahd I do have the current ones I had also run update.packages() both as a command and from the console pull down menu. I have probably missed something obvious, I would guess you need to use a more up-to-date mirror. It's also possible that you have somehow messed up the path to your library and are installing to one place but loading from another, but normally new installs go into the first search position, so I don't see how that could be the cause. Duncan Murdoch Thanks, Philip -Original Message- From: Duncan Murdoch [mailto:murdoch.dun...@gmail.com] Sent: 16 July 2010 15:24 To: Philip Whittall Cc: r-help@r-project.org Subject: Re: [R] Packages built before R 2.10.0 On 16/07/2010 9:50 AM, Philip Whittall wrote: Dear list, I am running R2.11.1 on 32 bit windows. I am receiving messages as follows ... require(car) Loading required package: car Error: package 'car' was built before R 2.10.0: please re-install it The package kohonen was another example. This failure appears to be fatal and not only affects the package concerned, but also all its dependents. Is there anything I can do at my end, or do I have to wait for the packages to be re-built, Just follow the instructions: re-install the packages and they will be fine. They've already been rebuilt for 2.11.x long ago. Duncan Murdoch Thanks, Philip This message should be regarded as confidential. If you have received this email in error please notify the sender and destroy it immediately. Statements of intent shall only become binding when confirmed in hard copy by an authorised signatory. The contents of this email may relate to dealings with other companies within the Detica Limited group of companies. Detica Limited is registered in England under No: 1337451. Registered offices: Surrey Research Park, Guildford, Surrey, GU2 7YP, England. [[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. This message should be regarded as confidential. If you have received this email in error please notify the sender and destroy it immediately. Statements of intent shall only become binding when confirmed in hard copy by an authorised signatory. The contents of this email may relate to dealings with other companies within the Detica Limited group of companies. Detica Limited is registered in England under No: 1337451. Registered offices: Surrey Research Park, Guildford, Surrey, GU2 7YP, England. This message should be regarded as confidential. If you have received this email in error please notify the sender and destroy it
Re: [R] Packages built before R 2.10.0
Hi Duncan, That fixed it. Many thanks indeed, I now know what to do if it happens again, Philip -Original Message- From: Duncan Murdoch [mailto:murdoch.dun...@gmail.com] Sent: 16 July 2010 16:00 To: Philip Whittall Cc: r-help@r-project.org Subject: Re: [R] Packages built before R 2.10.0 On 16/07/2010 10:51 AM, Philip Whittall wrote: I should have added that this problem is not serious under 2.10 as you only get a Warning and everything works require(candisc) Loading required package: candisc Loading required package: car Loading required package: heplots Warning message: package 'car' was built under R version 2.9.2 and help will not work correctly Please re-install it require(car) require(candisc) I am using the mirror from Imperial College London and a check on the \library\car subdirectory of my R-2.11.1 installation show that it was updated at the expected time, I just did an install from the UK (London) mirror (the same one?) and it works fine. So I've got no idea what's going wrong for you. I'd suggest deleting the directory holding the problem package (i.e. \library\car) and confirming that the error changes to Error in library(car) : there is no package called 'car'. Then do an install using install.packages(car) and see if that fixes things. Duncan Murdoch Thanks, Philip -Original Message- From: Duncan Murdoch [mailto:murdoch.dun...@gmail.com] Sent: 16 July 2010 15:45 To: Philip Whittall Cc: r-help@r-project.org Subject: Re: [R] Packages built before R 2.10.0 On 16/07/2010 10:41 AM, Philip Whittall wrote: Hi Duncan, Many thanks for the response. I did indeed re-install car and this is what occurred ... utils:::menuInstallLocal() package 'car' successfully unpacked and MD5 sums checked require(candisc) Loading required package: candisc Loading required package: car Error: package 'car' was built before R 2.10.0: please re-install it utils:::menuInstallLocal() package 'candisc' successfully unpacked and MD5 sums checked require(candisc) Loading required package: candisc Loading required package: car Error: package 'car' was built before R 2.10.0: please re-install it require(car) Loading required package: car Error: package 'car' was built before R 2.10.0: please re-install it I had checked the .zip files on the CRAN site ahd I do have the current ones I had also run update.packages() both as a command and from the console pull down menu. I have probably missed something obvious, I would guess you need to use a more up-to-date mirror. It's also possible that you have somehow messed up the path to your library and are installing to one place but loading from another, but normally new installs go into the first search position, so I don't see how that could be the cause. Duncan Murdoch Thanks, Philip -Original Message- From: Duncan Murdoch [mailto:murdoch.dun...@gmail.com] Sent: 16 July 2010 15:24 To: Philip Whittall Cc: r-help@r-project.org Subject: Re: [R] Packages built before R 2.10.0 On 16/07/2010 9:50 AM, Philip Whittall wrote: Dear list, I am running R2.11.1 on 32 bit windows. I am receiving messages as follows ... require(car) Loading required package: car Error: package 'car' was built before R 2.10.0: please re-install it The package kohonen was another example. This failure appears to be fatal and not only affects the package concerned, but also all its dependents. Is there anything I can do at my end, or do I have to wait for the packages to be re-built, Just follow the instructions: re-install the packages and they will be fine. They've already been rebuilt for 2.11.x long ago. Duncan Murdoch Thanks, Philip This message should be regarded as confidential. If you have received this email in error please notify the sender and destroy it immediately. Statements of intent shall only become binding when confirmed in hard copy by an authorised signatory. The contents of this email may relate to dealings with other companies within the Detica Limited group of companies. Detica Limited is registered in England under No: 1337451. Registered offices: Surrey Research Park, Guildford, Surrey, GU2 7YP, England. [[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. This message should be regarded as confidential. If you have received this email in error please notify the sender and destroy it immediately. Statements of intent shall only become binding when confirmed in hard copy by an
Re: [R] assign
On 16/07/2010 10:57 AM, linda.s wrote: Hi. I am a beginner. What is the difference between: x-2 and x=2 It depends on the context. x - 2 always assigns the value 2 to the variable named x. Typed as an isolated command, that's what x = 2 does too. However, when used as an argument to a function, e.g. f(x = 2), it associates the value 2 to the *argument* matched by x in the function call. This is occasionally confusing, so many people recommend that you always use x - 2 when you mean to do an assignment, and reserve the use of = for function arguments. 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] question about string handling....
hey, guys, all these methods work perfectly. thank you!! -- View this message in context: http://r.789695.n4.nabble.com/question-about-string-handling-tp2289178p2291497.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] package for rank ordered logit
Is there a package in R that can run rank-ordered logit? Thanks, Suresh __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] save plot
I made a plot, but after I made a second plot, the previous plot was gone. How can I save all the plots in a file (I do not manually copy and paste them one by one)? Thanks. Linda __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] save plot
We need to know how you're doing this, with a minimal example that we can run. Most graphics devices accept a file or filename argument, so that's one way. If you're using the pdf device, multiple plots will create multiple pages in the final output.. linda.s wrote: I made a plot, but after I made a second plot, the previous plot was gone. How can I save all the plots in a file (I do not manually copy and paste them one by one)? Thanks. Linda __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Simple question regarding name of column headers
names(miceTrainSample) [1] b_double KierA2KierFlex Q_VSA_POS pID50 In the above code, how do I delete pID50 column to store the resulting object without indicating column 5. The code below does the trick, but I wish to delete the column by specifying -pID50 instead of 5. names(miceTrainSample)[-5] [1] b_double KierA2KierFlex Q_VSA_POS -- View this message in context: http://r.789695.n4.nabble.com/Simple-question-regarding-name-of-column-headers-tp2291534p2291534.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] changing names numeric to a time series
Dear R People: What is the best way to change a named numeric (in which the names are dates) to a time series, please? str(y1) Named int [1:730] 102 145 147 120 132 125 137 103 128 130 ... - attr(*, names)= chr [1:730] 2006-01-01 2006-01-02 2006-01-03 2006-01-04 ... Thanks in advance, Sincerely, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@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.
[R] changing names numeric to a time series - solved
Here is the original question: What is the best way to change a named numeric to a time series str(y1) Named int [1:730] 102 145 147 120 132 125 137 103 128 130 ... - attr(*, names)= chr [1:730] 2006-01-01 2006-01-02 2006-01-03 2006-01-04 ... y2 - zoo(y1,order=names(y1)) Perfect! Thanks though, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@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] package for rank ordered logit
Did you try: library(MASS) ?polr ? Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- On Fri, Jul 16, 2010 at 6:15 PM, Suresh Singh singh@osu.edu wrote: Is there a package in R that can run rank-ordered logit? Thanks, Suresh __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Simple question regarding name of column headers
Hi Addi, On Fri, Jul 16, 2010 at 3:22 PM, Addi Wei addi...@gmail.com wrote: names(miceTrainSample) [1] b_double KierA2 KierFlex Q_VSA_POS pID50 In the above code, how do I delete pID50 column to store the resulting object without indicating column 5. The code below does the trick, but I wish to delete the column by specifying -pID50 instead of 5. names(miceTrainSample)[-5] [1] b_double KierA2 KierFlex Q_VSA_POS If I understand you correctly, than this code will not do the trick. All it does is print the column names minus pID50. It does nothing to miceTrainSample. Anyway, I have often wished that something like new.mt.sample - miceTrainSample[, -pID50] would return miceTrainSample without the pID50 column. Here are three alternative ways to do it. # Method 1: Assign NULL to the column new.mt.sample - miceTrainsSample new.mt.sample$pID50 - NULL # Method 2: Use which() new.mt.sample - miceTrainSample[, - which(names(miceTrainSample == pID50)] # Method 3: use %in% (the one I usually use) new.mt.sample - miceTrainSample[, ! names(miceTrainSample) %in% pID50] Hope it helps, Ista -- View this message in context: http://r.789695.n4.nabble.com/Simple-question-regarding-name-of-column-headers-tp2291534p2291534.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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] changing names numeric to a time series
On Fri, Jul 16, 2010 at 11:26 AM, Erin Hodgess erinm.hodg...@gmail.com wrote: Dear R People: What is the best way to change a named numeric (in which the names are dates) to a time series, please? str(y1) Named int [1:730] 102 145 147 120 132 125 137 103 128 130 ... - attr(*, names)= chr [1:730] 2006-01-01 2006-01-02 2006-01-03 2006-01-04 ... Try this: zoo(unname(y1), as.Date(names(y1))) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 need help making a data.fame comprised of selected columns of an original data frame.
I must have missed something simple, but still, i don't know what. I obtained my basic data as follows: x - sprintf(SELECT m_id,sale_date,YEAR(sale_date) AS sale_year,WEEK(sale_date) AS sale_week,return_type,0.0001 + DATEDIFF(return_date,sale_date) AS elapsed_time FROM `merchants2`.`risk_input` WHERE DATEDIFF(return_date,sale_date) IS NOT NULL) moreinfo - dbGetQuery(con, x) I then made the data frame I want to use as follows: fun_m_id - function(df) if (length(df$elapsed_time) 5) { rv = fitdist(df$elapsed_time,exp) rv$mid = df$m_id[1] rv } aaa - lapply(split(moreinfo,list(moreinfo$m_id),drop = TRUE), fun_m_id) m_id_default_res - do.call(rbind, aaa) At this point, each row in m_id_default_res corresponds to one data.frame produced by fitdist. When I print it, I get the output I expected. However, I need to store only some of it into my DB. And then, because fitdist produces a data frame that includes a lot of info I don't need to store in the DB, I tried making a new data.frame containing only the info I need as follows: ndf = data.frame() for (i in 1:length(m_id_default_res[,1])) { ndf$mid[i] = m_id_default_res$mid[i] ndf$estimate[i] = m_id_default_res$estimate[i] ndf$sd[i] = m_id_default_res$sd[i] ndf$n[i] = m_id_default_res[i] ndf$loglik[i] = m_id_default_res$loglik[i] ndf$aic[i] = m_id_default_res$aic[i] ndf$bic[i] = m_id_default_res$bic[i] ndf$chisq[i] = m_id_default_res$chisq[i] ndf$chisqpvalue[i] = m_id_default_res$chisqpvalue[i] ndf$chisqdf[i] = m_id_default_res$chisqdf[i] } ndf And I get the following error: Error in `$-.data.frame`(`*tmp*`, n, value = list(0.114752782316094)) : replacement has 1 rows, data has 0 I need to either get rid of the columns in m_id_default_res that I don't need, or I need to copy only those columns I need to a new data.frame. How do I do this. Obviously, doing an element-wise copy, at least as I tried to do it, doesn't work. Thanks, Ted [[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] discrepancy matrix
I guess your data frame is a little different from the reference, so your as.logical doesn't work. attach(Q) FUN - function(X, Y) {abs(X - Y)} round(outer(rank(date)[colour==b],rank(date)[colour==g],FUN) + outer(rank(number)[colour==b],rank(number)[colour==g],FUN)) detach(Q) - A R learner. -- View this message in context: http://r.789695.n4.nabble.com/discrepancy-matrix-tp2291126p2291585.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] I need help making a data.fame comprised of selected columns of an original data frame.
Hi, First: it's kind of hard to play along w/o some reproducible data. To that end, you can paste into an email the output of: dput(moreinfo) If there are lots of rows in `moreinfo`, just give us the first ~10-20 dput(head(moreinfo, 20)) Anyway: snip At this point, each row in m_id_default_res corresponds to one data.frame produced by fitdist. When I print it, I get the output I expected. However, I need to store only some of it into my DB. And then, because fitdist produces a data frame that includes a lot of info I don't need to store in the DB, I tried making a new data.frame containing only the info I need as follows: ndf = data.frame() for (i in 1:length(m_id_default_res[,1])) { ndf$mid[i] = m_id_default_res$mid[i] ndf$estimate[i] = m_id_default_res$estimate[i] ndf$sd[i] = m_id_default_res$sd[i] ndf$n[i] = m_id_default_res[i] ndf$loglik[i] = m_id_default_res$loglik[i] ndf$aic[i] = m_id_default_res$aic[i] ndf$bic[i] = m_id_default_res$bic[i] ndf$chisq[i] = m_id_default_res$chisq[i] ndf$chisqpvalue[i] = m_id_default_res$chisqpvalue[i] ndf$chisqdf[i] = m_id_default_res$chisqdf[i] } Forget the for loop. How about: ndf - m_id_default[, c('mid, 'estimate', 'sd', 'loglik', 'aic', 'bic', 'chisq', 'chisqpvalue', 'chisqdf') Having just written that, I see something strange in your for loop. Specifically this line: ndf$n[i] = m_id_default_res[i] m_id_default_res is a data.frame, right? Why don't you try to see what `m_id_default_res[1]` returns. I'm not sure that that's what your error message is coming from, but I foresee this to be a problem anyway, if I follow your build up code correctly. Hope that helps, -- 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] Simple question regarding name of column headers
Anyway, I have often wished that something like new.mt.sample - miceTrainSample[, -pID50] would return miceTrainSample without the pID50 column. Here are three alternative ways to do it. # Method 1: Assign NULL to the column new.mt.sample - miceTrainsSample new.mt.sample$pID50 - NULL # Method 2: Use which() new.mt.sample - miceTrainSample[, - which(names(miceTrainSample == pID50)] # Method 3: use %in% (the one I usually use) new.mt.sample - miceTrainSample[, ! names(miceTrainSample) %in% pID50] As a variation on Method 1... df - data.frame(a = 1:10, b = 2:11, c = 3:12) transform(df, a = NULL) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 skip a specific value when using apply() function to a matrix?
Hello Nikhil and Wu, Thank you very much for your reply! What I want is to calculate the student's score column-wise by ignoring the specific values such as zeros for example only using c(2,1) in column 8 in the tmp1 and generate tmp2. I changed the zeros to NAs and modified my stud fun to student as below. So I can ignore these specific values but can not put back the NAs to the right position in the resulted matrix. Any suggestions to put back NAs to their original positions in column 7 and 8 either to list tmp4 or matrix tmp5? tmp1[tmp1==0]-NA student- function(x){ x-x[!is.na(x)] x-(x-mean(x))/sd(x) return (x) } tmp4-apply(tmp1, 2, student) tmp4 [[1]] [1] 1.1296201 0.1613743 -1.2909944 1.1296201 -0.3227486 -0.8068715 [[2]] [1] 0.000 0.000 -1.4680505 -0.5872202 0.5872202 1.4680505 [[3]] [1] -0.5207910 -0.4817316 -0.4036130 0.2994548 1.9008870 -0.7942062 [[4]] [1] -0.8630035 -0.2380699 -0.7737273 -0.5951748 1.5474546 0.9225210 [[5]] [1] -0.1913482 -0.6944435 -0.7202433 0.5826446 1.7565336 -0.7331431 [[6]] [1] -0.1132277 0.5661385 -1.4719601 -0.7925939 0.5661385 1.2455047 [[7]] [1] -0.9561829 0.2390457 1.4342743 0.2390457 -0.9561829 [[8]] [1] 0.7071068 -0.7071068 tmp5- matrix(unlist(tmp4),nrow=6) tmp5 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [1,] 1.1296201 0.000 -0.5207910 -0.8630035 -0.1913482 -0.1132277 -0.9561829 -0.7071068 [2,] 0.1613743 0.000 -0.4817316 -0.2380699 -0.6944435 0.5661385 0.2390457 1.1296201 [3,] -1.2909944 -1.4680505 -0.4036130 -0.7737273 -0.7202433 -1.4719601 1.4342743 0.1613743 [4,] 1.1296201 -0.5872202 0.2994548 -0.5951748 0.5826446 -0.7925939 0.2390457 -1.2909944 [5,] -0.3227486 0.5872202 1.9008870 1.5474546 1.7565336 0.5661385 -0.9561829 1.1296201 [6,] -0.8068715 1.4680505 -0.7942062 0.9225210 -0.7331431 1.2455047 0.7071068 -0.3227486 Joshua - Original Message - From: Shuhua Zhan sz...@uoguelph.ca To: r-help@r-project.org Sent: Thursday, July 15, 2010 11:08:34 PM GMT -05:00 US/Canada Eastern Subject: [R] how to skip a specific value when using apply() function to a matrix? Hello R experts, I'd like to studentize a matrix (tmp1) by column using apply() function and skip some specific values such as zeros in the example below to tmp2 but not tmp3. I used the script below and only can get a matrix tmp3. Could you please help me to studentize the matrix (tmp1) without changing the zeros and generate a new matrix tmp2? Thanks, Joshua tmp1 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [1,] 1579 49 60320 [2,] 137 10 56 21430 [3,] 102 12 50 19102 [4,] 155 30 52 120240 [5,] 129 71 76 211431 [6,] 11 122 69 18520 tmp2 [1,] 1.1296201 0.000 -0.5207910 -0.8630035 -0.1913482 -0.1132277 -0.9561829 0.000 [2,] 0.1613743 0.000 -0.4817316 -0.2380699 -0.6944435 0.5661385 0.2390457 0.000 [3,] -1.2909944 -1.4680505 -0.4036130 -0.7737273 -0.7202433 -1.4719601 0.000 0.7071068 [4,] 1.1296201 -0.5872202 0.2994548 -0.5951748 0.5826446 -0.7925939 1.4342743 0.000 [5,] -0.3227486 0.5872202 1.9008870 1.5474546 1.7565336 0.5661385 0.2390457 -0.7071068 [6,] -0.8068715 1.4680505 -0.7942062 0.9225210 -0.7331431 1.2455047 -0.9561829 0.000 tmp3 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [1,] 1.1296201 0.000 -0.5207910 -0.8630035 -0.1913482 -0.1132277 -0.243975 -0.5976143 [2,] 0.1613743 0.000 -0.4817316 -0.2380699 -0.6944435 0.5661385 0.487950 -0.5976143 [3,] -1.2909944 -1.4680505 -0.4036130 -0.7737273 -0.7202433 -1.4719601 -1.707825 1.7928429 [4,] 1.1296201 -0.5872202 0.2994548 -0.5951748 0.5826446 -0.7925939 1.219875 -0.5976143 [5,] -0.3227486 0.5872202 1.9008870 1.5474546 1.7565336 0.5661385 0.487950 0.5976143 [6,] -0.8068715 1.4680505 -0.7942062 0.9225210 -0.7331431 1.2455047 -0.243975 -0.5976143 Here is my script: stud- function(x){ x-(x-mean(x))/sd(x) return (x) } tmp3-apply(tmp1,2,stud) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] read.table input array
Here is a way of creating a separate list of variable length vectors that you can use in your processing: # read into a dataframe x - read.table(textConnection(ABCTLengths + 14.00.001525878918c(1,2,3) + 14.00.001525878918c(1,2,6,7,8,3) + 14.00.001525878918c(1,2,3,1,2,3,4,5,6,7,9) + 14.00.001525878918c(1,2,3) + 11.00.001716613824c(1,1,4)), header=TRUE) # create a 'list' with the variable length vectors # assuming the the Lengths are legal R expressions using 'c' x$varList - lapply(x$Lengths, function(a) eval(parse(text=a))) x A B C T Lengths varList 1 1 4 0.001525879 18 c(1,2,3) 1, 2, 3 2 1 4 0.001525879 18 c(1,2,6,7,8,3)1, 2, 6, 7, 8, 3 3 1 4 0.001525879 18 c(1,2,3,1,2,3,4,5,6,7,9) 1, 2, 3, 1, 2, 3, 4, 5, 6, 7, 9 4 1 4 0.001525879 18 c(1,2,3) 1, 2, 3 5 1 1 0.001716614 24 c(1,1,4) 1, 1, 4 str(x) 'data.frame': 5 obs. of 6 variables: $ A : int 1 1 1 1 1 $ B : num 4 4 4 4 1 $ C : num 0.00153 0.00153 0.00153 0.00153 0.00172 $ T : int 18 18 18 18 24 $ Lengths: Factor w/ 4 levels c(1,1,4),c(1,2,3),..: 2 4 3 2 1 $ varList:List of 5 ..$ : num 1 2 3 ..$ : num 1 2 6 7 8 3 ..$ : num 1 2 3 1 2 3 4 5 6 7 ... ..$ : num 1 2 3 ..$ : num 1 1 4 On Fri, Jul 16, 2010 at 10:51 AM, Balpo ba...@gmx.net wrote: Hello to all! I am new with R and I need your help. I'm trying to read a file which contests are similar to this: A B C T Lengths 1 4.0 0.0015258789 18 c(1,2,3) 1 1.0 0.0017166138 24 c(1,1,4) So all the columns are numeric values, except Lengths, which is supposed to be an variable length array of integers. How can I make R read them as arrays of integers? Or otherwise, convert the character array to an array of integers. When I read the file, I do it like this t1 = read.table(file=paste(./borrar.dat,sep=), header=T, colClasses=c(numeric, numeric, numeric, numeric, array)) But the 5th column is treated as an array of characters, and when trying to convert it to another class of data, I either get two strings c(1,2,3) and c(1,1,4) or using a toRaw converter, I get the corresponding ASCII ¿? values. Should the input be modified in order to be able to read it as an array of integers? Thank you for your help. Balpo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Simple question regarding name of column headers
subset(miceTrainSample, select = -plD50) On Fri, Jul 16, 2010 at 11:22 AM, Addi Wei addi...@gmail.com wrote: names(miceTrainSample) [1] b_double KierA2 KierFlex Q_VSA_POS pID50 In the above code, how do I delete pID50 column to store the resulting object without indicating column 5. The code below does the trick, but I wish to delete the column by specifying -pID50 instead of 5. names(miceTrainSample)[-5] [1] b_double KierA2 KierFlex Q_VSA_POS -- View this message in context: http://r.789695.n4.nabble.com/Simple-question-regarding-name-of-column-headers-tp2291534p2291534.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] I need help making a data.fame comprised of selected columns of an original data frame.
Hi Steve, Thanks Here is a tiny subset of the data: dput(head(moreinfo, 40)) structure(list(m_id = c(171, 206, 206, 206, 206, 206, 206, 218, 224, 224, 227, 229, 229, 229, 229, 229, 229, 229, 229, 233, 233, 238, 238, 251, 251, 251, 251, 251, 251, 251, 251, 251, 251, 251, 251, 251, 251, 251, 251, 251), sale_date = c(2008-04-25 07:41:09, 2008-05-09 20:58:12, 2008-09-06 19:51:52, 2008-05-01 21:26:40, 2008-08-06 23:53:17, 2008-05-29 18:44:50, 2008-05-16 16:10:52, 2008-12-30 17:59:54, 2008-11-06 18:15:40, 2008-09-05 17:43:51, 2008-10-31 21:55:52, 2008-04-30 21:30:36, 2008-11-11 00:43:54, 2008-07-24 22:26:29, 2008-10-07 17:57:22, 2008-04-23 20:39:41, 2008-09-08 22:42:12, 2008-11-13 00:09:59, 2008-04-15 22:57:31, 2008-07-05 08:52:58, 2008-10-04 13:17:02, 2008-03-20 23:02:12, 2008-08-08 16:48:42, 2008-06-04 04:31:20, 2008-09-27 07:02:14, 2008-09-08 07:16:39, 2008-09-25 07:09:11, 2008-09-23 07:02:39, 2008-08-09 07:31:46, 2008-09-28 07:02:13, 2008-07-05 07:26:46, 2008-05-11 04:01:55, 2008-06-26 07:46:17, 2008-07-09 07:36:16, 2008-07-21 18:36:44, 2008-10-11 07:01:36, 2008-07-21 19:03:42, 2008-05-07 04:21:23, 2008-10-14 07:07:02, 2008-05-12 04:26:21 ), sale_year = c(2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L), sale_week = c(16L, 18L, 35L, 17L, 31L, 21L, 19L, 52L, 44L, 35L, 43L, 17L, 45L, 29L, 40L, 16L, 36L, 45L, 15L, 26L, 39L, 11L, 31L, 22L, 38L, 36L, 38L, 38L, 31L, 39L, 26L, 19L, 25L, 27L, 29L, 40L, 29L, 18L, 41L, 19L ), return_type = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), elapsed_time = c(1e-04, 1e-04, 3.0001, 4.0001, 21.0001, 5.0001, 24.0001, 1.0001, 8.0001, 1e-04, 1e-04, 8.0001, 14.0001, 55.0001, 35.0001, 1e-04, 1e-04, 4.0001, 1e-04, 2.0001, 5.0001, 1e-04, 52.0001, 4.0001, 28.0001, 49.0001, 34.0001, 72.0001, 5.0001, 53.0001, 128.0001, 8.0001, 2.0001, 55.0001, 1.0001, 12.0001, 46.0001, 30.0001, 12.0001, 12.0001)), .Names = c(m_id, sale_date, sale_year, sale_week, return_type, elapsed_time), row.names = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40), class = data.frame) The full dataset has almost 200,000 observations! That is why I hadn't posted the raw data. And m_id_default_res is even bigger because it includes all the original data along with the computed stats. Yes, the following line you pointed out has a typo: ndf$n[i] = m_id_default_res[i] It should have been ndf$n[i] = m_id_default_res$n[i] Correcting that makes the error go away, but at the end of the loop, ndf is said to have 0 columns and 0 rows. That I don't understand. But your statement (as corrected for the right source name) below does what I'd intended. ndf - m_id_default_res[, c('mid', 'estimate', 'sd', 'loglik', 'aic','bic', 'chisq', 'chisqpvalue', 'chisqdf')] Thanks Ted On Fri, Jul 16, 2010 at 12:04 PM, Steve Lianoglou mailinglist.honey...@gmail.com wrote: Hi, First: it's kind of hard to play along w/o some reproducible data. To that end, you can paste into an email the output of: dput(moreinfo) If there are lots of rows in `moreinfo`, just give us the first ~10-20 dput(head(moreinfo, 20)) Anyway: snip At this point, each row in m_id_default_res corresponds to one data.frame produced by fitdist. When I print it, I get the output I expected. However, I need to store only some of it into my DB. And then, because fitdist produces a data frame that includes a lot of info I don't need to store in the DB, I tried making a new data.frame containing only the info I need as follows: ndf = data.frame() for (i in 1:length(m_id_default_res[,1])) { ndf$mid[i] = m_id_default_res$mid[i] ndf$estimate[i] = m_id_default_res$estimate[i] ndf$sd[i] = m_id_default_res$sd[i] ndf$n[i] = m_id_default_res[i] ndf$loglik[i] = m_id_default_res$loglik[i] ndf$aic[i] = m_id_default_res$aic[i] ndf$bic[i] = m_id_default_res$bic[i] ndf$chisq[i] = m_id_default_res$chisq[i] ndf$chisqpvalue[i] = m_id_default_res$chisqpvalue[i] ndf$chisqdf[i] = m_id_default_res$chisqdf[i] } Forget the for loop. How about: ndf - m_id_default[, c('mid, 'estimate', 'sd', 'loglik', 'aic', 'bic', 'chisq', 'chisqpvalue', 'chisqdf') Having just written that, I see something strange in your for loop. Specifically this line: ndf$n[i] = m_id_default_res[i] m_id_default_res is a data.frame, right? Why don't you try to see what `m_id_default_res[1]` returns. I'm not sure that that's what your error message is coming from, but I foresee this to be a problem anyway, if I follow your build up code correctly. Hope that helps, -- Steve Lianoglou Graduate Student: Computational Systems
[R] setting up dates
I have several data sets, which begin early in 2002 and run until yesterday. They do not have observations every day. For example: xd1[1:10] 2002-02-25 2002-02-26 2002-02-28 2002-03-01 2002-03-04 2002-03-05 2002-03-07 7 8 1 9 12 3 5 2002-03-08 2002-03-11 2002-03-12 7 10 5 I want to set up zoo series which has every day from 2002-01-01 through yesterday. There should be zeros on the non appearing dates and the previously seen values on the appearing dates. I've tried union and merge, but they didn't seem to work correctly. Thank you in advance, Sincerely, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@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.
[R] Toggle between the various pages for multi-page figures
Hello, I am a new R user having transitioned over from S-plus recently. I have a question that is probably very trivial but I am having trouble finding a solution. In S-plus, graphic pages are created as tabs when multi-page figures are created. I have shown the R code for xpose.VPC (a function within library xpose4 for R) where I want the figure from each Strata (STRT) to displayed on a different page. When I run the code, the pages just zoom by and I was wondering if I could toggle between the various pages. I can only export the last of the 8 pages that are created with the code below (and I wish to export all 8 pages not just the last one): xpose.VPC (vpc.info=vpc1/vpc_results.csv, vpctab=vpc1/vpctab1, PI=NULL, by=STRT, PI.ci=area, PI.real=TRUE,type=n, PI.limits=c(0.05,0.95),*layout=c(1,1,8)*,xlb=Time (week),ylb=Concentration (ng/mL), scales = list(x = list(at=seq(0,3360,by=336) , labels=seq(0,20,by=2 )), y = list(at=log(c(.3,1,3,7.5,20,50,150)), labels=c(.3,1,3,7.5,20,50,150)) )) Please help, MNS [[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 skip a specific value when using apply() function to a matrix?
Hello, This does what you want. The simple solution is shorter but requires that there is only one value you wish to exclude (e.g., 0). The second works for any number of values you wish to exclude, but is subsequently longer. Also there is no need to create your own function to 'studentize', ?scale will do it for you (as well as simply center), this has the added benefit of not needing to convert the results of apply() back to a matrix. ##Create data## tmp1 - structure(c(15L, 13L, 10L, 15L, 12L, 11L, 7L, 7L, 2L, 5L, 9L, 12L, 9L, 10L, 12L, 30L, 71L, 2L, 49L, 56L, 50L, 52L, 76L, 69L, 60L, 21L, 19L, 120L, 211L, 18L, 3L, 4L, 1L, 2L, 4L, 5L, 2L, 3L, 0L, 4L, 3L, 2L, 0L, 0L, 2L, 0L, 1L, 0L), .Dim = c(6L, 8L)) tmp2 - tmp1 #for use in second solution ##Simple Solution## tmp1[tmp1 == 0] - NA #change 0s to NAs tmp1 - apply(tmp1, 2, scale) # 'studentize' tmp1[is.na(tmp1)] - 0 #change NAs back to 0s ##More General Solution## #Stores positions of 0s and 1s in origianl matrix positions - which(tmp2 == 0 | tmp2 == 1) #Store original values at 'positions' replacements - tmp2[positions] #Change these to NAs tmp2[positions] - NA #Scale using NAs tmp2 - apply(tmp2, 2, scale) #Now replace the NAs with the origianl values tmp2[positions] - replacements #Print to screen tmp1 tmp2 HTH, Josh On Fri, Jul 16, 2010 at 9:11 AM, Shuhua Zhan sz...@uoguelph.ca wrote: Hello Nikhil and Wu, Thank you very much for your reply! What I want is to calculate the student's score column-wise by ignoring the specific values such as zeros for example only using c(2,1) in column 8 in the tmp1 and generate tmp2. I changed the zeros to NAs and modified my stud fun to student as below. So I can ignore these specific values but can not put back the NAs to the right position in the resulted matrix. Any suggestions to put back NAs to their original positions in column 7 and 8 either to list tmp4 or matrix tmp5? tmp1[tmp1==0]-NA student- function(x){ x-x[!is.na(x)] x-(x-mean(x))/sd(x) return (x) } tmp4-apply(tmp1, 2, student) tmp4 [[1]] [1] 1.1296201 0.1613743 -1.2909944 1.1296201 -0.3227486 -0.8068715 [[2]] [1] 0.000 0.000 -1.4680505 -0.5872202 0.5872202 1.4680505 [[3]] [1] -0.5207910 -0.4817316 -0.4036130 0.2994548 1.9008870 -0.7942062 [[4]] [1] -0.8630035 -0.2380699 -0.7737273 -0.5951748 1.5474546 0.9225210 [[5]] [1] -0.1913482 -0.6944435 -0.7202433 0.5826446 1.7565336 -0.7331431 [[6]] [1] -0.1132277 0.5661385 -1.4719601 -0.7925939 0.5661385 1.2455047 [[7]] [1] -0.9561829 0.2390457 1.4342743 0.2390457 -0.9561829 [[8]] [1] 0.7071068 -0.7071068 tmp5- matrix(unlist(tmp4),nrow=6) tmp5 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [1,] 1.1296201 0.000 -0.5207910 -0.8630035 -0.1913482 -0.1132277 -0.9561829 -0.7071068 [2,] 0.1613743 0.000 -0.4817316 -0.2380699 -0.6944435 0.5661385 0.2390457 1.1296201 [3,] -1.2909944 -1.4680505 -0.4036130 -0.7737273 -0.7202433 -1.4719601 1.4342743 0.1613743 [4,] 1.1296201 -0.5872202 0.2994548 -0.5951748 0.5826446 -0.7925939 0.2390457 -1.2909944 [5,] -0.3227486 0.5872202 1.9008870 1.5474546 1.7565336 0.5661385 -0.9561829 1.1296201 [6,] -0.8068715 1.4680505 -0.7942062 0.9225210 -0.7331431 1.2455047 0.7071068 -0.3227486 Joshua - Original Message - From: Shuhua Zhan sz...@uoguelph.ca To: r-help@r-project.org Sent: Thursday, July 15, 2010 11:08:34 PM GMT -05:00 US/Canada Eastern Subject: [R] how to skip a specific value when using apply() function to a matrix? Hello R experts, I'd like to studentize a matrix (tmp1) by column using apply() function and skip some specific values such as zeros in the example below to tmp2 but not tmp3. I used the script below and only can get a matrix tmp3. Could you please help me to studentize the matrix (tmp1) without changing the zeros and generate a new matrix tmp2? Thanks, Joshua tmp1 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [1,] 15 7 9 49 60 3 2 0 [2,] 13 7 10 56 21 4 3 0 [3,] 10 2 12 50 19 1 0 2 [4,] 15 5 30 52 120 2 4 0 [5,] 12 9 71 76 211 4 3 1 [6,] 11 12 2 69 18 5 2 0 tmp2 [1,] 1.1296201 0.000 -0.5207910 -0.8630035 -0.1913482 -0.1132277 -0.9561829 0.000 [2,] 0.1613743 0.000 -0.4817316 -0.2380699 -0.6944435 0.5661385 0.2390457 0.000 [3,] -1.2909944 -1.4680505 -0.4036130 -0.7737273 -0.7202433 -1.4719601 0.000 0.7071068 [4,] 1.1296201 -0.5872202 0.2994548 -0.5951748 0.5826446 -0.7925939 1.4342743 0.000 [5,] -0.3227486 0.5872202 1.9008870 1.5474546 1.7565336 0.5661385 0.2390457 -0.7071068 [6,] -0.8068715 1.4680505 -0.7942062 0.9225210 -0.7331431 1.2455047 -0.9561829 0.000 tmp3 [,1] [,2] [,3] [,4] [,5] [,6] [,7]
Re: [R] package for rank ordered logit
My understanding is that polr will do ordered logit but I am not sure if it is also suited for rank ordered logit (or is there no such distinction) I am thinking of following two situations 1. there is an ordered response (say small,medium,large coffee) and each individual selects one of these options. the order is predetermined i.e we know which one is small, medium or large and interested in knowing which option is selected. in this case each choice is independent because different individuals choose them 2. an individual ranks some or all the options (say three different types of coffee). We do not know apriori what the order is beforehand - these ranks are dependent because the same individual selects them I am calling the 1st situation - ordered logit and 2nd situation - rank ordered logit. Are these equivalent situations and is polr suited for both? Suresh On Fri, Jul 16, 2010 at 11:41 AM, Tal Galili tal.gal...@gmail.com wrote: Did you try: library(MASS) ?polr ? Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- On Fri, Jul 16, 2010 at 6:15 PM, Suresh Singh singh@osu.edu wrote: Is there a package in R that can run rank-ordered logit? Thanks, Suresh __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to skip a specific value when using apply() function to a matrix?
Hi szhan, I think Joshua gives all you wants -- scale is a really good function. You can also make your own function work by setting an argument na.rm. tmp1[tmp1==0]-NA student- function(x){ x-(x-mean(x,na.rm=T))/sd(x,na.rm=T) return (x) } tmp4-apply(tmp1, 2, student) - A R learner. -- View this message in context: http://r.789695.n4.nabble.com/how-to-skip-a-specific-value-when-using-apply-function-to-a-matrix-tp2290898p2291678.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] setting up dates
On Fri, Jul 16, 2010 at 12:38 PM, Erin Hodgess erinm.hodg...@gmail.com wrote: I have several data sets, which begin early in 2002 and run until yesterday. They do not have observations every day. For example: xd1[1:10] 2002-02-25 2002-02-26 2002-02-28 2002-03-01 2002-03-04 2002-03-05 2002-03-07 7 8 1 9 12 3 5 2002-03-08 2002-03-11 2002-03-12 7 10 5 I want to set up zoo series which has every day from 2002-01-01 through yesterday. There should be zeros on the non appearing dates and the previously seen values on the appearing dates. I've tried union and merge, but they didn't seem to work correctly. Try this: z - zoo(c(7, 8, 1, 9, 12, 3, 5, 7, 10, 5), as.Date(c(2002-02-25, 2002-02-26, 2002-02-28, 2002-03-01, 2002-03-04, 2002-03-05, 2002-03-07, 2002-03-08, 2002-03-11, 2002-03-12))) dd - seq(start(z), end(z), day) merge(z, zoo(,dd), fill = 0) Please try displaying your data using dput to make it easier to copy it into R. For example, dput(z) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Access web content from within R
On 7/16/2010 6:00 AM, r-help-requ...@r-project.org wrote: Message: 5 Date: Thu, 15 Jul 2010 03:36:21 -0700 (PDT) From: Bart Joosenbartjoo...@hotmail.com To:r-help@r-project.org Subject: [R] Access web content from within R Message-ID:1279190181074-2289953.p...@n4.nabble.com Content-Type: text/plain; charset=us-ascii Hi, I have to search in an online db for registered manufacturers of raw materials. Can I use R for the following: I have a list with monograph numbers eg: l- c(198, 731,355) Now I want to make a dataframe, containing the monograph number and the information listed under COS: Certificate holder, certificate number, Status, Type Is this possible with R? kind regards Bart -- View this message in context: http://r.789695.n4.nabble.com/Access-web-content-from-within-R-tp2289953p2289953.html Sent from the R help mailing list archive at Nabble.com. You don't describe the format of the database. If it's HTML or XML, the scrapeR package may do the trick. Marsh Feldman __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 collapse categories or re-categorize variables?
I am sure this is a very basic question: I have 600,000 categorical variables in a data.frame - each of which is classified as 0, 1, or 2 What I would like to do is collapse 1 and 2 and leave 0 by itself, such that after re-categorizing 0 = 0; 1 = 1 and 2 = 1 --- in the end I only want 0 and 1 as categories for each of the variables. Also, if possible I would rather not create 600,000 new variables, if I can replace the existing variables with the new values that would be great! What would be the best way to do this? Thank you! -- Thanks, CC [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Help with Sink Function
iterations - 100 nvars - 4 combined - rbind(scaleMiceTrain, scaleMiceTest) reducedSample - combined reducedSample - subset(reducedSample, select = -pID50) reducedSample - subset(reducedSample, select = -id) for (i in 1:iterations) { miceSample - sample(combined[,-c(1,2)],nvars, replace=FALSE) miceSample$pID50 - combined$pID50 miceTestSample - miceSample[47:55,] miceTrainSample - miceSample[1:46,] fit.kknn - kknn(pID50~., miceTrainSample, miceTestSample) table(miceTestSample$pID50, fit.kknn$fit) (fit.train1 - train.kknn(pID50~., miceTrainSample, kmax=15, kernel=c(rectangular), distance=1)) predictedTrain - predict(fit.train1, miceTrainSample, miceTrainSample$pID50) pID50Train - miceTrainSample$pID50 lmTrain - lm(predictedTrain~pID50Train) slm - summary(lmTrain) str(slm) if (i == 1) { previousR2 -slm$r.squared sink(file=R2outputKKNN.txt, append=TRUE) previousR2 sink() } else if(i!=1) { currentR2 - slm$r.squared if (previousR2 currentR2) { currentR2 - previousR2 } if (previousR2 currentR2) { sink(file=R2outputKKNN.txt, append=TRUE) currentR2 sink() } } } In my code above, I can't get sink to work. In summary, I'm trying to write the first run's R2, which is called previousR2 to file, and then anytime currentR2 previousR2, I will write currentR2 to file. After running the code above, my file R2outputKKNN.txt is empty... However, just running the code below writes / works fine: previousR2 -slm$r.squared sink(file=R2outputKKNN.txt, append=TRUE) previousR2 sink() -- View this message in context: http://r.789695.n4.nabble.com/Help-with-Sink-Function-tp2291705p2291705.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] Help with Sink Function
This is not reproducible, and does not look minimal. You'll get better answers, and probably solve many issues on your own, if you construct small examples that illustrate the same problem you're having with your real data. Addi Wei wrote: iterations - 100 nvars - 4 combined - rbind(scaleMiceTrain, scaleMiceTest) reducedSample - combined reducedSample - subset(reducedSample, select = -pID50) reducedSample - subset(reducedSample, select = -id) for (i in 1:iterations) { miceSample - sample(combined[,-c(1,2)],nvars, replace=FALSE) miceSample$pID50 - combined$pID50 miceTestSample - miceSample[47:55,] miceTrainSample - miceSample[1:46,] fit.kknn - kknn(pID50~., miceTrainSample, miceTestSample) table(miceTestSample$pID50, fit.kknn$fit) (fit.train1 - train.kknn(pID50~., miceTrainSample, kmax=15, kernel=c(rectangular), distance=1)) predictedTrain - predict(fit.train1, miceTrainSample, miceTrainSample$pID50) pID50Train - miceTrainSample$pID50 lmTrain - lm(predictedTrain~pID50Train) slm - summary(lmTrain) str(slm) if (i == 1) { previousR2 -slm$r.squared sink(file=R2outputKKNN.txt, append=TRUE) previousR2 sink() } else if(i!=1) { currentR2 - slm$r.squared if (previousR2 currentR2) { currentR2 - previousR2 } if (previousR2 currentR2) { sink(file=R2outputKKNN.txt, append=TRUE) currentR2 sink() } } } In my code above, I can't get sink to work. In summary, I'm trying to write the first run's R2, which is called previousR2 to file, and then anytime currentR2 previousR2, I will write currentR2 to file. After running the code above, my file R2outputKKNN.txt is empty... However, just running the code below writes / works fine: previousR2 -slm$r.squared sink(file=R2outputKKNN.txt, append=TRUE) previousR2 sink() __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Help with Sink Function
Sorry about that. Still new to this... The code below should be reproducible.All R2 should just be 1, and I should write 1 to R2outputKKNN.txt 10 timesnothing is happening. Appreciate the efforts to help! for (i in 1:10) { adata = 1:5 bdata = 6:10 lm - lm(adata~bdata) slm - summary(lm) str(slm) if (i == 1) { previousR2 -slm$r.squared sink(file=R2outputKKNN.txt, append=TRUE) previousR2 sink() } else if(i!=1) { currentR2 - slm$r.squared if (previousR2 currentR2) { currentR2 - previousR2 } if (previousR2 currentR2) { sink(file=R2outputKKNN.txt, append=TRUE) currentR2 sink() } } } -- View this message in context: http://r.789695.n4.nabble.com/Help-with-Sink-Function-tp2291705p2291717.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 collapse categories or re-categorize variables?
Do you want to replace specific values of a data set? df - sample(c(0,1,2),600,replace=T) table(df) df[df==2]-1 table(df) - A R learner. -- View this message in context: http://r.789695.n4.nabble.com/how-to-collapse-categories-or-re-categorize-variables-tp2291704p2291727.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] Mathematica and R
Hi Albyn, Thank you very much for the suggestion. I managed to install Sage on Windows (via a Linux VM), but I cannot find any documentation on how to use R from Sage. Maybe I should use the web interface of Sage to avoid having to install R on the VM. Best regards, David On 10-07-14 10:24, Albyn Jones wrote: Take a look at Sage, which is an open source alternative. It already integrates R (http://www.sagemath.org) albyn Quoting David Bickel davidbickel.com+rh...@gmail.com: What are some effective ways to leverage the strengths of R and Mathematica for the analysis of a single data set? More specifically, are there any functions that can assist with any of the following? 1. Calling an R function from Mathematica. 2. Calling a Mathematica function from R. 3. Using XML or another reliable data format to pass vectors, matrices, and/or lists from one environment to the other. Any advice would be appreciated. David -- David R. Bickel, PhD Associate Professor Ottawa Institute of Systems Biology Biochem., Micro. and I. Department Mathematics and Statistics Department University of Ottawa 451 Smyth Road Ottawa, Ontario K1H 8M5 http://www.statomics.com Office Tel: (613) 562-5800 ext. 8670 Office Fax: (613) 562-5185 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Deleting a variable number of characters from a string
I have a text processing problem I'm hoping someone can help me solve. This issue it this. I have a character string in which I need to delete a variable number of characters from the string. The string itself contains the number of characters to be deleted. The number of characters to be deleted is proceeded by either a + or a -. A toy example: Suppose I have x-c(A-1CB-2GHX, *+11gAgggTgtgggH) x [1] A-1CB-2GHX *+11gAgggTgtgggH What I need as output is ABX *H I know I can use gsub to remove the control character and the number portion with gsub((\\-|\\+)([0-9]+), replacement=, x) However, I can't figure out how to delete the variable number of characters after the number portion of the string. Any ideas? In case this helps sessionInfo() R version 2.11.1 (2010-05-31) x86_64-pc-mingw32 locale: [1] LC_COLLATE=English_United States.1252 [2] LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United States.1252 Brian [[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] Creating Enumerated Variables
Hi: Hadley's solution is certainly preferred here due to its relative simplicity. I just wanted to correct an error from my earlier post. On Thu, Jul 15, 2010 at 2:08 PM, Dennis Murphy djmu...@gmail.com wrote: Hi: I sincerely hope there's an easier way, but one method to get this is as follows, with d as the data frame name of your test data: d - d[order(with(d, Age, School, rev(Grade))), ] Should be d - d[with(d, order(Age, School, rev(Grade))), ] d$Count - do.call(c, mapply(seq, 1, as.vector(t(with(d, table(Age, School)) d d ID Age School Grade Count 1 1 10 198 1 3 3 10 192 2 7 7 10 180 3 8 8 10 179 4 2 2 10 297 1 4 4 11 190 1 5 5 11 180 2 6 6 11 270 1 9 9 11 270 2 The code to get the count is a little convoluted: - first, find the frequency table of Age and School, transpose it and then unlist into a vector - use mapply to generate a sequence for each group from 1 up to its group count; mapply() is necessary to use the counts as a vector argument. This returns a list of sequences. - do.call() applies a function (here, c) to an input list, yielding the vector of groupwise indices we wanted. Basically, it flattens the list. This is what we assign to d$Count. Side note: I didn't get the correct ordering the first time, but I did the second time (2.11.1 64bit, Windows 7). And now we know why :) D. HTH, Dennis On Thu, Jul 15, 2010 at 7:45 AM, jdellava jdell...@vcu.edu wrote: Hi, I am trying to create a variable counting the number of individuals based on two variables. I am able to do it or one variable, but not two. In SAS I was able to sort by two variables and use a first. statement to create the counts based on both. Here is an example: What I have ID Age School Grade 1 10 1 98 2 10 2 97 3 10 1 92 4 11 1 90 5 11 1 80 6 11 2 70 7 10 1 80 8 10 1 79 9 11 2 70 What I need ID Age School Grade School Count 1 10 1 98 1 3 10 1 92 2 7 10 1 80 3 8 10 1 79 4 2 10 2 97 1 4 11 1 90 1 5 11 1 80 2 6 11 2 70 1 9 11 2 70 2 I want to create counts of individuals age 10 in school 1 then age 10 in school two (the what I need set) Anyway to do this? Thank you. -- View this message in context: http://r.789695.n4.nabble.com/Creating-Enumerated-Variables-tp2290262p2290262.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] threshold in plot
Hi: Here's a simple example (divide through by 10 for your case): x - 1:10 y - rnorm(10, x, s = 0.3) clr - ifelse(x = 5, 'red', 'blue') plot(x, y, col = clr) HTH, Dennis On Fri, Jul 16, 2010 at 6:08 AM, azam jaafari azamjaaf...@yahoo.com wrote: Hi I want to draw a plot from observed and predicted data and also shows threshold and data before threshold are identified with different color from data after threshold. Suppose: abserved data are 0 or 1 predicted data= 0 to 1 threshold=0.5 Thanks alot [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] Deleting a variable number of characters from a string
Hi Davis, Please try ??regex gsub((\\-|\\+)([0-9]+)(\\w*)(\\w), replacement=\\4, x) - A R learner. -- View this message in context: http://r.789695.n4.nabble.com/Deleting-a-variable-number-of-characters-from-a-string-tp2291754p2291797.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] Help with Sink Function
Your code between calls to sink() does not generate any output. Hence, nothing will be diverted to the file. To illustrate this point, consider for(i in 1:10) i This produces no output. However, for(i in 1:10) print(i) produces output as expected. -Matt On Fri, 2010-07-16 at 13:34 -0400, Addi Wei wrote: Sorry about that. Still new to this... The code below should be reproducible.All R2 should just be 1, and I should write 1 to R2outputKKNN.txt 10 timesnothing is happening. Appreciate the efforts to help! for (i in 1:10) { adata = 1:5 bdata = 6:10 lm - lm(adata~bdata) slm - summary(lm) str(slm) if (i == 1) { previousR2 -slm$r.squared sink(file=R2outputKKNN.txt, append=TRUE) previousR2 sink() } else if(i!=1) { currentR2 - slm$r.squared if (previousR2 currentR2) { currentR2 - previousR2 } if (previousR2 currentR2) { sink(file=R2outputKKNN.txt, append=TRUE) currentR2 sink() } } } -- Matthew S. Shotwell Graduate Student Division of Biostatistics and Epidemiology Medical University of South Carolina http://biostatmatt.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] Access web content from within R
Marsh, you are absolutely right, I forget the link to the db. Actually its a webpage for each monograph number: http://extranet.pheur.org/4DLink1/4DCGI/Web_View/mono/198 http://extranet.pheur.org/4DLink1/4DCGI/Web_View/mono/731 ... As I have a list with the numbers of interest (l- c(198, 731,355)), I can paste the webadress together with the numbers, but then I need to substract the COS info. Kind regards Bart -- View this message in context: http://r.789695.n4.nabble.com/Access-web-content-from-within-R-tp2289953p2291839.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 collapse categories or re-categorize variables?
Hi: See ? levels. Here's a toy example: x - factor(sample(0:2, 10, replace = TRUE)) x [1] 1 2 1 0 2 2 2 2 2 1 Levels: 0 1 2 levels(x) - c(0, 1, 1)# Change level 2 to 1 x [1] 1 1 1 0 1 1 1 1 1 1 Levels: 0 1 HTH, Dennis On Fri, Jul 16, 2010 at 10:18 AM, CC turtysm...@gmail.com wrote: I am sure this is a very basic question: I have 600,000 categorical variables in a data.frame - each of which is classified as 0, 1, or 2 What I would like to do is collapse 1 and 2 and leave 0 by itself, such that after re-categorizing 0 = 0; 1 = 1 and 2 = 1 --- in the end I only want 0 and 1 as categories for each of the variables. Also, if possible I would rather not create 600,000 new variables, if I can replace the existing variables with the new values that would be great! What would be the best way to do this? Thank you! -- Thanks, CC [[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] Elementary question about computing confidence intervals.
I would have thought this to be relatively elementary, but I can't find it mentioned in any of my stats texts. Please consider the following: library(fitdistrplus) fp = fitdist(y,exp); rate = fp$estimate; sd = fp$sd fOneWeek = exp(-rate*7); #fraction that happens within a week - y is measured in days fr = exp(-rate*dt); #fraction remaining - dt = elapsed time from time of sample to present fh = 1 - fr; # fraction that occurred from time of sample to present # assume n = total number that have happened from time of sample to present T = n / fh # t is the total number at y = 0 NR = fr * T NNW = NR * (1 - fOneWeek) (If you wanted to run this, just populate y with random numbers from an exponential distribution.) What I show here simply extracts an estimate and standard deviation from the data.frame returned by fitdist, and tries to compute a number of integrals. What I need is the number of events that can be expected next week, next month, and from now to the end of time. Unless I have gone senile in my old age, I have the integrals correct. Please correct me if I missed something. But what I need help (to refresh my memory - I used to know this way back in the stone age) to compute the confidence intervals for each of these integrals. So I don't bother anyone with similar elementary questions, what web resource exists that defines confidence intervals for such integrals for arbitrary distributions? or does such a resource exist? Thanks Ted [[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 collapse categories or re-categorize variables?
Hi, On Fri, Jul 16, 2010 at 5:18 PM, CC turtysm...@gmail.com wrote: I am sure this is a very basic question: I have 600,000 categorical variables in a data.frame - each of which is classified as 0, 1, or 2 What I would like to do is collapse 1 and 2 and leave 0 by itself, such that after re-categorizing 0 = 0; 1 = 1 and 2 = 1 --- in the end I only want 0 and 1 as categories for each of the variables. Something like this should work for (i in names(dat)) { dat[, i] - factor(dat[, i], levels = c(0, 1, 2), labels = c(0, 1, 1)) } -Ista Also, if possible I would rather not create 600,000 new variables, if I can replace the existing variables with the new values that would be great! What would be the best way to do this? Thank you! -- Thanks, CC [[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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Dot Plot with Confidence Limits
On Wed, Jul 14, 2010 at 10:12 AM, Neil123 neil.wh...@plants.ox.ac.uk wrote: Hi, I have the following dataset and I would like to create a dotplot with confidence limits: CAT1 CAT2 MEAN Lower Upper 1 1 1 0.619 0.392 0.845 2 1 10 1.774 1.030 2.518 3 1 100 7.700 4.810 10.586 4 1 1000 45.536 23.612 67.392 5 2 1 0.500 0.244 0.755 6 2 10 1.725 1.109 2.341 7 2 100 15.200 10.924 19.473 8 2 1000 88.200 48.030 128.369 I need the data grouped by the two categories (independent variables CAT1 CAT2). Each row would be a separate dot, and colour-coded by CAT1. I have been able to create a dotplot with the data of just one of the CAT1's, but not both together in the same graph... I am not sure what your question is. It would probably help to have reproducible code showing the progress you have made so far. -Deepayan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] invalid factor level, NAs generated
I've seen a few threads about this, but none that seem to answer my problem I have a list of .txt files in a directory that I am reading into R and row binding together. I am using the following code to do so: # Directory where files are found my.txt.file.directory - C:/Jared/Data/Kenya/Wildebeest/Tracking_Data names.of.txt.files - list.files(my.txt.file.directory,pattern=all_data,ignore.case=TRUE, full.names=TRUE) # Print names that meet criteria in directory names.of.txt.files # The names.of.txt.files will be a vector with the names of all the txt files # Dataset will contain all the data in the directory wildebeest - NULL # Run loop for (i in 1:length(names.of.txt.files)) { dat - read.table(names.of.txt.files[i],header=FALSE) # Row bind all data together into a file called 'wildebeest' wildebeest - rbind.data.frame(wildebeest,dat) rm(dat) } When I run this script, I get an error such as: 18: In `[-.factor`(`*tmp*`, ri, value = c(1714.36, 1711.27, ... : invalid factor level, NAs generated I think I have identified the problem such that when I identify the structure of some of the files that I am reading in, columns are labeled as Factors. In other files, the same columns are labeled as numeric values. Is there a way to assign the data structure to these columns in the dataframe as they are being read in? Any other suggestions to why I am getting this error is appreciated. Jared [[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] invalid factor level, NAs generated
snip I think I have identified the problem such that when I identify the structure of some of the files that I am reading in, columns are labeled as Factors. In other files, the same columns are labeled as numeric values. Is there a way to assign the data structure to these columns in the dataframe as they are being read in? Any other suggestions to why I am getting this error is appreciated. Yes, as ?read.table describes, see the colClasses argument. However, you should investigate why read.table wants to treat these particular columns as factors. If they are indeed simply consisting of all numeric values, there shouldn't be a problem. The fact that they are coming out as factors raises a flag to me ... __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] invalid factor level, NAs generated
Hi Jared: Is it possible you're using read.table with variable names in line 1 but not using header = TRUE as an argument? HTH, Dennis On Fri, Jul 16, 2010 at 12:41 PM, Erik Iverson er...@ccbr.umn.edu wrote: snip I think I have identified the problem such that when I identify the structure of some of the files that I am reading in, columns are labeled as Factors. In other files, the same columns are labeled as numeric values. Is there a way to assign the data structure to these columns in the dataframe as they are being read in? Any other suggestions to why I am getting this error is appreciated. Yes, as ?read.table describes, see the colClasses argument. However, you should investigate why read.table wants to treat these particular columns as factors. If they are indeed simply consisting of all numeric values, there shouldn't be a problem. The fact that they are coming out as factors raises a flag to me ... __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Sage and R (was: Mathematica and R)
Dear David, I managed to install Sage on Windows (via a Linux VM), but I cannot find any documentation on how to use R from Sage. Maybe I should use the web interface of Sage to avoid having to install R on the VM. In the Sage command line, you can type sage: r? to get some very basic info, and sage: r.[tab] to get various commands. This part of the interface still needs some work, though it suffices (particularly via r.eval()) for many needs. You do NOT need to reinstall R; a full copy of R (with all recommended packages) is in any recent Sage. However, based on your earlier emails in the thread, you may want to start Sage, and then type sage: notebook() to launch the web server on your own computer, from which you can get a Mma-style worksheet and do all R computations in there, by simply selecting 'r' from the drop-down menu at the top which would currently read 'sage', or by typing %r at the beginning of each cell you want to use R in. You are, however, right that there is very little easy-to-find documentation on how to use R within Sage, and we VERY much welcome improvements on this front. The worksheets http://prep.sagenb.org/home/pub/34/ and http://sagenb.org/home/pub/2232/ might have a few tidbits for you, and the thread at http://groups.google.com/group/sage-support/browse_thread/thread/b8411dfebdb54406/0bca74c09bd4145a?lnk=gstq=r+integration#0bca74c09bd4145a may as well. In particular, if anyone wants to help improve this (though again, quite a bit already works seamlessly), you may be interested in the following talk (mine) at useR! 2010 next week: http://user2010.org/abstracts/Crisman.pdf We definitely need experts, and also really crave feedback on how Sage can best be of use to the R community (why R is useful to Sage should be obvious). Karl-Dieter Crisman __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] make an model object (e.g. nlme) available in a user defined function (xyplot related)
On Mon, Jul 12, 2010 at 8:16 AM, Jun Shen jun.shen...@gmail.com wrote: Dear Deepayan, Thank you for taking the time to look into this issue. I have a data object called Data, please find it at the end of the message. Then I can run the code below separately in the console. [...] Then I have my real function as follows: If I run the code as, compare.curves(Data=Data) The analytical part is working but not the plotting part (Error using packet 1, object 'model' not found) I don't have much to help you, but the problem is not in lattice, but in formula.nlme. The following modification of your function also fails: compare.curves - function(curve='ascending', Data=stop('A data object must be specified'), parameter='EC50',random.pdDiag=FALSE, start.values=c(Emax=100,E0=1,EC50=50,gamma=2),...) { mymodel=as.formula('RESP ~ E0+(Emax-E0)*CP**gamma/(EC50**gamma+CP**gamma)') mod.nlme-nlme(model=mymodel,data=Data,method='REML', fixed=Emax+E0+EC50+gamma~1, random= if (length(parameter)==1) eval(substitute(variable~1,list(variable=as.name(parameter else { variable-as.name(parameter[1]) for (i in 2:length(parameter)) variable- paste(variable,'+',as.name(parameter[i])) formula-as.formula(paste(variable,'~1')) if (random.pdDiag) list(pdDiag(formula)) else formula }, groups=~ID, start=list(fixed=start.values) ) formula(mod.nlme) } -Deepayan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Deleting a variable number of characters from a string
On Fri, Jul 16, 2010 at 1:59 PM, Davis, Brian brian.da...@uth.tmc.edu wrote: I have a text processing problem I'm hoping someone can help me solve. This issue it this. I have a character string in which I need to delete a variable number of characters from the string. The string itself contains the number of characters to be deleted. The number of characters to be deleted is proceeded by either a + or a -. A toy example: Suppose I have x-c(A-1CB-2GHX, *+11gAgggTgtgggH) x [1] A-1CB-2GHX *+11gAgggTgtgggH What I need as output is ABX *H I know I can use gsub to remove the control character and the number portion with gsub((\\-|\\+)([0-9]+), replacement=, x) However, I can't figure out how to delete the variable number of characters after the number portion of the string. Using gsubfn in the gsubfn package we match - the - or + via [-+], - the digits via \\d+ and - the remaining characters via [^-+]* parenthesizing the digits and remaining characters so that they form back references which are passed to the function as args 1 and 2 respectively. gsubfn supports a formula notation for functions and the specified function using that formula notation has arguments d and s and function body which strips the characters and returns the rest to be substituted back in: library(gsubfn) gsubfn([-+](\\d+)([^-+]*), d + s ~ substring(s, as.numeric(d) + 1), x) [1] ABX *H See http://gsubfn.googlecode.com for more. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to skip a specific value when using apply() function to a matrix?
Hello Joshua and Wu, Thank you for your excellent solutions. Joshua - Original Message - From: Joshua Wiley jwiley.ps...@gmail.com To: Shuhua Zhan sz...@uoguelph.ca Cc: r-help@r-project.org Sent: Friday, July 16, 2010 12:39:22 PM GMT -05:00 US/Canada Eastern Subject: Re: [R] how to skip a specific value when using apply() function to a matrix? Hello, This does what you want. The simple solution is shorter but requires that there is only one value you wish to exclude (e.g., 0). The second works for any number of values you wish to exclude, but is subsequently longer. Also there is no need to create your own function to 'studentize', ?scale will do it for you (as well as simply center), this has the added benefit of not needing to convert the results of apply() back to a matrix. ##Create data## tmp1 - structure(c(15L, 13L, 10L, 15L, 12L, 11L, 7L, 7L, 2L, 5L, 9L, 12L, 9L, 10L, 12L, 30L, 71L, 2L, 49L, 56L, 50L, 52L, 76L, 69L, 60L, 21L, 19L, 120L, 211L, 18L, 3L, 4L, 1L, 2L, 4L, 5L, 2L, 3L, 0L, 4L, 3L, 2L, 0L, 0L, 2L, 0L, 1L, 0L), .Dim = c(6L, 8L)) tmp2 - tmp1 #for use in second solution ##Simple Solution## tmp1[tmp1 == 0] - NA #change 0s to NAs tmp1 - apply(tmp1, 2, scale) # 'studentize' tmp1[is.na(tmp1)] - 0 #change NAs back to 0s ##More General Solution## #Stores positions of 0s and 1s in origianl matrix positions - which(tmp2 == 0 | tmp2 == 1) #Store original values at 'positions' replacements - tmp2[positions] #Change these to NAs tmp2[positions] - NA #Scale using NAs tmp2 - apply(tmp2, 2, scale) #Now replace the NAs with the origianl values tmp2[positions] - replacements #Print to screen tmp1 tmp2 HTH, Josh On Fri, Jul 16, 2010 at 9:11 AM, Shuhua Zhan sz...@uoguelph.ca wrote: Hello Nikhil and Wu, Thank you very much for your reply! What I want is to calculate the student's score column-wise by ignoring the specific values such as zeros for example only using c(2,1) in column 8 in the tmp1 and generate tmp2. I changed the zeros to NAs and modified my stud fun to student as below. So I can ignore these specific values but can not put back the NAs to the right position in the resulted matrix. Any suggestions to put back NAs to their original positions in column 7 and 8 either to list tmp4 or matrix tmp5? tmp1[tmp1==0]-NA student- function(x){ x-x[!is.na(x)] x-(x-mean(x))/sd(x) return (x) } tmp4-apply(tmp1, 2, student) tmp4 [[1]] [1] 1.1296201 0.1613743 -1.2909944 1.1296201 -0.3227486 -0.8068715 [[2]] [1] 0.000 0.000 -1.4680505 -0.5872202 0.5872202 1.4680505 [[3]] [1] -0.5207910 -0.4817316 -0.4036130 0.2994548 1.9008870 -0.7942062 [[4]] [1] -0.8630035 -0.2380699 -0.7737273 -0.5951748 1.5474546 0.9225210 [[5]] [1] -0.1913482 -0.6944435 -0.7202433 0.5826446 1.7565336 -0.7331431 [[6]] [1] -0.1132277 0.5661385 -1.4719601 -0.7925939 0.5661385 1.2455047 [[7]] [1] -0.9561829 0.2390457 1.4342743 0.2390457 -0.9561829 [[8]] [1] 0.7071068 -0.7071068 tmp5- matrix(unlist(tmp4),nrow=6) tmp5 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [1,] 1.1296201 0.000 -0.5207910 -0.8630035 -0.1913482 -0.1132277 -0.9561829 -0.7071068 [2,] 0.1613743 0.000 -0.4817316 -0.2380699 -0.6944435 0.5661385 0.2390457 1.1296201 [3,] -1.2909944 -1.4680505 -0.4036130 -0.7737273 -0.7202433 -1.4719601 1.4342743 0.1613743 [4,] 1.1296201 -0.5872202 0.2994548 -0.5951748 0.5826446 -0.7925939 0.2390457 -1.2909944 [5,] -0.3227486 0.5872202 1.9008870 1.5474546 1.7565336 0.5661385 -0.9561829 1.1296201 [6,] -0.8068715 1.4680505 -0.7942062 0.9225210 -0.7331431 1.2455047 0.7071068 -0.3227486 Joshua - Original Message - From: Shuhua Zhan sz...@uoguelph.ca To: r-help@r-project.org Sent: Thursday, July 15, 2010 11:08:34 PM GMT -05:00 US/Canada Eastern Subject: [R] how to skip a specific value when using apply() function to a matrix? Hello R experts, I'd like to studentize a matrix (tmp1) by column using apply() function and skip some specific values such as zeros in the example below to tmp2 but not tmp3. I used the script below and only can get a matrix tmp3. Could you please help me to studentize the matrix (tmp1) without changing the zeros and generate a new matrix tmp2? Thanks, Joshua tmp1 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [1,] 15 7 9 49 60 3 2 0 [2,] 13 7 10 56 21 4 3 0 [3,] 10 2 12 50 19 1 0 2 [4,] 15 5 30 52 120 2 4 0 [5,] 12 9 71 76 211 4 3 1 [6,] 11 12 2 69 18 5 2 0 tmp2 [1,] 1.1296201 0.000 -0.5207910 -0.8630035 -0.1913482 -0.1132277 -0.9561829 0.000 [2,] 0.1613743 0.000 -0.4817316 -0.2380699 -0.6944435 0.5661385 0.2390457 0.000 [3,] -1.2909944 -1.4680505 -0.4036130 -0.7737273 -0.7202433 -1.4719601 0.000 0.7071068 [4,] 1.1296201
Re: [R] Access web content from within R
Try this: library(XML) readHTMLTable(http://extranet.pheur.org/4DLink1/4DCGI/Web_View/mono/198;, which = 5) On Fri, Jul 16, 2010 at 4:08 PM, Bart Joosen bartjoo...@hotmail.com wrote: Marsh, you are absolutely right, I forget the link to the db. Actually its a webpage for each monograph number: http://extranet.pheur.org/4DLink1/4DCGI/Web_View/mono/198 http://extranet.pheur.org/4DLink1/4DCGI/Web_View/mono/731 ... As I have a list with the numbers of interest (l- c(198, 731,355)), I can paste the webadress together with the numbers, but then I need to substract the COS info. Kind regards Bart -- View this message in context: http://r.789695.n4.nabble.com/Access-web-content-from-within-R-tp2289953p2291839.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. -- 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.
[R] sqldf modify table
Hi - I am something of a newbie and am a little perplexed. When (trying to) modify a table I issue the following commands with subsequent errors sqldf(alter table Korea drop column code, dbname = mydb) error in statement: near drop: syntax error or sqldf(alter table Korea rename column hyr to hyrI, dbname = mydb) error in statement: near column: syntax error These are simple commands - am I missing something obvious? I can retrieve data from them, and retrieve their table_info Thanks Peter -- View this message in context: http://r.789695.n4.nabble.com/sqldf-modify-table-tp2291804p2291804.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] Mixed Conditional Logit with nested data
Hello Everyone,  This is my first attempt to do something in R. As a precursor to a Willingness to Pay analysis, I want to conduct a Mixed Conditional Logit analysis but am unsure how to proceed because of some nesting within my data.  Below is some data and code that illustrate what Iâm trying to do. The data are based on responses to a conjoint survey obtained during pilot testing. In the survey, cancer patients are asked to complete several discrete choice tasks. In each task, the patient indicates whether they prefer treatment A or treatment B. The attributes of treatment A and treatment B generally vary from one task to the next. The data also contain some of the predictors that that are presumed to influence patient choices (chance of side effects, duration of side effects, severity of side effects).  The mclogit package seems like a possible avenue for conducting my analysis. The code below appears to be properly specified and produces some intuitive results. Even with only 4 respondents, there appears to be a tendency for patients to prefer treatments with a low chance of side effects, a short duration of side effects, and a low severity of side effects.  The only problem is that the current setup doesn't seem to address the fact that I have multiple discrete choice tasks within each respondent. It seems to me that knowing which option person 1 chose in task 1 might also indicate something about their responses in the other conjoint tasks and that my model doesn't account for this lack of statistical independence.  So I'm wondering if there is any way to perform my analysis while taking this non-independence into account.  Any assistance that people can render will be most appreciated.  Thanks,  Paul  wtp_string - Subject,Task,Option,selected,chance_low,chance_medium,chance_high,duration_short,duration_medium,duration_long,severity_low,severity_medium,severity_high 1,1,A,1,0,0,1,1,0,0,1,0,0 1,1,B,0,0,1,0,0,0,1,0,0,1 1,2,A,1,1,0,0,1,0,0,0,0,1 1,2,B,0,0,1,0,0,1,0,0,1,0 1,3,A,0,0,0,1,0,1,0,1,0,0 1,3,B,1,1,0,0,0,0,1,0,1,0 1,4,A,1,0,0,1,0,1,0,1,0,0 1,4,B,0,0,1,0,0,0,1,0,0,1 1,5,A,1,0,1,0,1,0,0,1,0,0 1,5,B,0,1,0,0,0,1,0,0,1,0 1,6,A,1,1,0,0,1,0,0,0,0,1 1,6,B,0,0,0,1,0,0,1,0,1,0 1,7,A,1,1,0,0,0,0,1,1,0,0 1,7,B,0,0,1,0,0,1,0,0,0,1 1,8,A,1,0,0,1,1,0,0,0,1,0 1,8,B,0,0,1,0,0,1,0,0,0,1 1,9,A,1,0,1,0,1,0,0,1,0,0 1,9,B,0,0,0,1,0,1,0,0,1,0 1,10,A,1,1,0,0,1,0,0,0,1,0 1,10,B,0,0,0,1,0,0,1,1,0,0 1,11,A,1,0,1,0,0,1,0,1,0,0 1,11,B,0,0,0,1,1,0,0,0,0,1 1,12,A,1,1,0,0,0,1,0,1,0,0 1,12,B,0,0,1,0,0,0,1,0,1,0 1,13,A,0,0,0,1,0,0,1,0,1,0 1,13,B,1,1,0,0,0,1,0,0,0,1 1,14,A,0,0,0,1,0,0,1,0,0,1 1,14,B,1,0,1,0,1,0,0,1,0,0 1,15,A,1,1,0,0,1,0,0,0,1,0 1,15,B,0,0,0,1,0,1,0,0,0,1 1,16,A,1,1,0,0,0,0,1,1,0,0 1,16,B,0,0,1,0,0,1,0,0,1,0 1,17,A,1,0,1,0,1,0,0,0,1,0 1,17,B,0,0,0,1,0,0,1,1,0,0 1,18,A,1,1,0,0,1,0,0,1,0,0 1,18,B,0,0,0,1,0,0,1,0,0,1 1,19,A,1,1,0,0,1,0,0,0,0,1 1,19,B,0,0,0,1,0,1,0,0,1,0 1,20,A,0,0,0,1,0,0,1,0,0,1 1,20,B,1,0,1,0,1,0,0,1,0,0 1,21,A,1,1,0,0,0,1,0,1,0,0 1,21,B,0,0,1,0,0,0,1,0,0,1 1,22,A,1,0,0,1,1,0,0,1,0,0 1,22,B,0,1,0,0,0,1,0,0,1,0 1,23,A,0,1,0,0,0,1,0,0,0,1 1,23,B,1,0,1,0,0,0,1,0,1,0 1,24,A,1,0,0,1,1,0,0,0,1,0 1,24,B,0,0,1,0,0,0,1,1,0,0 1,25,A,0,1,0,0,0,0,1,1,0,0 1,25,B,1,0,1,0,1,0,0,0,0,1 2,1,A,0,0,0,1,1,0,0,1,0,0 2,1,B,1,0,1,0,0,0,1,0,0,1 2,2,A,0,1,0,0,1,0,0,0,0,1 2,2,B,1,0,1,0,0,1,0,0,1,0 2,3,A,1,0,0,1,0,1,0,1,0,0 2,3,B,0,1,0,0,0,0,1,0,1,0 2,4,A,0,0,0,1,0,1,0,1,0,0 2,4,B,1,0,1,0,0,0,1,0,0,1 2,5,A,1,0,1,0,1,0,0,1,0,0 2,5,B,0,1,0,0,0,1,0,0,1,0 2,6,A,1,1,0,0,1,0,0,0,0,1 2,6,B,0,0,0,1,0,0,1,0,1,0 2,7,A,1,1,0,0,0,0,1,1,0,0 2,7,B,0,0,1,0,0,1,0,0,0,1 2,8,A,1,0,0,1,1,0,0,0,1,0 2,8,B,0,0,1,0,0,1,0,0,0,1 2,9,A,0,0,1,0,1,0,0,1,0,0 2,9,B,1,0,0,1,0,1,0,0,1,0 2,10,A,1,1,0,0,1,0,0,0,1,0 2,10,B,0,0,0,1,0,0,1,1,0,0 2,11,A,1,0,1,0,0,1,0,1,0,0 2,11,B,0,0,0,1,1,0,0,0,0,1 2,12,A,1,1,0,0,0,1,0,1,0,0 2,12,B,0,0,1,0,0,0,1,0,1,0 2,13,A,0,0,0,1,0,0,1,0,1,0 2,13,B,1,1,0,0,0,1,0,0,0,1 2,14,A,1,0,0,1,0,0,1,0,0,1 2,14,B,0,0,1,0,1,0,0,1,0,0 2,15,A,1,1,0,0,1,0,0,0,1,0 2,15,B,0,0,0,1,0,1,0,0,0,1 2,16,A,0,1,0,0,0,0,1,1,0,0 2,16,B,1,0,1,0,0,1,0,0,1,0 2,17,A,0,0,1,0,1,0,0,0,1,0 2,17,B,1,0,0,1,0,0,1,1,0,0 2,18,A,0,1,0,0,1,0,0,1,0,0 2,18,B,1,0,0,1,0,0,1,0,0,1 2,19,A,1,1,0,0,1,0,0,0,0,1 2,19,B,0,0,0,1,0,1,0,0,1,0 2,20,A,0,0,0,1,0,0,1,0,0,1 2,20,B,1,0,1,0,1,0,0,1,0,0 2,21,A,0,1,0,0,0,1,0,1,0,0 2,21,B,1,0,1,0,0,0,1,0,0,1 2,22,A,1,0,0,1,1,0,0,1,0,0 2,22,B,0,1,0,0,0,1,0,0,1,0 2,23,A,0,1,0,0,0,1,0,0,0,1 2,23,B,1,0,1,0,0,0,1,0,1,0 2,24,A,1,0,0,1,1,0,0,0,1,0 2,24,B,0,0,1,0,0,0,1,1,0,0 2,25,A,1,1,0,0,0,0,1,1,0,0 2,25,B,0,0,1,0,1,0,0,0,0,1 3,1,A,1,0,0,1,1,0,0,1,0,0 3,1,B,0,0,1,0,0,0,1,0,0,1 3,2,A,0,1,0,0,1,0,0,0,0,1 3,2,B,1,0,1,0,0,1,0,0,1,0 3,3,A,1,0,0,1,0,1,0,1,0,0 3,3,B,0,1,0,0,0,0,1,0,1,0 3,4,A,1,0,0,1,0,1,0,1,0,0 3,4,B,0,0,1,0,0,0,1,0,0,1 3,5,A,0,0,1,0,1,0,0,1,0,0 3,5,B,1,1,0,0,0,1,0,0,1,0 3,6,A,0,1,0,0,1,0,0,0,0,1 3,6,B,1,0,0,1,0,0,1,0,1,0 3,7,A,1,1,0,0,0,0,1,1,0,0 3,7,B,0,0,1,0,0,1,0,0,0,1
[R] a issue about the qutation mark?
Following is a function that I wrote (It is working well). It's a simple one, nothing complicated. The only question that I have is a qutation mark issue, I guess. # funcname - function(trait.file){#line1 setwd('/root/subroot') # line 2 load('imge.RData')# line3 imge - imge[,-c(3)] # line4 imge - imge[complete.cases(imge),] # line5 trait- read.csv(trait.file) # line6 ngenes - nrow(imge) # line7 nsnp - nrow(trait) #line 8 for(i in 1:ngenes) { for(j in 1:nsnp) { if(imge$d1[i]==trait$d1[j] imge$d2[i]==trait$d2[j]) trait$imgene2[j] - imge$Gene[i] else trait$imgene2[j] - NA } } return(trait) } hypertension - funcname(folder/hyper.csv) # last line ## So, as we all know, when using read.csv, we need to use qutation mark out side the filename which we wanna read in. At first, for line 8, I wrote: read.csv(trait.file), at last line, I wrote: funcname(folder/hyper.csv), but it did not work in this way. Unless I changed the code to the current one that I showed above, I couldn't get what I want. So, to be straightforward, I will show the difference: 1) the code not working: read.csv(trait.file) #line 8 funcname(folder/hyper.csv) #last line 2) the code working: read.csv(trait.file) # line 8 funcname(folder/hyper.csv) # last line anyone can tell me why is the difference? thank you, karena -- View this message in context: http://r.789695.n4.nabble.com/a-issue-about-the-qutation-mark-tp2291537p2291537.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] Nested if help
Hello, I am trying to find a direct way to write a nested if of sorts to find data for a specific time range for a specific day (across a range of days) and have exhausted my abilities with the manuals I have at hand. I have a good deal of data of this approximate form: day time price 1 1am5 1 2am7 1 3am 9 1 4am 12 2 1am5 2 2am7 2 3am 9 2 4am 12 etc I am reading from a file I loaded and using a while statement. I then am trying the direct approach of writing the if: if(time=2am time =4am) { #specifying desired time range--since a while loop format I don't think date is necessary and if it is I don't know how to say this? time1-time #sets first time in desired interval to base time px1-px #sets first price in desired interval to base price if(pxpx1){ #nested if stmt to see if subsequent times are higher than base, thus replacing base with new max (I am seeking max in the time period in this instance) px2-px #px2 would be the new higher maximum time2-time #time associated with px2 px3-px+1 #price immediately following max time3-time+1 #time immed. follows max out-(cur_date,px2,time2,px3,time3) #output the high price/time and the immediately following price/time cat(out,\n)} This code however, does nothing. Any help would be apreciated. The manuals seem to only take one so far. Thanks, George [[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] Troubles with DBI's dbWriteTable in RMySQL
I am feeling rather dumb right now. I created what I thought was a data.frame as follows: aaa - lapply(split(moreinfo,list(moreinfo$m_id),drop = TRUE), fun_m_id) m_id_default_res - do.call(rbind, aaa) print(==) m_id_default_res print(==) ndf - m_id_default_res[, c('mid', 'estimate', 'sd', 'loglik', 'aic','bic', 'chisq', 'chisqpvalue', 'chisqdf')] ndf The data in NDF is perfect, exactly what I expected when I print the contents as shown in the last statement above. On the asumption tha tthat is a data frame, I tried dbWriteTable(con,test1,ndf); But I received the following error: Error in function (classes, fdef, mtable) : unable to find an inherited method for function dbWriteTable, for signature MySQLConnection, character, matrix Then, on the assumption it is trivial to convert a matrix into a data.frame, i tried: dbWriteTable(con,test2,as.data.frame(ndf)); But this produced the following error: Error in write.table(x, file, nrow(x), p, rnames, sep, eol, na, dec, as.integer(quote), : unimplemented type 'list' in 'EncodeElement' The silly, and frustrating, thing is that I used dbWriteTable before, and that worked adequately. But that was with a simple data frame (within a for loop, element by element - res$var[[i]] = expression), not the result of do.call(rbind(...)) The principle limitation I saw in my previous use of dbWriteTable is that all fields are given the type 'TEXT', and that it insists on creating a new table. What I'd prefer is a kind of bulk interset that just makes extra records for an existing table. So, given my past experience with dbWriteTable, it is a question of what do.call(rbind(..)) did to produce ndf that has the effect that dbWriteTable doesn't like that data.frame. So, then, what is the bext way to either get dbWriteTable working (ideally in a way that works around the limitations I mention above) or to do a bulk insert into my MySQL table (yes, I already have a table in the relevant schema with all the right data types for each field, and I load RMySQL at the start of my program.) In a worst case, I can live with an insertion one record at a time. Thanks Ted PS: If it helps, here is the the contents of ndf - as shown by entering 'ndf' at the R prompt: ndf mid estimate sd loglikaic bic chisq chisqpvalue chisqdf 206 206 0.1147528 0.04336918 -22.15483 46.30965 46.25556 4.433502 0.035240131 229 229 0.0736 0.01999671 -56.41179 114.8236 115.5962 195307.1 0 2 251 251 0.074421 0.002171616 -4224.072 8450.144 8455.212 593302.2 0 18 252 252 0.03710208 0.0004556731 -28426.82 56855.65 56862.45 3543373 0 38 253 253 0.01397349 0.0005900857 -2925.179 5852.358 5856.677 283.9848 5.232282e-51 16 254 254 0.09043846 0.01528502 -119.108 240.216 241.7713 23.52441 3.139385e-05 3 255 255 0.05078883 0.0006021373 -28294.38 56590.76 56597.63 1988844 0 35 260 260 0.03392846 0.005499136 -166.5730 335.1461 336.7837 10.83060 0.054844135 268 268 0.05357114 0.01785082 -35.3407 72.6814 72.87863 82995.79 0 2 286 286 0.09321947 0.01987217 -74.20157 150.4031 151.4942 1.698603 0.6372445 3 290 290 0.03841793 0.006584153 -144.8139 291.6277 293.1541 135.8937 2.902434e-29 3 292 292 0.06289269 0.01988338 -37.66325 77.32651 77.6291 143099.8 0 2 297 297 0.01674874 0.004047625 -86.52035 175.0407 175.8739 47.27713 3.034432e-10 3 302 302 0.02878066 0.003876092 -250.1428 502.2857 504.293 9.22447 0.2369393 7 306 306 0.07904849 0.0004164051 -127449.0 254899.9 254908.4 111574416 0 40 307 307 0.01655872 0.001320903 -795.7314 1593.463 1596.513 57.38622 1.127804e-08 10 308 308 0.02631102 0.000884155 -4095.149 8192.298 8197.081 142.8876 3.904898e-20 21 309 309 0.09891599 0.0084501-453.9474 909.8947 912.8147 357135.5 0 8 310 310 0.09332047 0.004580396 -1399.262 2800.524 2804.552 217126 0 13 311 311 0.06378327 0.0005049166 -59848.62 119699.2 119706.9 59481893 0 34 313 313 0.06203001 0.0006486936 -34546.67 69095.34 69102.46 18207698 0 32 316 316 0.173 0.07026985 -25.04100 52.08199 52.38458 18002.22 0 2 317 317 0.04405086 0.0005949207 -22578.44 45158.88 45165.49 8923236 0 33 320 320 0.05747093 0.006634162 -289.2357 580.4714 582.7889 8.641322 0.2794433 7 321 321 0.06365155 0.003692525 -1115.037 2232.073 2235.767 19.10553 0.0860133712 322 322 0.05737672 0.01532991 -54.01363 110.0273 110.6663 9.597753 0.008238998 2 323 323 0.03116934 0.001909146 -1188.573 2379.146 2382.73 109.7663 6.656046e-18 12 324 324 0.03027327 0.0004146385 -23922.15 47846.3 47852.88 47330365 0 32 325 325 0.06047783 0.00922026 -163.6356 329.2711 331.0323 1695781 0 3 326 326 0.05627898 0.0008642285 -16432.57 32867.13 32873.48 3405089 0 29 327 327 0.07052627
[R] Creating symbolic expressions in R
Hello, I'm trying to do some differential equation modeling in R using the package 'deSolve.' Briefly, I'm trying to use the law of mass action (the details of which aren't really important) to structure a vector of rate equation which will be passed into an ODE function and solved with associated functions from 'deSolve.' Roughly what this entails is scanning through a very large stoichiometric matrix containing integers which map metabolites to reactions and then assembling a series of monomials that describe the rates of the reactions. I'm running into trouble because R does not like doing numerical operations on characters, but I need the rate to be in symbolic form. Below I've described an example. The input is a matrix like this one, but a lot bigger: rxn1 rxn2 rxn3 met1 -2 0 2 met2 -1 -1 0 met30 -1 -1 and the goal is to generate a vector of monomials representing the rate of each reaction 1 - 3: rateRxn1 = (met1)^2 * (met2)^1 rateRxn2 = (met2)^1 * (met3)^1 rateRxn3 = (met3)^1 The rates need to be represented symbolically for me to pass into the ODE solver where the metabolites will be assigned starting values. I tried using the functions quote and substitute but unfortunately they are tough to use within a loop because if I pass in a metabolite label generated from a loop (e.g. metaboliteNames[i]) it's taken verbatim in quote(), so I get metaboliteNames[i]^-stoich[i, j] instead of met1^2. My goal is to make a package of functions for modeling and simulation of chemical kinetics and I want to make sure that they are open-source and freely available to all researchers, so any advice on how to proceed would be greatly appreciated! Erin -- Erin Rachael Shellman The University of Michigan Bioinformatics PhD Candidate http://www.erinshellman.com shell...@umich.edu (937) 321.1129 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] RMySQL package on 64bit R for Windows
Did you ever find a solution for this? -- View this message in context: http://r.789695.n4.nabble.com/RMySQL-package-on-64bit-R-for-Windows-tp2248726p2291892.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] sqldf modify table
On Fri, Jul 16, 2010 at 2:46 PM, PeterTucker pthet...@gmail.com wrote: Hi - I am something of a newbie and am a little perplexed. When (trying to) modify a table I issue the following commands with subsequent errors sqldf(alter table Korea drop column code, dbname = mydb) error in statement: near drop: syntax error or sqldf(alter table Korea rename column hyr to hyrI, dbname = mydb) error in statement: near column: syntax error These are simple commands - am I missing something obvious? I can retrieve data from them, and retrieve their table_info SQLite does not support dropping columns. See: http://www.sqlite.org/lang_altertable.html however, sqldf does support the H2 and PostgreSQL databases in addition to sqlite so you can try one of those if this feature is important to you. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Nested if help
Hi: I'm guessing that your time variable is not defined with a class that respects (time) ordering, so your first if statement is meaningless. In the absence of further information, either create a meaningful time/date variable or at the very least, an ordered factor. Given what you've provided, the best one can ascertain is that time is a(n unordered) factor: d - read.table(textConnection( + day time price + 1 1am5 + 1 2am7 + 1 3am 9 + 1 4am 12 + 2 1am5 + 2 2am7 + 2 3am 9 + 2 4am 12), header = TRUE) str(d) 'data.frame': 8 obs. of 3 variables: $ day : int 1 1 1 1 2 2 2 2 $ time : Factor w/ 4 levels 1am,2am,3am,..: 1 2 3 4 1 2 3 4 $ price: int 5 7 9 12 5 7 9 12 This is what I (or anyone else on the list) would see in an R session. Whether this is reflective of what you see on your end is another matter. My response above was conditioned on the observation that time is an unordered factor, and logical testing based on order will not work with an unordered factor. It would be easier to diagnose the problem if you provided your data in the following form: dput(d) structure(list(day = c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L), time = structure(c(1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L), .Label = c(1am, 2am, 3am, 4am), class = factor), price = c(5L, 7L, 9L, 12L, 5L, 7L, 9L, 12L)), .Names = c(day, time, price), class = data.frame, row.names = c(NA, -8L)) and copy/paste this into your help request (as suggested in the Posting Guide, BTW). dput() outputs not merely the data, but its structure - in particular, the class of each variable. When you provide data in this form, there is no ambiguity between what you see and what potential helpers will see in their R sessions, so problem diagnosis is accomplished more efficiently. To create meaningful time variables, look into ?DateTimeClasses or package chron for starters. HTH, Dennis On Fri, Jul 16, 2010 at 10:00 AM, George Coyle gcoy...@gmail.com wrote: Hello, I am trying to find a direct way to write a nested if of sorts to find data for a specific time range for a specific day (across a range of days) and have exhausted my abilities with the manuals I have at hand. I have a good deal of data of this approximate form: day time price 1 1am5 1 2am7 1 3am 9 1 4am 12 2 1am5 2 2am7 2 3am 9 2 4am 12 etc I am reading from a file I loaded and using a while statement. I then am trying the direct approach of writing the if: if(time=2am time =4am) { #specifying desired time range--since a while loop format I don't think date is necessary and if it is I don't know how to say this? time1-time #sets first time in desired interval to base time px1-px #sets first price in desired interval to base price if(pxpx1){ #nested if stmt to see if subsequent times are higher than base, thus replacing base with new max (I am seeking max in the time period in this instance) px2-px #px2 would be the new higher maximum time2-time #time associated with px2 px3-px+1 #price immediately following max time3-time+1 #time immed. follows max out-(cur_date,px2,time2,px3,time3) #output the high price/time and the immediately following price/time cat(out,\n)} This code however, does nothing. Any help would be apreciated. The manuals seem to only take one so far. Thanks, George [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] a issue about the qutation mark?
Hi Karena, On Fri, Jul 16, 2010 at 11:23 AM, karena dr.jz...@gmail.com wrote: snip So, as we all know, when using read.csv, we need to use qutation mark out side the filename which we wanna read in. At first, for line 8, I wrote: read.csv(trait.file), at last line, I wrote: funcname(folder/hyper.csv), but it did not work in this way. Unless I changed the code to the current one that I showed above, I couldn't get what I want. So, to be straightforward, I will show the difference: 1) the code not working: read.csv(trait.file) #line 8 funcname(folder/hyper.csv) #last line The problem here is that unquoted commands used to refer to objects saved in your R working environment (well I may not be using the right terminology here. But I hope it is clear enough). Also, the / character is an arithmetic function. So when you call funcname(folder/hyper.csv) R will look for an object named folder and try to divide it by an object named hyper.csv). This could sometimes make sense, e.g., test.fun - function(x) { (sqrt(x)) } folder - 8 hyper.csv - 2 test.fun(folder/hyper.csv) but it is not what you want here. In your case, you need to pass a string to the read.csv function containing the filename. Even if you got passed this problem, you have another one, which is that by quoting the argument in read.csv(trait.file) you are asking read.csv to find a file located in the current working directory named trait.file. This is not what you want. You want read.csv to find a file specified by the argument to the funcname() function. 2) the code working: read.csv(trait.file) # line 8 funcname(folder/hyper.csv) # last line anyone can tell me why is the difference? This works because you are correctly passing a string to the read.csv() function. Maybe it helps to try this: dat - data.frame(a=rnorm(10), b=rnorm(10)) write.csv(dat, file=test.csv) file.name - test.csv dat2 - read.csv(file.name) dat2 - read.csv(file.name) Best, Ista thank you, karena -- View this message in context: http://r.789695.n4.nabble.com/a-issue-about-the-qutation-mark-tp2291537p2291537.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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] a issue about the qutation mark?
You need to understand the difference between a variable and a value. In your case that doesn't work, you are supplying a value, trait.value. but you have no file named trait.value. In the case that does work you are supplying a variable, trait.value, and the value contained in that variable is the name of a file that does exist. It is not quite correct to say that when using read.csv() you put quotation marks outside the filename. What you do is supply read.csv() with the name of a file, and that name can either be a character string, or a variable whose value is a character string. -Don On 7/16/10 8:23 AM, karena dr.jz...@gmail.com wrote: Following is a function that I wrote (It is working well). It's a simple one, nothing complicated. The only question that I have is a qutation mark issue, I guess. # funcname - function(trait.file){#line1 setwd('/root/subroot') # line 2 load('imge.RData')# line3 imge - imge[,-c(3)] # line4 imge - imge[complete.cases(imge),] # line5 trait- read.csv(trait.file) # line6 ngenes - nrow(imge) # line7 nsnp - nrow(trait) #line 8 for(i in 1:ngenes) { for(j in 1:nsnp) { if(imge$d1[i]==trait$d1[j] imge$d2[i]==trait$d2[j]) trait$imgene2[j] - imge$Gene[i] else trait$imgene2[j] - NA } } return(trait) } hypertension - funcname(folder/hyper.csv) # last line ## So, as we all know, when using read.csv, we need to use qutation mark out side the filename which we wanna read in. At first, for line 8, I wrote: read.csv(trait.file), at last line, I wrote: funcname(folder/hyper.csv), but it did not work in this way. Unless I changed the code to the current one that I showed above, I couldn't get what I want. So, to be straightforward, I will show the difference: 1) the code not working: read.csv(trait.file) #line 8 funcname(folder/hyper.csv) #last line 2) the code working: read.csv(trait.file) # line 8 funcname(folder/hyper.csv) # last line anyone can tell me why is the difference? thank you, karena -- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory 925 423-1062 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] invalid factor level, NAs generated
On 2010-07-16 13:38, Jared Stabach wrote: I've seen a few threads about this, but none that seem to answer my problem I have a list of .txt files in a directory that I am reading into R and row binding together. I am using the following code to do so: # Directory where files are found my.txt.file.directory- C:/Jared/Data/Kenya/Wildebeest/Tracking_Data names.of.txt.files- list.files(my.txt.file.directory,pattern=all_data,ignore.case=TRUE, full.names=TRUE) # Print names that meet criteria in directory names.of.txt.files # The names.of.txt.files will be a vector with the names of all the txt files # Dataset will contain all the data in the directory wildebeest- NULL # Run loop for (i in 1:length(names.of.txt.files)) { dat- read.table(names.of.txt.files[i],header=FALSE) # Row bind all data together into a file called 'wildebeest' wildebeest- rbind.data.frame(wildebeest,dat) rm(dat) } When I run this script, I get an error such as: 18: In `[-.factor`(`*tmp*`, ri, value = c(1714.36, 1711.27, ... : invalid factor level, NAs generated I think I have identified the problem such that when I identify the structure of some of the files that I am reading in, columns are labeled as Factors. In other files, the same columns are labeled as numeric values. Is there a way to assign the data structure to these columns in the dataframe as they are being read in? Any other suggestions to why I am getting this error is appreciated. Jared Jared, I'd guess that you have invalid data in some of your files. Perhaps missing values coded as '*' or as 'N/A'. If so, set the na.strings= argument. -Peter Ehlers __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] invalid factor level, NAs generated
Yes, this is problem. Thanks for the suggestion. I had deleted the N/A values later in the script but should have taken care of them in this first step. Thanks very much Jared On Fri, Jul 16, 2010 at 4:11 PM, Peter Ehlers ehl...@ucalgary.ca wrote: On 2010-07-16 13:38, Jared Stabach wrote: I've seen a few threads about this, but none that seem to answer my problem I have a list of .txt files in a directory that I am reading into R and row binding together. I am using the following code to do so: # Directory where files are found my.txt.file.directory- C:/Jared/Data/Kenya/Wildebeest/Tracking_Data names.of.txt.files- list.files(my.txt.file.directory,pattern=all_data,ignore.case=TRUE, full.names=TRUE) # Print names that meet criteria in directory names.of.txt.files # The names.of.txt.files will be a vector with the names of all the txt files # Dataset will contain all the data in the directory wildebeest- NULL # Run loop for (i in 1:length(names.of.txt.files)) { dat- read.table(names.of.txt.files[i],header=FALSE) # Row bind all data together into a file called 'wildebeest' wildebeest- rbind.data.frame(wildebeest,dat) rm(dat) } When I run this script, I get an error such as: 18: In `[-.factor`(`*tmp*`, ri, value = c(1714.36, 1711.27, ... : invalid factor level, NAs generated I think I have identified the problem such that when I identify the structure of some of the files that I am reading in, columns are labeled as Factors. In other files, the same columns are labeled as numeric values. Is there a way to assign the data structure to these columns in the dataframe as they are being read in? Any other suggestions to why I am getting this error is appreciated. Jared Jared, I'd guess that you have invalid data in some of your files. Perhaps missing values coded as '*' or as 'N/A'. If so, set the na.strings= argument. -Peter Ehlers -- Jared Stabach PhD Student Natural Resource Ecology Laboratory Colorado State University Room B226 NESB Fort Collins, CO 80523-1499 jstab...@rams.colostate.edu [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] multivariate graphs, averaging on some vars
Hello I have a table of this kind: functionx1 x2 x3 2.232 1 1 1.00 2.242 1 1 1.01 2.732 1 1 1.02 2.770 1 2 1.00 1.932 1 2 1.01 2.132 1 2 1.02 3.222 1.2 1 1 . ... .. .. The table represents the values of a function(x1, x2, x3) for each combination x1, x2, x3. I'd like to generate a plot where each point has the coordinates x=x1, y=x2, z=(mean of function(x1, x2) for all different x3). How can I do it? fox example, with the data from above the first point would be: x=x1=1, y=x2=1, z=(2.232+2.242+2.732)/3 In truth, my table has many columns and I want to take the mean over all the variables except the ones I represent at the axes, for example represent function(x1, x2) taking the mean over x3, x4, x5. Or using the maximum value of function(x1, x2) over all x1, x2, x3 How can I do it? Another question. How can I plot function(x1, x2, x3) with x=x1, y=x2, z=x3, different colours=function thanks -- View this message in context: http://r.789695.n4.nabble.com/multivariate-graphs-averaging-on-some-vars-tp2292039p2292039.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 comment off sections
Hello, Is there an way to easy comment of sections of code? I was thinking something along the lines of \dontrun{ codeline 1 codeline k } but that could be used in regular script files. When I am still working on a script, I often want to being using what is done, but I would like the parts I am still working on not to be run when I use source() on the file. I can set everything off with #, but that gets to be tedious. Thanks, Josh -- 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] how to comment off sections
if (FALSE) { codeline 1 codeline k } On Fri, Jul 16, 2010 at 7:59 PM, Joshua Wiley jwiley.ps...@gmail.comwrote: Hello, Is there an way to easy comment of sections of code? I was thinking something along the lines of \dontrun{ codeline 1 codeline k } but that could be used in regular script files. When I am still working on a script, I often want to being using what is done, but I would like the parts I am still working on not to be run when I use source() on the file. I can set everything off with #, but that gets to be tedious. Thanks, Josh -- 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.htmlhttp://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.