Re: [R] convert factor data to numeric

2010-01-13 Thread S Devriese
On 01/13/2010 05:41 PM, Peter Ehlers wrote:
> S Devriese wrote:
>> On 01/13/2010 10:47 AM, Ahmet Temiz wrote:
>>> hello
>>>
>>>  could you give me a hint to convert data in factor type to numeric
>>> (float) ?
>>>
>>>   regards
>>>
>>> -- 
>>> Open WebMail Project (http://openwebmail.org)
>>>
>>>
>> you could try as.numeric but without more details it is difficult to see
>> if this will work. How did you end up with a factor (e.g. through
>> import)?
>>
> No, don't use as.numeric(). Do follow Dimitris' advice.
> But the question of how you got the factor data is good; you
> can usually avoid getting factors to begin with.
> 
>  -Peter Ehlers
> 
>> Stephan
>>
>> __
>> 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.
>>
>>
> 

I know, slightly sloppy answer (see Dimitri's answer), but I hoped to
find out how he got the factor in the first place, because if it is an
import issue (and e,g. decimal character is different from the locale
decimal character) the FAQ answer might not work as expected.

Stephan

__
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] convert factor data to numeric

2010-01-13 Thread S Devriese
On 01/13/2010 10:47 AM, Ahmet Temiz wrote:
> hello
> 
>  could you give me a hint to convert data in factor type to numeric (float) ?
> 
>   regards
> 
> --
> Open WebMail Project (http://openwebmail.org)
> 
> 
you could try as.numeric but without more details it is difficult to see
if this will work. How did you end up with a factor (e.g. through import)?

Stephan

__
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] Placing eps files from R into Adobe InDesign documents: specifying fontfamily

2010-01-12 Thread S Devriese
On 01/12/2010 04:36 PM, dwalcerz wrote:
> 
> This is a solution I am posting for a problem that others may have.
> 
> If you want to:
> 1.  Place lattice graphics from R into an Adobe InDesign document, and
> 2.  Use the export as eps function in R to maximize resolution (it is much
> better than exporting as a metafile or bitmap), and
> 3.  Use long strings of text in your titles or captions or to label your
> axes.
> 
> Then you will have problems because:
> 1.  Adobe InDesign doesn't recognize R fontfamilies in eps files, and
> 2.  Adobe InDesing replaces the default R font, Helvetica, with a fontfamily
> that looks like Courier, which significantly changes the physical length of
> each character string and disrupts the spacing and justification of titles,
> captions, and axis labels.
> 
> The way I solved this problem is:
> 1.  When you execute a graph in R, use the Hershey family of fonts.  I
> particulary like HersheySans.  You can specify the fontfamily for axes and
> strips and titles as shown in the example below.
> 2.  Export the file in eps by right-clicking the on-screen display and
> selecting 'save as postscript'.
> 3.  Place the file in InDesign using the usual command (ctrl-D) and
> selecting the file.  You will still get the Adobe error about unrecognized
> fonts, but the automatic replacement that Adobe uses for the Hershey
> fontfamily is much better than the one they use for Helvetica, your spacing
> and justification will be almost perfect, and you get the excellent
> resolution and small size of vector-graphics.
> 
> In the following example the fontfamily is specified for strips, axes, and
> titles with these lines:
> par.strip.text=list(fontfamily="HersheySans") #for strips
> scales=list(alternating=1, tck=c(1,0), fontfamily="HersheySans") #for axes
> xlab=list("Combined Score", fontfamily="HersheySans") #for titles such as
> 'main', 'sub', 'xlab' and 'ylab'
> 
> Here is the example:
> bwplot(school.name~score|assessment+course_code, data=temp2.stack,
>   plot.points=FALSE, drop.unused.levels=TRUE,
>   panel=function(..., box.ratio, varwidth) {
>   panel.violin(..., col="cornsilk", varwidth=FALSE, 
> box.ratio=box.ratio)
>   panel.bwplot(..., box.ratio=0.1)
>   },
>   layout=c(2,3,1),
>   par.strip.text=list(fontfamily="HersheySans"),
>   scales=list(alternating=1, tck=c(1,0),
>   fontfamily="HersheySans",
>   x=list(relation="same", cex=0.7, rot=90),
>   y=list(relation="same", cex=0.7, rot=0)),
>   xlab=list("Combined Score", fontfamily="HersheySans"),
>   ylab=list("School(State)(students)", fontfamily="HersheySans")
> )
> 

You might also have a look at the embedFonts function of the grDevices
packages

Stephan

__
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] generate XML

