Displaying 20 results from an estimated 10000 matches similar to: "modify particular factor levels"
2008 May 01
1
Locale problem with umlauts in factor levels in 2.7.0 (patched) from grid or lattice
With 2.7.0 patched (not tested with 2.0.0), I get an error message in a
program that ran correctly in R 2.6.2 when the grouping factor of a
stripplot contains an Umlaut:
I am aware that there are a few locale-changes in R 2.7.0, but I could not
easily
locate who's at fault
Dieter
library(lattice)
dt = data.frame(x=rnorm(100),y=1:100,levs= as.factor(c("Gru","Gr?")))
2008 Aug 09
2
levels values of cut()
Dear list,
I have the following example, from which I am hoping to retrieve
numeric values of the factor levels (that is, without the brackets):
>
> x <- seq(1, 15, length=100)
> y <- sin(x)
>
> my.cuts <- cut(which(abs(y) < 1e-1), 3)
> levels(my.cuts)
hist() does not suit me for this, as it does not necessarily respect
the number of breaks.
getAnywhere
2009 Nov 10
3
drop unused levels in subset.data.frame
Dear list,
subset has a 'drop' argument that I had often mistaken for the one in
[.factor which removes unused levels.
Clearly it doesn't work that way, as shown below,
d <- data.frame(x = factor(letters[1:15]), y = factor(LETTERS[1:3]))
s <- subset(d, y=="A", drop=TRUE)
str(s)
'data.frame': 5 obs. of 2 variables:
$ x: Factor w/ 15 levels
2009 Jan 09
2
recursive relevel
Dear list,
I'm having second thoughts after solving a very trivial problem: I
want to extend the relevel() function to reorder an arbitrary number
of levels of a factor in one go. I could not find a trivial way of
using the code obtained by getS3method("relevel","factor"). Instead, I
thought of solving the problem in a recursive manner (possibly after
reading
2009 Sep 30
5
Condition to factor (easy to remember)
Dear List,
creating factors in a given non-default orders is notoriously difficult to
explain in a course. Students love the ifelse construct given below most,
but I remember some comment from Martin M?chler (?) that ifelse should be
banned from courses.
Any better idea? Not necessarily short, easy to remember is important.
Dieter
data = c(1,7,10,50,70)
levs =
2011 Mar 09
2
switch and factors
Dear list,
Reading the help page for ?switch didn't give me more than a hint at
what's going on here,
x = 5
y = 2
foo <- function(a="x"){
switch(a, "x" = x,
"y" = y)
}
foo(factor('x', levels=c('y', 'x')))
# 2
It seems that switch, when given a factor, uses the numeric codes
rather than the string
2009 Oct 01
1
inverse currying
Dear list,
I have the following function,
sugar = function(fun, id = "id"){
ff <- formals(fun)
if( id %in% names(ff))
stop("id is part of args(fun)")
formals(fun) <- c(unlist(ff), alist(id=))
fun
}
which one may use on a function foo,
foo = function(x){
x
}
sugar(foo) # results in the extended closure,
function (x, id)
{
x
}
Its limitation (other
2010 Aug 21
1
R-level expansion of Rplot%03d.png
Dear list,
I'm using the brew package to generate a report containing various
plots. I wrote a function that creates a plot in png and pdf formats,
and outputs a suitable text string to insert the file in the final
document using the asciidoc syntax,
<%
tmp <- 1
makePlot = function(p, name=paste("tmp",tmp,sep=""), width=300)
{
2018 Mar 24
1
Function 'factor' issues
I am trying once again.
By just changing
f <- match(xlevs[f], nlevs)
to
f <- match(xlevs, nlevs)[f]
, function 'factor' in R devel could be made more consistent and back-compatible. Why not picking it?
--------------------------------------------
On Sat, 25/11/17, Suharto Anggono Suharto Anggono <suharto_anggono at yahoo.com> wrote:
Subject: Re: [Rd] Function
2017 Oct 15
2
Function 'factor' issues
In R devel, function 'factor' has been changed, allowing and merging duplicated 'labels'.
Issue 1: Handling of specified 'labels' without duplicates is slower than before.
Example:
x <- rep(1:26, 40000)
system.time(factor(x, levels=1:26, labels=letters))
Function 'factor' is already rather slow because of conversion to character. Please don't add slowdown.
2010 Sep 09
1
scalable < > delimiters in plotmath
Dear list,
I read in ?plotmath that I can use bgroup to draw scalable delimiters
such as [ ] and ( ). The same technique fails with < > however, and I
cannot find a workaround,
grid.text(expression(bgroup("<",atop(x,y),">")))
Error in bgroup("<", atop(x, y), ">") : invalid group delimiter
Regards,
baptiste
sessionInfo()
R version
2010 Sep 09
1
scalable < > delimiters in plotmath
Dear list,
I read in ?plotmath that I can use bgroup to draw scalable delimiters
such as [ ] and ( ). The same technique fails with < > however, and I
cannot find a workaround,
grid.text(expression(bgroup("<",atop(x,y),">")))
Error in bgroup("<", atop(x, y), ">") : invalid group delimiter
Regards,
baptiste
sessionInfo()
R version
2004 Oct 04
2
AW: constructing specially ordered factor
Hi Dimitris,
thank you for your reply,
> does the following work in your data:
>
> levs <- unique.default(Names)
> factor(Names, levs[order(unique.default(Weights))])
your solution is really shorter, but has two issues to be
meant here:
1. "unique.default" is applied twice, what might
be a bit expensive for strings.
2. your solution brings an implicit
2009 Sep 28
2
dichromat, regexp, and grid objects
Dear list,
The dichromat package defines a dichromat function which "Collapses
red-green color distinctions to approximate the effect of the two
common forms of red-green colour blindness, protanopia and
deuteranopia."
library(dichromat)
library(grid)
colorStrip <-
function (colors = 1:3, draw = TRUE)
{
x <- seq(0, 1 - 1/length(colors), length = length(colors))
y <-
2010 Mar 10
4
write.fortran
Dear all,
I'm trying to write tabular data to a text file, these data will be
the input of a Fortran program. The format needs to be
"(i7,2x,7(e15.7,2x))". I have not been able to find a clean way of
producing this output with write.table. I searched for a
"write.fortran" function similar to read.fortran() in package utils
but I couldn't find any. Below is a small
2010 Aug 27
2
export 4D data as povray density files
Dear list,
I wish to visualise some 4D data as a kind of colour / translucent
cloud in 3D. I haven't seen such plots in R (but perhaps I missed a
feature of rgl). The easiest option I found would be to export the
data in povray's df3 (density file) format and visualise it with
povray.
The format specification baffles me a little,
http://www.povray.org/documentation/view/3.6.1/374/ ;
2009 Apr 03
3
plyr and table question
Dear all,
I'm puzzled by the following example inspired by a recent question on
R-help,
cc <- textConnection("user_id website time
20 google 0930
21 yahoo 0935
20 facebook 1000
25 facebook 1015
61 google 0940")
d <- read.table(cc, head=T) ; close(cc)
table(d$user_id) # count the
2010 May 18
1
lattice::panel.levelplot.raster too picky with unequal spacing
Dear all,
I got a couple of warnings using panel.levelplot.raster,
In panel.levelplot.raster(..., interpolate = TRUE) :
'y' values are not equispaced; output will be wrong
although I was quite sure my data were equally spaced (indeed, I
created them with seq()). A closer look at the source code reveals
that the function tests for exact uniformity in grid spacing,
if
2010 Sep 21
3
bivariate vector numerical integration with infinite range
Dear list,
I'm seeking some advice regarding a particular numerical integration I
wish to perform.
The integrand f takes two real arguments x and y and returns a vector
of constant length N. The range of integration is [0, infty) for x and
[a,b] (finite) for y. Since the integrand has values in R^N I did not
find a built-in function to perform numerical quadrature, so I wrote
my own after
2009 Mar 25
2
"[.data.frame" and lapply
Dear all,
Trying to extract a few rows for each element of a list of
data.frames, I'm puzzled by the following behaviour,
> d <- lapply(1:4, function(i) data.frame(x=rnorm(5), y=rnorm(5)))
> str(d)
>
> lapply(d, "[", i= c(1)) # fine, this extracts the first columns
> lapply(d, "[", j= c(1, 3)) # doesn't do nothing ?!
>
> library(plyr)