Re: [R] Help with functions as arguments

2013-02-12 Thread Rainer M Krug
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 12/02/13 08:30, Ian Renner wrote: Hi, I am trying to write a function which defines some arguments, then uses those arguments as arguments of other function calls. It's a bit tricky to explain, so a simple example will have to suffice. I

Re: [R] Help with functions as arguments

2013-02-12 Thread Barry Rowlingson
On Tue, Feb 12, 2013 at 7:30 AM, Ian Renner ian_ren...@yahoo.com wrote: Where I am running into trouble is when I want to call function f1 within function f2: f2(x = 3, z = f1(x)) This returns the error: Error in f1(x) : object 'x' not found I'm not sure how to define environments

[R] Is there a neat R trick for this?

2013-02-12 Thread Robert Latest
Hello all, given two vectors X and Y I'd like to receive a vector Z which contains, for each element of X, the index of the corresponding element in Y (or NA if that element isn't in Y). Example: x - c(4,5,6) y - c(10,1,5,12,4,13,14) z - findIndexIn(x, y) z [1] 5 3 NA 1st element of z is 5,

Re: [R] Is there a neat R trick for this?

2013-02-12 Thread Jorge I Velez
Robert, Try match(x, y) HTH, Jorge.- On Tue, Feb 12, 2013 at 9:09 PM, Robert Latest boblat...@gmail.com wrote: Hello all, given two vectors X and Y I'd like to receive a vector Z which contains, for each element of X, the index of the corresponding element in Y (or NA if that element

Re: [R] Is there a neat R trick for this?

2013-02-12 Thread Rainer Hurling
Am 12.02.2013 11:09 (UTC+1) schrieb Robert Latest: x - c(4,5,6) y - c(10,1,5,12,4,13,14) Please try #match(x,y) [1] 5 3 NA HTH, Rainer Hurling __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the

Re: [R] Is there a neat R trick for this?

2013-02-12 Thread Berend Hasselman
On 12-02-2013, at 11:09, Robert Latest boblat...@gmail.com wrote: Hello all, given two vectors X and Y I'd like to receive a vector Z which contains, for each element of X, the index of the corresponding element in Y (or NA if that element isn't in Y). Example: x - c(4,5,6) y -

Re: [R] Is there a neat R trick for this?

2013-02-12 Thread Robert Latest
Hi guys, like so often, the answert came to me minutes after posting. pmatch() does exactly what I need. match() gives the values of the elements, but not their positions. Thanks, robert __ R-help@r-project.org mailing list

Re: [R] Is there a neat R trick for this?

2013-02-12 Thread Pascal Oettli
Hello, ?match x - c(4,5,6) y - c(10,1,5,12,4,13,14) match(x,y) [1] 5 3 NA Hope this helps, Pascal Le 12/02/2013 19:09, Robert Latest a écrit : Hello all, given two vectors X and Y I'd like to receive a vector Z which contains, for each element of X, the index of the corresponding

Re: [R] Help with functions as arguments

2013-02-12 Thread Jan T Kim
On Tue, Feb 12, 2013 at 09:38:19AM +0100, Rainer M Krug wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 12/02/13 08:30, Ian Renner wrote: Hi, I am trying to write a function which defines some arguments, then uses those arguments as arguments of other function calls. It's

Re: [R] Inserting rows of interpolated data

2013-02-12 Thread PIKAL Petr
Hi Why you do not change date and time to POSIX object? It is simple and saves you a lot of frustration when merging two data frames. If you changed lightdata date and time to new column lightdata$newdate - strptime(paste(lightdata$date, lightdata$time, sep= ), format = %d/%m/%y %H:%M:%S)

[R] reorganize data

2013-02-12 Thread Niklas Larson
Hi R users, Wonder if somebody could give me help on how to reshape this type of data: --- Date:10.09.19 Time:21:39:05 Lat:N62.37.18 Long:E018.07.32 -0010 | 28| 28

