[R] Sales invoice

2018-11-05 Thread Kenn Konstabel
Good day, Your Kenn Konstabel invoice is available Sincerely, Kenn Konstabel T: 0865 102 7899 e-Mail:lebats...@gmail.com We are committed to reducing its impact on the environment. Please don't print this email unless absolutely necessary. ___

Re: [R] R on Windows crashes when source'ing UTF-8 file

2014-07-10 Thread Kenn Konstabel
-8-BOM" reads in the file correctly. On Thu, Jul 10, 2014 at 5:50 PM, Duncan Murdoch wrote: > On 10/07/2014 9:53 AM, Kenn Konstabel wrote: >> >> Wow. Thanks a lot! >> >> source("http://psych.ut.ee/~nek/R/test-utf8.txt";, encoding="UTF-8-BOM")

Re: [R] R on Windows crashes when source'ing UTF-8 file

2014-07-10 Thread Kenn Konstabel
Wow. Thanks a lot! source("http://psych.ut.ee/~nek/R/test-utf8.txt";, encoding="UTF-8-BOM") # works correctly on my Windows 7 machine # (and without encoding argument it still crashes R) Kenn On Thu, Jul 10, 2014 at 4:33 PM, John McKown wrote: > On Thu, Jul 10, 2014 at

[R] R on Windows crashes when source'ing UTF-8 file

2014-07-10 Thread Kenn Konstabel
e everything worked). Context: I was trying to find out how to make files that could be source'd on both windows and linux. This is partly solved so I have no specific question other than "is this a bug in windows version?" but any comments on the general topic

Re: [R] importing multiple text files in R

2014-04-01 Thread Kenn Konstabel
you can extract numbers from your file names and then sort them like this: filelist = list.files(pattern = ".s*.txt") filelist[order(as.integer(gsub("[^0-9]", "", filelist)))] (cf with alphabetic order: filelist[order(gsub("[^0-9]", "", filelist))] Or if you just have s1...s120 you can construct

Re: [R] Fwd: rbind error - duplicated row.names not allowed

2014-04-01 Thread Kenn Konstabel
deleting the old rownames might help. rownames(df1) <- rownames(df2) <- rownames(df3) <- NULL But a reproducible example would be interestng. In simple cases there is no problem with "duplicated" rownames as they are automatically renamed: > df1 <- data.frame(A=1, B=2, row.names="A") > df2 <- da

Re: [R] can you explain the cov2cor function

2013-09-19 Thread Kenn Konstabel
On Wed, Sep 18, 2013 at 12:14 PM, Pascal Oettli wrote: > It's a function of package "sos", quite useful to find functions in R. > > > It is interesting to note that neither RSiteSearch("cov2cor") nor findFn("cov2cor") seem to be able to find cov2cor (from the stats package! so it's there on every

Re: [R] can you explain the cov2cor function

2013-09-18 Thread Kenn Konstabel
Hi, > What does every line mean especially the expression > [1L], [2L], and > (1L:p, 1L:p) 1L, 2L etc are integers. (That is, identical to as.integer(1) , as.integer(2) etc) Using integers (instead of "numeric" type) is more efficient as here they're used as indexes and would be converted to int

Re: [R] aggregate.data.frame with NAs and different types

2013-05-13 Thread Kenn Konstabel
or without plyr you could do, e.g., aggregate(df2aggregate[,-1], df2aggregate["id"], function(..) if(is.numeric(..)) mean(..) else if(is.character(..)) ..[1]) Kenn On Mon, May 13, 2013 at 1:30 AM, Spencer Graves < spencer.gra...@structuremonitoring.com> wrote: > Hi, Arun: Thanks. That's exac

[R] Notes and warnings in building a package ('ms-dos style file name', 'no visible binding' and using .C("bincount", ..., PACKAGE = "base"))

2013-04-11 Thread Kenn Konstabel
C("bincount", ..., PACKAGE = "base") Packages should not make .C/.Call/.Fortran calls to base packages. They are not part of the API, for use only by R itself and subject to change without notice." I understand the reasons but what would be a good solution if I like the way it

Re: [R] (no subject)

2013-04-11 Thread Kenn Konstabel
<-cat('"',a,'"',sep="")} > utf2uxxx("õäöü") > #"\u00f5\u00e4\u00f6\u00fc" > > sessionInfo() > R version 3.0.0 (2013-04-03) > Platform: x86_64-unknown-linux-gnu (64-bit) > > A.K. > > > > - Original Me

[R] (no subject)