2010-01-08 Thread S Devriese
On 01/07/2010 11:36 AM, robert-mcfad...@o2.pl wrote:
> 
> 
> 
> Dnia 7 stycznia 2010 11:30 S Devriese  napisał(a):
>> you might try
>>
>> # open file connection
>> sink("item1.xml")
>> # print object
>> my.matrix
>> # close file connection
>> sink()
> 
> Unfortunately, It does not code letter appropriate. To #print object it's 
> better to use write.table. But thank you for help.  
> 
> __
> 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.


Mhh, you could have a look at write.matrix in the MASS package, but I'm
afraid that you might have to specify the encoding explicitly (see
?connections, the section on encoding)

__
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] generate XML

2010-01-07 Thread S Devriese
On 01/07/2010 10:57 AM, robert-mcfad...@o2.pl wrote:
> Dnia 7 stycznia 2010 10:41 S Devriese  napisał(a):
>> Have you checked the XML package?
>>
>> If you print the matrix within R, this it look like you want (including
>> correct langauge encoding? Because in that case, you probably could use
>> sink (see ?sink).
>>
>> Stephan
> 
> Yes. In R I get correct view. How to use sink? I have the object: my.matrix
> and I want to create a file item1.xml How 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.

you might try

# open file connection
sink("item1.xml")
# print object
my.matrix
# close file connection
sink()

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


Re: [R] generate XML

2010-01-07 Thread S Devriese
On 01/07/2010 10:13 AM, Robert wrote:
> Finally, I managed to automatically generate rather simple XML code. In R 
> this is a matrix. The problem concerns how to write that matrix to file. I 
> use write.table and the extension of file .xml Everything works perfect 
> beside coding some language letters (Polish). But the problem disappears when 
> I change the extension to .txt Therefore I write a file with .txt extension 
> and after that I manually change the extension to .xml  - it does not solve 
> the problem. Is it possible to write my matrix or txt file to valid xml file? 
> I need to do it automatically.
> 
> Best,
> Robert  
> 
> __
> 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.

Have you checked the XML package?

If you print the matrix within R, this it look like you want (including
correct langauge encoding? Because in that case, you probably could use
sink (see ?sink).

Stephan

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


Re: [R] simple main effect.

2009-12-20 Thread S Devriese
On 12/20/2009 04:56 PM, Or Duek wrote:
> I don't have missing data.
> about what I need.
> Lets say the drug*strain interaction is significant - now I want to check
> for drug under the levels of strain - compare drug 1 and 2 only on strain 1
> and then only on strain 2.
> Or I'd like to compare the strains under levels of exposure.
> This is the kind of data I fail to see in summary() but it is important to
> understand the interactions.
> thank you.
> 

Do you main pairwise multiple comparison tests like Tukey Honest
Significant Difference tests? Then you could use TukeyHSD in the stats
package or see the DTK package (Dunnett-Tukey-Kramer Pairwise Multiple
Comparison Test Adjusted for Unequal Variances and Unequal Sample Sizes)

Stephan

__
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] Inserting .png plots in MS Word.

2009-12-19 Thread S Devriese
On 12/19/2009 09:06 PM, Wenjie Lee wrote:
> Thanks David and Duncan,
> 
> pdf()/eps() are good options. Can you please tell which function produces
> .wmf images.
> 
> I finally want to copy/insert these images into word file (.doc) and submit
> it to my adviser, and keep a possibility to re-size pictures.
> 
> Is it possible to add these .pdf / .eps images into word (instead of latex).

You can use gsview (and ghistscript, see
http://pages.cs.wisc.edu/~ghost/gsview/) for that. Open the pdf file in
gsview and copy paste to word.

Stephan

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


Re: [R] Creating Dummy Variables in R

2009-12-16 Thread S Devriese
On 12/16/2009 03:58 PM, whitaker m. (mw1006) wrote:
> Hi,
> I am trying to create a set of dummy variables to use within a multiple 
> linear regression and am unable to find the codes within the manuals.
> 
> For example i have:
> Price Weight Clarity
>  IF  VVS1VVS2
> 5008 1 0  0
> 1000  5.2  0 0  1
> 8643  01  0
> 3402.6  0 0  1
> 90  0.5  1 0  0 
> 4502.3  0 1  0
> 
> Where price is dependent upon weight (single value in each observation) and 
> clarity (split into three levels, IF, VVS1, VVS2).
> I am having trouble telling the program that clarity is a set of 3 dummy 
> variables and keep getting error messages, what is the correct way?
> 

Without an example of your code, it's a bit difficult. But it might be
easier to use one variable "clarity" with three possible values (IF,
VVS1, VVS2), defined as a factor.
lm(Price ~ Weight + Clarity) should then do the trick (unless you
explicitly want to use a different dummy coding than the default)

Stephan

__
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] R & very large files

2009-12-16 Thread S Devriese
On 12/16/2009 11:59 AM, Albert-Jan Roskam wrote:
> Hi,
>  
> I very recently started using R (as in: last week) and I was wondering if 
> anyone could point me to website(s) with sample code to deal with large 
> datasets (length- and/or breadthwise). I understood that R was never designed 
> to work with datasets larger than, say, a couple of hundred Mb. One way is 
> (as I also read) to let R work in conjunction with SQL. That's one 
> interesting approach I'd like to know more about. But I was also hoping that 
> there also were pure R solutions for working with very large tables (was 
> 'scan' designed for that?). In any case, a standard approach would be 
> desirable.
>  
> Thanks in advance.
> 
> Cheers!!
> Albert-Jan
> 
> ~~
> In the face of ambiguity, refuse the temptation to guess.
> ~~
> 

See for example the "Large memory and out-of-memory data" section of the
taskview "High-Performance and Parallel Computing with R"
(pick a mirror on http://cran.r-project.org/mirrors.html then "Task
Views" then "HighPerformanceComputing")

Stephan

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


Re: [R] Creating bibtex file of all installed packages?

2009-12-16 Thread S Devriese
On 12/16/2009 10:12 AM, Achim Zeileis wrote:
> On Wed, 16 Dec 2009, S Devriese wrote:
>
>> On 12/16/2009 08:32 AM, Achim Zeileis wrote:
>>> On Tue, 15 Dec 2009, Michael Friendly wrote:
>>>
>>>> Achim and others:
>>>>
>>>> Achim's solution could be directly usable if it also added a BibTeX
>>>> key,
>>>> perhaps just the name of the package to the '@Manual{,' initial line
>>>> of each. I wrapped the previous suggestions in a function, and played
>>>> around with the components, but can't quite see how to account for the
>>>> failed citation calls.  Can anyone take the next step?
>>>
>>> I had also thought about this after sending my previous solution, so
>>> here is an update Michael's version of the function (renamed to the
>>> name of the default file). Apart from some smaller touch-ups this has
>>> the following changes:
>>>
>>>   - Instead of taking the unique() bibs, I now use the unique() pkgs.
>>>
>>> (In principle, packages with the same name could be installed in
>>> different libraries, potentially containing different citations.
>>> But I thought it would be overkill to check for that.)
>>>
>>>   - Citation keys are simply "pkgname" if there is only a single
>>> BibTeX item, and "pkgname1" to "pkgnameN" if there are N BibTeX
>>> items.
>>>
>>> (This does not assure that citation keys are unique, though. If
>>> there is a package "foo" with 2 citation entries and another
>>> package
>>> "foo2" with only a single entry, these could be confused. A
>>> workaround
>>> would be to use "pkgname1" instead of "pkgname" as the citation key
>>> even if there is a single citation only. But I thought that would
>>> be less intuitive.)
>> Another possibility would be to use pkgname_versionnumber (e.g.
>> lattice1226). This would probably provide uniqueness and if used on
>> subsequent updates  of packages does not break older (latex) documents
>> where previous versions of packages were used.
>> Just a thought.
>
> No, it doesn't. As pointed out above, the function currently only
> calls citation() once for each package name (i.e., ignores multiple
> versions if any). The multiple entries do not stem from multiple
> versions of the package, but from multiple citations within a single
> package. See
>
>   citation("sandwich")
>
> for an example.
> Z
>
I'm sorry my thoughts were somewhat confusing in the mail. I did catch
that the current mechanism to avoid multiple entries solves the one
package-multiple citations problem and not a multiple package-one
citiation problem. I was just thinking of a way to alter the function
when used sequentially in time. I know that was not the original
poster's problem, but  it's one I and several of my colleagues have
encountered often (and until the function posted here, we used a more
manual way of solving the problem of getting the citations of all
installed (or loaded) packages :-). I know that simply using seperate
.bib files for each latex document partially solves the
sequential-in-time problem, but this is actually a different topic, so I
probably should start a different thread.

Stephan

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


Re: [R] Creating bibtex file of all installed packages?

2009-12-16 Thread S Devriese
On 12/16/2009 08:32 AM, Achim Zeileis wrote:
> On Tue, 15 Dec 2009, Michael Friendly wrote:
>
>> Achim and others:
>>
>> Achim's solution could be directly usable if it also added a BibTeX key,
>> perhaps just the name of the package to the '@Manual{,' initial line
>> of each. I wrapped the previous suggestions in a function, and played
>> around with the components, but can't quite see how to account for the
>> failed citation calls.  Can anyone take the next step?
>
> I had also thought about this after sending my previous solution, so
> here is an update Michael's version of the function (renamed to the
> name of the default file). Apart from some smaller touch-ups this has
> the following changes:
>
>   - Instead of taking the unique() bibs, I now use the unique() pkgs.
>
> (In principle, packages with the same name could be installed in
> different libraries, potentially containing different citations.
> But I thought it would be overkill to check for that.)
>
>   - Citation keys are simply "pkgname" if there is only a single
> BibTeX item, and "pkgname1" to "pkgnameN" if there are N BibTeX
> items.
>
> (This does not assure that citation keys are unique, though. If
> there is a package "foo" with 2 citation entries and another package
> "foo2" with only a single entry, these could be confused. A
> workaround
> would be to use "pkgname1" instead of "pkgname" as the citation key
> even if there is a single citation only. But I thought that would
> be less intuitive.)
Another possibility would be to use pkgname_versionnumber (e.g.
lattice1226). This would probably provide uniqueness and if used on
subsequent updates  of packages does not break older (latex) documents
where previous versions of packages were used.
Just a thought.