Re: [R] Is there a neat R trick for this?

2013-02-12 Thread Duncan Murdoch
On 13-02-12 5:18 AM, Robert Latest wrote: Hi guys, like so often, the answert came to me minutes after posting. pmatch() does exactly what I need. match() gives the values of the elements, but not their positions. I think you should read the docs more closely. match() does what you need;

Re: [R] Help with functions as arguments

2013-02-12 Thread Duncan Murdoch
On 13-02-12 5:34 AM, Jan T Kim wrote: On Tue, Feb 12, 2013 at 09:38:19AM +0100, Rainer M Krug wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 12/02/13 08:30, Ian Renner wrote: Hi, I am trying to write a function which defines some arguments, then uses those arguments as arguments of

[R] error message from predict.coxph

2013-02-12 Thread Andrews, Chris
In one particular situation predict.coxph gives an error message. Namely: stratified data, predict='expected', new data, se=TRUE. I think I found the error but I'll leave that to you to decide. Thanks, Chris CODE library(survival) set.seed(20121221) nn - 10 # sample size in each

[R] Exact p-values in lm() - rounding problem

2013-02-12 Thread Torvon
I need to report exact p-values in my dissertation. Looking at my lm() results of many regressions with huge datasets I have the feeling that p-values are rounded to the smallest value of 2e-16, because this p-value is very common. Is that true or just chance? If it is true, how do I obtain the

[R] Deviance and AIC in weighted NLS

2013-02-12 Thread Andrej-Nikolai Spiess
Dear All, I encounter some discrepancies when comparing the deviance of a weighted and unweigthed model with the AIC values. A general example (from 'nls'): DNase1 - subset(DNase, Run == 1) fm1DNase1 - nls(density ~ SSlogis(log(conc), Asym, xmid, scal), DNase1) Now for a weighted fit:

Re: [R] Inserting rows of interpolated data

2013-02-12 Thread Joshua Ulrich
Hi Jon, zoo is great for tasks like this, not just for na.approx. :) I would approach the problem like this: library(zoo) # put lightdata into a zoo object z - with(lightdata, zoo(light, as.POSIXct(paste(date, time), format=%m/%d/%y %H:%M:%S))) # merge the above zoo object with an empty zoo #

Re: [R] Exact p-values in lm() - rounding problem

2013-02-12 Thread Uwe Ligges
On 12.02.2013 13:37, Torvon wrote: I need to report exact p-values in my dissertation. Looking at my lm() results of many regressions with huge datasets I have the feeling that p-values are rounded to the smallest value of 2e-16, because this p-value is very common. Is that true or just

Re: [R] Changing the order of months within a year

2013-02-12 Thread Rui Barradas
Hello, Maybe there's some date trick, but I think the following will do the job. dat - read.table(text = site date year precipitation temp_max temp_min 1 castlepeak Jan-71 197126.2903226 38.29032 18.06452 2 castlepeak Feb-71 1971 9.1071429 39.60714 17.5 3 castlepeak

Re: [R] Exact p-values in lm() - rounding problem

2013-02-12 Thread Torvon
Thank you, Uwe. summary(m1) gives me p-value estimates of: (Intercept) 2e-16 x1 6.9e-15 x2 1.9e-07 x3 2.7e-09 While coef(summary(m1))[,4] gives me: (Intercept) 3.0e-23 x1 5.7e-13 x2 2.6e-07 x3 1.7e-17 While the first one confirms my suspicion (-23 instead of -16), the latter one vary

Re: [R] Exact p-values in lm() - rounding problem

2013-02-12 Thread Ben Bolker
Torvon torvon at gmail.com writes: Thank you, Uwe. summary(m1) gives me p-value estimates of: (Intercept) 2e-16 x1 6.9e-15 x2 1.9e-07 x3 2.7e-09 While coef(summary(m1))[,4] gives me: (Intercept) 3.0e-23 x1 5.7e-13 x2 2.6e-07 x3 1.7e-17 While the first one confirms my suspicion