2013-04-11 Thread Kenn Konstabel
this. (I couldn't find anything useful from searches incl RSiteSearch). Thanks in advance, Kenn -- P.S. Apologies if this is double posted - there was a network error and the first message doesn't seem to have been sent out (but maybe it was). Kenn Konstabel Department of Chroni

Re: [R] map two names into one

2012-09-26 Thread Kenn Konstabel
It may be easy or difficult depending on what your data are like. "GALAXY ACE S 5830" vs "S 5830 GALAXY ACE" One easy and reasonably general way would be to divide each such bit into 4 "words" and then compare if set 2 contains exactly all words in set 1 but possibly in different order. x1 <- "G

Re: [R] add reference lines (or grid) in background

2012-09-18 Thread Kenn Konstabel
e white background of boxplot; so it might help to make this background transparent instead of white; but I haven't examined the code so can't be sure this is what bxp does). Or it might be easier to do it with ggplot. Regards, Kenn Konstabel On 9/18/12, John Kane wrote: > Not sure

Re: [R] pass by reference

2012-08-14 Thread Kenn Konstabel
You can use macros for this effect. Or environments: daf <- data.frame(a=1:10, b=rnorm(10)) env <- as.environment(daf) fun <- function(x) x$c <- x$a+x$b fun(daf) fun(env) daf$c env$c You can see that the same function (fun) changes one object but leaves another one unchanged. But before using i

Re: [R] Standard introductory presentation

2012-08-13 Thread Kenn Konstabel
Not really an answer but since you said something about "blessings" and "spreading the word": I have a small presentation introducing the time saving aspects of R comparing it to a programme called Statistica that I used to use but that I now use mainly to convert its native files to a rreadable f

Re: [R] set working directory to current source directory

2012-08-13 Thread Kenn Konstabel
When you close R it asks whether to save the workspace. I often say "yes" and later start R by double clicking on that workspace (named .Rdata) -- then the wd is automatically set. Alternatively you can have setwd("X:/some/thing") at the beginning of your source file. On Tue, Aug 14, 2012 at 3:40

Re: [R] R exercises - too confusing for me.

2012-05-09 Thread Kenn Konstabel
Hi, But what if your professor reads this list? Anyway, who cares, two hints: 1. It might be useful to read the explanations provided with the problem. For example, your exercise tells you that "use the help command ?rexp to read how to generate exponentially distributed variables". On a careful

Re: [R] Global variables