Stephan

__
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] lattice - 2 graphs per panel with 2 differents colours

2009-12-13 Thread S Devriese
On 12/11/2009 02:03 PM, PtitBleu wrote:
> Hello,
>
> I would like to get a lattice plot of 8 panels (unique(df$fact)=8) with 2
> graphs (df$y1 and df$y2 as a function of df$x) and 1 red point at (500,
> ymax) per panel.
>
> The script below is quite ok but I'm not able to define two different colors
> for the two graphs.
> If you have an idea how to use the "col" function in order to attribute the
> colors, it will be very kind of you to share it with a newbie.
>
> Have a nice week-end,
> Ptit Bleu.
>
>
> x11(15,12)
> xyplot(df$y1 + df$y1/df$coeff ~ df$x | df$fact,
> panel = function(x, y) {
> panel.grid(h=-1, v=-1, col="gray")
> panel.xyplot(x, y, type="p", pch=20)
> panel.points(500, ymax[panel.number()], col="red", pch=20,
> cex=1.6)
> },
>  xlab="X", ylab="Y")
>
>   
If you add '...' to your panel function, it will allow the panel
function to use the info you did not provide explicitly:

panel = function(x, y, ...) {
panel.grid(h=-1, v=-1, col="gray")
panel.xyplot(x, y, type="p", pch=20, ...)
panel.points(500, ymax[panel.number()], col="red", pch=20,
cex=1.6)
},