Re: [R] Exact p-values in lm() - rounding problem

2013-02-12 Thread Uwe Ligges
On 12.02.2013 14:44, Torvon wrote: Thank you, Uwe. summary(m1) gives me p-value estimates of: (Intercept) 2e-16 x1 6.9e-15 x2 1.9e-07 x3 2.7e-09 While coef(summary(m1))[,4] gives me: (Intercept) 3.0e-23 x1 5.7e-13 x2 2.6e-07 x3 1.7e-17 While the first one confirms my suspicion (-23

Re: [R] Exact p-values in lm() - rounding problem

2013-02-12 Thread Torvon
The code is quite long because I am running a WLS regression instead of an OLS regression (due to heteroscedasticity). First, I get mean structure, then get mean/SD relationship, then improve the variance structure by using weights proportional to 1/variance. I am quite sure this is not relevant,

Re: [R] Exact p-values in lm() - rounding problem

2013-02-12 Thread Uwe Ligges
On 12.02.2013 15:15, Torvon wrote: The code is quite long because I am running a WLS regression instead of an OLS regression (due to heteroscedasticity). First, I get mean structure, then get mean/SD relationship, then improve the variance structure by using weights proportional to 1/variance.

Re: [R] Exact p-values in lm() - rounding problem

2013-02-12 Thread Torvon
I'm sorry, no clue how I did not see that. Thank you! On 12 February 2013 15:21, Uwe Ligges lig...@statistik.tu-dortmund.dewrote: On 12.02.2013 15:15, Torvon wrote: The code is quite long because I am running a WLS regression instead of an OLS regression (due to heteroscedasticity).

[R] an assert() function

2013-02-12 Thread Greg Minshall
hi. i've looked for (and not found) an assert() function. needing one, i created the following (from stop()). i'm posting it in case 1) someone sees a problem with this; and 2) someone else has a need. cheers, Greg ## an assert mechanism... assert - function (shouldbe, ...) { if

[R] remove from mailing list

2013-02-12 Thread Sarah d'Apollonia
please remove me from the R-help mailing list thank you! [[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

Re: [R] Help with functions as arguments

2013-02-12 Thread Frans Marcelissen
Hi Ian, The remark of Rainer is correct, but I think the solution is very simpe: f1 = function(a) { b = a + 1 b } f2 = function(x, z) { y = x*z(x) -2 y } f2(x = 3, z = f1) [1] 10 Or are you intending something else? Best wishes, Frans -Oorspronkelijk bericht- Van:

Re: [R] match a complete data.frame

2013-02-12 Thread Mat
i found a way :-) data-merge(data,project,by.x=PJ_ID,by.y=PROJ_ID,all.x=TRUE) perhaps this can help someone Mat -- View this message in context: http://r.789695.n4.nabble.com/match-a-complete-data-frame-tp4658250p4658252.html Sent from the R help mailing list archive at Nabble.com.

[R] match a complete data.frame

2013-02-12 Thread Mat
hello togehter, how can i match a complete data.frame to another one? I know i can match one column with that code: A-match(data$PJ_ID,project$PROJ_ID) data$Name-proj$Name[A] but how can i match the total data.frame from project to data? indivduel matching for each column is not very

[R] AUC from ENFA model

2013-02-12 Thread Leandro Abade
Dear all, I am currently running an ENFA in R using Adehabitat pkg to assess species distribution and I am really stuck and need some help to finalize my project. I run the ENFA in both original location data and pseudo-absence points (the latter randomly generated using dismo pkg), and now I

Re: [R] Changing the order of months within a year

2013-02-12 Thread arun
Hi, You could try: dat1- read.table(text=     site  date year precipitation temp_max temp_min 1  castlepeak Jan-71 1971    26.2903226 38.29032 18.06452 2  castlepeak Feb-71 1971    9.1071429 39.60714 17.5 3  castlepeak Mar-71 1971    36.3548387 38.87097 17.77419 4  castlepeak

[R] subsetting data file by intoducing a second file

2013-02-12 Thread Ozgul Inceoglu
Hello, I have a very data matrix and I have a file which has the names that I need to subset. However I cannot manage to subset the main file. ANy idea? bg - read.table (file.choose(), header=T, row.names) bg Otu00022 Otu00029 Otu00039 Otu00042 Otu00101 Otu00105 Otu00125 Otu00131

Re: [R] an assert() function

2013-02-12 Thread Duncan Murdoch
On 12/02/2013 9:11 AM, Greg Minshall wrote: hi. i've looked for (and not found) an assert() function. needing one, i created the following (from stop()). i'm posting it in case 1) someone sees a problem with this; and 2) someone else has a need. stopifnot() might do what you want. The

