Re: [R] populating an array

2009-10-15 Thread Kenn Konstabel
Could you possibly consider reading An Introduction to R, especially the first few pages of chapter 5, and also a bit about vectors from chapter 2, and maybe eventually even some other parts... You have x[i][j] where length(i)==1, so x[i] will be a single element. Having [j] there makes no sense

Re: [R] Q-type factor analysis

2007-10-12 Thread Kenn Konstabel
On 10/12/07, Julia Kröpfl [EMAIL PROTECTED] wrote: Is there a package in R that does Q-type factor analysis? I know how to do principal component analysis, but haven't found any application of Q-type factor analysis. Q-mode factor analysis is not a separate type of factor analysis but (in

Re: [R] How to read a list into R??

2009-06-30 Thread Kenn Konstabel
Hi, It would be much better to save your list with dump or dput or save (then you can read it, respectively, with source, dget, or load). Sink is not useful for this, but if you really have to (i.e., if you for some reason can't re-run the analyses and make these lists anew), you can do something

Re: [R] Clearing out or reclaiming memory

2009-06-30 Thread Kenn Konstabel
On Tue, Jun 30, 2009 at 2:36 PM, gug guygr...@netvigator.com wrote: I've been using attach because I was following one of the approaches recommended in this Basic Statistics and R tutorial (http://ehsan.karim.googlepages.com/lab251t3.pdf), in order to be able to easily use the column

Re: [R] Clearing out or reclaiming memory

2009-07-01 Thread Kenn Konstabel
On Wed, Jul 1, 2009 at 3:02 AM, gug guygr...@netvigator.com wrote: sapply(ls(), function(x) object.size(get(x))) -This lists all objects with the memory each is using (I should be honest and say that, never having used sapply before, I don't truly understand the syntax of this, but it

Re: [R] Question about - assignment

2009-07-02 Thread Kenn Konstabel
On Thu, Jul 2, 2009 at 4:34 AM, Rolf Turner r.tur...@auckland.ac.nz wrote: On 2/07/2009, at 12:20 PM, Hsiu-Khuern Tang wrote: Is this expected behavior? z - 1:5 z[1] - 0 Error in z[1] - 0 : object z not found The documentation seems to suggest that z will be found in the global

Re: [R] why is 0 not an integer?

2009-08-06 Thread Kenn Konstabel
On Wed, Aug 5, 2009 at 11:28 PM, Erik Iverson eiver...@nmdp.org wrote: First, this has nothing to do with 0. Assigning 1000 to an element of v would also have this effect. Two, the first element of a vector is indexed by 1, not 0. While what you wrote isn't a syntax error (v[0] - 0), it

Re: [R] Statistics on raster pictures - asking for an advice

2008-08-06 Thread Kenn Konstabel
Take a look at packages pixmap and rimage ... and read.picture() in package SoPhy for reading tiff images. Currently there seems to be no way of reading in png files directly, so they need to be converted first. Kenn On Wed, Aug 6, 2008 at 11:47 AM, Tomas Lanczos [EMAIL PROTECTED] wrote:

Re: [R] multiple tapply

2008-08-07 Thread Kenn Konstabel
one way would be: mapply(tapply, iris[,1:4], MoreArgs=list(iris[,5], mean)) K On Thu, Aug 7, 2008 at 2:01 PM, glaporta [EMAIL PROTECTED] wrote: Hi folk, I tried this and it works just perfectly tapply(iris[,1],iris[5],mean) but, how to obtain a single table from multiple variables? In

Re: [R] RPro

2008-08-08 Thread Kenn Konstabel
There's more to this trend: SPSS and Statistica now advertise R language support : http://www.statsoft.com/industries/Rlanguage.htm http://www.spss.com/spssdirections/na/sessions.cfm?sessionType=2 Kenn Konstabel On Fri, Aug 8, 2008 at 5:30 PM, Marc Schwartz [EMAIL PROTECTED]wrote: on 08/08

Re: [R] Deleting NA in list()

2008-08-25 Thread Kenn Konstabel
lt[!is.na(lt)] is a rather obvious way... On Fri, Aug 22, 2008 at 9:41 PM, Dong-hyun Oh [EMAIL PROTECTED] wrote: Dear useRs, I would like to know the way of deleting NA in list(). Following is a example. lt - list(a = 1:3, b = NA, c = letters[1:3], d = NA) for(i in length(lt):1) {

Re: [R] Deleting NA in list()

2008-08-25 Thread Kenn Konstabel
this: sapply(lt, function(x) all(is.na(x))) Kenn On Mon, Aug 25, 2008 at 3:33 AM, Kenn Konstabel [EMAIL PROTECTED] wrote: lt[!is.na(lt)] is a rather obvious way... On Fri, Aug 22, 2008 at 9:41 PM, Dong-hyun Oh [EMAIL PROTECTED] wrote: Dear useRs, I would like to know the way

Re: [R] frequency table across multiple variables

2008-09-19 Thread Kenn Konstabel
or ... sapply(m,function(x) table(factor(x, levels=c(NA, 1:4), exclude=NULL))) On Fri, Sep 19, 2008 at 12:59 PM, Ralikwen [EMAIL PROTECTED] wrote: Hi, I went for a slight alteration of your solution x1-c(1,2,3,4,NA ,NA ,NA, 3, 1, 1, 1, 1, 2, 2, 3, 4, 4)

Re: [R] How to change the class of data?

2008-06-12 Thread Kenn Konstabel
Conversion to factor may happen (and often does) when you read in data with read.table(). So one solution may be reading in the same data again in a slightly different way: read.table(file=mydatafile, as.is=TRUE) # see also ?read.table You can also specify a class to each column of the data

Re: [R] Draw curve for histogram

2008-06-20 Thread Kenn Konstabel
On Fri, Jun 20, 2008 at 2:47 AM, Anh Tran [EMAIL PROTECTED] wrote: Thanks. I think I've got it. However, the density is plotted, not the frequency. Is there a way to convert the density back to frequency. Thanks a bunch. an easy answer is that hist returns an object which you plot in any way

Re: [R] Convert character string to number

2008-06-21 Thread Kenn Konstabel
another way to do it is using eval and parse: yyy-numeric() for(i in 1:length(xxx)) yyy[i] - eval(parse(text=xxx[i])) or ... unlist(lapply(as.list(xxx), function(x) eval(parse(text=x then xxx can contain any valid expressions (not necessarily fractions) Kenn On Sat, Jun 21, 2008 at 12:44

Re: [R] converting an R function into VBA

2008-06-21 Thread Kenn Konstabel
Can't you just import data from Excel using RODBC, then use your function in R, and then write the results to Excel again? It would be much less painful than doing it in VBA... Otherwise, look for MMult and Transpose and similar things in VB help, and then ask some VB experts... Kenn On Sat,

Re: [R] Accessing Named Column in a Matrix

2008-06-25 Thread Kenn Konstabel
On Mon, Jun 23, 2008 at 9:12 PM, Gundala Viswanath [EMAIL PROTECTED] wrote: I've also tried with data$var But still fail to access var column you can't use $ with matrices (see help($) !), but you can use [ with names, or convert you matrix to a data frame: myData[, var]

Re: [R] Is this sapply behaviour normal?

2008-06-25 Thread Kenn Konstabel
On Wed, Jun 25, 2008 at 6:00 PM, Victor Homar [EMAIL PROTECTED] wrote: Hi, I'm trying to use sapply to compute the min of several variables, each of them stored in data.frames, grouped as a list: Is it normal that mean() and min() produce different objects dimensions? it is exactly

Re: [R] Find max of a row in data frame (like Excel)

2008-06-25 Thread Kenn Konstabel
apply max to columns f1...f4 and assign it to rs$f: rs$f - apply(rs[,paste(f,1:4,sep=)],1,max) or rs$f - apply(rs[,2:5],1,max) On Wed, Jun 25, 2008 at 1:41 AM, Anh Tran [EMAIL PROTECTED] wrote: Hi, Here's the data we have: rs[1:5,] probe_id f1 f2 f3 f4 MA f

Re: [R] Is this sapply behaviour normal?

2008-06-26 Thread Kenn Konstabel
On Thu, Jun 26, 2008 at 12:14 AM, Wacek Kusnierczyk [EMAIL PROTECTED] wrote: sapply(dats,function(x){sapply(x,min)}) you can achieve the same with sapply(dats, sapply, min) Did you actually try it? dats - data.frame(1:10,2:11) sapply(dats,sapply,min) X1.10 X2.11 [1,]

Re: [R] Is this sapply behaviour normal?

2008-06-26 Thread Kenn Konstabel
Sorry, my mistake, - it works both ways with a correct example and neither way with the wrong example. k On Thu, Jun 26, 2008 at 4:25 PM, Wacek Kusnierczyk [EMAIL PROTECTED] wrote: sapply(dats,function(x){sapply(x,min)}) you can achieve the same with sapply(dats, sapply, min)

Re: [R] lm and NA

2008-07-01 Thread Kenn Konstabel
use the function resid instead of lm.object$residuals to extract the residuals: resid(lm(a~b, na.action=na.exclude)) 1 2 3 4 5 6 -2.533445e-17 4.222409e-17 -8.444818e-18 -8.444818e-18 NANA lm(a~b,

Re: [R] trivial list question

2008-07-01 Thread Kenn Konstabel
another way: split(1:184, rep(1:92, each=2)) On Tue, Jul 1, 2008 at 3:46 PM, Boks, M.P.M. [EMAIL PROTECTED] wrote: Dear experts, For the makeGenotype function I need a list as in the example. However, since my list needs to be 184 long there must be an easy way to make it.

Re: [R] multiplication question

2008-07-02 Thread Kenn Konstabel
for example ... x - 1:5 ; y- 6:8 (m - x %o% y) # is this what you mean by product of two vectors? sum(m[row(m)!=col(m)]) # or ... sum(m)-sum(diag(m)) On Wed, Jul 2, 2008 at 7:30 PM, Murali Menon [EMAIL PROTECTED] wrote: folks, is there a clever way to compute the sum of the product of

Re: [R] Sum(Random Numbers)=100

2008-07-08 Thread Kenn Konstabel
On Tue, Jul 8, 2008 at 9:53 AM, Shubha Vishwanath Karanth [EMAIL PROTECTED] wrote: ...actually I need to allocate certain amount of money (here I mentioned it as 100) to a randomly selected stocks(50 stocks)... i.e., 100 being divided among 50 stocks and preferably all are integer

Re: [R] Manipulate Data (with regular expressions)

2008-07-11 Thread Kenn Konstabel
try something like this: x-c(220a1, 220ab1, 220a12, a34dkaffdse223, abc123) sub(.*([[:digit:]]{3}).*, \\1, x) ( ?regexp is also useful) kk On Fri, Jul 11, 2008 at 12:04 PM, Kunzler, Andreas [EMAIL PROTECTED] wrote: Thank you a lot, I am almost done, but unfortunately I have to manipulate

Re: [R] Subsetting an array by a vector of dimensions

2008-07-24 Thread Kenn Konstabel
Returning to the old question ... Is it possible to subset an n-dimensional array by a vector of n dimensions? On Sat, Jul 12, 2008 at 1:34 AM, Wolfgang Huber [EMAIL PROTECTED] wrote: do.call([, list(x,1,2,TRUE)) [1] 3 9 15 21 See also

Re: [R] problem with nested loops

2008-07-30 Thread Kenn Konstabel
What you need is chapter 9 in http://cran.r-project.org/doc/manuals/R-intro.pdf . And you could also use chapter 2, especially 2.2. specdist -matrix(NA,nrow=40,ncol=20) for (j in 1:40){ for(i in 1:20){

Re: [R] matrix from list

2008-04-28 Thread Kenn Konstabel
On Sun, Apr 27, 2008 at 4:43 AM, Greg Snow [EMAIL PROTECTED] wrote: What if mylist - list( 1:10, 101:110 , some.other.things) so the first 2 elements are vectors of length 10. then mylist[1:2] makes sense as still being a list with the 2 vectors. What should mylist[[1:2]] return in this

[R] Consecutive zeros in a vector

2008-04-29 Thread Kenn Konstabel
Suppose X is a long vector of integers (typically about 3 elements). Is there an efficient way to detect whether there are at least N consecutive zeros in X, and if yes, where does this occur? for example, suppose X is: 1 2 3 4 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 4 2 0 1 2 0 0 0 2 2 2 2 2 ...

Re: [R] applying cor.test to a (m, n) matrix

2008-05-09 Thread Kenn Konstabel
I've used the following function (I wrote it some time ago so I don't remember any more why I needed it, but I checked and it still works). I don't think you can get rid of for loops altogether: if you look at the code of apply, you'll see some there too. The argument STATS specifies those

Re: [R] Inconsistent linear model calculations

2008-05-15 Thread Kenn Konstabel
On Thu, May 15, 2008 at 3:05 PM, e-letter [EMAIL PROTECTED] wrote: Using version 251 I tried the following command: lm(y~a+b,data=datafile) Resulting in, inter alia: ... coefficients (intercept) a 1.2 3.4 [...] When using version 171 I entered the same command:

Re: [R] Dimensions of svd V matrix

2008-05-16 Thread Kenn Konstabel
I'm not an expert at all, but isn't it that you really want svd(x)$u to be different (instead of V)? that would be easy to do: x - matrix(rnorm(15), 3, 5) s1 - svd(x) s2 - svd(x, nv=ncol(x)) x1 - s1$u %*% diag(s1$d) %*% t(s1$v) x2 - cbind(s2$u,1,1) %*% diag(c(s1$d,0,0)) %*% t(s2$v)

Re: [R] Need some hint on faster data manipulation.

2008-05-17 Thread Kenn Konstabel
Can it be this: foo-tapply(d$tt, d$v, min) data.frame(v=names(foo), tt=foo) On Sat, May 17, 2008 at 10:56 PM, jim holtman [EMAIL PROTECTED] wrote: Is this what you want: v-c(rep(v1,3), rep(v2,4), rep(v3,2),v4,rep(v5,6)) tt-c(1,2,3,3,1,2,3,4,5,2,7,9,2,3,1,4)

Re: [R] Factor Analysis Output from R and SAS

2009-03-31 Thread Kenn Konstabel
As it was already pointed out by others, you used different methods (principal components in SAS vs. factor analysis in R). When you use the same method (+ varimax rotation) in both programs, there may still be a *small* difference: this comes from (possibly) different stopping criteria. In R, the

Re: [R] A way to get the R data stored temporarily in working memory?

2009-04-27 Thread Kenn Konstabel
You can interrupt the loop (e.g.. by pressing ESC), look at the results, and then start it again. e.g. mumbo - list() for(jumbo in 1:1e+5000) { mumbo[[jumbo]] - do.many.time.consuming.things.with(jumbo) } # wait for a few days # then press ESC save(mumbo, file=head of mumbo) # now

Re: [R] A way to get the R data stored temporarily in working memory?

2009-04-28 Thread Kenn Konstabel
What ESC does is stopping current computation -- no idea how to do it in ESS, but there's been a similar question in another list: http://www.archivum.info/gnu.emacs.help/2005-10/msg00509.html KK On Mon, Apr 27, 2009 at 9:11 PM, Friedericksen golu...@gmx.de wrote: Hey, that is very cool!

Re: [R] an unsophisticated question about recoding in a data frame with control structure if {}

2008-10-01 Thread Kenn Konstabel
if expects just one condition (no vectors); see ?ifelse dataframe$thevector - ifelse(dataframe$factor==3, a.mean, dataframe$thevector) K On Wed, Oct 1, 2008 at 12:05 PM, Whitt Kilburn [EMAIL PROTECTED] wrote: Hello all, I apologize for a terribly simple question. I'm used to using Stata

Re: [R] create list of data frames

2008-10-27 Thread Kenn Konstabel
Hi, To realize the data frame I've tried this for (i in 1:1000) { foo-list(c(foo[],data.frame( Ce=DATA1.x[,i],Qe=DATA1.y[,i]))) } I think the following would do it: foo - list() for(i in 1:1000) foo[[i]] - data.frame(Ce = DATA1.x[,i], Qe=DATA1.y[,i]) But then again, do you really

Re: [R] Vectorizing sample()

2008-11-07 Thread Kenn Konstabel
Hi, I'm not quite sure I understood everything but is this something close? d - read.table(textConnection(Dad_ID SpouseYN NKids NSick 1 10 1 2 02 2 3 10 2 4 13 3), header=TRUE) mapply(sample,

Re: [R] Variable passed to function not used in function in select=... in subset

2008-11-11 Thread Kenn Konstabel
On Tue, Nov 11, 2008 at 12:27 PM, Wacek Kusnierczyk [EMAIL PROTECTED] wrote: it's certainly hard to design and implement a system of the size of r. it's certainly easier to just complain rather than make a better tool. but it would really be a pitiful world if all of us were just developing,

Re: [R] Selectively Removing objects

2009-02-02 Thread Kenn Konstabel
You can get a list of all functions in your workspace with ls()[sapply(ls(), function(x) is.function(get(x)))] # or ls()[sapply(sapply(ls(), get), is.function)] Removing everything else is rm(list=ls()[sapply(ls(), function(x) !is.function(get(x)))]) # or rm(list=ls()[!sapply(sapply(ls(),

Re: [R] Problem in appending a row to *.csv file

2009-02-09 Thread Kenn Konstabel
For some clever reason, write.csv won't let you set col.names argument to FALSE, but you can use it with write.table using sep=,. A self-contained, minimal, and working example: write.csv(matrix(1:10,2,5), test.csv) write.table(matrix(11:20,2,5), test.csv, sep=,, append=TRUE, col.names=FALSE)

Re: [R] Python and R

2009-02-18 Thread Kenn Konstabel
lm does lots of computations, some of which you may never need. If speed really matters, you might want to compute only those things you will really use. If you only need coefficients, then using %*%, solve and crossprod will be remarkably faster than lm # repeating someone else's example #

Re: [R] Python and R

2009-02-20 Thread Kenn Konstabel
. Problem is that I suspect my colleagues who are providing some guidance with the stats end are not quite experts themselves, and certainly new to R. Cheers, Esmail Kenn Konstabel wrote: lm does lots of computations, some of which you may never need. If speed really matters, you

Re: [R] Hiding information about functions in newly developed packages

2008-12-01 Thread Kenn Konstabel
is my print.function only used if print is called explicitly. (Using R 2.7.0 on Windows.) Kenn Kenn Konstabel Department of Chronic Diseases National Institute for Health Development Hiiu 42 Tallinn, Estonia On Thu, Jul 17, 2008 at 6:55 PM, Peter Dalgaard [EMAIL PROTECTED]wrote: Tudor Bodea wrote

Re: [R] Logical inconsistency

2008-12-11 Thread Kenn Konstabel
Rounding can do no good because round(8.8,1)-round(7.8,1)1 # still TRUE round(8.8)-round(7.7)1 # FALSE What you might do is compute a-b-1 and compare it to a very small number: (8.8-7.8-1) 1e-10 # TRUE K On Wed, Dec 10, 2008 at 11:47 AM, emma jane [EMAIL PROTECTED] wrote: Thanks Greg,

Re: [R] Logical inconsistency

2008-12-11 Thread Kenn Konstabel
(7.8,1)1 [1] TRUE round(8.8-7.8,1)1 [1] FALSE round(8.8-7.8,1)==1 [1] TRUE Bernardo Rangel Tura, M.D,MPH,Ph.D National Institute of Cardiology Brazil -- Original Message --- From: Kenn Konstabel [EMAIL PROTECTED] To: emma jane [EMAIL PROTECTED] Cc: R help [EMAIL

Re: [R] Is = now the same as - in assigning values

2008-12-18 Thread Kenn Konstabel
Hi, On Tue, Dec 16, 2008 at 9:13 AM, Wacek Kusnierczyk waclaw.marcin.kusnierc...@idi.ntnu.no wrote: ... but this is also legal if you really hate - : foo({x = 2}) # assign to x, pass to foo as a This is legal but doesn't do what you probably expect -- although documentation for `-` says

Re: [R] Is = now the same as - in assigning values

2008-12-18 Thread Kenn Konstabel
suspected. Best regards, Kenn Konstabel Department of Chronic Diseases National Institute for Health Development Hiiu 42 Tallinn Estonia [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman

Re: [R] Extracting Hash via Vector

2009-01-13 Thread Kenn Konstabel
Which R version do you have? I'm asking this because my 2.7.0 gives a different error message: x[[q]] Error in x[[q]] : recursive indexing failed at level 2 Anyway, as Wacek said, x[[q]] is equivalent to x[[some]][[more]][[not_there]] -- and you don't have an element called more in x[[some]].

Re: [R] Strange behaviour of paste

2009-01-14 Thread Kenn Konstabel
It's done -- in any case -- just once, after the loop is finished. Remember that hash sign is not just that, it's used for comments! Why should it be surprising that your code will be doing something else when you comment out (i.e. skip) some parts of it? Try this simplified example: sample_times

Re: [R] help with expression()

2009-08-18 Thread Kenn Konstabel
All of it is an expression (see ?expression). Maybe you'd better explain what exactly you're trying to do or what you mean by standard format and usual way (this part depends very much on what you're used to). You can manipulate parts of this expression, say, like this: foo -

Re: [R] R : how does %in% operator work?

2009-08-18 Thread Kenn Konstabel
It would be helpful to give a MUCH shorter example. The problem you have doesn't seem to be too complicated -- you don't need to explain all possible details, just the ones that you think might cause the problem. (Saying it doesn't work isn't helpful -- please be more specific and tell us what you

Re: [R] abind, but on lists?

2009-09-03 Thread Kenn Konstabel
On Thu, Sep 3, 2009 at 5:50 AM, Peter Meilstrup peter.meilst...@gmail.comwrote: I'm trying to massage some data from Matlab into R. The matlab file has a struct array which when imported into R using the R.matlab package, becomes an R list with 3+ dimensions, the first of which corresponds to

Re: [R] export list to csv

2011-03-16 Thread Kenn Konstabel
The optimal way of doing it depends on how you want to use the result. An easy way has been recommended - if you have boo - list(first=data.frame(a=1:5, b=2:6), second=data.frame(a=6:10, b=7:11)) .. then sink(boo.txt) boo # or: print(boo) sink() ... will put it all in the same file, the same

Re: [R] Referring to objects themselves

2011-03-19 Thread Kenn Konstabel
You could (in addition to the other suggestions) try package proto (. refers to self but see also the package's vignette) account - proto( deposit = function(., amount) { if(amount = 0) stop(Deposits must be positive!\n) .$total - .$total + amount

Re: [R] Referring to objects themselves

2011-03-19 Thread Kenn Konstabel
you can omit the list and do the following: open.account.2 - function(total) { deposit - function(amount) { if(amount = 0) stop(Deposits must be positive!\n) total - total + amount cat(amount, deposited. Your balance is, this$balance(),\n\n)

Re: [R] Referring to objects themselves

2011-03-19 Thread Kenn Konstabel
On Sun, Mar 20, 2011 at 4:13 AM, Kenn Konstabel lebats...@gmail.com wrote: you can omit the list and do the following: /.../ (but you don't really need this in this case as you can use balance instead of this$balance) P.S. using this would make some difference in one case: instead

Re: [R] Referring to objects themselves

2011-03-20 Thread Kenn Konstabel
On Sun, Mar 20, 2011 at 12:43 PM, Duncan Murdoch murdoch.dun...@gmail.comwrote: On 11-03-19 10:21 PM, Kenn Konstabel wrote: On Sun, Mar 20, 2011 at 4:13 AM, Kenn Konstabellebats...@gmail.com wrote: you can omit the list and do the following: /.../ (but you don't really need

[R] Curry with `[.function` ?

2011-03-21 Thread Kenn Konstabel
functions that one could be bothered to redefine this way - probably none.) Thanks in advance for any ideas and comments (including the ones saying that this is an awful idea) Best regards, Kenn Kenn Konstabel Department of Chronic Diseases National Institute for Health Development Hiiu 42 Tallinn

Re: [R] Curry with `[.function` ?

2011-03-21 Thread Kenn Konstabel
On Mon, Mar 21, 2011 at 2:53 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Mon, Mar 21, 2011 at 8:46 AM, Kenn Konstabel lebats...@gmail.com wrote: Dear all, I sometimes use the following function: Curry - function(FUN,...) { # by Byron Ellis, https://stat.ethz.ch

Re: [R] Stucked with as.numeric function

2011-03-21 Thread Kenn Konstabel
On Mon, Mar 21, 2011 at 5:57 PM, pat...@gmx.de wrote: Hi list, I have problems with the as.numeric function. I have imported probabilities from external data, but they are classified as factors as str() shows. Therefore my goal is to convert the colum from factor to numeric level with

Re: [R] Accelerating the calculation of the moving average

2011-03-22 Thread Kenn Konstabel
On Tue, Mar 22, 2011 at 3:05 PM, Tonja Krueger tonja.krue...@web.de wrote: Dear List, I have a data frame with approximately 50 rows that looks like this: Datetimevalue … 19.07.1956 12:00:00 4.84 19.07.1956 13:00:00 4.85

Re: [R] Loading mdb

2011-03-22 Thread Kenn Konstabel
I've used RODBC to read in ms access files... or if you're as lazy as me you could use the following below (it can handle some other ms office file types too and thinks it can recognize file types but as has been pointed out in this list, using it with excel probably means trouble) read.mso -

Re: [R] How to convert a single column into many rows

2011-03-23 Thread Kenn Konstabel
On Wed, Mar 23, 2011 at 11:13 AM, Zablone Owiti zow...@ncst.go.ke wrote: Dear users, I wish to convert a column of data  containing  pentad (5day mean data) from 1962 - 2000 into rows with each row having 73 values (ie. 73 pentads per year).  1962  pent1  pent2  pent73 . .

Re: [R] Extract the names of the arguments in an expression

2011-03-24 Thread Kenn Konstabel
I tried this as an exercise and here's what I arrived to: collector - function(expr){ RES - list() foo - function(x) unlist(lapply(x, as.list)) EXPR - foo(expr) while(length(EXPR) 0){ if(is.symbol(EXPR[[1]])){ RES - c(RES, EXPR[[1]]) EXPR - EXPR[-1]

Re: [R] subset and as.POSIXct / as.POSIXlt oddness

2011-03-24 Thread Kenn Konstabel
On Thu, Mar 24, 2011 at 1:29 PM, Michael Bach pha...@gmail.com wrote: Dear R users, Given this data: x - seq(1,100,1) dx - as.POSIXct(x*900, origin=2007-06-01 00:00:00) dfx - data.frame(dx) Now to play around for example: subset(dfx, dx as.POSIXct(2007-06-01 16:00:00)) Ok. Now for

Re: [R] read.xls - rotate data.frame

2011-03-25 Thread Kenn Konstabel
Hi Knut, On Fri, Mar 25, 2011 at 10:43 AM, Knut Krueger r...@knut-krueger.de wrote: Hi to all, how could I  to rotate automatically a data sheet which was imported by read.xls?     x1 x2 x3 xn y1 1   4  7   ...  xn/y1 y2 2   5  8   xn/y2 y3 3   6  9    xn/y2 yn ... ... ...  

[R] Preserving the class of POSIXt objects

2011-03-25 Thread Kenn Konstabel
in the example above. Best regards, Kenn Kenn Konstabel National Institute for Health Development Hiiu 42 Tallinn Estonia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org

Re: [R] Reversing order of vector

2011-03-29 Thread Kenn Konstabel
On Tue, Mar 29, 2011 at 10:20 AM, Vincy Pyne vincy_p...@yahoo.ca wrote: Dear R helpers Suppose I have a vector as vect1 = as.character(c(ABC, XYZ, LMN, DEF)) vect1 [1] ABC XYZ LMN DEF I want to reverse the order of this vector as vect2 = c(DEF, LMN, XYZ, ABC) rev(vect1) Kindly guide

Re: [R] a for loop to lapply

2011-03-30 Thread Kenn Konstabel
Hi Alex, lapply is not a substitute for for, so it not only does things differenly, it does a different thing. Shadowlist-array(data=NA,dim=c(dimx,dimy,dimmaps)) for (i in c(1:dimx)){    Shadowlist[,,i]-i } Note that your test case is not reproducible as you haven't defined dimx, dimy,

Re: [R] Quick recode of -999 to NA in R

2011-03-30 Thread Kenn Konstabel
It could be done in a large number of ways depending on how often you need it etc. You might take a look at defmacro in package gtools: # library(gtools) setNA - macro(df, var, values) { df$var[df$var %in% values] - NA } then instead of dat0[dat0$e1dq==-999.,e1dq] - NA you could

Re: [R] how about a p- operator?

2011-03-31 Thread Kenn Konstabel
Regards, Kenn Kenn Konstabel National Institute for Health Development Hiiu 42 Tallinn On Thu, Mar 31, 2011 at 2:50 AM, William Dunlap wdun...@tibco.com wrote: The %...% operators are not a panacea. they have the same precedence as `*` and `/` (I think) so you get things like:   x %-% 10 - 8

Re: [R] That dreaded floating point trap

2011-03-31 Thread Kenn Konstabel
n Thu, Mar 31, 2011 at 3:56 PM, Alexander Engelhardt a...@chaotic-neutral.de wrote: Am 31.03.2011 14:41, schrieb Sarah Goslee: On Thu, Mar 31, 2011 at 8:14 AM, Alexander Engelhardt this helps, thank you. But if this code is in a function, and some user supplies a vector, I will still have

Re: [R] How to update R?

2011-04-01 Thread Kenn Konstabel
On Thu, Mar 31, 2011 at 9:04 PM, Shi, Tao shida...@yahoo.com wrote: This question has been asked by many people already.  The easiest way is: 1) install the new version 2) copy all or the libraries that you installed later from the library folder of older version to the new version 3)

Re: [R] do not execute newline command

2011-04-05 Thread Kenn Konstabel
On Tue, Apr 5, 2011 at 10:40 AM, Lorenzo Cattarino l.cattar...@uq.edu.au wrote: Hi R-users, To automate the creation of scripts, I converted the code (example below) into a character string and wrote the object to a file: Repeat - myvec - c(1:12) cat('vector= ', myvec, '\n') write

Re: [R] Avoiding a loop

2011-04-08 Thread Kenn Konstabel
2011/4/8 Juan Carlos Borrás jcbor...@gmail.com: #Use the indexes of S in a sapply function. N - 10 S - sample(c(0,1), size=N, replace=TRUE) v1 - sapply(c(1:N-1), function(i) S[i]S[i+1]) You can achieve the same v1 using v1.2 - S[2:N-1] S[2:N] .. or if you insist on having NA as the first

Re: [R] Password-protect R script files

2011-04-11 Thread Kenn Konstabel
: # This is a holy Script, please edit it not Regards, Kenn Konstabel There is a way to do this  from within R, atleast in Windows XP I have tried this and it certainly works , The method  is very different from the OS based folder protection route,  however making available such a method in the open

Re: [R] mapply to lapply

2011-04-18 Thread Kenn Konstabel
On Mon, Apr 18, 2011 at 2:10 PM, Alaios ala...@yahoo.com wrote: Dear Andreas, I would like to thank you for your reply. I have tried two alternatives but none of the two worked out: F2[i+1,j+1]-sum(lapply(1:nrow(cells), function(rowInd)

Re: [R] Deleting the last value of a vector

2011-04-18 Thread Kenn Konstabel
On Mon, Apr 18, 2011 at 4:14 AM, helin_susam helin.su...@gmail.com wrote: if you have a vector like as follows; r=c(1,2,3,4,5) then use r2=r[1:length(r)-1] Umm ... this works and gives the intended answer but does so in an ugly way -- 1:length(r)-1 is equivalent to (1:length(r))-1 or

Re: [R] zero fill empty cell in data.frame

2011-04-19 Thread Kenn Konstabel
regards, Kenn Konstabel __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.

Re: [R] random typing over text

2011-04-25 Thread Kenn Konstabel
On Mon, Apr 25, 2011 at 4:22 AM, Jim Lemon j...@bitwrit.com.au wrote: On 04/24/2011 08:13 AM, derek wrote: Thank you very much. It was the Insert key. It was very annoying. Actually is this owerwrite function of any use? Hi derek, As Duncan mentioned, it is very useful when one wishes to

Re: [R] Assignments inside lapply

2011-04-27 Thread Kenn Konstabel
On Wed, Apr 27, 2011 at 12:58 PM, Nick Sabbe nick.sa...@ugent.be wrote: No, that does not work. You cannot do assignment within (l)apply. Nor in any other function for that matter. Yes that may work if you want to. You can do non-local assignment within lapply using - (and, for that matter,

Re: [R] Still confused about classes

2011-04-29 Thread Kenn Konstabel
The function for getting the year from date is there in package lubridate (as well as many other convenient functions to work with dates). More generally, finding all methods for a given class may be a little tricky. If all means everything you have installed and currently attached to your

Re: [R] Reference variables by string in for loop

2011-04-29 Thread Kenn Konstabel
On Fri, Apr 29, 2011 at 1:03 PM, Michael Bach pha...@gmail.com wrote: Dear R Users, I am trying to get the following to work better: namevec - c(one, two, three) for (name in namevec) {    namedf - eval(parse(text=paste(name, _df, sep=)))    ...    ... } The rationale behind it being

Re: [R] Global variables

2011-05-02 Thread Kenn Konstabel
On Mon, May 2, 2011 at 2:19 PM, abhagwat bhagwatadi...@gmail.com wrote: Well, what would be really helpful is to restrict the scope of all non-function variables, but keep a global for scope of all function variables. Then, you still have access to all loaded functions, but you don't mix up

Re: [R] lapply, if statement and concatenating to a list

2011-05-05 Thread Kenn Konstabel
Hi Lorenzo, On Thu, May 5, 2011 at 8:38 AM, Lorenzo Cattarino l.cattar...@uq.edu.au wrote: Hi R users I was wondering on how to use lapply co when the applied function has a conditional statement and the output is a 'growing' object. See example below: list1 - list('A','B','C') list2 -

Re: [R] extracting p-values in scientific notation

2011-10-03 Thread Kenn Konstabel
is(x) [1] htest # take a look at stats:::print.htest format.pval(x$p.value) [1] 2.22e-16 Does that answer your question? KK On Mon, Oct 3, 2011 at 10:53 AM, Liviu Andronic landronim...@gmail.com wrote: Dear all How does print.htest display the p-value in scientific notation? (x -

Re: [R] 'Apply' giving me errors

2011-10-21 Thread Kenn Konstabel
On Fri, Oct 21, 2011 at 3:09 AM, kickout kyle.ko...@gmail.com wrote: So i have a simple function: bmass=function(y){ weight=y$WT*y$MSTR return(bio) } But this just returns bio and since an object with that name is not defined in the function, it will be looked up in the global environment

Re: [R] R for loop nested?

2011-10-25 Thread Kenn Konstabel
and then start adding something to it) more obvious. Besides, NULL is quicker and more efficient. Sorry for not giving any useful advice, it's late here. Best regards, Kenn Konstabel On Tue, Oct 25, 2011 at 3:19 PM, Delia Shelton delss...@indiana.edu wrote: Hi, I'm trying to execute the same R code

Re: [R] lapply to list of variables

2011-11-10 Thread Kenn Konstabel
Hi hi, It is much easier to deal with lists than a large number of separate objects. So the first answer to your question How can I apply a function to a list of variables. .. might be to convert your list of variables to a regular list. Instead of ... monday - 1:3 tuesday - 4:7 wednesday -

Re: [R] Multiple linear Regression: Standardized Coefficients

2012-02-15 Thread Kenn Konstabel
It's a bit dangerous to call them betas in this list. Standardized regression coefficients sounds much better :) A simple way is to first standardize your variables and then run lm again. lm(scale(height)~scale(age) + factor(sex)) # or, depending on what you want:

Re: [R] how to merge within range?

2011-05-15 Thread Kenn Konstabel
I'd've first said it's simply sapply(df1$time, function(x) if(any(foo - (x=df2$from x=df2$to))0) df2$value[which(foo)] else NA ) but the following are much nicer (except that instead of NA you'll have 0 but that's easy to change if necessary): colSums(sapply(df1$time, function(x) (x=df2$from

Re: [R] Apply or Tapply to Build Set of Tables

2011-05-24 Thread Kenn Konstabel
On Tue, May 24, 2011 at 4:01 AM, Jim Holtman jholt...@gmail.com wrote: untested x - lapply(names(infert),function(a)table(infert[[a]])) This part can be simpler: lapply(infert,table) But extending it to the rest of the problem (i.e., 2-way tables) is not trivial and can be confusing. # 1

Re: [R] skip reading a file.

2011-05-24 Thread Kenn Konstabel
You might use dir() to get the file names (if they are in the same folder), or something like dir(pattern=^file.*) if you want to read only some files from there. Then for storing the result as something like store[i,j] as in your example, you could split the file name using something like

Re: [R] Count of rows while looping through data

2011-05-25 Thread Kenn Konstabel
An alternative approach would be to `split` the data frame by family, then `lapply` a function selecting random row from each slice, and then `rbind` it all together. x = data.frame(family = rep(1:20,sample(2:5,20,replace=TRUE)), xyz=1) randomrow - function(x) x[sample(1:nrow(x),1),] # step by

Re: [R] Subtracting rows by id

2011-05-26 Thread Kenn Konstabel
Or without plyr: # Dennis's sample data but with shortened names ds - data.frame(id = rep(1:3, each = 10), value1 = sample(seq_len(100), 30, replace = TRUE)) k - data.frame(id = 1:3, sv = c(1, 3, 5)) do.call(rbind, mapply( function(a,b) subset(ds, id==a)[-1:-b,],

Re: [R] NaN, Inf to NA

2011-05-27 Thread Kenn Konstabel
On Fri, May 27, 2011 at 11:27 AM, Albert-Jan Roskam fo...@yahoo.com wrote: Aha! Thank you very much for that clarification! It would be much more user friendly if R generated a NotImplementedError or something similar. The 'garbage results' are pretty misleading, esp. to a novice. I wanted

  1   2   >