I tested with:
library(lattice)
tmp <- data.frame(y1=11:20,coeff=1:10,x1=21:30)
xyplot(y1 + y1/coeff ~ x1, data=tmp,
   panel=function(x,y,...) {
 panel.xyplot(x, y, type="p", pch=20, ...)
   }

)

Stephan

__
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 scale a histogram

2009-12-10 Thread S Devriese
On 12/10/2009 04:01 PM, terry johnson wrote:
> If I want to scale a histogram ie multiply by a constant how would I do
> this? Thanks
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>   
Without further details I would guess:
suppose
tmp <- runif(100,0,100)
hist(tmp)

then hist(tmp*.01) will rescale the range from 0 to 100 to 0 to 1

Stephan

__
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] Grouped Barplot

2009-11-25 Thread S Devriese
On 11/25/2009 07:48 PM, Gary wrote:
> Hi R Users,
>
> I tried plotting a similar boxplot as it is on the FOLLOWING LINK:
>
> http://www.imachordata.com/wp-content/uploads/2009/09/boxplot.png
>
> Sample data is attached -- there are 9 years and 5 cities. In my case I'm
> looking to plot "Year" on x-axis and grouping boxplots by "City". I tried
> the following code.
>
> foo<-read.table("SampleData.csv", sep=",", header=TRUE)
> attach(foo)
> boxplot(Admit ~ City + Year, range=0.5, col=2:6) # its not solving the
> purpose
>
> I need some help with:
> 1) Plotting only 9 labels on x-axis (1996-2004).
> 2) For each "Year", I need to plot FIVE boxplots -- one for each "City". [so
> it will look like nine clusters with five boxplots each (with no gap between
> them, but with gaps between year labels].
> 3) Adding "MEAN" to the boxplots.
> 4) And, legend including "color" + "city name".
>
> Any help would be greatly appreciated!
>
> ~Gary
>   
>
>
> __
> 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.
>   
Have a look at
https://stat.ethz.ch/pipermail/r-help/2000-November/009191.html. Might
be what you're looking for.

[[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] order of panels in xyplots

2009-11-25 Thread S Devriese
On 11/25/2009 07:33 PM, Titus Malsburg wrote:
> On Wed, Nov 25, 2009 at 7:03 PM, Titus Malsburg  wrote:
>   
>>  I was expecting
>> that this should plot the panels in the order in which the levels
>> occur in the data frame:
>>
>>  xyplot(dur~roi|trial, data, index.cond=unique(as.integer(data$trial)))
>> 
> The answer is apparently:
>
>   xyplot(dur~roi|trial, data, index.cond=rank(unique(data$trial)))
>
> (Strange phenomenon, that I very often find the solution myself
> minutes after posting to the mailing list.)
>
> Best,
>Titus
>
> __
> 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.
>   
An alternative could be to reorder the levels of "trial" prior to
calling xyplot or in the xyplot call itself (useful if you want to order
the levels on some other criterion like the mean or median of another
variable). See ?reorder

Just a thought

S

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