Re: [R] Parallel code using parLapply

2012-12-21 Thread Gabor Grothendieck
On Fri, Dec 21, 2012 at 10:42 AM, Chris Hergarten  wrote:
> Dear R-users
>
> I was running into problems with my R code trying to run clh sampling (clhs 
> package) in parallel mode (=on various data sets simultaneously).
>
> Here is the code (which I developed with some help:)):
> **
> library("clhs")
> library("snow")
> a <- as.data.frame(replicate(1000, rnorm(20)))
> b <- as.data.frame(replicate(1000, rnorm(20)))
> c <- as.data.frame(replicate(1000, rnorm(20)))
> d <- as.data.frame(replicate(1000, rnorm(20)))
> abcd <- list(a, b, c, d)
> cl <- makeCluster(4)
> results <- parLapply(cl,
>X = abcd,
>FUN = function(i) {
>  clhs(x = i, size = round(nrow(i) / 5), iter = 2000, simple = FALSE)
>},
> )
> stopCluster(cl)
> **
>
> Before running the last line, R is throwing an error: "Error in length(x) : 
> 'x' is missing". Any ideas what I am doing wrong and how to improve?
>

Loading clhs on the primary does not automatically load it on the workers.  Try:

clusterEvalQ(cl, library(clhs))

--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

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


Re: [R] how to control the naming of factors in regression

2012-12-21 Thread William Dunlap
The '.L', ..., '^6' are the column names from the output contr.poly(),
the default contrasts function for ordered factors.  You can define
your own contrasts function that calls contr.poly() and renames the
columns to something you like, then set options("contrasts") so your
contrasts function is used for ordered factors.

> contr.myPoly <- function(...) { tmp <- contr.poly(...) ; colnames(tmp) <- 
> paste0("Degree",seq_len(ncol(tmp))) ; tmp }
> options(contrasts=c("contr.treatment", "contr.myPoly"))
> d <- data.frame(y=1:20, x=ordered(rep(letters[1:6],length=20)))
> lm(y ~ x, data=d)

Call:
lm(formula = y ~ x, data = d)

Coefficients:
(Intercept) xDegree1 xDegree2 xDegree3 xDegree4 xDegree5  
10.5000   1.3148   1.3093   0.4472  -1.1339   0.7559  

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 Francesco Sarracino
> Sent: Friday, December 21, 2012 5:13 PM
> To: r-help@r-project.org
> Subject: [R] how to control the naming of factors in regression
> 
> Dear R listers,
> 
> I am regressing an ordered variable over an ordered independent variable
> using polr.
> 
> The output lists every level of the ordered independent variable repeating
> its name and adding a suffix. In my case my variable is called "o.particip"
> and in my regression table I get the following:
> 
> o.particip.L
> 
> o.particip.Q
> 
> o.particip.C
> 
> o.particip^4
> 
> o.particip^5
> 
> o.particip^6
> 
> 
> Is there any way to control the way R name the levels? I'd like each level
> to be consistently identified (either numbers or letters) and preferably
> I'd prefer to see the original naming of the level (the value label - in
> Stata dictionary). Moreover, the little "hat" in "o.particip^4" drives
> latex nuts. Any ideas on how to fix these things?
> Thank you very much for your kind help,
> f.
> 
> --
> Francesco Sarracino, Ph.D.
> https://sites.google.com/site/fsarracino/
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] how to control the naming of factors in regression

2012-12-21 Thread Francesco Sarracino
Dear R listers,

I am regressing an ordered variable over an ordered independent variable
using polr.

The output lists every level of the ordered independent variable repeating
its name and adding a suffix. In my case my variable is called "o.particip"
and in my regression table I get the following:

o.particip.L

o.particip.Q

o.particip.C

o.particip^4

o.particip^5

o.particip^6


Is there any way to control the way R name the levels? I'd like each level
to be consistently identified (either numbers or letters) and preferably
I'd prefer to see the original naming of the level (the value label - in
Stata dictionary). Moreover, the little "hat" in "o.particip^4" drives
latex nuts. Any ideas on how to fix these things?
Thank you very much for your kind help,
f.

-- 
Francesco Sarracino, Ph.D.
https://sites.google.com/site/fsarracino/

[[alternative HTML version deleted]]

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


Re: [R] NRI reclassification table improveProb Cox

2012-12-21 Thread Frank Harrell
As describe in the Hmisc package's improveProb function, that function is for
binary Y.  And it's best to use category-free methods.
Frank

Petergodsk wrote
> Hi
> 
> I'm new to R. 
> 
> Is it possible to use the improveProb function to generate categorybased
> NRI using a Cox model?
> I believe I saw someone mentioning the possibility, but I can't find the
> syntax in the R help. 
> 
> Thanks,
> Peter Godsk





-
Frank Harrell
Department of Biostatistics, Vanderbilt University
--
View this message in context: 
http://r.789695.n4.nabble.com/NRI-reclassification-table-improveProb-Cox-tp4653768p4653770.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] texreg error while exporting regression table

2012-12-21 Thread Francesco Sarracino
Dear listers,

I am trying to export my regression table to my latex document.
Let's say I have two variables:
an ordered factor:
group <- gl(3,5,20, labels=c("Ctl","Trt","prp"))
and a continuous variable:
weight <- runif(20)

I want to regress group over weigth, therefore I run:

reg2 <- polr(group ~ weight, Hess = TRUE, method = "logistic", model = TRUE)

Finally, I wish to include a table with the results in my latex document.
Hence I run:

tt <- texreg(reg2)

but I get the following error:

Error in beta[, 1] : incorrect number of dimensions


Any ideas about what am I doing wrong?

Thanks in advance,

f.


-- 
Francesco Sarracino, Ph.D.
https://sites.google.com/site/fsarracino/

[[alternative HTML version deleted]]

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


Re: [R] ggplot2: setting martin

2012-12-21 Thread Ista Zahn
Well, the margin is being set large enough to accommodate  the labels.
So if you want narrower margins just shorten the labels:

library(stringr)
P + scale_x_discrete(labels = function(x) str_wrap(x, width=12))


HTH,
Ista
On Fri, Dec 21, 2012 at 5:35 PM, Frans Marcelissen
 wrote:
> Is it possible to set the margin in ggplot2 to a fixed size? I create many
> plots, and I want them to look the same.
>
> Especially I want them to have the same left margin.
>
> But
>
> P<-ggplot()+geom_bar(aes(c("short label1","short
> label2"),runif(2)))+coord_flip()
>
> P<-creates a plot with another margin as
>
> ggplot()+geom_bar(aes(c("very very very very long label1","short
> label2"),runif(2)))+coord_flip()
>
>
>
> In the standard plot system margins can be set with par(mar=c(...)), but
> this doesn't work in ggplot2
>
> I thought I could do it with plot.margin, but
>
> p+theme(plot.margin= unit(c(0, 0, 0,3), "cm"))
>
> doesn't work,it adds extra, external margins.
>
> Does anyone know a solution?
>
> Thanks
>
> Frans
>
> ---
> dr F.H.G. (Frans) Marcelissen
> DigiPsy (  www.DigiPsy.nl)
> Pomperschans 26
> 5595 AV Leende
> tel: 040 7630487 (let op: nieuw nummer, oude nummer blijft actief)
> skype adres: frans.marcelissen
> email:   frans.marcelis...@digipsy.nl
>
>
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] ggplot2: setting martin

2012-12-21 Thread Frans Marcelissen
Is it possible to set the margin in ggplot2 to a fixed size? I create many
plots, and I want them to look the same.

Especially I want them to have the same left margin.

But

P<-ggplot()+geom_bar(aes(c("short label1","short
label2"),runif(2)))+coord_flip()

P<-creates a plot with another margin as 

ggplot()+geom_bar(aes(c("very very very very long label1","short
label2"),runif(2)))+coord_flip()

 

In the standard plot system margins can be set with par(mar=c(...)), but
this doesn't work in ggplot2

I thought I could do it with plot.margin, but

p+theme(plot.margin= unit(c(0, 0, 0,3), "cm"))

doesn't work,it adds extra, external margins.

Does anyone know a solution?

Thanks

Frans

---
dr F.H.G. (Frans) Marcelissen
DigiPsy (  www.DigiPsy.nl)
Pomperschans 26
5595 AV Leende
tel: 040 7630487 (let op: nieuw nummer, oude nummer blijft actief)
skype adres: frans.marcelissen
email:   frans.marcelis...@digipsy.nl

 


[[alternative HTML version deleted]]

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


Re: [R] Legend symbols

2012-12-21 Thread Greg Snow
Using pch you can use all the symbols in the current font, try:

plot(0:15, 0:15, type='n')
points( (0:255)%%16, (0:255)%/%16, pch=0:255 )

then do it again with
points( (0:255)%%16, (0:255)%/%16, pch=0:255, font=5 )

(font 5 is usually a symbol font, fonts 2, 3, and 4 are bold and italic
versions of the base font (font 1)).

If that does not give you enough variety in symbols then look at the
my.symbols function in the TeachingDemos package, this lets you create and
use your own symbols (though automatic legends are not available).


On Fri, Dec 21, 2012 at 3:06 PM, Diviya Smith wrote:

> Hi there,
>
> I was wondering if there is any R package that one can use for plotting
> that has more legend symbols - the standard pch has 18 symbols but I need
> ~30 for my application- and just using different colors is not an option.
>
> Thank you in advance,
> Diviya
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

[[alternative HTML version deleted]]

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


[R] Legend symbols

2012-12-21 Thread Diviya Smith
Hi there,

I was wondering if there is any R package that one can use for plotting
that has more legend symbols - the standard pch has 18 symbols but I need
~30 for my application- and just using different colors is not an option.

Thank you in advance,
Diviya

[[alternative HTML version deleted]]

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


Re: [R] how can I import op.gz files with read.csv or otherwise

2012-12-21 Thread Rui Barradas

Hello,

It can be read using readLines. I've changed url to URL because there's 
a function of that name.

I've also changed dest.

URL <- "ftp://ftp.ncdc.noaa.gov/pub/data/gsod/2012/285880-9-2012.op.gz";
dest <- "weather.op.gz"
download.file(URL, dest)
gz <- gzfile(dest, open = "rt")
x <- readLines(gz)
close(gz)
x


Like you say, headers and data are not consistent, it seems some column 
headers are missing.


Hope this helps,

Rui Barradas

Em 21-12-2012 17:44, John Kane escreveu:

Try downloading it and decompress it:

   url <- "ftp://ftp.ncdc.noaa.gov/pub/data/gsod/2012/285880-9-2012.op.gz";
   dest <- "/home/john/rdata/weather.op.gz"
   download.file(url, dest)

However it does not look like a nicely formatted file and you may have to do 
some cleanup in a text editior or perhaps load it into a spreadsheet before you 
read it into R.

I tried the method from the link arun provided and it did not work.  It looks 
like the headers and data are not consistant
John Kane
Kingston ON Canada



-Original Message-
From: herrdittm...@yahoo.co.uk
Sent: Fri, 21 Dec 2012 14:51:05 + (GMT)
To: r-help@r-project.org
Subject: [R] how can I import op.gz files with read.csv or otherwise

Dear R-users,

I am struggling to directly read an "op.gz" file into R. NOAA kindly
provides daily weather data on their FTP server for download.



sessionInfo()

R version 2.15.1 (2012-06-22)
Platform: x86_64-pc-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_United Kingdom.1252B  LC_CTYPE=English_United
Kingdom.1252B B B  LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=CB B B B B B B B B B B B B B B B B B B B B B B B B B B
LC_TIME=English_United Kingdom.1252B B  B
attached base packages:
[1] statsB B B B  graphicsB  grDevices utilsB B B B  datasetsB  methodsB
B  baseB B B  B
loaded via a namespace (and not attached):
[1] tools_2.15.1

Here is the data set in question:
x <-

read.csv(file="ftp://ftp.ncdc.noaa.gov/pub/data/gsod/2012/285880-9-2012.op.gz";,

skip = 1, sep = "")

and "structure" returns some incomprehensible gibberish:


str(x)

'data.frame':B B  70 obs. ofB  6 variables:
B $ X4C tYd...C?C?8.C%WD...C+C<.C/C?.X.QTC1VP..B B B B B B B B B B B B B
B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B
B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B
B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B  : Factor w/
70 levels "\005~4C(dE?C?C-E\031y\020C?C-B:\035JC+C/C?IK?C?C-\021b?
BC?C?R{E>Ykv\035`b??C,B0a\017Z\021C?sPb??eC?hC?C?""| __truncated__,..: 44
13 56 64 28 23 67 3 2 33 ...
B $ X.C6oMC=C?T..C?B:_...C?C-gC?7.C"..TC>.CC-C?j.QC
..C#.eC?F?C?GmC2C=C'B:g..a...C?C&.J..C?.C#sC'.C*E .C;.C
klsUDC?.E ..C"U...u1.zC?.WC?..x...3._..E.C2.C
ZD.C/oC?C?.dvC&C2k.C.y...8h: Factor w/ 41 levels

"","\025C'\016\vC?B2i;B'4F?C1\002\001Pb??C!\0025B6b?"C"C?{C?C?b?"B9=C?B$4&C0wQB-B4b?:B-C?B4\"hnC?b?"b?0IB(C?E

b*B*E!\035b\b>6C?C?$W!C?C?R=B(\022b??PqK?[B;j\004$TC?b?"3B2*C?B1%C
B-Nb??b?:\"| __truncated__,..: 1 1 1 39 1 1 1 8 1 5 ...
B $ X.iE?.yC?C;..C=2.h..C;C
7.C#J.3k..jLm...Q..uYC?JC$.K.zkU.8.C6C?..Y.7.3...Cb? B6C%\006%5l[b??Bhttps://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.


FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!

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


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


[R] segfault reading large BLOB from SQL Server

2012-12-21 Thread jeffrey.j.hallman

I am getting segfaults when I try to read a large binary object from a SQL
Server database via RODBC.  I am using the FreeTDS ODBC driver, and it has
been working fine when reading from this same database.  I have included
relevant parts of the session below.

Each row of the v_MAFiles view holds a  text, html or pdf version of a
document.  The FileType entry is one of TXT, PDF, or HTML.  If it's PDF,
the FileString variable is empty and the FileBLOB holds the (binary)
contents of the pdf.  If FileType is TXT or HTML, then FileBLOB is empty
and the file contents are in FileString.

Note that the COLUMN_SIZE for FileBLOB and FileString are both 2 GB.
However, the actual strings and blobs in there are actually only about 60
KB.

I can read the FileString column with no problem.  But trying to read a
FileBLOB entry segfaults, apparently when R is calling malloc().  I suspect
that R is trying and failing to allocate 2 GB of memory to hold something
with the reported COLUMN_SIZE.  But it doesn't barf when it loads a
FileString entry of about the same 60 KB size.  Perhaps the RODBC code is
somehow discovering that the string in FileString is not really 2 GB, but
it's not finding that out for a FileBLOB?

Any help with this would be much appreciated.


> Sys.info()
  sysname   release
version
  "Linux" "2.6.18-308.24.1.el5"
"#1 SMP Wed Nov 21 11:42:14 EST 2012"
 nodename   machine
login
"mralx1.rsma.frb.gov"  "x86_64"
"unknown"
 usereffective_user
"m1jjh00" "m1jjh00"
> sessionInfo()
R version 2.15.0 (2012-03-30)
Platform: x86_64-redhat-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US   LC_NUMERIC=C LC_TIME=en_US
LC_COLLATE=en_US LC_MONETARY=en_US
 [6] LC_MESSAGES=en_USLC_PAPER=C   LC_NAME=C
LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base

other attached packages:
[1] mra_1.0 frb_3.9 fame_2.19   tis_1.23
RODBC_1.3-6
[6] RObjectTables_0.3-1

loaded via a namespace (and not attached):
[1] data.table_1.8.2 XML_3.9-4
> conn <- h41Connect(devl = T)
> odbcGetInfo(conn)
 DBMS_Name   DBMS_VerDriver_ODBC_Ver
Data_Source_NameDriver_Name
"Microsoft SQL Server"   "10.50.4000""03.50"
"h41_devl""libtdsodbc.so"
Driver_Ver   ODBC_VerServer_Name
"0.91""03.52"  "MSSDEV1"
> sqlColumns(conn, "v_MAFiles")
  TABLE_CAT TABLE_SCHEM TABLE_NAME COLUMN_NAME DATA_TYPE TYPE_NAME
COLUMN_SIZE BUFFER_LENGTH DECIMAL_DIGITS
1   H41 dbo  v_MAFiles   ReleaseId 1  char
3 3 NA
2   H41 dbo  v_MAFilesAsOfDate-9  date
1020 NA
3   H41 dbo  v_MAFiles   GeneratedDate93  datetime
2316  3
4   H41 dbo  v_MAFilesFileType12   varchar
4 4 NA
5   H41 dbo  v_MAFilesFileBLOB-4 image
21474836472147483647 NA
6   H41 dbo  v_MAFiles  FileString-1  text
21474836472147483647 NA
7   H41 dbo  v_MAFiles   UpdatedBy12   varchar
6060 NA
8   H41 dbo  v_MAFiles UpdatedDateTime93  datetime
2316  3
  NUM_PREC_RADIX NULLABLE REMARKS COLUMN_DEF SQL_DATA_TYPE SQL_DATETIME_SUB
CHAR_OCTET_LENGTH ORDINAL_POSITION
1 NA01   NA
31
2 NA0   -9   NA
NA2
3 NA093
NA3
4 NA0   12   NA
44
5 NA1   -4   NA
21474836475
6 NA1   -1   NA
21474836476
7 NA0   12   NA
607
8 NA093
NA8
  IS_NULLABLE SS_DATA_TYPE
1  NO   47
2  NO0
3  NO   61
4  NO   39
5 YES   37
6 YES   39
7  NO   39
8  NO   61

> z <- odbcQuery(conn, "select FileBLOB from v_MAFiles where ReleaseId =
'L61' and AsOfDate = '2012-12-1

Re: [R] Difficulty importing data from PARI/GP

2012-12-21 Thread arun
HI,

May be this helps:
Lines1<-"15,30,45;20,45,39;60,49,32;48,59,63"
res1<-read.table(text=unlist(strsplit(Lines1,split=";")),sep=",")
str(res1)
#'data.frame':    4 obs. of  3 variables:
# $ V1: int  15 20 60 48
# $ V2: int  30 45 49 59
# $ V3: int  45 39 32 63

#or
res2<-read.table(text=gsub(";","\n",Lines1),sep=",",stringsAsFactors=FALSE)
 res2
#  V1 V2 V3
#1 15 30 45
#2 20 45 39
#3 60 49 32
#4 48 59 63
identical(res1,res2)
#[1] TRUE
A.K.



- Original Message -
From: murfs 
To: r-help@r-project.org
Cc: 
Sent: Friday, December 21, 2012 12:39 PM
Subject: [R] Difficulty importing data from PARI/GP

I'm trying to import a matrix created in PARI/GP into R but am having
problems.
The data in the text file has entries separated by commas but the rows
themselves are separated by semicolons rathen than being on a new line. Is
there a way to get R to recognise that ";" means start a new row ?  



--
View this message in context: 
http://r.789695.n4.nabble.com/Difficulty-importing-data-from-PARI-GP-tp4653736.html
Sent from the R help mailing list archive at Nabble.com.

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


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


Re: [R] Difficulty importing data from PARI/GP

2012-12-21 Thread William Dunlap
By the way, you can leave out the write-to-file step, as read.table's text=
argument does the equivalent.  E.g.,

  > x <- 
"1,2,3,4,5,6;1,2,3,4,5,6;1,2,3,4,5,6;1,2,3,4,5,6;1,2,3,4,5,6;1,2,3,4,5,6;1,2,3,4,5,6;1,2,3,4,5,6;1,2,3,4,5,6;1,2,3,4,5,6;1,2,3,4,5,6;1,2,3,4,5,6\r\n"
  > p <- read.table(text=gsub(";","\n",x),sep=",")
  > str(p)
  'data.frame':   12 obs. of  6 variables:
   $ V1: int  1 1 1 1 1 1 1 1 1 1 ...
   $ V2: int  2 2 2 2 2 2 2 2 2 2 ...
   $ V3: int  3 3 3 3 3 3 3 3 3 3 ...
   $ V4: int  4 4 4 4 4 4 4 4 4 4 ...
   $ V5: int  5 5 5 5 5 5 5 5 5 5 ...
   $ V6: int  6 6 6 6 6 6 6 6 6 6 ...

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 jim holtman
> Sent: Friday, December 21, 2012 12:51 PM
> To: murfs
> Cc: r-help@r-project.org
> Subject: Re: [R] Difficulty importing data from PARI/GP
> 
> One way is to use 'readLines' to read in the file, change the ';' to
> '\n', write the file out and then read it back in:
> 
> > x <- readChar('/temp/test.txt', 1e6)
> > print(x)
> [1]
> "1,2,3,4,5,6;1,2,3,4,5,6;1,2,3,4,5,6;1,2,3,4,5,6;1,2,3,4,5,6;1,2,3,4,5,6;1,2,3,4,5,6;1,2,3,4,
> 5,6;1,2,3,4,5,6;1,2,3,4,5,6;1,2,3,4,5,6;1,2,3,4,5,6\r\n"
> > x <- gsub(';', '\n', x)
> > writeChar(x, '/temp/testNew.txt')
> > # now read in the data
> > x.df <- read.table('/temp/testNew.txt', sep = ',')
> > x.df
>V1 V2 V3 V4 V5 V6
> 1   1  2  3  4  5  6
> 2   1  2  3  4  5  6
> 3   1  2  3  4  5  6
> 4   1  2  3  4  5  6
> 5   1  2  3  4  5  6
> 6   1  2  3  4  5  6
> 7   1  2  3  4  5  6
> 8   1  2  3  4  5  6
> 9   1  2  3  4  5  6
> 10  1  2  3  4  5  6
> 11  1  2  3  4  5  6
> 12  1  2  3  4  5  6
> 
> 
> On Fri, Dec 21, 2012 at 12:39 PM, murfs  wrote:
> > I'm trying to import a matrix created in PARI/GP into R but am having
> > problems.
> > The data in the text file has entries separated by commas but the rows
> > themselves are separated by semicolons rathen than being on a new line. Is
> > there a way to get R to recognise that ";" means start a new row ?
> >
> >
> >
> > --
> > View this message in context: 
> > http://r.789695.n4.nabble.com/Difficulty-importing-
> data-from-PARI-GP-tp4653736.html
> > Sent from the R help mailing list archive at Nabble.com.
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> 
> 
> 
> --
> Jim Holtman
> Data Munger Guru
> 
> What is the problem that you are trying to solve?
> Tell me what you want to do, not how you want to do it.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
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] Difficulty importing data from PARI/GP

2012-12-21 Thread jim holtman
One way is to use 'readLines' to read in the file, change the ';' to
'\n', write the file out and then read it back in:

> x <- readChar('/temp/test.txt', 1e6)
> print(x)
[1] 
"1,2,3,4,5,6;1,2,3,4,5,6;1,2,3,4,5,6;1,2,3,4,5,6;1,2,3,4,5,6;1,2,3,4,5,6;1,2,3,4,5,6;1,2,3,4,5,6;1,2,3,4,5,6;1,2,3,4,5,6;1,2,3,4,5,6;1,2,3,4,5,6\r\n"
> x <- gsub(';', '\n', x)
> writeChar(x, '/temp/testNew.txt')
> # now read in the data
> x.df <- read.table('/temp/testNew.txt', sep = ',')
> x.df
   V1 V2 V3 V4 V5 V6
1   1  2  3  4  5  6
2   1  2  3  4  5  6
3   1  2  3  4  5  6
4   1  2  3  4  5  6
5   1  2  3  4  5  6
6   1  2  3  4  5  6
7   1  2  3  4  5  6
8   1  2  3  4  5  6
9   1  2  3  4  5  6
10  1  2  3  4  5  6
11  1  2  3  4  5  6
12  1  2  3  4  5  6


On Fri, Dec 21, 2012 at 12:39 PM, murfs  wrote:
> I'm trying to import a matrix created in PARI/GP into R but am having
> problems.
> The data in the text file has entries separated by commas but the rows
> themselves are separated by semicolons rathen than being on a new line. Is
> there a way to get R to recognise that ";" means start a new row ?
>
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Difficulty-importing-data-from-PARI-GP-tp4653736.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

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


Re: [R] Memory filling up while looping

2012-12-21 Thread jim holtman
I ran your code and did not see any growth:

 used (Mb) gc trigger (Mb) max used (Mb)
Ncells 463828 24.8 818163 43.7   818163 43.7
Vcells 546318  4.21031040  7.9   909905  7.0
1 (1) - eval : <33.6 376.6> 376.6 : 48.9MB
 used (Mb) gc trigger (Mb) max used (Mb)
Ncells 471049 25.2 818163 43.7   818163 43.7
Vcells 544105  4.21031040  7.9   909905  7.0
2 (1) - eval : <35.9 379.2> 379.2 : 48.7MB
 used (Mb) gc trigger (Mb) max used (Mb)
Ncells 479520 25.7 818163 43.7   818163 43.7
Vcells 543882  4.21031040  7.9   909905  7.0
3 (1) - eval : <38.0 381.4> 381.4 : 48.7MB
 used (Mb) gc trigger (Mb) max used (Mb)
Ncells 488376 26.1 818163 43.7   818163 43.7
Vcells 544191  4.21031040  7.9   909905  7.0
4 (1) - eval : <40.0 383.4> 383.4 : 48.8MB
 used (Mb) gc trigger (Mb) max used (Mb)
Ncells 496695 26.6 818163 43.7   818163 43.7
Vcells 543971  4.21031040  7.9   909905  7.0
5 (1) - eval : <42.0 385.4> 385.4 : 48.7MB
 used (Mb) gc trigger (Mb) max used (Mb)
Ncells 505562 27.0 899071 48.1   818163 43.7
Vcells 544034  4.21031040  7.9   909905  7.0
6 (1) - eval : <44.1 387.5> 387.5 : 48.8MB
 used (Mb) gc trigger (Mb) max used (Mb)
Ncells 513896 27.5 899071 48.1   899071 48.1
Vcells 543973  4.21031040  7.9   909905  7.0
7 (1) - eval : <46.2 389.8> 389.8 : 52.5MB
 used (Mb) gc trigger (Mb) max used (Mb)
Ncells 523203 28.0 899071 48.1   899071 48.1
Vcells 544751  4.21031040  7.9   909905  7.0
8 (1) - eval : <48.5 392.2> 392.2 : 46.7MB
 used (Mb) gc trigger (Mb) max used (Mb)
Ncells 531519 28.4 899071 48.1   899071 48.1
Vcells 544418  4.21031040  7.9   909905  7.0
9 (1) - eval : <50.6 394.5> 394.5 : 47.3MB
 used (Mb) gc trigger (Mb) max used (Mb)
Ncells 539556 28.9 899071 48.1   899071 48.1
Vcells 544057  4.21031040  7.9   909905  7.0
10 (1) - eval : <52.6 396.6> 396.6 : 47.8MB

started out with 48M and ended with 47M.  This is with

R version 2.15.2 (2012-10-26) -- "Trick or Treat"
Copyright (C) 2012 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-w64-mingw32/x64 (64-bit)


On Fri, Dec 21, 2012 at 10:27 AM, Peter Meißner
 wrote:
> Here is an working example that reproduces the behavior by creating 1000
> xml-files and afterwards parsing them.
>
> At my PC, R starts with about 90MB of RAM with every cycle another 10-12MB
> are further added to the RAM-usage so I end up with 200MB RAM usage.
>
> In the real code one chunk-cycle eats about 800MB of RAM which was one of
> the reasons I decided to splitt up the process in seperate chunks in the
> first place.
>
> 
> 'Minimal'Example - START
> 
>
> # the general problem
> require(XML)
>
> chunk <- function(x, chunksize){
> # source: http://stackoverflow.com/a/3321659/1144966
> x2 <- seq_along(x)
> split(x, ceiling(x2/chunksize))
> }
>
>
>
> chunky <- chunk(paste("test",1:1000,".xml",sep=""),100)
>
> for(i in 1:1000){
> writeLines(c(paste('\n \n Tove\n
> ',i,'\nJani\n Reminder\n
> ',sep=""), paste(rep('Do not forget me this
> weekend!\n',sample(1:10, 1)),sep="" ) , ' ')
> ,paste("test",i,".xml",sep=""))
> }
>
> for(k in 1:length(chunky)){
> gc()
> print(chunky[[k]])
> xmlCatcher <- NULL
>
> for(i in 1:length(chunky[[k]])){
> filename<- chunky[[k]][i]
> xml <- xmlTreeParse(filename)
> xml <- xmlRoot(xml)
> result  <- sapply(getNodeSet(xml,"//body"), xmlValue)
> id  <- sapply(getNodeSet(xml,"//nr"), xmlValue)
> dummy   <- cbind(id,result)
> xmlCatcher  <- rbind(xmlCatcher,dummy)
> }
> save(xmlCatcher,file=paste("xmlCatcher",k,".RData"))
> }
>
> 
> 'Minimal'Example - END
> 
>
>
>
> Am 21.12.2012 15:14, schrieb jim holtman:
>
>> Can you send either your actual script or the console output so I can
>> get an idea of how fast memory is growing.  Also at the end, can you
>> list the sizes of the objects in the workspace.  Here is a function I
>> use to get the space:
>>
>> my.ls <-
>> function (pos = 1, sorted = FALSE, envir = as.environment(pos))
>> {
>>  .result <- sapply(ls(envir = envir, all.names = TRUE),
>> function(..x) object.size(eval(as.symbol(..x),
>>  envir = envir)))
>>  if (length(.result) == 0)
>>  return("No objects to list")
>>  if (sorted) {
>>  .result <- rev(sort(.result))
>>  }
>>  .ls <- as.data.frame(rbind(as.matrix(.result), `**Total` =
>> sum(.result)))
>>  names(.ls) <- "Size"
>>  .ls$Size <- formatC(.ls$Size, big.mark = ",", digits = 0,
>>  format = "f")
>>  .ls$Class <- c(unlist(lapply(rownames(.ls)[-nrow(.ls)],
>> function(x) class(eval(as.symbol(x),
>>  envir = envir))[1L])), "---")
>>  .ls$Length <- c(unlist(lapply(rownames(.ls)[-nrow(.ls)],
>>  functi

Re: [R] Rterm does not load personal library

2012-12-21 Thread Bond, Stephen
I have to apologize to everybody. The thing was failing because my library did 
not have that particular function in R 2.12.
The library actually loads fine, just the function is missing.

Merry Christmas to those celebrating.

Stephen 

-Original Message-
From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de] 
Sent: Friday, December 21, 2012 1:01 PM
To: Bond, Stephen
Cc: r-help@r-project.org
Subject: Re: [R] Rterm does not load personal library



On 21.12.2012 18:16, Bond, Stephen wrote:
> Greetings,
>
> I am trying to run a short script from a shell:
>
> c:\projects\hell>Rscript --default-packages=mypack X:/4Stephen/commit/curve.R 
> > X:/4Stephen/commit/run1.out
>
> Loading required package: utils
> Warning message:
> package 'RODBC' was built under R version 2.12.2
> Error: could not find function "normalize"
> Execution halted
> Warning message:
> closing unused RODBC handle 1
>
> function 'normalize' is in "mypack" and I even attempt to load it from inside 
> the script:
>
> ## curve.R
> dt <- Sys.Date()
> library(RODBC)
> pipe <- odbcConnect("commit")
> library(mypack) # with quotes it's the same result
> normalize(pipe)
>
> any ideas how to make Rterm load the library?? Running from inside ESS works 
> fine. Also from RGui. It does not work if I start a session by "R -vanilla" 
> on the command line.


I guess some dependencies on other base R packages are not declared and 
those packages are not loaded by your package.
If you start RGui some packages are loaded that are not loaded if you 
start via --vanilla, but we cannot know more without information about 
mypack.

Uwe Ligges


> Thanks and happy holidays.
>
> Stephen
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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


Re: [R] comparison of large data set

2012-12-21 Thread Adams, Jean
Irucka,

You should cc R-help on all correspondence so that other readers of the
list can follow the conversation.

(1)  You say that you need 0s and 1s rather than TRUE/FALSE.  Since a 0/1
matrix and TRUE/FALSE matrix behave exactly the same way in most
applications, I'm not sure why it would matter which one you had.

(2)  My mistake.  I had not noticed that you were eliminating the case
where both the observed and the modeled were FALSE.  I have modified my
code to give the same results as your f2 function.
compare.all <- sapply(modeldepth, function(md) mean((md==observeddepth)[md
| observeddepth]))

(3)  My mistake again.  There should be only single brackets, not double
brackets.
justbig <- modeldepth[compare.all > 0.7]

Jean



On Fri, Dec 21, 2012 at 11:27 AM, Irucka Embry wrote:

>  Hi Jean Adams, how are you?
>
> I want to thank you for your response to my request for assistance.
>
> I received some assistance yesterday afternoon and I was able to update
> the code which is posted here:
> http://r.789695.n4.nabble.com/variable-names-in-numeric-list-and-Bayesian-inference-td4653674.html.
> I posted the new code with some new questions that I have with regards to
> the code that I have written. Can you look over that post and suggest any
> code revisions for those aspects that do not work? Thank-you.
>
> The code that you suggested worked well overall, except for 3 aspects of
> it:
>
> Here I actually needed the binary 0s and 1s rather than a TRUE/FALSE
> logical matrix
>
> # a function to read in the data as a matrix of logicals
> myreadfun <- function(file) {
> as.matrix(read.ascii.grid(file)$data)!=0
> }
>
> Here I needed to calculate the f2 probability rather than the mean
>
> compare.all <- sapply(modeldepths, function(md) mean(md==observeddepth))
> > str(compare.all)
> num [1:54] 0.936 0.94 0.944 0.944 0.945 ...
>
> Here most of the entries are greater than 0.7, but it should just be 31 of
> the 54 that are greater than 0.7
>
> > justbig <- modeldepths[[compare.all > 0.7]]
> Error in modeldepths[[compare.all > 0.7]] :
> recursive indexing failed at level 2
>
> Once again, thank-you for your assistance.
>
> Irucka Embry
>
>
> <-Original Message->
> >From: Adams, Jean [jvad...@usgs.gov]
> >Sent: 12/21/2012 10:32:54 AM
> >To: iruc...@mail2world.com
> >Cc: r-help@r-project.org
> >Subject: Re: [R] comparison of large data set
> >
> >Irucka,
> >
> >
> >I did not test this code out on any data, but I think it will work.
> >
> >
> >Jean
> >
> >
> >
> >
> ># a function to read in the data as a matrix of logicals
> >myreadfun <- function(file) {
> >as.matrix(read.ascii.grid(file)$data)!=0
> >}
> >
> >
> ># names of the 54 modeled depth files
> >modfiles <- paste0("MaxFloodDepth_", 1:54, ".txt")
> >
> >
> ># read in the observed and modeled depth files
> ># observeddepth is a matrix
> >observeddepth <- myreadfun("MaxFloodDepth_Observed.txt")
> >
> ># modeldepths is a list of matrices
> >modeldepths <- lapply(filenames, myreadfun)
> >
> >
> ># calculate the proportion of matrix elements that agree with the
> observed file
> ># the results is a vector with one number for each modeled depth matrix
> >compare.all <- sapply(modeldepths, function(md) mean(md==observeddepth))
> >
> >
> ># select just those matrices that had a large proportion of agreements
> ># justbig is a list of matrices
> >justbig <- modeldepths[[compare.all > 0.7]]
> >
> >__
> >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.
>
> ___
> Get the Free email that has everyone talking at http://www.mail2world.com
> Unlimited Email Storage – POP3 – Calendar – SMS – Translator – Much More!
>

[[alternative HTML version deleted]]

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


Re: [R] Memory filling up while looping

2012-12-21 Thread Peter Meißner

THANKS a lot!

This actually solved the problem even without calling free() explicitly:

xmlTreeParse(..., useInternalNodes=TRUE)

Best, Peter


Am 21.12.2012 19:48, schrieb Milan Bouchet-Valat:

Le vendredi 21 décembre 2012 à 18:41 +0100, Peter Meißner a écrit :

Yeah, thanks,
I know: !DO NOT USE RBIND! !

But it does not help, although using a predefined list to store results
as suggested there, it does not help.

The problems seems to stem from the XML-package and not from the way I
store the data until saved.

So you may want to use xmlParse() or the equivalent
xmlTreeParse(useInternalNodes=TRUE) instead of plain xmlTreeParse().
This will avoid creating too many R objects that will need to be freed.
But do not forget to call free() on the resulting object at the end of
the loop.

See this page for details:
http://www.omegahat.org/RSXML/MemoryManagement.html


Regards



__
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] remove from column a group of elements I have in another vector

2012-12-21 Thread Sarah Goslee
You can probably do it with not in in R too:
for a data frame x where you want to remove rows where values in
column A are not in the vector y:

x[!(x$A %in% y), ]

If you'd provided a reproducible example, I could give code that works
in your particular circumstance.

Sarah

On Fri, Dec 21, 2012 at 12:43 PM, Estefanía Gómez Galimberti
 wrote:
> Hi,
>
> I have a data frame and I would need to remove from one of
> the columns a group of elements I have in another vector. How can I do that? 
> I know how to do it with criteria but i would need to do it in a more 
> automatic way
> In SQL I would use  where
>  not in 
>
> Thank you,
> Estefania

--
Sarah Goslee
http://www.functionaldiversity.org

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


Re: [R] Memory filling up while looping

2012-12-21 Thread Milan Bouchet-Valat
Le vendredi 21 décembre 2012 à 18:41 +0100, Peter Meißner a écrit :
> Yeah, thanks,
> I know: !DO NOT USE RBIND! !
> 
> But it does not help, although using a predefined list to store results 
> as suggested there, it does not help.
> 
> The problems seems to stem from the XML-package and not from the way I 
> store the data until saved.
So you may want to use xmlParse() or the equivalent
xmlTreeParse(useInternalNodes=TRUE) instead of plain xmlTreeParse().
This will avoid creating too many R objects that will need to be freed.
But do not forget to call free() on the resulting object at the end of
the loop.

See this page for details:
http://www.omegahat.org/RSXML/MemoryManagement.html


Regards

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


[R] remove from column a group of elements I have in another vector

2012-12-21 Thread Estefanía Gómez Galimberti
Hi,
 
I have a data frame and I would need to remove from one of
the columns a group of elements I have in another vector. How can I do that? I 
know how to do it with criteria but i would need to do it in a more automatic 
way
In SQL I would use  where
 not in 

Thank you,
Estefania
[[alternative HTML version deleted]]

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


Re: [R] how to recode an ordered factor

2012-12-21 Thread arun

HI,

May be this helps:

 dat1<-data.frame(var1=factor(rep(1:4,times=3)))
dat1<-transform(dat1,o.var1=ordered(var1,levels=c(1,2,3,4),labels=c("very
 satisfied", "fairly satisfied","not very satisfied", "not at all 
satisfied")))
dat2<-transform(dat1,or.var1=factor(o.var1,levels=rev(levels(o.var1
str(dat2)
#'data.frame':    12 obs. of  3 variables:
# $ var1   : Factor w/ 4 levels "1","2","3","4": 1 2 3 4 1 2 3 4 1 2 ...
# $ o.var1 : Ord.factor w/ 4 levels "very satisfied"<..: 1 2 3 4 1 2 3 4 1 2 ...
# $ or.var1: Ord.factor w/ 4 levels "not at all satisfied"<..: 4 3 2 1 4 3 2 1 
4 3 ...
 levels(dat2[,2])
#[1] "very satisfied"   "fairly satisfied" "not very satisfied"  
#[4] "not at all satisfied"
 levels(dat2[,3])
#[1] "not at all satisfied" "not very satisfied"   "fairly satisfied"    
#[4] "very satisfied"    


#or
dat3<-transform(dat1,or.var1=reorder(o.var1,
 new.order=c("not at all satisfied","not very satisfied","fairly 
satisfied","very satisfied")))
 identical(dat3,dat2)
#[1] TRUE
A.K.



- Original Message -
From: Francesco Sarracino 
To: r-help@r-project.org
Cc: 
Sent: Friday, December 21, 2012 11:43 AM
Subject: [R] how to recode an ordered factor

Dear R helpers,

I'm trying to recode an ordered factor to reverse its scale, but I can't
figure out how to make it. I am using the Recode function provided by the
Car package.

I've created an ordered variable:
data$o.var1 <- ordered(data$var1, levels=c(1,2,3,4), labels =c("very
satisfied", "fairly satisfied", "not very satisfied", "not at all
satisfied"))

Now, I'd like to have a new variable ranging from 4 = Very satisfied to 1=
not at all satisfied.

I've tried with the following:
data$or.var1 <- Recode(data$o.var1, "1 = 4; 2 = 3; 3=2; 4=1")
but it looks like the new variable loses the order:
the output of table(data$or.var1) looks like:

fairly satisfied not at all satisfied not very satisfied very satisfied

I believe the new variable is ordered in alphabetical order, but when I
tried to use the levels option I lost the initial information.
Can you help figuring out what I am doing wrong?
thanks in advance,
f.





-- 
Francesco Sarracino, Ph.D.
https://sites.google.com/site/fsarracino/

    [[alternative HTML version deleted]]

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


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


[R] Difficulty importing data from PARI/GP

2012-12-21 Thread murfs
I'm trying to import a matrix created in PARI/GP into R but am having
problems.
The data in the text file has entries separated by commas but the rows
themselves are separated by semicolons rathen than being on a new line. Is
there a way to get R to recognise that ";" means start a new row ?  



--
View this message in context: 
http://r.789695.n4.nabble.com/Difficulty-importing-data-from-PARI-GP-tp4653736.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Print plot to pdf,

2012-12-21 Thread Tobias Kisch
Dear Duncan

Sorry if I’m not ment to contact you with this through this channel... I’m 
a complete newbie in asking things about r packages...

But anyways, just let me know if I’m in the wrong place here!

My problem is concerning scatter3d (rgl, Rcmdr... I guess (hope) I’m at least 
right that you’re the man for this packages...).

Actually everything works out fine, let’s say perfect, it’s really fun to 
work with this packages.
But as soon as I try to label my axes I’m getting into problems...:
Whenever I try to use a german umlaut  (“a/o/u with dots (on top)”) my rgl 
crashes, saying: “Java™ Platform SE binary is not working anymore 
(translated from german...)”. (It works when I replace an “a with dot” by 
“ae”...)

Do you have a clou whats going wrong here (or where I should ask something like 
this?)

Thanks anyway!
Best,
Tobias Kisch

P.S.:
Here’s what made in R (ignore the path, data and variables...)

library(rgl)
library(Rcmdr)
library(mgcv)

setwd("C:\\Users\\KIT\\Documents\\Eclipse\\workspace\\StatKtZH\\R\\data")
bivmod <- 
read.csv("C:\\Users\\KIT\\Documents\\Eclipse\\workspace\\StatKtZH\\R\\data\\sozialhilfe1.csv",
 header=TRUE, sep=";")
attach(bivmod)

scatter3d(shq~expatr_per + unimpl_per, fit="linear", xlab="Sozialhilfequote",
ylab="Arbeitslosenrate", zlab="Auslaenderanteil")

scatter3d(shq~expatr_per + unimpl_per, fit="linear", xlab="Sozialhilfequote",
ylab="Arbeitslosenrate", zlab="Ausländeranteil")
[[alternative HTML version deleted]]

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


Re: [R] Rterm does not load personal library

2012-12-21 Thread Bond, Stephen
Uwe,

Thank you for the suggestion. I checked and there are no dependencies involved. 
I discovered the problem is calling an old version

c:\projects\hell>which Rscript
which Rscript
/cygdrive/c/Program Files/R/R-2.12.1/bin/Rscript

Mypack is installed under 2.15.

Will change my paths and that should fix it.
Would be nice if Rscript produced a message saying it could not find the lib.

It returns nothing so it looks like the load worked, while it did not:

c:\projects\hell>R --vanilla
R --vanilla

R version 2.12.1 (2010-12-16)
Copyright (C) 2010 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: i386-pc-mingw32/i386 (32-bit)


> library(RODBC)
library(RODBC)
Warning message:
package 'RODBC' was built under R version 2.12.2 
> library(mypack)
library(mypack)
> normalize
normalize
Error: object 'normalize' not found
Execution halted


Stephen 

-Original Message-
From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de] 
Sent: Friday, December 21, 2012 1:01 PM
To: Bond, Stephen
Cc: r-help@r-project.org
Subject: Re: [R] Rterm does not load personal library



On 21.12.2012 18:16, Bond, Stephen wrote:
> Greetings,
>
> I am trying to run a short script from a shell:
>
> c:\projects\hell>Rscript --default-packages=mypack X:/4Stephen/commit/curve.R 
> > X:/4Stephen/commit/run1.out
>
> Loading required package: utils
> Warning message:
> package 'RODBC' was built under R version 2.12.2
> Error: could not find function "normalize"
> Execution halted
> Warning message:
> closing unused RODBC handle 1
>
> function 'normalize' is in "mypack" and I even attempt to load it from inside 
> the script:
>
> ## curve.R
> dt <- Sys.Date()
> library(RODBC)
> pipe <- odbcConnect("commit")
> library(mypack) # with quotes it's the same result
> normalize(pipe)
>
> any ideas how to make Rterm load the library?? Running from inside ESS works 
> fine. Also from RGui. It does not work if I start a session by "R -vanilla" 
> on the command line.


I guess some dependencies on other base R packages are not declared and 
those packages are not loaded by your package.
If you start RGui some packages are loaded that are not loaded if you 
start via --vanilla, but we cannot know more without information about 
mypack.

Uwe Ligges


> Thanks and happy holidays.
>
> Stephen
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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


Re: [R] Rterm does not load personal library

2012-12-21 Thread Uwe Ligges



On 21.12.2012 18:16, Bond, Stephen wrote:

Greetings,

I am trying to run a short script from a shell:

c:\projects\hell>Rscript --default-packages=mypack X:/4Stephen/commit/curve.R > 
X:/4Stephen/commit/run1.out

Loading required package: utils
Warning message:
package 'RODBC' was built under R version 2.12.2
Error: could not find function "normalize"
Execution halted
Warning message:
closing unused RODBC handle 1

function 'normalize' is in "mypack" and I even attempt to load it from inside 
the script:

## curve.R
dt <- Sys.Date()
library(RODBC)
pipe <- odbcConnect("commit")
library(mypack) # with quotes it's the same result
normalize(pipe)

any ideas how to make Rterm load the library?? Running from inside ESS works fine. Also 
from RGui. It does not work if I start a session by "R -vanilla" on the command 
line.



I guess some dependencies on other base R packages are not declared and 
those packages are not loaded by your package.
If you start RGui some packages are loaded that are not loaded if you 
start via --vanilla, but we cannot know more without information about 
mypack.


Uwe Ligges



Thanks and happy holidays.

Stephen

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



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


Re: [R] how can I import op.gz files with read.csv or otherwise

2012-12-21 Thread John Kane
Try downloading it and decompress it:

  url <- "ftp://ftp.ncdc.noaa.gov/pub/data/gsod/2012/285880-9-2012.op.gz";
  dest <- "/home/john/rdata/weather.op.gz"
  download.file(url, dest) 

However it does not look like a nicely formatted file and you may have to do 
some cleanup in a text editior or perhaps load it into a spreadsheet before you 
read it into R.  

I tried the method from the link arun provided and it did not work.  It looks 
like the headers and data are not consistant
John Kane
Kingston ON Canada


> -Original Message-
> From: herrdittm...@yahoo.co.uk
> Sent: Fri, 21 Dec 2012 14:51:05 + (GMT)
> To: r-help@r-project.org
> Subject: [R] how can I import op.gz files with read.csv or otherwise
> 
> Dear R-users,
> 
> I am struggling to directly read an "op.gz" file into R. NOAA kindly
> provides daily weather data on their FTP server for download.
> 
> 
>> sessionInfo()
> R version 2.15.1 (2012-06-22)
> Platform: x86_64-pc-mingw32/x64 (64-bit)
> locale:
> [1] LC_COLLATE=English_United Kingdom.1252B  LC_CTYPE=English_United
> Kingdom.1252B B B  LC_MONETARY=English_United Kingdom.1252
> [4] LC_NUMERIC=CB B B B B B B B B B B B B B B B B B B B B B B B B B B
> LC_TIME=English_United Kingdom.1252B B  B
> attached base packages:
> [1] statsB B B B  graphicsB  grDevices utilsB B B B  datasetsB  methodsB
> B  baseB B B  B
> loaded via a namespace (and not attached):
> [1] tools_2.15.1
> 
> Here is the data set in question:
> x <-
read.csv(file="ftp://ftp.ncdc.noaa.gov/pub/data/gsod/2012/285880-9-2012.op.gz";,
> skip = 1, sep = "")
> 
> and "structure" returns some incomprehensible gibberish:
> 
>> str(x)
> 'data.frame':B B  70 obs. ofB  6 variables:
> B $ X4C tYd...C?C?8.C%WD...C+C<.C/C?.X.QTC1VP..B B B B B B B B B B B B B
> B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B
> B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B
> B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B  : Factor w/
> 70 levels "\005~4C(dE?C?C-E\031y\020C?C-B:\035JC+C/C?IK?C?C-\021b?
> BC?C?R{E>Ykv\035`b??C,B0a\017Z\021C?sPb??eC?hC?C?""| __truncated__,..: 44
> 13 56 64 28 23 67 3 2 33 ...
> B $ X.C6oMC=C?T..C?B:_...C?C-gC?7.C"..TC>.CC-C?j.QC
> ..C#.eC?F?C?GmC2C=C'B:g..a...C?C&.J..C?.C#sC'.C*E .C;.C
> klsUDC?.E ..C"U...u1.zC?.WC?..x...3._..E.C2.C
> ZD.C/oC?C?.dvC&C2k.C.y...8h: Factor w/ 41 levels
"","\025C'\016\vC?B2i;B'4F?C1\002\001Pb??C!\0025B6b?"C"C?{C?C?b?"B9=C?B$4&C0wQB-B4b?:B-C?B4\"hnC?b?"b?0IB(C?E
> b*B*E!\035b\b>6C?C?$W!C?C?R=B(\022b??PqK?[B;j\004$TC?b?"3B2*C?B1%C
> B-Nb??b?:\"| __truncated__,..: 1 1 1 39 1 1 1 8 1 5 ...
> B $ X.iE?.yC?C;..C=2.h..C;C
> 7.C#J.3k..jLm...Q..uYC?JC$.K.zkU.8.C6C?..Y.7.3...C C.A.C
> .3C;C?..Z..5...C"E!.B B B B B B B B B B B B B B B B B B B B B B B B B B B
> B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B
> B B B  : Factor w/ 29 levels "","\001qC?^+nC*1",..: 1 1 1 4 1 1 1 14 1 6
> ...
> B $ X.C.Fd.m.E ..v.B B B B B B B B B B B B B B B B B B B B B B B B B B B
> B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B
> B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B
> B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B
> : Factor w/ 17 levels "","B B4SL\aE!C?C?B0\035d)b??B<$C-ZC?B b??C$C>b? B6C%\006%5l[b??B ...
> B $ C?A..E.E8JkEZ.C?C
> .C!.C+...E?.z..C?.z..E?..C2C?.C?C?C#g.C6B B B B B B B B B B B B B B B
> B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B
> B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B
> B B B B B B B B B B B B B B B  : Factor w/ 8 levels
> "","\001S\177B?\017iSC?C?iC?C?#\017\"UgC?:iB4C-\016pC?\031UC?C)D""|
> __truncated__,..: 1 1 1 1 1 1 1 1 1 1 ...
> B $ X..oC0C'nPC?oC?WC5j.C)C?..B..C?C?C+.QC*C9...C8B B B B  B
> 
> 
> While I can manually open and read the op.gz file in a text editor,
> read.csv() or read.table() the imported file is simply unreadable.
> 
> How can I best get the job done? Any pointers, suggestions, ideas most
> welcome!!
> 
> Thanks in advance!
> 
> Bernd
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!

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


Re: [R] Memory filling up while looping

2012-12-21 Thread Peter Meißner

Yeah, thanks,
I know: !DO NOT USE RBIND! !

But it does not help, although using a predefined list to store results 
as suggested there, it does not help.


The problems seems to stem from the XML-package and not from the way I 
store the data until saved.


Best, Peter



Am 21.12.2012 18:33, schrieb Patrick Burns:

Circle 2 of 'The R Inferno' may help you.

http://www.burns-stat.com/pages/Tutor/R_inferno.pdf

In particular, it has an example of how to do what
Duncan suggested.

Pat


On 21/12/2012 15:27, Peter Meißner wrote:

Here is an working example that reproduces the behavior by creating 1000
xml-files and afterwards parsing them.

At my PC, R starts with about 90MB of RAM with every cycle another
10-12MB are further added to the RAM-usage so I end up with 200MB RAM
usage.

In the real code one chunk-cycle eats about 800MB of RAM which was one
of the reasons I decided to splitt up the process in seperate chunks in
the first place.


'Minimal'Example - START


# the general problem
require(XML)

chunk <- function(x, chunksize){
 # source: http://stackoverflow.com/a/3321659/1144966
 x2 <- seq_along(x)
 split(x, ceiling(x2/chunksize))
 }



chunky <- chunk(paste("test",1:1000,".xml",sep=""),100)

for(i in 1:1000){
 writeLines(c(paste('\n \n
Tove\n',i,'\nJani\n
Reminder\n',sep=""), paste(rep('Do not
forget me this weekend!\n',sample(1:10, 1)),sep="" ) , ' ')
 ,paste("test",i,".xml",sep=""))
}

for(k in 1:length(chunky)){
 gc()
 print(chunky[[k]])
 xmlCatcher <- NULL

 for(i in 1:length(chunky[[k]])){
 filename<- chunky[[k]][i]
 xml <- xmlTreeParse(filename)
 xml <- xmlRoot(xml)
 result  <- sapply(getNodeSet(xml,"//body"), xmlValue)
 id  <- sapply(getNodeSet(xml,"//nr"), xmlValue)
 dummy   <- cbind(id,result)
 xmlCatcher  <- rbind(xmlCatcher,dummy)
 }
 save(xmlCatcher,file=paste("xmlCatcher",k,".RData"))
}


'Minimal'Example - END




Am 21.12.2012 15:14, schrieb jim holtman:

Can you send either your actual script or the console output so I can
get an idea of how fast memory is growing.  Also at the end, can you
list the sizes of the objects in the workspace.  Here is a function I
use to get the space:

my.ls <-
function (pos = 1, sorted = FALSE, envir = as.environment(pos))
{
 .result <- sapply(ls(envir = envir, all.names = TRUE),
function(..x) object.size(eval(as.symbol(..x),
 envir = envir)))
 if (length(.result) == 0)
 return("No objects to list")
 if (sorted) {
 .result <- rev(sort(.result))
 }
 .ls <- as.data.frame(rbind(as.matrix(.result), `**Total` =
sum(.result)))
 names(.ls) <- "Size"
 .ls$Size <- formatC(.ls$Size, big.mark = ",", digits = 0,
 format = "f")
 .ls$Class <- c(unlist(lapply(rownames(.ls)[-nrow(.ls)],
function(x) class(eval(as.symbol(x),
 envir = envir))[1L])), "---")
 .ls$Length <- c(unlist(lapply(rownames(.ls)[-nrow(.ls)],
 function(x) length(eval(as.symbol(x), envir = envir,
 "---")
 .ls$Dim <- c(unlist(lapply(rownames(.ls)[-nrow(.ls)], function(x)
paste(dim(eval(as.symbol(x),
 envir = envir)), collapse = " x "))), "---")
 .ls
}


which gives output like this:


my.ls()

  Size   Class  Length Dim
.Last 736function   1
.my.env.jph28 environment  39
x 424 integer 100
y  40,024 integer   1
z   4,000,024 integer 100
**Total 4,041,236 --- --- ---


On Fri, Dec 21, 2012 at 8:03 AM, Peter Meißner
 wrote:

Thanks for your answer,

yes, I tried 'gc()' it did not change the bahavior.

best, Peter


Am 21.12.2012 13:37, schrieb jim holtman:


have you tried putting calls to 'gc' at the top of the first loop to
make sure memory is reclaimed? You can print the call to 'gc' to see
how fast it is growing.

On Thu, Dec 20, 2012 at 6:26 PM, Peter Meissner
 wrote:


Hey,

I have an double loop like this:


chunk <- list(1:10, 11:20, 21:30)
for(k in 1:length(chunk)){
  print(chunk[k])
  DummyCatcher <- NULL
  for(i in chunk[k]){
  print("i load something")
  dummy <- 1
  print("i do something")
  dummy <- dummy + 1
  print("i do put it together")
  DummyCatcher = rbind(DummyCatcher, dummy)
  }
  print("i save a chunk and restart with another chunk of
data")
}

The problem now is that with each 'chunk'-cycle the memory used by R
becomes
bigger and bigger until it exceeds my RAM but the RAM it needs for
any of
the chunk-cycles alone is only a 1/5th of what I have overall.

Does somebody have an idea why this behaviour might occur? Note
that all
the
objects (like 'Du

Re: [R] Memory filling up while looping

2012-12-21 Thread Patrick Burns

Circle 2 of 'The R Inferno' may help you.

http://www.burns-stat.com/pages/Tutor/R_inferno.pdf

In particular, it has an example of how to do what
Duncan suggested.

Pat


On 21/12/2012 15:27, Peter Meißner wrote:

Here is an working example that reproduces the behavior by creating 1000
xml-files and afterwards parsing them.

At my PC, R starts with about 90MB of RAM with every cycle another
10-12MB are further added to the RAM-usage so I end up with 200MB RAM
usage.

In the real code one chunk-cycle eats about 800MB of RAM which was one
of the reasons I decided to splitt up the process in seperate chunks in
the first place.


'Minimal'Example - START


# the general problem
require(XML)

chunk <- function(x, chunksize){
 # source: http://stackoverflow.com/a/3321659/1144966
 x2 <- seq_along(x)
 split(x, ceiling(x2/chunksize))
 }



chunky <- chunk(paste("test",1:1000,".xml",sep=""),100)

for(i in 1:1000){
 writeLines(c(paste('\n \n
Tove\n',i,'\nJani\n
Reminder\n',sep=""), paste(rep('Do not
forget me this weekend!\n',sample(1:10, 1)),sep="" ) , ' ')
 ,paste("test",i,".xml",sep=""))
}

for(k in 1:length(chunky)){
 gc()
 print(chunky[[k]])
 xmlCatcher <- NULL

 for(i in 1:length(chunky[[k]])){
 filename<- chunky[[k]][i]
 xml <- xmlTreeParse(filename)
 xml <- xmlRoot(xml)
 result  <- sapply(getNodeSet(xml,"//body"), xmlValue)
 id  <- sapply(getNodeSet(xml,"//nr"), xmlValue)
 dummy   <- cbind(id,result)
 xmlCatcher  <- rbind(xmlCatcher,dummy)
 }
 save(xmlCatcher,file=paste("xmlCatcher",k,".RData"))
}


'Minimal'Example - END




Am 21.12.2012 15:14, schrieb jim holtman:

Can you send either your actual script or the console output so I can
get an idea of how fast memory is growing.  Also at the end, can you
list the sizes of the objects in the workspace.  Here is a function I
use to get the space:

my.ls <-
function (pos = 1, sorted = FALSE, envir = as.environment(pos))
{
 .result <- sapply(ls(envir = envir, all.names = TRUE),
function(..x) object.size(eval(as.symbol(..x),
 envir = envir)))
 if (length(.result) == 0)
 return("No objects to list")
 if (sorted) {
 .result <- rev(sort(.result))
 }
 .ls <- as.data.frame(rbind(as.matrix(.result), `**Total` =
sum(.result)))
 names(.ls) <- "Size"
 .ls$Size <- formatC(.ls$Size, big.mark = ",", digits = 0,
 format = "f")
 .ls$Class <- c(unlist(lapply(rownames(.ls)[-nrow(.ls)],
function(x) class(eval(as.symbol(x),
 envir = envir))[1L])), "---")
 .ls$Length <- c(unlist(lapply(rownames(.ls)[-nrow(.ls)],
 function(x) length(eval(as.symbol(x), envir = envir,
 "---")
 .ls$Dim <- c(unlist(lapply(rownames(.ls)[-nrow(.ls)], function(x)
paste(dim(eval(as.symbol(x),
 envir = envir)), collapse = " x "))), "---")
 .ls
}


which gives output like this:


my.ls()

  Size   Class  Length Dim
.Last 736function   1
.my.env.jph28 environment  39
x 424 integer 100
y  40,024 integer   1
z   4,000,024 integer 100
**Total 4,041,236 --- --- ---


On Fri, Dec 21, 2012 at 8:03 AM, Peter Meißner
 wrote:

Thanks for your answer,

yes, I tried 'gc()' it did not change the bahavior.

best, Peter


Am 21.12.2012 13:37, schrieb jim holtman:


have you tried putting calls to 'gc' at the top of the first loop to
make sure memory is reclaimed? You can print the call to 'gc' to see
how fast it is growing.

On Thu, Dec 20, 2012 at 6:26 PM, Peter Meissner
 wrote:


Hey,

I have an double loop like this:


chunk <- list(1:10, 11:20, 21:30)
for(k in 1:length(chunk)){
  print(chunk[k])
  DummyCatcher <- NULL
  for(i in chunk[k]){
  print("i load something")
  dummy <- 1
  print("i do something")
  dummy <- dummy + 1
  print("i do put it together")
  DummyCatcher = rbind(DummyCatcher, dummy)
  }
  print("i save a chunk and restart with another chunk of
data")
}

The problem now is that with each 'chunk'-cycle the memory used by R
becomes
bigger and bigger until it exceeds my RAM but the RAM it needs for
any of
the chunk-cycles alone is only a 1/5th of what I have overall.

Does somebody have an idea why this behaviour might occur? Note
that all
the
objects (like 'DummyCatcher') are reused every cycle so that I would
assume
that the RAM used should stay about the same after the first 'chunk'
cycle.


Best, Peter


SystemInfo:

R version 2.15.2 (2012-10-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Win7 Enterprise, 8 GB RAM

__
R-help@r-

Re: [R] Can data.frame be saved as image?

2012-12-21 Thread arun
Hi Katherine,

You could try this:
library(plotrix)
png("katherine.png")
 plot(0:3,0:3,xlab="",ylab="",type="n",axes=FALSE)
 addtable2plot(1,1,output1,cex=2)
 dev.off()


A.K.




- Original Message -
From: Katherine Gobin 
To: r-help@r-project.org
Cc: 
Sent: Friday, December 21, 2012 8:59 AM
Subject: [R] Can data.frame be saved as image?

Dear R forum

I have one stupid question, but I have no other solution to it in sight?

Suppose some R process creates graphs etc alongwith main output as data.frame 
e.g 

output1 = data.frame(bands = c("A", "B", "C"), results = c(74, 108,  65))

I normally save this output as some csv file.

But I need to save this output as some image (I understand this is weird, but I 
need to find out some way to do so) e.g. for graph, I use 'png' as

png("histogram.png", width=480,height=480)

.

..

dev.off()

Please advise.

Regards

Katherine


    [[alternative HTML version deleted]]


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


[R] Parallel code using parLapply

2012-12-21 Thread Chris Hergarten
Dear R-users

I was running into problems with my R code trying to run clh sampling (clhs 
package) in parallel mode (=on various data sets simultaneously).

Here is the code (which I developed with some help:)):
**
library("clhs")
library("snow")
a <- as.data.frame(replicate(1000, rnorm(20)))
b <- as.data.frame(replicate(1000, rnorm(20)))
c <- as.data.frame(replicate(1000, rnorm(20)))
d <- as.data.frame(replicate(1000, rnorm(20)))
abcd <- list(a, b, c, d)
cl <- makeCluster(4)
results <- parLapply(cl,
   X = abcd,
   FUN = function(i) {
     clhs(x = i, size = round(nrow(i) / 5), iter = 2000, simple = FALSE)
   },
)
stopCluster(cl)
**

Before running the last line, R is throwing an error: "Error in length(x) : 'x' 
is missing". Any ideas what I am doing wrong and how to improve?

Many thanks!

Best, Chega
[[alternative HTML version deleted]]

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


Re: [R] how can I import op.gz files with read.csv or otherwise

2012-12-21 Thread arun
HI,

May be this link helps you:
http://stackoverflow.com/questions/5764499/decompress-gz-file-using-r
A.K.




- Original Message -
From: herr dittmann 
To: "r-help@r-project.org" 
Cc: 
Sent: Friday, December 21, 2012 9:51 AM
Subject: [R] how can I import op.gz files with read.csv or otherwise

Dear R-users,

I am struggling to directly read an "op.gz" file into R. NOAA kindly provides 
daily weather data on their FTP server for download. 


> sessionInfo()
R version 2.15.1 (2012-06-22)
Platform: x86_64-pc-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United 
Kingdom.1252    LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C    LC_TIME=English_United 
Kingdom.1252    
attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base     
loaded via a namespace (and not attached):
[1] tools_2.15.1

Here is the data set in question:
x <- 
read.csv(file="ftp://ftp.ncdc.noaa.gov/pub/data/gsod/2012/285880-9-2012.op.gz";,
 skip = 1, sep = "")

and "structure" returns some incomprehensible gibberish:

> str(x)
'data.frame':   70 obs. of  6 variables:
 $ 
X4àtYd...ÂÚ8.åWD...ëü.ïß.X.QTñVP.. 
 : Factor w/ 70 levels 
"\005~4èdŒÚíE\031y\020ÿíº\035JëïÒI˜Æí\021†BÆÌR{žYkv\035`“ì°a\017Z\021ÅsP’eÏhÞÇ""|
 __truncated__,..: 44 13 56 64 28 23 67 3 2 33 ...
 $ 
X.öoMýßT..º_...Öígß7.â..Tþ.üÔ.ª...5ÕJ...žíÕj.QÊ..ã.eŃÎGmòýçºg..a...Õæ.J..Å.ãsç.êŠ.û.ÊklsUDÙ.Š..âU...u1.zË.WÜ..x...3._..E.ò.ÊZD.ïoÚÇ.dvæòk.C.y...8h:
 Factor w/ 41 levels 
"","\025ç\016\vβi;§4ƒñ\002\001P–á\0025¶•âÆ{ÐÄ™¹=¤4&ðwQ­´›­Ü´\"hnÅ™‰I¨ÅŠb*ªš\035b\b>6ÆÙ$W!ÖËR=¨\022“Pqˆ[»j\004$TÄ•3²*Ó±%à­N”›\"|
 __truncated__,..: 1 1 1 39 1 1 1 8 1 5 ...
 $ 
X.iŒ.yÐû..ý2.h..ûÉ7.ãJ.3k..jLm...Q..uYÓJä.K.zkU.8.öÖ..Y.7.3...üÊîA.Ê.3ûÄ..Z..5...âš.   
 : Factor w/ 29 levels "","\001qË^+nê1",..: 1 1 1 4 1 1 1 14 1 6 ...
 $ 
X.îFd.m.Š..v.  
 : Factor w/ 17 levels 
""," ´SL\ašÜÝ°\035d)‚¼$íZƼò¶îßJÉ‚äþ†B6å\006%5l[‘¼š\025a\024ñï+gT+3",..: 1 1 1 
16 1 1 1 1 1 1 ...
 $ 
ÿA..E.ŸJkEZ.ÐÊ.á.ë...œ.z..Â.z..œ..òË.ÙÖãg.ö
 : Factor w/ 8 levels "","\001S\177¿\017iSÞÖiÓÈ#\017\"UgË:i´í\016pÝ\031UÄéD""| 
__truncated__,..: 1 1 1 1 1 1 1 1 1 1 ...
 $ X..oðçnPÔoÎWõj.éÔ..B..Âÿë.Qêù...ø  


While I can manually open and read the op.gz file in a text editor, read.csv() 
or read.table() the imported file is simply unreadable.

How can I best get the job done? Any pointers, suggestions, ideas most welcome!!

Thanks in advance!

Bernd

    [[alternative HTML version deleted]]


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


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


Re: [R] Can data.frame be saved as image?

2012-12-21 Thread Katherine Gobin
Dear Sir,

Thanks a lot for your suggestion. In the meantime I came across 

http://stackoverflow.com/questions/10587621/how-to-print-to-paper-a-nicely-formatted-data-frame

and got to know about the package "gridExtra"

So I used following code 

png(filename = "output1.png", width=480,height=480)
grid.table(output1)

dev.off()

And that solved it. 

Thanks again Sir for suggesting other two  pacakages 'lattice' or 'ggplot2' as 
definitely I will like to decipher these two.

I understand before posting the mail to the forum, I should have tried old 
mails etc, but I was bit desperate to know the solution and somehow I felt it's 
a stupid thing to do so. I will remember it next time.

Regards

Katherine



--- On Fri, 21/12/12, jim holtman  wrote:

From: jim holtman 
Subject: Re: [R] Can data.frame be saved as image?
To: "Katherine Gobin" 
Cc: r-help@r-project.org
Date: Friday, 21 December, 2012, 2:39 PM

do you want to save the dataframe used in the plot and then the plot
itself?  If so consider using 'lattice' or 'ggplot2' which create an
object for "print" and this would allow you to use 'save' to save both
objects in a file.

If you want to generate the 'png' file, the you would have to 'save'
the dataframe and then 'zip' the .RData and png file into a new file.

So what is it that you intend to do with the data that is saved in the
common file?

On Fri, Dec 21, 2012 at 8:59 AM, Katherine Gobin
 wrote:
> Dear R forum
>
> I have one stupid question, but I have no other solution to it in sight?
>
> Suppose some R process creates graphs etc alongwith main output as data.frame 
> e.g
>
> output1 = data.frame(bands = c("A", "B", "C"), results = c(74, 108,  65))
>
> I normally save this output as some csv file.
>
> But I need to save this output as some image (I understand this is weird, but 
> I need to find out some way to do so) e.g. for graph, I use 'png' as
>
> png("histogram.png", width=480,height=480)
>
> .
>
> ..
>
> dev.off()
>
> Please advise.
>
> Regards
>
> Katherine
>
>
>         [[alternative HTML version deleted]]
>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

[[alternative HTML version deleted]]

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


[R] Rterm does not load personal library

2012-12-21 Thread Bond, Stephen
Greetings,

I am trying to run a short script from a shell:

c:\projects\hell>Rscript --default-packages=mypack X:/4Stephen/commit/curve.R > 
X:/4Stephen/commit/run1.out

Loading required package: utils
Warning message:
package 'RODBC' was built under R version 2.12.2 
Error: could not find function "normalize"
Execution halted
Warning message:
closing unused RODBC handle 1

function 'normalize' is in "mypack" and I even attempt to load it from inside 
the script:

## curve.R
dt <- Sys.Date()
library(RODBC)
pipe <- odbcConnect("commit")
library(mypack) # with quotes it's the same result
normalize(pipe)

any ideas how to make Rterm load the library?? Running from inside ESS works 
fine. Also from RGui. It does not work if I start a session by "R -vanilla" on 
the command line.

Thanks and happy holidays.

Stephen 

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


Re: [R] how to recode an ordered factor

2012-12-21 Thread William Dunlap
Will calling factor(var,levels=rev(levels(var))) work for you?

  > o <- factor(c("Good","Bad","Good","Neutral"), 
levels=c("Bad","Neutral","Good"), ordered=TRUE)
  > orev <- factor(o, levels=rev(levels(o)))
  > str(o)
   Ord.factor w/ 3 levels "Bad"<"Neutral"<..: 3 1 3 2
  > str(orev)
   Ord.factor w/ 3 levels "Good"<"Neutral"<..: 1 3 1 2
  > o
  [1] GoodBad GoodNeutral
  Levels: Bad < Neutral < Good
  > orev
  [1] GoodBad GoodNeutral
  Levels: Good < Neutral < Bad

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 Francesco Sarracino
> Sent: Friday, December 21, 2012 8:44 AM
> To: r-help@r-project.org
> Subject: [R] how to recode an ordered factor
> 
> Dear R helpers,
> 
> I'm trying to recode an ordered factor to reverse its scale, but I can't
> figure out how to make it. I am using the Recode function provided by the
> Car package.
> 
> I've created an ordered variable:
> data$o.var1 <- ordered(data$var1, levels=c(1,2,3,4), labels =c("very
> satisfied", "fairly satisfied", "not very satisfied", "not at all
> satisfied"))
> 
> Now, I'd like to have a new variable ranging from 4 = Very satisfied to 1=
> not at all satisfied.
> 
> I've tried with the following:
> data$or.var1 <- Recode(data$o.var1, "1 = 4; 2 = 3; 3=2; 4=1")
> but it looks like the new variable loses the order:
> the output of table(data$or.var1) looks like:
> 
> fairly satisfied not at all satisfied not very satisfied very satisfied
> 
> I believe the new variable is ordered in alphabetical order, but when I
> tried to use the levels option I lost the initial information.
> Can you help figuring out what I am doing wrong?
> thanks in advance,
> f.
> 
> 
> 
> 
> 
> --
> Francesco Sarracino, Ph.D.
> https://sites.google.com/site/fsarracino/
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R] how to recode an ordered factor

2012-12-21 Thread Francesco Sarracino
Dear R helpers,

I'm trying to recode an ordered factor to reverse its scale, but I can't
figure out how to make it. I am using the Recode function provided by the
Car package.

I've created an ordered variable:
data$o.var1 <- ordered(data$var1, levels=c(1,2,3,4), labels =c("very
satisfied", "fairly satisfied", "not very satisfied", "not at all
satisfied"))

Now, I'd like to have a new variable ranging from 4 = Very satisfied to 1=
not at all satisfied.

I've tried with the following:
data$or.var1 <- Recode(data$o.var1, "1 = 4; 2 = 3; 3=2; 4=1")
but it looks like the new variable loses the order:
the output of table(data$or.var1) looks like:

fairly satisfied not at all satisfied not very satisfied very satisfied

I believe the new variable is ordered in alphabetical order, but when I
tried to use the levels option I lost the initial information.
Can you help figuring out what I am doing wrong?
thanks in advance,
f.





-- 
Francesco Sarracino, Ph.D.
https://sites.google.com/site/fsarracino/

[[alternative HTML version deleted]]

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


Re: [R] comparison of large data set

2012-12-21 Thread Adams, Jean
Irucka,

I did not test this code out on any data, but I think it will work.

Jean


# a function to read in the data as a matrix of logicals
myreadfun <- function(file) {
as.matrix(read.ascii.grid(file)$data)!=0
}

# names of the 54 modeled depth files
modfiles <- paste0("MaxFloodDepth_", 1:54, ".txt")

# read in the observed and modeled depth files
# observeddepth is a matrix
observeddepth <- myreadfun("MaxFloodDepth_Observed.txt")
# modeldepths is a list of matrices
modeldepths <- lapply(filenames, myreadfun)

# calculate the proportion of matrix elements that agree with the observed
file
# the results is a vector with one number for each modeled depth matrix
compare.all <- sapply(modeldepths, function(md) mean(md==observeddepth))

# select just those matrices that had a large proportion of agreements
# justbig is a list of matrices
justbig <- modeldepths[[compare.all > 0.7]]



On Thu, Dec 20, 2012 at 12:42 PM, Irucka Embry wrote:

> Hi, how are you?
>
> I have the following truncated R code:
>
> fileobs <- "MaxFloodDepth_Observed.txt"
> file1 <- "MaxFloodDepth_1.txt"
> file2 <- "MaxFloodDepth_2.txt"
>
> ...
>
> file54 <- "MaxFloodDepth_54.txt"
>
>
> observeddepth = as.matrix(read.ascii.grid(fileobs)$data)
> observeddepth[observeddepth!=0]<-1
>
> modeldepth1 = as.matrix(read.ascii.grid(file1)$data)
> modeldepth1[modeldepth1!=0]<-1
>
> modeldepth2 = as.matrix(read.ascii.grid(file2)$data)
> modeldepth2[modeldepth2!=0]<-1
>
> ...
>
> modeldepth54 = as.matrix(read.ascii.grid(file54)$data)
> modeldepth54[modeldepth54!=0]<-1
>
> Each modeldepth* and observeddepth is 272x976
>
> f2 <- function(obs, dat){
> obs <- as.logical(obs)
> dat <- as.logical(dat)
> s1 <- sum(obs & dat)
> s2 <- sum(obs & !dat)
> s3 <- sum(!obs & dat)
> s1/(s1 + s2 + s3)
> }
>
> f2all <- f2(observeddepth, modeldepth[1:54]) # I am including the
> "[1:54]" in the code to indicate that I want to compare the
> observeddepth data to each of the modeldepth data files
>
> modeldepth <- as.matrix(c(modeldepth1, modeldepth2, ... modeldepth54))
>
> modeldepth <- modeldepth_index[, f2 > 0.7] # I want to end with
> modeldepth that only lists the specific 272x976 modeldepth data files
> that had an f2 greater than 0.7
>
> Is there any way to reduce the code? As you see, I am using the name for
> all 54 files with both file and also modeldepth.
>
> How can I create an f2 for each of the 54 comparisons?
>
> Thank-you.
>
> Irucka Embry
>
>
>  style="font-size:13.5px">___Get
> the Free email that has everyone talking at  http://www.mail2world.com target=new>http://www.mail2world.com
>  Unlimited Email Storage – POP3 – Calendar
> – SMS – Translator – Much More!
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


Re: [R] Memory filling up while looping

2012-12-21 Thread Peter Meißner
I'll consider it. But in fact the whole data does not fit into memory at 
once with the overhead to create it in addition - I think. That was one 
of the reasons I wanted to do it chunk by chunk in the first place.


Thanks, Best, Peter

Am 21.12.2012 15:07, schrieb Duncan Murdoch:

On 12-12-20 6:26 PM, Peter Meissner wrote:

Hey,

I have an double loop like this:


chunk <- list(1:10, 11:20, 21:30)
for(k in 1:length(chunk)){
print(chunk[k])
DummyCatcher <- NULL
for(i in chunk[k]){
print("i load something")
dummy <- 1
print("i do something")
dummy <- dummy + 1
print("i do put it together")
DummyCatcher = rbind(DummyCatcher, dummy)
}
print("i save a chunk and restart with another chunk of data")
}

The problem now is that with each 'chunk'-cycle the memory used by R
becomes bigger and bigger until it exceeds my RAM but the RAM it needs
for any of the chunk-cycles alone is only a 1/5th of what I have overall.

Does somebody have an idea why this behaviour might occur? Note that all
the objects (like 'DummyCatcher') are reused every cycle so that I would
assume that the RAM used should stay about the same after the first
'chunk' cycle.


You should pre-allocate your result matrix.  By growing it a few rows at
a time, R needs to do this:

allocate it
allocate a bigger one, copy the old one in
delete the old one, leaving a small hole in memory
allocate a bigger one, copy the old one in
delete the old one, leaving a bigger hold in memory, but still too small
to use...

etc.

If you are lucky, R might be able to combine some of those small holes
into a bigger one and use that, but chances are other variables will
have been created there in the meantime, so the holes will go mostly
unused.  R never moves an object during garbage collection, so if you
have fragmented memory, it's mostly wasted.

If you don't know how big the final result will be, then allocate large,
and when you run out, allocate bigger.  Not as good as one allocation,
but better than hundreds.

Duncan Murdoch




Best, Peter


SystemInfo:

R version 2.15.2 (2012-10-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Win7 Enterprise, 8 GB RAM

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





--
Peter Meißner
Workgroup 'Comparative Parliamentary Politics'
Department of Politics and Administration
University of Konstanz
Box 216
78457 Konstanz
Germany

+49 7531 88 5665
http://www.polver.uni-konstanz.de/sieberer/home/

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


Re: [R] Memory filling up while looping

2012-12-21 Thread Peter Meißner
Here is an working example that reproduces the behavior by creating 1000 
xml-files and afterwards parsing them.


At my PC, R starts with about 90MB of RAM with every cycle another 
10-12MB are further added to the RAM-usage so I end up with 200MB RAM 
usage.


In the real code one chunk-cycle eats about 800MB of RAM which was one 
of the reasons I decided to splitt up the process in seperate chunks in 
the first place.



'Minimal'Example - START


# the general problem
require(XML)

chunk <- function(x, chunksize){
# source: http://stackoverflow.com/a/3321659/1144966
x2 <- seq_along(x)
split(x, ceiling(x2/chunksize))
}



chunky <- chunk(paste("test",1:1000,".xml",sep=""),100)

for(i in 1:1000){
writeLines(c(paste('\n \n 
Tove\n',i,'\nJani\n 
Reminder\n',sep=""), paste(rep('Do not 
forget me this weekend!\n',sample(1:10, 1)),sep="" ) , ' ')

,paste("test",i,".xml",sep=""))
}

for(k in 1:length(chunky)){
gc()
print(chunky[[k]])
xmlCatcher <- NULL

for(i in 1:length(chunky[[k]])){
filename<- chunky[[k]][i]
xml <- xmlTreeParse(filename)
xml <- xmlRoot(xml)
result  <- sapply(getNodeSet(xml,"//body"), xmlValue)
id  <- sapply(getNodeSet(xml,"//nr"), xmlValue)
dummy   <- cbind(id,result)
xmlCatcher  <- rbind(xmlCatcher,dummy)
}
save(xmlCatcher,file=paste("xmlCatcher",k,".RData"))
}


'Minimal'Example - END




Am 21.12.2012 15:14, schrieb jim holtman:

Can you send either your actual script or the console output so I can
get an idea of how fast memory is growing.  Also at the end, can you
list the sizes of the objects in the workspace.  Here is a function I
use to get the space:

my.ls <-
function (pos = 1, sorted = FALSE, envir = as.environment(pos))
{
 .result <- sapply(ls(envir = envir, all.names = TRUE),
function(..x) object.size(eval(as.symbol(..x),
 envir = envir)))
 if (length(.result) == 0)
 return("No objects to list")
 if (sorted) {
 .result <- rev(sort(.result))
 }
 .ls <- as.data.frame(rbind(as.matrix(.result), `**Total` = sum(.result)))
 names(.ls) <- "Size"
 .ls$Size <- formatC(.ls$Size, big.mark = ",", digits = 0,
 format = "f")
 .ls$Class <- c(unlist(lapply(rownames(.ls)[-nrow(.ls)],
function(x) class(eval(as.symbol(x),
 envir = envir))[1L])), "---")
 .ls$Length <- c(unlist(lapply(rownames(.ls)[-nrow(.ls)],
 function(x) length(eval(as.symbol(x), envir = envir,
 "---")
 .ls$Dim <- c(unlist(lapply(rownames(.ls)[-nrow(.ls)], function(x)
paste(dim(eval(as.symbol(x),
 envir = envir)), collapse = " x "))), "---")
 .ls
}


which gives output like this:


my.ls()

  Size   Class  Length Dim
.Last 736function   1
.my.env.jph28 environment  39
x 424 integer 100
y  40,024 integer   1
z   4,000,024 integer 100
**Total 4,041,236 --- --- ---


On Fri, Dec 21, 2012 at 8:03 AM, Peter Meißner
 wrote:

Thanks for your answer,

yes, I tried 'gc()' it did not change the bahavior.

best, Peter


Am 21.12.2012 13:37, schrieb jim holtman:


have you tried putting calls to 'gc' at the top of the first loop to
make sure memory is reclaimed? You can print the call to 'gc' to see
how fast it is growing.

On Thu, Dec 20, 2012 at 6:26 PM, Peter Meissner
 wrote:


Hey,

I have an double loop like this:


chunk <- list(1:10, 11:20, 21:30)
for(k in 1:length(chunk)){
  print(chunk[k])
  DummyCatcher <- NULL
  for(i in chunk[k]){
  print("i load something")
  dummy <- 1
  print("i do something")
  dummy <- dummy + 1
  print("i do put it together")
  DummyCatcher = rbind(DummyCatcher, dummy)
  }
  print("i save a chunk and restart with another chunk of data")
}

The problem now is that with each 'chunk'-cycle the memory used by R
becomes
bigger and bigger until it exceeds my RAM but the RAM it needs for any of
the chunk-cycles alone is only a 1/5th of what I have overall.

Does somebody have an idea why this behaviour might occur? Note that all
the
objects (like 'DummyCatcher') are reused every cycle so that I would
assume
that the RAM used should stay about the same after the first 'chunk'
cycle.


Best, Peter


SystemInfo:

R version 2.15.2 (2012-10-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Win7 Enterprise, 8 GB RAM

__
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] Why can't I "unclass" an array?

2012-12-21 Thread Martin Maechler
[ Diverted from  R-devel : ]

> Terry Therneau 
> on Fri, 21 Dec 2012 08:05:21 -0600 writes:

> In a real example I was trying to remove the class from the result of 
table, just because 
> it was to be used as a building block for other things and a simple 
integer vector seemed 
> likely to be most efficient.
> I'm puzzled as to why unclass doesn't work.

It does work, exactly as intended
(but indeed not as expected by you):

?unclasssays

 ‘unclass’ returns (a copy of) its argument with its class
 attribute removed. 

Note *attribute*.
In R (and I think newer versions of S, too),
class(x) *always* returns something reasonable, so there is
always an implicit class, e.g. "integer" as see below.

"matrix" and "array" are of a similar category in this respect,
their class is no attribute :

> attributes(array(1,1))
$dim
[1] 1

> attributes(matrix(1,1))
$dim
[1] 1 1

> m <- matrix(1,1); identical(m, unclass(m))
[1] TRUE
> a <- array(1,1); identical(a, unclass(a))
[1] TRUE
> 

Martin Maechler, ETH Zurich


>> zed <- table(1:5)
>> class(zed)
> [1] "table"
>> class(unclass(zed))
> [1] "array"
>> class(unclass(unclass(unclass(zed
> [1] "array"

>> class(as.vector(zed))
> [1] "integer"
>> sessionInfo()
> R Under development (unstable) (2012-11-28 r61176)
> Platform: i686-pc-linux-gnu (32-bit)

> locale:
> [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
> [3] LC_TIME=en_US.UTF-8LC_COLLATE=C
> [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
> [7] LC_PAPER=C LC_NAME=C
> [9] LC_ADDRESS=C   LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods   base

> __
> r-de...@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

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


Re: [R] How to run chaid in R

2012-12-21 Thread Sarah Goslee
The link given mentions a function and package.

You can also go to www.rseek.org and type in CHAID yourself.

Or google, for that matter. Let me demonstrate:
http://lmgtfy.com/?q=chaid+r

It's incumbent on querents here to do at least a bit of their own work
before asking for help.

Sarah

On Fri, Dec 21, 2012 at 6:00 AM, saumya Joshi  wrote:
> Hi,
>
> I don't find the chaid code in the mail/webpage.
>
> Thanks,
> Saumya
>
> --- On Fri, 21/12/12, Pascal Oettli  wrote:
>
>
> From: Pascal Oettli 
> Subject: Re: [R] How to run chaid in R
> To: "saumya Joshi" 
> Cc: r-help@r-project.org
> Received: Friday, 21 December, 2012, 10:46 AM
>
>
> https://stat.ethz.ch/pipermail/r-help/2009-August/209752.html
>
>
> Le 21/12/2012 18:07, saumya Joshi a écrit :
>> Could you please let me know how to run chaid in R.
>>
>>
>> Thanks,
>> Saumyha

--
Sarah Goslee
http://www.functionaldiversity.org

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


[R] how can I import op.gz files with read.csv or otherwise

2012-12-21 Thread herr dittmann
Dear R-users,

I am struggling to directly read an "op.gz" file into R. NOAA kindly provides 
daily weather data on their FTP server for download. 


> sessionInfo()
R version 2.15.1 (2012-06-22)
Platform: x86_64-pc-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United 
Kingdom.1252    LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C                            
LC_TIME=English_United Kingdom.1252    
attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   
base     
loaded via a namespace (and not attached):
[1] tools_2.15.1

Here is the data set in question:
x <- 
read.csv(file="ftp://ftp.ncdc.noaa.gov/pub/data/gsod/2012/285880-9-2012.op.gz";,
 skip = 1, sep = "")

and "structure" returns some incomprehensible gibberish:

> str(x)
'data.frame':   70 obs. of  6 variables:
 $ 
X4àtYd...ÂÚ8.åWD...ëü.ïß.X.QTñVP..                                                                                                                     
 : Factor w/ 70 levels 
"\005~4èdŒÚíE\031y\020ÿíº\035JëïÒI˜Æí\021†BÆÌR{žYkv\035`“ì°a\017Z\021ÅsP’eÏhÞÇ""|
 __truncated__,..: 44 13 56 64 28 23 67 3 2 33 ...
 $ 
X.öoMýßT..º_...Öígß7.â..Tþ.üÔ.ª...5ÕJ...žíÕj.QÊ..ã.eŃÎGmòýçºg..a...Õæ.J..Å.ãsç.êŠ.û.ÊklsUDÙ.Š..âU...u1.zË.WÜ..x...3._..E.ò.ÊZD.ïoÚÇ.dvæòk.C.y...8h:
 Factor w/ 41 levels 
"","\025ç\016\vβi;§4ƒñ\002\001P–á\0025¶•âÆ{ÐÄ™¹=¤4&ðwQ­´›­Ü´\"hnÅ™‰I¨ÅŠb*ªš\035b\b>6ÆÙ$W!ÖËR=¨\022“Pqˆ[»j\004$TÄ•3²*Ó±%à­N”›\"|
 __truncated__,..: 1 1 1 39 1 1 1 8 1 5 ...
 $ 
X.iŒ.yÐû..ý2.h..ûÉ7.ãJ.3k..jLm...Q..uYÓJä.K.zkU.8.öÖ..Y.7.3...üÊîA.Ê.3ûÄ..Z..5...âš.                                                                   
 : Factor w/ 29 levels "","\001qË^+nê1",..: 1 1 1 4 1 1 1 14 1 6 ...
 $ 
X.îFd.m.Š..v.                                                                                                                                          
 : Factor w/ 17 levels 
""," ´SL\ašÜÝ°\035d)‚¼$íZƼò¶îßJÉ‚äþ†B6å\006%5l[‘¼š\025a\024ñï+gT+3",..:
 1 1 1 16 1 1 1 1 1 1 ...
 $ 
ÿA..E.ŸJkEZ.ÐÊ.á.ë...œ.z..Â.z..œ..òË.ÙÖãg.ö                                                                                                        
 : Factor w/ 8 levels 
"","\001S\177¿\017iSÞÖiÓÈ#\017\"UgË:i´í\016pÝ\031UÄéD""| 
__truncated__,..: 1 1 1 1 1 1 1 1 1 1 ...
 $ X..oðçnPÔoÎWõj.éÔ..B..Âÿë.Qêù...ø      


While I can manually open and read the op.gz file in a text editor, read.csv() 
or read.table() the imported file is simply unreadable.

How can I best get the job done? Any pointers, suggestions, ideas most welcome!!

Thanks in advance!

Bernd

[[alternative HTML version deleted]]

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


Re: [R] Can data.frame be saved as image?

2012-12-21 Thread jim holtman
do you want to save the dataframe used in the plot and then the plot
itself?  If so consider using 'lattice' or 'ggplot2' which create an
object for "print" and this would allow you to use 'save' to save both
objects in a file.

If you want to generate the 'png' file, the you would have to 'save'
the dataframe and then 'zip' the .RData and png file into a new file.

So what is it that you intend to do with the data that is saved in the
common file?

On Fri, Dec 21, 2012 at 8:59 AM, Katherine Gobin
 wrote:
> Dear R forum
>
> I have one stupid question, but I have no other solution to it in sight?
>
> Suppose some R process creates graphs etc alongwith main output as data.frame 
> e.g
>
> output1 = data.frame(bands = c("A", "B", "C"), results = c(74, 108,  65))
>
> I normally save this output as some csv file.
>
> But I need to save this output as some image (I understand this is weird, but 
> I need to find out some way to do so) e.g. for graph, I use 'png' as
>
> png("histogram.png", width=480,height=480)
>
> .
>
> ..
>
> dev.off()
>
> Please advise.
>
> Regards
>
> Katherine
>
>
> [[alternative HTML version deleted]]
>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

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


[R] useR meetup group in Munich, Germany

2012-12-21 Thread Markus Schmidberger
Dear all,

I would like to invite Munich (Germany) area R users for our first meeting: 
16th January 2013. The group is aimed to bring together practitioners (from 
industry and academia) in order to exchange knowledge and experience in solving 
data analysis & statistical problems by using R. More information about the 
group at: 
http://www.meetup.com/munich-useR-group/

1. Meeting: http://www.meetup.com/munich-useR-group/events/63749502/

Merry Christmas, happy New Year and see you in 2013
Markus

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


Re: [R] Memory filling up while looping

2012-12-21 Thread Duncan Murdoch

On 12-12-20 6:26 PM, Peter Meissner wrote:

Hey,

I have an double loop like this:


chunk <- list(1:10, 11:20, 21:30)
for(k in 1:length(chunk)){
print(chunk[k])
DummyCatcher <- NULL
for(i in chunk[k]){
print("i load something")
dummy <- 1
print("i do something")
dummy <- dummy + 1
print("i do put it together")
DummyCatcher = rbind(DummyCatcher, dummy)
}
print("i save a chunk and restart with another chunk of data")
}

The problem now is that with each 'chunk'-cycle the memory used by R
becomes bigger and bigger until it exceeds my RAM but the RAM it needs
for any of the chunk-cycles alone is only a 1/5th of what I have overall.

Does somebody have an idea why this behaviour might occur? Note that all
the objects (like 'DummyCatcher') are reused every cycle so that I would
assume that the RAM used should stay about the same after the first
'chunk' cycle.


You should pre-allocate your result matrix.  By growing it a few rows at 
a time, R needs to do this:


allocate it
allocate a bigger one, copy the old one in
delete the old one, leaving a small hole in memory
allocate a bigger one, copy the old one in
delete the old one, leaving a bigger hold in memory, but still too small 
to use...


etc.

If you are lucky, R might be able to combine some of those small holes 
into a bigger one and use that, but chances are other variables will 
have been created there in the meantime, so the holes will go mostly 
unused.  R never moves an object during garbage collection, so if you 
have fragmented memory, it's mostly wasted.


If you don't know how big the final result will be, then allocate large, 
and when you run out, allocate bigger.  Not as good as one allocation, 
but better than hundreds.


Duncan Murdoch




Best, Peter


SystemInfo:

R version 2.15.2 (2012-10-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Win7 Enterprise, 8 GB RAM

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



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


[R] Can data.frame be saved as image?

2012-12-21 Thread Katherine Gobin
Dear R forum

I have one stupid question, but I have no other solution to it in sight?

Suppose some R process creates graphs etc alongwith main output as data.frame 
e.g 

output1 = data.frame(bands = c("A", "B", "C"), results = c(74, 108,  65))

I normally save this output as some csv file.

But I need to save this output as some image (I understand this is weird, but I 
need to find out some way to do so) e.g. for graph, I use 'png' as

png("histogram.png", width=480,height=480)

.

..

dev.off()

Please advise.

Regards

Katherine


[[alternative HTML version deleted]]

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


Re: [R] Memory filling up while looping

2012-12-21 Thread Peter Meißner

Thanks for your answer,

yes, I tried 'gc()' it did not change the bahavior.

best, Peter


Am 21.12.2012 13:37, schrieb jim holtman:

have you tried putting calls to 'gc' at the top of the first loop to
make sure memory is reclaimed? You can print the call to 'gc' to see
how fast it is growing.

On Thu, Dec 20, 2012 at 6:26 PM, Peter Meissner
 wrote:

Hey,

I have an double loop like this:


chunk <- list(1:10, 11:20, 21:30)
for(k in 1:length(chunk)){
 print(chunk[k])
 DummyCatcher <- NULL
 for(i in chunk[k]){
 print("i load something")
 dummy <- 1
 print("i do something")
 dummy <- dummy + 1
 print("i do put it together")
 DummyCatcher = rbind(DummyCatcher, dummy)
 }
 print("i save a chunk and restart with another chunk of data")
}

The problem now is that with each 'chunk'-cycle the memory used by R becomes
bigger and bigger until it exceeds my RAM but the RAM it needs for any of
the chunk-cycles alone is only a 1/5th of what I have overall.

Does somebody have an idea why this behaviour might occur? Note that all the
objects (like 'DummyCatcher') are reused every cycle so that I would assume
that the RAM used should stay about the same after the first 'chunk' cycle.


Best, Peter


SystemInfo:

R version 2.15.2 (2012-10-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Win7 Enterprise, 8 GB RAM

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






--
Peter Meißner
Workgroup 'Comparative Parliamentary Politics'
Department of Politics and Administration
University of Konstanz
Box 216
78457 Konstanz
Germany

+49 7531 88 5665
http://www.polver.uni-konstanz.de/sieberer/home/

__
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] Filling Lists or Arrays of variable dimensions

2012-12-21 Thread Tim Howard
Jessica,
In terms of initializing your list for populating it in a later step, I think 
this partially gets at your question -- it removes the upper loop assignment, 
but then does require a loop to get the second level. Perhaps there's something 
here you can work with ...
 
 
height<-c("high","low")
width<-c("slim","wide")
 
l <- vector("list",length(height))   
names(l) <- height
 
for(i in 1:length(l)){
l[[i]] <- vector("list",length(width))
names(l[[i]]) <- width
}
 
 
Best
Tim
 
Date: Fri, 21 Dec 2012 11:34:06 +0100
From: Jessica Streicher 
To: David Winsemius 
Cc: R help 
Subject: Re: [R] Filling Lists or Arrays of variable dimensions
Message-ID: 
Content-Type: text/plain; charset=us-ascii

@David : In my mind it was quite complete enough.

@William: Thanks, didn't know you could do that with data frames, if i ever 
have to do something similar again i might try this.

On 20.12.2012, at 22:39, David Winsemius wrote:

> 
> On Dec 20, 2012, at 10:01 AM, Jessica Streicher wrote:
> 
>> Really must have been unclear at some point, sorry.
> 
> Hasn't it become abundantly clear that this would have progress farther had 
> you post a complete example?
> 
> -- 
> David.
>> 
>> William, thats interesting, but not really helping the main problem, which 
>> is: how to do 
>> 
>>> l[[ as.character(grid[1, ]) ]] <- 1
>> 
>> without having initialized the list in the loop before. 
>> 
>> Well, or how to initialize it without having to do the loop thing, because 
>> the loop stuff can only be done for a specific set of parameter vectors. But 
>> those change, and i don't want to have to write another loop construct every 
>> time for the new version.
>> 
>> I want to say: hey, i have these vectors here with these values (my 
>> parameters), could you build me that nested list structure (tree - whatever) 
>> from it? And the function will give me that structure whatever i give it 
>> without me needing to intervene in form of changing the code.
>> 
>> -- Clarification -
>> 
>> First: i am not computing statistics over the parameters. I'm computing 
>> stuff from other data, and the computation is affected by the parameters. 
>> 
>> I am computing classifiers for different sets of parameters for those 
>> classifiers. So the result of doSomething() isn't a simple value. Its 
>> usually a list of 6 lists (doing cross validation), which in turn have the 
>> classifier object, some statistics of the classifier (e.g what was 
>> missclassified), and the subsets of data used in them.
>> That doesn't really fit in a data.frame, hence the use of lists. I want the 
>> nested lists because it helps me find stuff in the object browser faster, 
>> and because all my other code is already geared towards it. If i had the 
>> time i might still go for a flat structure that everyone keeps telling me to 
>> use (got a few mails off the list),
>> but i really haven't the time.
>> 
>> If theres no good way i'll just keep things as they are now.
>> 
>> 
>> On 20.12.2012, at 18:37, William Dunlap wrote:
>> 
>>> Arranging data as a list of lists of lists of lists [...] of scalar values 
>>> generally
>>> will lead to slow and hard-to-read R code, mainly because R is designed to
>>> work on long vectors of simple data.  If you were to start over, consider 
>>> constructing
>>> a data.frame with one column for each attribute.  Then tools like aggregate 
>>> and
>>> the plyr functions would be useful.
>>> 
>>> However, your immediate problem may be solved by creating your 'grid' object
>>> as a data.frame of character, not factor, columns because as.character 
>>> works differently
>>> on lists of scalar factors and lists of scalar characters.  Usually 
>>> as.(x), when
>>> x is a list of length-1 items, gives the same result as 
>>> as.(unlist(x)), but not when
>>> x is a list of length-1 factors:
>>> 
 height<-c("high", "low")
 width<-c("slim", "wide")
 gridF <- expand.grid(height, width, stringsAsFactors=FALSE)
 gridT <- expand.grid(height, width, stringsAsFactors=TRUE)
 as.character(gridF[1,])
>>> [1] "high" "slim"
 as.character(gridT[1,])
>>> [1] "1" "1"
 as.character(unlist(gridT[1,])) # another workaround
>>> [1] "high" "slim"
>>> 
>>> Your example was not self-contained so I changed the call to doSomething() 
>>> to paste(h,w,sep="/"):
>>> 
>>> height<-c("high", "low")
>>> width<-c("slim", "wide")
>>> 
>>> l <- list()
>>> for(h in height){
>>>l[[h]] <- list()
>>>for(w in width){
>>>l[[h]][[w]] <- paste(h, w, sep="/") # doSomething()
>>>}
>>> }
>>> 
>>> grid <- expand.grid(height, width, stringsAsFactors=FALSE)
>>> as.character(grid[1,])
>>> # [1] "high" "slim", not the [1] "1" "1" you get with stringsAsFactors=TRUE
>>> l[[ as.character(grid[1, ]) ]]
>>> # [1] "high/slim"
>>> l[[ as.character(grid[1, ]) ]] <- 1
>>> l[[ as.character(grid[1, ]) ]]
>>> # [1] 1
>>> 
>>> Bill Dunlap
>>> Spotfire, TIBCO Software
>>> wdunlap tibco.com
>>> 
>>

Re: [R] Memory filling up while looping

2012-12-21 Thread jim holtman
have you tried putting calls to 'gc' at the top of the first loop to
make sure memory is reclaimed? You can print the call to 'gc' to see
how fast it is growing.

On Thu, Dec 20, 2012 at 6:26 PM, Peter Meissner
 wrote:
> Hey,
>
> I have an double loop like this:
>
>
> chunk <- list(1:10, 11:20, 21:30)
> for(k in 1:length(chunk)){
> print(chunk[k])
> DummyCatcher <- NULL
> for(i in chunk[k]){
> print("i load something")
> dummy <- 1
> print("i do something")
> dummy <- dummy + 1
> print("i do put it together")
> DummyCatcher = rbind(DummyCatcher, dummy)
> }
> print("i save a chunk and restart with another chunk of data")
> }
>
> The problem now is that with each 'chunk'-cycle the memory used by R becomes
> bigger and bigger until it exceeds my RAM but the RAM it needs for any of
> the chunk-cycles alone is only a 1/5th of what I have overall.
>
> Does somebody have an idea why this behaviour might occur? Note that all the
> objects (like 'DummyCatcher') are reused every cycle so that I would assume
> that the RAM used should stay about the same after the first 'chunk' cycle.
>
>
> Best, Peter
>
>
> SystemInfo:
>
> R version 2.15.2 (2012-10-26)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
> Win7 Enterprise, 8 GB RAM
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

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


Re: [R] permutation of vectors (1 or 0)

2012-12-21 Thread jim holtman
use the 64-bit version of R and get at least 4e18 bytes of memory.
Since that is quite a bit, you might want to use another approach
since you would need that much disk to just store the result which
might take 1.3 million cpu hours to calculate.

On Thu, Dec 20, 2012 at 9:07 AM, Olga Lyashevska  wrote:
> On 12/20/2012 02:13 PM, arun wrote:
>> library(gtools)
>> permutations(2,10,0:1,repeats.allowed=TRUE)
>
> This does what I need, but if I increase a number of permutations (59
> instead of 10), then I get an error.
>
> Error: cannot allocate vector of size 1.5 Gb
>
> Is there a smart way of increasing the maximum number of permutations
> that R can handle?
>
>
> Cheers,
> Olga
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

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


Re: [R] How to run chaid in R

2012-12-21 Thread saumya Joshi
Hi,
 
I don't find the chaid code in the mail/webpage.
 
Thanks,
Saumya

--- On Fri, 21/12/12, Pascal Oettli  wrote:


From: Pascal Oettli 
Subject: Re: [R] How to run chaid in R
To: "saumya Joshi" 
Cc: r-help@r-project.org
Received: Friday, 21 December, 2012, 10:46 AM


https://stat.ethz.ch/pipermail/r-help/2009-August/209752.html


Le 21/12/2012 18:07, saumya Joshi a écrit :
> Could you please let me know how to run chaid in R.
>
>
> Thanks,
> Saumyha
>     [[alternative HTML version deleted]]
>
>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


Re: [R] How to run chaid in R

2012-12-21 Thread Pascal Oettli

https://stat.ethz.ch/pipermail/r-help/2009-August/209752.html


Le 21/12/2012 18:07, saumya Joshi a écrit :

Could you please let me know how to run chaid in R.


Thanks,
Saumyha
[[alternative HTML version deleted]]



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



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


Re: [R] Filling Lists or Arrays of variable dimensions

2012-12-21 Thread Jessica Streicher
@David : In my mind it was quite complete enough.

@William: Thanks, didn't know you could do that with data frames, if i ever 
have to do something similar again i might try this.

On 20.12.2012, at 22:39, David Winsemius wrote:

> 
> On Dec 20, 2012, at 10:01 AM, Jessica Streicher wrote:
> 
>> Really must have been unclear at some point, sorry.
> 
> Hasn't it become abundantly clear that this would have progress farther had 
> you post a complete example?
> 
> -- 
> David.
>> 
>> William, thats interesting, but not really helping the main problem, which 
>> is: how to do 
>> 
>>> l[[ as.character(grid[1, ]) ]] <- 1
>> 
>> without having initialized the list in the loop before. 
>> 
>> Well, or how to initialize it without having to do the loop thing, because 
>> the loop stuff can only be done for a specific set of parameter vectors. But 
>> those change, and i don't want to have to write another loop construct every 
>> time for the new version.
>> 
>> I want to say: hey, i have these vectors here with these values (my 
>> parameters), could you build me that nested list structure (tree - whatever) 
>> from it? And the function will give me that structure whatever i give it 
>> without me needing to intervene in form of changing the code.
>> 
>> -- Clarification -
>> 
>> First: i am not computing statistics over the parameters. I'm computing 
>> stuff from other data, and the computation is affected by the parameters. 
>> 
>> I am computing classifiers for different sets of parameters for those 
>> classifiers. So the result of doSomething() isn't a simple value. Its 
>> usually a list of 6 lists (doing cross validation), which in turn have the 
>> classifier object, some statistics of the classifier (e.g what was 
>> missclassified), and the subsets of data used in them.
>> That doesn't really fit in a data.frame, hence the use of lists. I want the 
>> nested lists because it helps me find stuff in the object browser faster, 
>> and because all my other code is already geared towards it. If i had the 
>> time i might still go for a flat structure that everyone keeps telling me to 
>> use (got a few mails off the list),
>> but i really haven't the time.
>> 
>> If theres no good way i'll just keep things as they are now.
>> 
>> 
>> On 20.12.2012, at 18:37, William Dunlap wrote:
>> 
>>> Arranging data as a list of lists of lists of lists [...] of scalar values 
>>> generally
>>> will lead to slow and hard-to-read R code, mainly because R is designed to
>>> work on long vectors of simple data.  If you were to start over, consider 
>>> constructing
>>> a data.frame with one column for each attribute.  Then tools like aggregate 
>>> and
>>> the plyr functions would be useful.
>>> 
>>> However, your immediate problem may be solved by creating your 'grid' object
>>> as a data.frame of character, not factor, columns because as.character 
>>> works differently
>>> on lists of scalar factors and lists of scalar characters.  Usually 
>>> as.(x), when
>>> x is a list of length-1 items, gives the same result as 
>>> as.(unlist(x)), but not when
>>> x is a list of length-1 factors:
>>> 
 height<-c("high", "low")
 width<-c("slim", "wide")
 gridF <- expand.grid(height, width, stringsAsFactors=FALSE)
 gridT <- expand.grid(height, width, stringsAsFactors=TRUE)
 as.character(gridF[1,])
>>> [1] "high" "slim"
 as.character(gridT[1,])
>>> [1] "1" "1"
 as.character(unlist(gridT[1,])) # another workaround
>>> [1] "high" "slim"
>>> 
>>> Your example was not self-contained so I changed the call to doSomething() 
>>> to paste(h,w,sep="/"):
>>> 
>>> height<-c("high", "low")
>>> width<-c("slim", "wide")
>>> 
>>> l <- list()
>>> for(h in height){
>>>l[[h]] <- list()
>>>for(w in width){
>>>l[[h]][[w]] <- paste(h, w, sep="/") # doSomething()
>>>}
>>> }
>>> 
>>> grid <- expand.grid(height, width, stringsAsFactors=FALSE)
>>> as.character(grid[1,])
>>> # [1] "high" "slim", not the [1] "1" "1" you get with stringsAsFactors=TRUE
>>> l[[ as.character(grid[1, ]) ]]
>>> # [1] "high/slim"
>>> l[[ as.character(grid[1, ]) ]] <- 1
>>> l[[ as.character(grid[1, ]) ]]
>>> # [1] 1
>>> 
>>> 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 Jessica Streicher
 Sent: Thursday, December 20, 2012 8:43 AM
 To: Chris Campbell
 Cc: R help
 Subject: Re: [R] Filling Lists or Arrays of variable dimensions
 
 Aggregate is highly confusing (and i would have appreciated if you used my 
 example
 instead, i don't get it to do anything sensible on my stuff).
 
 And this seems not what i asked for anyway. This may be a named list but 
 not named and
 structured as i want it at all.
 
 happy Christmas too
 
 On 20.12.2012, at 15:48, Chris Campbell wrote:
 
>>

[R] How to run chaid in R

2012-12-21 Thread saumya Joshi
Could you please let me know how to run chaid in R.
 
 
Thanks,
Saumyha
[[alternative HTML version deleted]]

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


[R] [R-pkgs] Package exams with Moodle and OLAT support

2012-12-21 Thread Achim Zeileis

Dear useRs,

this week we have released a new version (1.9) of the "exams" package 
which now contains flexible tools for generating e-learning exams for
various learning management systems: As in earlier versions of the package 
exam generation is still based on separate Sweave files for each exercise. 
But rather than just producing different types of PDF output files, the 
package can now render the same exercises into a wide variety of output 
formats. These include HTML (with various options for displaying 
mathematical content) and XML specifications for online exams in learning 
management systems such as Moodle or OLAT.


The package is available from http://CRAN.R-project.org/package=exams and 
the new features are described in detail in the new vignette("exams2", 
package = "exams"). A short intro is also available in a guest post to 
Tal Galili's blog at: 
http://www.r-statistics.com/2012/12/generation-of-e-learning-exams-in-r-for-moodle-olat-etc/


If you or someone else at your department wants to use this infrastructure
in practice and experiences any problems with it, just let us know (either
through e-mail or the support forum on R-Forge).

Best wishes,
Z

___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages

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