2012-05-06 Thread Kenn Konstabel
On Fri, May 4, 2012 at 3:06 PM, Luis Goncalves wrote: > > > On May 2 2011, 3:02 pm, Kenn Konstabel wrote: >> On Mon, May 2, 2011 at 2:19 PM, abhagwat wrote: >> > Well, what would be really helpful is to restrict the scope of all >> > non-function variables, b

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: lm(height~scale(age)+factor(

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] R for loop nested?

2011-10-25 Thread Kenn Konstabel
table a `name` may be confusing to some readers. And saying that xx<- c() ... is just another way of saying that xx <- NULL . NULL is clearer than c() as it makes your intention (to make an empty object and then start adding something to it) more obvious. Besides, NULL is quicker and more ef

Re: [R] 'Apply' giving me errors

2011-10-21 Thread Kenn Konstabel
On Fri, Oct 21, 2011 at 3:09 AM, kickout 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 (workspace) an

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 wrote: > Dear all > How does print.htest display the p-value in scientific notation? >> (x <- cor.test(iris

Re: [R] In a formula, what is the interaction of the intercept and a factor?

2011-05-31 Thread Kenn Konstabel
With some guessing: does lm(formula = y ~ -1 + group + x:group, data = dat) do what you want? I'm not sure now 1:group is treated, if at all. Kenn On Tue, May 31, 2011 at 11:35 PM, Kevin Wright wrote: > For a pedagogical purpose, I was trying to show how the formula for a simple > regression lin

Re: [R] how to store object without loosing their class property

2011-05-31 Thread Kenn Konstabel
use "list" instead of "c": models <- list(model,model) sapply(models, class) # [,1] [,2] # [1,] "svm.formula" "svm.formula" # [2,] "svm" "svm" For understanding what c does in your case: c(list(first=1, second=2), list(third=3, fourth=4)) # compare this with list(list(firs

Re: [R] Put names in the elements of lapply result

2011-05-30 Thread Kenn Konstabel
On Fri, May 27, 2011 at 6:12 PM, Bert Gunter wrote: > Jonathan et. al: > > Yes, of course, but I'd say Type III error: Right answer to wrong question. > The real question (imho only obviously) is: "What data structure > should be used?" -- and the standard answer for this sort of thing in > R is:

Re: [R] NaN, Inf to NA

2011-05-27 Thread Kenn Konstabel
On Fri, May 27, 2011 at 11:27 AM, Albert-Jan Roskam 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 to recode

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,], k$i

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 s

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 strspl

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 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 lapply(infert, fu

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>=df

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 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 <- c() > > myf

Re: [R] Global variables

2011-05-02 Thread Kenn Konstabel
On Mon, May 2, 2011 at 2:19 PM, abhagwat 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 variables. > > How wou

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 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

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 se

Re: [R] Assignments inside lapply

2011-04-27 Thread Kenn Konstabel
On Wed, Apr 27, 2011 at 12:58 PM, Nick Sabbe 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, within any other

Re: [R] random typing over text

2011-04-25 Thread Kenn Konstabel
On Mon, Apr 25, 2011 at 4:22 AM, Jim Lemon 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 type ove

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

2011-04-19 Thread Kenn Konstabel
in a list of 20, and in data entry, checked items were entered as 1's but the cells corresponding to unchecked items were left empty ... so I had to replace all NA's with 0's except in rows with nothing but NA's; there are probably many other legitimate examples). Best regards, Kenn Ko

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 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 0:(length(r)-1) --

Re: [R] mapply to lapply

2011-04-18 Thread Kenn Konstabel
On Mon, Apr 18, 2011 at 2:10 PM, Alaios 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) > Fwithcellvalue(i=i,j=j,a=cells[rowInd,2],b=cells[rowInd,4],c=cel

Re: [R] Password-protect R script files

2011-04-11 Thread Kenn Konstabel
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 for

Re: [R] Avoiding a loop

2011-04-08 Thread Kenn Konstabel
2011/4/8 Juan Carlos Borrás : > #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 elemen

Re: [R] do not execute newline command

2011-04-05 Thread Kenn Konstabel
On Tue, Apr 5, 2011 at 10:40 AM, Lorenzo Cattarino 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 (Repeat,

Re: [R] How to update R?

2011-04-01 Thread Kenn Konstabel
On Thu, Mar 31, 2011 at 9:04 PM, Shi, Tao 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) uninstall the

Re: [R] That dreaded floating point trap

2011-03-31 Thread Kenn Konstabel
n Thu, Mar 31, 2011 at 3:56 PM, Alexander Engelhardt 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 to r

Re: [R] how about a "

2011-03-31 Thread Kenn Konstabel
t; a %<-% 1000 + 1 [1] 1001 > a [1] 1000 Regards, Kenn Kenn Konstabel National Institute for Health Development Hiiu 42 Tallinn On Thu, Mar 31, 2011 at 2:50 AM, William Dunlap wrote: > The %...% operators are not a panacea. > they have the same precedence as `*` > and `/` (I th

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 coul

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] Reversing order of vector

2011-03-29 Thread Kenn Konstabel
On Tue, Mar 29, 2011 at 10:20 AM, Vincy Pyne 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(vect

[R] Preserving the class of POSIXt objects

2011-03-25 Thread Kenn Konstabel
ter these changes, [ and length would work "correctly" (in my possibly naive understanding), and length(trunc(foo, "day")) would return 10 in the example above. Best regards, Kenn Kenn Konstabel National Institute for Health Development Hiiu 42 Tallinn Estonia _

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 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 ... ... ...         Xn/Y

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 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 fo

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] 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 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] 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 <- fun

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 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 > 19.07.1956

Re: [R] Stucked with as.numeric function

2011-03-21 Thread Kenn Konstabel
On Mon, Mar 21, 2011 at 5:57 PM, 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 > keeping the d

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

2011-03-21 Thread Kenn Konstabel
On Mon, Mar 21, 2011 at 2:53 PM, Gabor Grothendieck wrote: > On Mon, Mar 21, 2011 at 8:46 AM, Kenn Konstabel > wrote: > > Dear all, > > > > I sometimes use the following function: > > > > Curry <- function(FUN,...) { > > # by Byron Ellis, &g

[R] Curry with `[.function` ?

2011-03-21 Thread Kenn Konstabel
e. (And neither is replacing "[" with "Curry" by using substitute et al. inside `foo`, - this would make it usable only within 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 t

Re: [R] Referring to objects themselves

2011-03-20 Thread Kenn Konstabel
On Sun, Mar 20, 2011 at 12:43 PM, Duncan Murdoch wrote: > On 11-03-19 10:21 PM, Kenn Konstabel wrote: > >> On Sun, Mar 20, 2011 at 4:13 AM, Kenn Konstabel >> wrote: >> >> you can omit the list and do the following: >>> >>> >>> /.../ >&

Re: [R] Referring to objects themselves

2011-03-19 Thread Kenn Konstabel
On Sun, Mar 20, 2011 at 4:13 AM, Kenn Konstabel 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

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
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] 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 sa

Re: [R] Pointwise division of two zoo objects?

2011-03-15 Thread Kenn Konstabel
Hi, > returns.z = tail(prices.z,-1)/head(prices.z,-1) - 1 # should be equivalent > to returns = exp(diff(log(prices.z))) - 1 > > Curiously, I get a zoo object back with zeros everywhere and also with the > index having one fewer element than it should. > > Does anyone know how to pointwise divid

[R] sqlFetch (RODBC) question

2011-03-03 Thread Kenn Konstabel
graphics grDevices utils datasets methods base other attached packages: [1] RODBC_1.3-2 loaded via a namespace (and not attached): [1] iterators_1.0.3 tools_2.12.1 Thanks in advance, Kenn Kenn Konstabel Department of Chronic Diseases National Institute for He

Re: [R] Running out of memory when importing SPSS files

2011-02-10 Thread Kenn Konstabel
On Wed, Feb 18, 2009 at 9:21 PM, dobomode wrote: > I am trying to import a large dataset from SPSS into R. The SPSS file > is in .SAV format and is about 1GB in size. I use read.spss to import > the file and get an error saying that I have run out of memory. I am > on a MAC OS X 10.5 system with

Re: [R] Odp: Loop to mapply. Error

2011-02-03 Thread Kenn Konstabel
On Thu, Feb 3, 2011 at 1:16 PM, Alaios wrote: > I am sorry that I did not provide all the required data (for me is not very > straight-forward to understand what I have to provide and what not) > > > findCell<-function(x,sr){ # It is just for me understand how mapply works > sr[x[1],x[2]

Re: [R] mapply question (?)

2011-02-03 Thread Kenn Konstabel
On Thu, Feb 3, 2011 at 1:26 PM, Albert-Jan Roskam wrote: > Hi, > > I have a function myFun which I want to call multiple times, using > different > argument lists. > myFun("v1", "2009", 1) > myFun("v2", "2008", 1) > myFun("q", "2001") > Notice that the third call is different, you have 3 args in

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] abind, but on lists?

2009-09-03 Thread Kenn Konstabel
On Thu, Sep 3, 2009 at 5:50 AM, Peter Meilstrup wrote: > 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 the > structure fiel

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 yo

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 <- expression(NA_char

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 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 > may be no

Re: [R] Question about <<- assignment

2009-07-02 Thread Kenn Konstabel
On Thu, Jul 2, 2009 at 4:34 AM, Rolf Turner 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] Clearing out or reclaiming memory

2009-07-01 Thread Kenn Konstabel
On Wed, Jul 1, 2009 at 3:02 AM, gug 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 seems to work). >

Re: [R] Clearing out or reclaiming memory

2009-06-30 Thread Kenn Konstabel
On Tue, Jun 30, 2009 at 2:36 PM, gug 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 headings within the re

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] 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 wrote: > Hey, > > that is very cool! But there is

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 save(mumbo, file="head of mumbo") # now

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] Python and R

2009-02-20 Thread Kenn Konstabel
for you. > > > > > Not an expert in statistics myself, I am mostly concentrating on the > > programming aspects of R. Problem is that I suspect my colleagues who > > are providing some guidance with the stats end are not quite experts > > themselves, and certainly new

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 # lm(DAX

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=FA

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(), ge

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_time

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[[

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

2008-12-18 Thread Kenn Konstabel
is cleverer and much less obscure than I 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

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 `<-

Re: [R] Logical inconsistency

2008-12-11 Thread Kenn Konstabel
approach. > > The optimal use of round is using in last calculation: > > Look this > > > round(8.8,1)-round(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 > N

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

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

2008-12-01 Thread Kenn Konstabel
be interesting to know what is happening here.. i.e., why 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 Da

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 > develo

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, d$NKids+d$

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 re

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

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) > x2<-c(2,3,4,3,4,3,4,2,2,3,4

Re: [R] Deleting NA in list()

2008-08-25 Thread Kenn Konstabel
(x[1])? So I assume that what you meant is actually something like 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... > > > &g

  1   2   >