[R] standard error very high in maximum liklihood fitting

2013-02-12 Thread Abu Naser
Dear all, I have been trying to fit my data (only right censored) with gumbel distribution using fitdistrplus. I am getting very high standard error. I have been wondering why. The followings are the outputs: fit1=fitdistcens(dr0, gumbel, start=list(a=99, b=0.6), optim.method=

Re: [R] Predictions from the Segmented Package

2013-02-12 Thread oli tills
Rolf, many thanks for these suggestions, I will definitely give these a go. I ended up resorting to locator() to ascertain the x y coordinates I required, but obviously this isn't optimal. Thanks again,Oli Date: Thu, 7 Feb 2013 12:38:22 +1300 From: rolf.tur...@xtra.co.nz To:

Re: [R] standard error very high in maximum liklihood fitting

2013-02-12 Thread Ben Bolker
Abu Naser likhonnaser at hotmail.com writes: I have been trying to fit my data (only right censored) with gumbel distribution using fitdistrplus. I am getting very high standard error. I have been wondering why. The followings are the outputs: fit1=fitdistcens(dr0, gumbel,

Re: [R] remove from mailing list

2013-02-12 Thread peter dalgaard
On Feb 12, 2013, at 10:12 , Sarah d'Apollonia wrote: please remove me from the R-help mailing list Instructions are found in the footer. thank you! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list

[R] Bioinformatics Scientist

2013-02-12 Thread Agnès Paquet
Hi, Monogram Biosciences is recruiting a bioinformatics scientist for our bioinformatics/biostatistics group. If you are interested in this position, please apply directly using our career website at:

Re: [R] subsetting data file by intoducing a second file

2013-02-12 Thread Rui Barradas
Hello, Read the help page ?subset more carefully, it's argument 'select' you should be using: subset(bg, select = c_bg) Hope this helps, Rui Barradas Em 12-02-2013 14:29, Ozgul Inceoglu escreveu: Hello, I have a very data matrix and I have a file which has the names that I need to

Re: [R] reorganize data

2013-02-12 Thread David Winsemius
On Feb 12, 2013, at 2:56 AM, Niklas Larson wrote: Hi R users, Wonder if somebody could give me help on how to reshape this type of data: #Adding a bit of code to read this into R: Lines - readLines(textConnection(Date:10.09.19 Time:21:39:05 Lat:N62.37.18 Long:E018.07.32 -0010 | 28|

Re: [R] an assert() function

2013-02-12 Thread Greg Minshall
Duncan, thanks for the response. stopifnot() looks almost right. it's very useful if assertion failures issue an error message pointing at the source file/line (such as error produces); it might also be nice (but not necessary) to allow the caller to pass in a higher level message to be

[R] Max value of each 2 rows in dataframe

2013-02-12 Thread zuzana zajkova
Hello, I would like to ask you for help. I have quite a big dataframe (119 313 rows), this is a part of it: jul ind time secs geo act lig date.x clock h m s d mo y dtime land date.y sriseIC ssetIC dssetIC dsriseIC 1207 14628 5500519 2010-01-19 15:14:59 40197.635414 17016001 0 64 19/01/10

Re: [R] subsetting data file by intoducing a second file

2013-02-12 Thread arun
Hi, bg- read.table(text= Otu00022 Otu00029 Otu00039 Otu00042 Otu00101 Otu00105 Otu00125 Otu00131 Otu00137 Otu00155 Otu00158 Otu00172 Otu00181 Otu00185 Otu00190 Otu00209 Otu00218 Gi20Jun11  0.001217    0 0.001217    0 0.00    0    0    0 0.001217    0    0   

[R] AUC from ENFA model

2013-02-12 Thread Leandro Abade
Dear all, I am currently running an ENFA in R using Adehabitat pkg to assess species distribution and I am really stuck and need some help to finalize my project. I run the ENFA in both original location data and pseudo-absence points (the latter randomly generated using dismo pkg), and now I

Re: [R] integrate function

2013-02-12 Thread Prof. Dr. Matthias Kohl
use pmin instead of min. hth Matthias On 12.02.2013 16:41, dan wang wrote: Hi All, Can any one help to explain why min and max function couldn't work in the integrate function directly. For example, if issue following into R: integrand - function(x) {min(1-x, x^2)} integrate(integrand, lower

Re: [R] Help with functions as arguments

2013-02-12 Thread David Winsemius
On Feb 12, 2013, at 12:38 AM, Rainer M Krug wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 12/02/13 08:30, Ian Renner wrote: Hi, I am trying to write a function which defines some arguments, then uses those arguments as arguments of other function calls. It's a bit tricky

Re: [R] integrate function

2013-02-12 Thread William Dunlap
integrate() want a vectorized function, one such that length(f(x))==length(x). Use pmin or pmax instead of min or max. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of dan

Re: [R] integrate function

2013-02-12 Thread dan wang
Thanks. That works! min() function didn't vectorized but abs( ), pmin or + /- did. On Tue, Feb 12, 2013 at 12:18 PM, William Dunlap wdun...@tibco.com wrote: integrate() want a vectorized function, one such that length(f(x))==length(x). Use pmin or pmax instead of min or max. Bill Dunlap

Re: [R] Is there a neat R trick for this?

2013-02-12 Thread Nordlund, Dan (DSHS/RDA)
Another option is which(y %in% x) Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 -Original Message- From: r-help-boun...@r-project.org

Re: [R] subsetting data file by intoducing a second file

2013-02-12 Thread Eik Vettorazzi
Hi Ozgul, the interesting part is the select parameter in subset: subset(bg,select=c_bg[,1]) cheers Am 12.02.2013 15:29, schrieb Ozgul Inceoglu: Hello, I have a very data matrix and I have a file which has the names that I need to subset. However I cannot manage to subset the main file.

Re: [R] Max value of each 2 rows in dataframe

2013-02-12 Thread Rui Barradas
Hello, Your data example is a mess. Can't you please use ?dput to post it? Supposing your data is named 'dat', use dput(head(dat, 20)) # Paste the output of this in a post Hope this helps, Rui Barradas Em 12-02-2013 15:30, zuzana zajkova escreveu: Hello, I would like to ask you for

[R] fit an nls model

2013-02-12 Thread Giuseppe Amatulli
Hi, I'm trying to fit a not linear model with the nls function to some data. So far this is the best fitting that i found. download.file(http://dl.dropbox.com/u/29337496/data; , destfile=./data) load(data) plot (x06Veg,y06Pop) nlmod=nls( y06Pop ~ B + A * log(x06Veg) , start = list(A = 1, B =

Re: [R] match a complete data.frame

2013-02-12 Thread David Winsemius
On Feb 12, 2013, at 5:10 AM, Mat wrote: hello togehter, how can i match a complete data.frame to another one? I know i can match one column with that code: A-match(data$PJ_ID,project$PROJ_ID) data$Name-proj$Name[A] How about: data - data[ match(data$PJ_ID,project$PROJ_ID) , ]

Re: [R] Changing the order of months within a year

2013-02-12 Thread David Winsemius
On Feb 11, 2013, at 10:09 PM, nick pardikes wrote: I have data that looks like below and I would like to re-order the values within the date column. I would like to have each year organized like so: Sep-71 Oct-71 Nov-71 Dec-71 Jan-71 Feb-71 Mar-71 Apr-71 May-71 Jun-71 Jul-71

[R] Data sets online for student use

2013-02-12 Thread David Arnold
All, If you have any good links for sites that contain data sets that can easily be accessed and copied (or downloaded) by students in introductory statistics, could you please share them? Thanks. David -- View this message in context:

[R] caret: Errors with createGrid for rf (randomForest)

2013-02-12 Thread James Jong
When I try to crate a grid of parameters for training with caret I get various errors: my_grid - createGrid(rf) Error in if (p = len) { : argument is of length zero my_grid - createGrid(rf, 4) Error in if (p = len) { : argument is of

Re: [R] caret: Errors with createGrid for rf (randomForest)

2013-02-12 Thread David Winsemius
On Feb 12, 2013, at 10:53 AM, James Jong wrote: When I try to crate a grid of parameters for training with caret I get various errors: my_grid - createGrid(rf) Error in if (p = len) { : argument is of length zero my_grid -

Re: [R] Is there a neat R trick for this?

2013-02-12 Thread Bert Gunter
Take a look at: get(%in%) to see why this (i.e. which(y %in% x) ) is not a good idea. -- Bert On Tue, Feb 12, 2013 at 9:48 AM, Nordlund, Dan (DSHS/RDA) nord...@dshs.wa.gov wrote: Another option is which(y %in% x) Dan Daniel J. Nordlund Washington State Department of Social and Health

Re: [R] reorganize data

2013-02-12 Thread arun
Hi, Lines1 - readLines(textConnection(Date:10.09.19 Time:21:39:05  Lat:N62.37.18 Long:E018.07.32 -0010 |   28|   28 0010-0020|  302|  302 0020-0030|   42|   42 0030-0040|    2|    2 0040-0050|    1|    1 0060-0070|    1|    1 _ Date:10.09.19 Time:21:44:52 Lat:N62.38.00 Long:E018.09.07

Re: [R] Changing the order of months within a year

2013-02-12 Thread Clint Bowman
I'm sure the OP has reasons to reorder the months as shown but his data seems to argue that he shouldn't split the wet season (Oct - Apr) but should, instead, tack the 1972 months (Jan - Aug after the 1971 months (Sep - Dec). Clint Clint BowmanINTERNET:

Re: [R] caret: Errors with createGrid for rf (randomForest)

2013-02-12 Thread James Jong
That was the problem. Thanks David! James On Tue, Feb 12, 2013 at 2:08 PM, David Winsemius dwinsem...@comcast.netwrote: On Feb 12, 2013, at 10:53 AM, James Jong wrote: When I try to crate a grid of parameters for training with caret I get various errors:

[R] Putting priors on which factors to sample more from, in random forests

2013-02-12 Thread James Jong
I was wondering if anyone knows of a random forest implementation (or way of tweaking the standard randomForest library) that allows one to specify some sort of variable importance a* *priori. For example, say that I know that some variables/factors could be more informative than others for

Re: [R] improving/speeding up a very large, slow simulation

2013-02-12 Thread Benjamin Caldwell
Anindya, Completely understand why you wouldn't want to look into the code. I don't understand your suggestion well enough to implement it, I lost you at unlist your function variable . . .; I don't understand why one would want to do that. Are there examples you'd suggest? If not I'll take a

Re: [R] Is there a neat R trick for this?

2013-02-12 Thread Nordlund, Dan (DSHS/RDA)
I apologize for the noise. I did not read the original question carefully enough. Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 -Original Message-

[R] Write a dataframe or table to clipboard as an image to paste into an email

2013-02-12 Thread Lopez, Dan
Hi, Is there a way to write a dataframe or table to the clipboard as an image? I want to paste into an email. I use snagit or print screen to do this today but want to know if there is a way to do this through R. For example I know how to write to clipboard for copy and pasting into Excel:

Re: [R] grabbing from elements of a list without a loop

2013-02-12 Thread Bert Gunter
The answer is essentially no, a loop is required (as best I can see), although it can be in the form of an apply type call instead. Also, your code will fail with a 0 index. Something like this should work: newlist - lapply(1:3,function(i)if(!neededcolumns[i])NULL else

Re: [R] Write a dataframe or table to clipboard as an image to paste into an email

2013-02-12 Thread David Winsemius
On Feb 12, 2013, at 2:51 PM, Lopez, Dan wrote: Hi, Is there a way to write a dataframe or table to the clipboard as an image? I want to paste into an email. I use snagit or print screen to do this today but want to know if there is a way to do this through R. For example I know how

Re: [R] grabbing from elements of a list without a loop

2013-02-12 Thread Dimitri Liakhovitski
Arun, do you know why the first line works and the second doesn't? newlist-mapply(`[`,mylist,list(1,2,0),SIMPLIFY=FALSE) # it works neededcolumns-c(1,2,0) # it does not work newlist-mapply(`[`,mylist,list(neededcolumns),SIMPLIFY=FALSE) Dimitri On Tue, Feb 12, 2013 at 5:08 PM,

Re: [R] grabbing from elements of a list without a loop

2013-02-12 Thread David Winsemius
On Feb 12, 2013, at 3:01 PM, Dimitri Liakhovitski wrote: Arun, do you know why the first line works and the second doesn't? newlist-mapply(`[`,mylist,list(1,2,0),SIMPLIFY=FALSE) # it works neededcolumns-c(1,2,0) # it does not work

Re: [R] grabbing from elements of a list without a loop

2013-02-12 Thread Dimitri Liakhovitski
Thank you, David. I missed the key detail. Then Arun's option doesn't work as I need to parametrise needed columns (they will be a vector). Dimitri On Tue, Feb 12, 2013 at 6:04 PM, David Winsemius dwinsem...@comcast.netwrote: On Feb 12, 2013, at 3:01 PM, Dimitri Liakhovitski wrote: Arun, do

Re: [R] grabbing from elements of a list without a loop

2013-02-12 Thread Dimitri Liakhovitski
Maybe I am mistaken, but my code seems to work with a 0 index. In my final do.call I don't need anything if the index was 0. I've tested Bert's solution vs. my original one. It's about 25% faster. So, thanks a lot, Bert. Dimitri On Tue, Feb 12, 2013 at 5:52 PM, Bert Gunter gunter.ber...@gene.com

Re: [R] grabbing from elements of a list without a loop

2013-02-12 Thread Dimitri Liakhovitski
Than you so much for your suggestions, everyone! Arun's solution is elegant and it works - but it takes the same amount of time as my original code. Bill's code works too, it's a tiny-bit faster (for 10,000 iterations of the same code - it took about 16.2 secs vs. 16.6 sec for Arun's solution and

Re: [R] grabbing from elements of a list without a loop

2013-02-12 Thread William Dunlap
One could try using unlist(mylist, recursive=FALSE) to make a list of all the columns of the data.frames in mylist and subscripting from that. E.g., here is some barely tested code: nCols - vapply(mylist, ncol, 0L) neededcolumns-c(1,2,0) # I assume 0 means no column wanted from 3rd df in

Re: [R] Max value of each 2 rows in dataframe

2013-02-12 Thread zuzana zajkova
Hi, sorry for not useable data... When I tried to use the dput function to the dataframe let's call it A, had some problems with the time and clock variables... however I attach an other dataframe B, which is created by merging A with other dataframe. The B dataframe has a little different

[R] Is there a place to put executable R scripts in new packages?

2013-02-12 Thread Asis Hallab
Dear R users, writing an R package I wonder, if there is a place to put executable R scripts into. So that when the package is installed one can use the script from the command line. Say we have e new package called FunkyR and wanted to deliver with it an executable called FunkyCold.R, so that

[R] plot rtf in landscape orintation

2013-02-12 Thread bdeepthi
Hello All, I 'm trying to plot R graph in landscape orientation in a .rtf file. i 'm using library(rtf) for this. do we have any option in addPlot() function to rotate the orientation of the rtf file? Thank you, Deepthi BM PGDB-10-10-04 Institute of Bioinformatics and Applied Biotechnology

Re: [R] grabbing from elements of a list without a loop

2013-02-12 Thread arun
Hi,  mapply(`[`,mylist,list(1,2,0),SIMPLIFY=FALSE) #[[1]] #  a #1 1 #2 2 #[[2]]  # b #1 5 #2 6 #[[3]] #data frame with 0 columns and 2 rows A.K. - Original Message - From: Dimitri Liakhovitski dimitri.liakhovit...@gmail.com To: r-help r-help@r-project.org Cc: Sent: Tuesday,

[R] recovering from errors with lapply()

2013-02-12 Thread Andrew Barr
Hi all, I am searching for a way to recover results from lapply() when one or more values returns an error. I have a written a function that uses tryCatch() to recover from errors. Here is a very simple example of such a function. divideBy2-function(X){ result-tryCatch(X/2, error =

Re: [R] reorganize data

2013-02-12 Thread arun
Hi, Sorry, in my previous reply, I omitted one of the columns. Lines1 - readLines(textConnection(Date:10.09.19 Time:21:39:05  Lat:N62.37.18 Long:E018.07.32 -0010 |   28|   28 0010-0020|  302|  302 0020-0030|   42|   42 0030-0040|    2|    2 0040-0050|    1|    1 0060-0070|    1|    1 _

Re: [R] grabbing from elements of a list without a loop

2013-02-12 Thread arun
Hi Dimitri,  neededcolumns- c(1,2,0) mapply(`[`,mylist,lapply(neededcolumns,function(x) x),SIMPLIFY=FALSE) #[[1]]  # a #1 1 #2 2 # #[[2]]  # b #1 5 #2 6 #[[3]] #data frame with 0 columns and 2 rows A.K. From: Dimitri Liakhovitski

[R] How to install .tar.gz source package in Windows XP 32-bit operational system

2013-02-12 Thread Marino David
Dear all mailing listers, I failed in install source packages in Windows system. I have installed Rtools in order to install the source package based on the discussion available on the following link: http://r.789695.n4.nabble.com/Installing-a-Package-tar-gz-in-windows-td3411393.html. By the way,

Re: [R] Max value of each 2 rows in dataframe

2013-02-12 Thread arun
Hi, For the dataset A, Assuming that this is what you meant: the maximum value of lig in each 2 rows excluding the first row: #dataset: A A[-1,]-do.call(rbind,lapply(split(A[-1,],((1:nrow(A[-1,])-1)%/%2)+1),function(x){x[4]-max(x[4]);x}))  A #   ok    time secs lig  geo

Re: [R] Data sets online for student use

2013-02-12 Thread Bernd Klaus
Hi Arnold, I like the Data and Story library a lot and have already used it in my own courses: http://lib.stat.cmu.edu/DASL/ BW Bernd On Tue, 12 Feb 2013 10:51:04 -0800 (PST) David Arnold dwarnol...@suddenlink.net wrote: All, If you have any good links for sites that contain data sets