Try this and see the help desk article in R News 4/1:
x - 20080620.00
x2 - 20090218.00
num2Date - function(x) as.Date(paste(x), %Y%m%d)
num2Date(x2) - num2Date(x)
Time difference of 243 days
as.numeric(num2Date(x2) - num2Date(x))
[1] 243
On 6/20/07, [EMAIL PROTECTED]
[EMAIL PROTECTED]
xx is 1 in every position of the first run of TRUE, 2 in every
position in the 2nd run of TRUE and so on. The parenthesized
expression in the second line converts those to increasing
values and multiplying it by x zaps the garbage in the positions
that correspond to FALSE in x.
xx -
1.72
identical(out1, out2)
[1] TRUE
identical(out1, out3)
[1] TRUE
On 6/19/07, Gabor Grothendieck [EMAIL PROTECTED] wrote:
xx is 1 in every position of the first run of TRUE, 2 in every
position in the 2nd run of TRUE and so on. The parenthesized
expression in the second line converts those
Here it is with a few improvements:
- use as.is=TRUE on read.table to get character columns rather than factor
- use xaxt = FALSE rather than axes = FALSE to eliminate axis(2)
- use h$mids where h is the output of hist to avoid lots of tedious calcs
- eliminate all that attaching and detaching
-
This loads all the functions into an anonymous environment defined
by local and then exports f to the global environment.
f - local({
source(/a.R, local = TRUE)
environment(f) - .GlobalEnv
f
})
On 6/18/07, Weiwei Shi [EMAIL PROTECTED] wrote:
Dear Listers:
For example,
deleted
on the next garbage collection automatically.
On 6/18/07, Ted Harding [EMAIL PROTECTED] wrote:
On 18-Jun-07 14:28:35, Gabor Grothendieck wrote:
This loads all the functions into an anonymous environment defined
by local and then exports f to the global environment.
f - local
Try this:
paste(read.fwf(textConnection(foo), bar, as.is = TRUE), collapse = ,)
[1] have,a,nice,day
On 6/18/07, Christopher Marcum [EMAIL PROTECTED] wrote:
Hello All,
I've been using R for two years now and I am happy to say this is the
first time I could not find the answer to my problem
Try aggregate:
aggregate(table[2:3], table[1], mean)
On 6/17/07, Andrew Yee [EMAIL PROTECTED] wrote:
I have the following data.frame:
index - c(a,a,b,b,b)
alpha - c(1,2,3,4,5)
beta - c(2,3,4,5,6)
table -data.frame(index,alpha,beta)
I'm now interested in getting means of alpha and beta
A couple of easy ways are to create the calling sequence as a call or
character string and then evaluate it:
eval(bquote(lm(.(as.name(Ytext)) ~ Xvar, X)))
eval(parse(text = paste(lm(, Ytext, ~ Xvar, X
Note that these solutions both have the advantage over some of the prior
solutions that
Check out the engauge digitizer:
http://digitizer.sourceforge.net/
On 6/15/07, Ted Harding [EMAIL PROTECTED] wrote:
Hi Folks,
This is off-topic R-wise, but it may be close to
the heart of many R-users, so I think it may be
the best place to ask!
Users of 'gv' (the front end to
See:
https://stat.ethz.ch/pipermail/r-help/2007-April/130912.html
On 6/14/07, Andrew J Tyre [EMAIL PROTECTED] wrote:
I have a comma delimited text file in which many columns of numbers are
also quoted and have commas as well as decimals. I was surprised to find
read.csv() didn't import this
See ?quantcut in the gtools package.
On 6/11/07, Jiong Zhang, PhD [EMAIL PROTECTED] wrote:
Hi all,
I have a rather naive question. I have the height of 100 individuals in
a table and I want to assign the tallest 30% as Case=1 and the bottom
30% as Case=0. How do I do that?
thanks.
jiong
Try this. It takes a Date class date and in the first line month.day.year
converts unclass(x) to chron. In the last line of the function we convert
back to Date class. Its already vectorized so sapply is unneeded:
library(chron)
f - function(x) with(month.day.year(unclass(x)), {
month -
There are some online sources that you might find useful. You could
get started on those while you decide what books to get:
- CRAN contributed documentation
http://cran.r-project.org/other-docs.html
- S Poetry
http://www.burns-stat.com/pages/spoetry.html
- Zoonekynd book
When you reply in gmail be sure you are using Plain Text
and not Rich Formatting. If you press Reply or Reply All and
you see immediately above the text entry area
B I U ... Plain Text
then you are in Rich Text mode. Click on Plain Text at the right
of the line just above the text entry area
Its now at:
http://www.sciviews.org/_rgui/tcltk
On 6/13/07, Peter Ruckdeschel [EMAIL PROTECTED] wrote:
Hi,
as a starting point for using Tcl/Tk in R, I used to refer
to James Wettenhall's nicely presented TclTk Examples
formerly hosted at
How about this:
data.frame2 - function(...) {
L - list(...)
as.data.frame(L[!sapply(L, is.null)])
}
# test 1
include - FALSE
data.frame2(a = 1:3, junk = if (include) z, b = 3:1)
# test 2
z - letters[1:3]
include - TRUE
data.frame2(a = 1:3, junk = if (include) z, b = 3:1)
On
- readLines(myfile.ini)
Lines - readLines(textConnection(Lines.raw))
do.call(rbind, lapply(strsplit(Lines, =), f))
On 6/12/07, Gabor Grothendieck [EMAIL PROTECTED] wrote:
Here is yet another simplification. This one uses na.locf from the zoo
package to shorten it further and also make it easier
Here is some code. It replaces [ and ] with = sign and reads the result
into a data frame, DF. DF2 is similar except the section is now in V3.
DF3 is like like DF2 except sections are carried forward and finally
we remove the rows which only had sections.
Lines.raw - [Section1]
var1=value1
Generating Excel or reports seems to be two different questions:
1. Reports. You can use xtable together with Sweave. See figure 1 in this
link for an example:
http://www.ci.tuwien.ac.at/~leisch/Sweave/Sweave-Rnews-2002-3.pdf
2. Regarding writing Excel files this can be done on Windows using
==
subset(transform(DF, V3 = V2[which(L)[cumsum(L)]])[1:3], V1 != )
On 6/12/07, Gabor Grothendieck [EMAIL PROTECTED] wrote:
Here is some code. It replaces [ and ] with = sign and reads the result
into a data frame, DF. DF2 is similar except the section is now in V3.
DF3 is like like DF2 except
(transform(DF, V3 = na.locf(ifelse(V1 == , V2, NA))), V1 != )
On 6/12/07, Gabor Grothendieck [EMAIL PROTECTED] wrote:
In thinking about this a bit more here is an even shorter solution where
Lines.raw is as before:
# Lines - readLines(myfile.ini)
Lines - readLines(textConnection(Lines.raw
Try
match(0.4, a)
Also see ?match and the nomatch= argument, in particular. If your
numbers are only equal to within an absolute tolerance, tol, as
discussed in the R FAQ
http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f
you may need:
tol -
In gmail just hit Reply to All at the bottom of the post you wish to
follow up on.
On 6/8/07, Robert Wilkins [EMAIL PROTECTED] wrote:
That may sound like a stupid question, but if it confuses me, I'm sure
it confuses others as well. I've tried to find that information on the
R mail-group info
Try this:
write.ilog - function(X, file = ) {
w - function(x, z, file)
cat([, paste(x, collapse = ,), ], z, sep = , file = file)
if (!identical(file, )) {
file - open(file, w)
on.exit(close(file))
}
cat(X=[, file = file)
nr - nrow(X)
for(i in 1:nr)
That can be elegantly handled in R through R's object oriented programming
by defining a class for the fancy input. See this post:
https://stat.ethz.ch/pipermail/r-help/2007-April/130912.html
for a simple example of that style.
On 6/9/07, Robert Wilkins [EMAIL PROTECTED] wrote:
Here are
.
If I understand this correctly the sort.POSIXlt with
na.last = FALSE is dropping all the NAs. Very nice.
--- Gabor Grothendieck [EMAIL PROTECTED]
wrote:
Perhaps you want one of these:
sort(as.Date(aa$times, %d/%m/%Y))
[1] 1995-03-02 2001-05-12 2007-02-14
sort(as.Date(aa$times, %d
R isn't in your path. Either change your path to include it or place
Rcmd.bat from batchfiles anywhere in your existing path:
http://code.google.com/p/batchfiles/
and then:
Rcmd BATCH ...whatever...
On 6/8/07, Sébastien Bihorel [EMAIL PROTECTED] wrote:
Hi,
I am a complete newbe to
I am not entirely happy with this solution but it does seem to work.
In pg we pick groups out of its parent.frame and we place the
entire body of graph2 in eval.parent(substitute(...))
pg - function(x, y, subscripts, ..., group.number) {
panel.xyplot(x, y, ...)
panel.text(2,
This works on my Windows machine starting off at a new R session:
options(graphics.record = TRUE)
library(lattice)
xyplot(uptake ~ conc | Plant, CO2, layout = c(2,2))
Now switch focus to the graphics window and you can PgUp and PgDn
through them.
There are several variations to this:
1. use
Perhaps you want one of these:
sort(as.Date(aa$times, %d/%m/%Y))
[1] 1995-03-02 2001-05-12 2007-02-14
sort(as.Date(aa$times, %d/%m/%Y), na.last = TRUE)
[1] 1995-03-02 2001-05-12 2007-02-14 NA NA
[6] NA
On 6/7/07, John Kane [EMAIL PROTECTED] wrote:
I am trying to clean up some
A variation of Brian's idea of using resample in ?sample would be:
set.seed(1) # makes sample reproducible
aggregate(DF[1], DF[2], resample, size = 1)
Using resample ensures that the solution works even if some
of the Plots only have one Tree. Some of the solutions
that were presented in
Try this:
tryCatch(file.choose(), error = function(e) )
On 6/6/07, Ben Tupper [EMAIL PROTECTED] wrote:
Hello,
I have a file reading function that prompts the user with a file dialog
if a filename is not provided in the argument list. It is desirable to
return gracefully if the user
Don't think you can do that but you could respecify your function
so that the assigned variable must appear as the first argument:
foo - function(y, arg) {
y - substitute(y)
if (is.name(y)) assign(deparse(y), arg+1, parent.frame())
else cat(not assigned\n)
Try this:
library(lattice)
x - 1:10
i - 3
xlab - as.expression(substitute(beta[i] * x[i] + epsilon, list(i = i)))
xyplot(x ~ x, xlab = xlab)
On 6/6/07, Nitin Jain [EMAIL PROTECTED] wrote:
Dear R-users,
In the following example, I would like to see my ylabel as: beta[3] * x[3] +
epsilon
Note that chron does give the last day of the month:
library(chron)
seq(chron(1/31/2000), chron(1/31/2001), month)
[1] 01/31/00 02/29/00 03/31/00 04/30/00 05/31/00 06/30/00 07/31/00 08/31/00
[9] 09/30/00 10/31/00 11/30/00 12/31/00 01/31/01
The zoo package has a yearmon class whose
Try:
closeAllConnections()
On 6/4/07, elyakhlifi mustapha [EMAIL PROTECTED] wrote:
hello,
I wanna close the textConnection but I don't know how to do it can you help
me please?
thanks
_
Seems you want to diff X, not lag it.
We can either maintain the long form of the data and do it as in #1
or convert the data to wide form and do it as in #2 which is most
convenient using zoo where we make the individual time series into
zoo series, merge them and then apply diff:
Lines - ID
Check out ?sunflowerplot
On 6/2/07, mister_bluesman [EMAIL PROTECTED] wrote:
Hi there.
I have the following graph:
http://www.nabble.com/file/p10928148/map.jpg
However, some datapoints occur at the same place as other datapoints and are
so layered on top of each other. I would like to
Your frequency is 1. Suppose it were 3 :
(fit - StructTS(ts(x, freq = 3),type = BSM))
Call:
StructTS(x = ts(x, freq = 3), type = BSM)
Variances:
levelslope seas epsilon
3.0225 0. 0.1617 18.0978
On 6/2/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
Hi everybody,
I'am
See ?biplot.princomp
On 6/2/07, Soare Marcian-Alin [EMAIL PROTECTED] wrote:
hello,
Does nobody know what the problem could be? :
2007/5/26, Soare Marcian-Alin [EMAIL PROTECTED]:
Hello,
I have a problem with the function concar:
data set:
I think nearly this same question was just asked by someone within
the last few days:
Anyways, this multiplies gd by 10 and then places it back into the
original columns:
z[, -out] - 10*gd
On 6/1/07, antonio rodriguez [EMAIL PROTECTED] wrote:
Hi,
I have this dataset where columns z1.3 and
On 6/1/07, Alfonso Sammassimo [EMAIL PROTECTED] wrote:
Hi R-experts,
Thanks very much to Jim Holtman and Gabor on my previous question.
I am having another problem with data manipulation in zoo. The following is
data (Z) for first business day of every month in zoo format. I am trying to
library(chron)
dt1 - chron(1/1/2002, 00:00:00)
dt2 - chron(1/2/2002, 00:00:00)
chron(seq(as.numeric(dt1), as.numeric(dt2), by = 1/24))
Also (but see caveat in R News 4/1 help desk article):
dt1 - as.POSIXct(2002-01-01 00:00:00)
dt2 - as.POSIXct(2002-01-02 00:00:00)
seq(dt1, dt2, by = hour)
On
See:
http://tolstoy.newcastle.edu.au/R/e2/help/06/10/2242.html
which we can modify slightly for the case in question like this:
f - function(...) {
x - list(...)
if (is.null(names(x))) names(x) -
names(x)[names(x) == ] - NA
mc - match.call()[-1]
On 6/1/07, Mike Meredith [EMAIL PROTECTED] wrote:
Thanks very much to all of you. It looks like 'match.call' is the key, and
both Brian's and Gabor's solutions work fine. --- Mike.
Brian's is shorter but I think the one in my post is a bit more robust:
f1 - function(...) {
+m -
research assistant
dept. of fisheries and oceans
[EMAIL PROTECTED]
-Original Message-
From: Gabor Grothendieck [mailto:[EMAIL PROTECTED]
Sent: Tuesday, May 29, 2007 10:51 PM
To: Charles C. Berry
Cc: Tobin, Jared; r-help@stat.math.ethz.ch
Subject: Re: [R] Partially reading a file
Try this:
# ith arg is expanded if expand[[i]] is TRUE where expand is
# extended to vector of same length as ... .
# default is to expand all args if 1st arg is character
example2 - function(..., expand = is.character(..1)) {
L - list(...)
expand - rep(expand, length =
Regarding your other questions:
plot(z[,3:5]) # only plot columns 3 to 5
# only plot between indicated times
st - chron(01/01/03, 02:00:00)
en - chron(03/26/2003, 07:00:00)
zz - window(z, start = st, end = en)
plot(zz)
On 5/31/07, Gabor Grothendieck [EMAIL PROTECTED] wrote:
There seems
There seems to be an error in your names(DF) - line so I just renamed the
first 4 fields. Try this:
# Should be 3 lines in Lines.
Lines - MM DD HHP-ukP-kor P-SME EPOTEREA RO
R1 R2 RGES S-SNO SISSM SUZSLZ
2003 1 1 10.385 0.456
There is a venn package at these links:
http://fisher.stats.uwo.ca/faculty/murdoch/repos/html/vennv1.5.html
http://www.jstatsoft.org/v11/c01/
On 5/31/07, Earl F. Glynn [EMAIL PROTECTED] wrote:
I'm not sure where you're getting the venn package. I don't find venn in
either of these places:
-
One other point. If you find you need to set a system or user environment
variable then microsoft has a free tool called setx.exe that you can find here:
http://support.microsoft.com/kb/927229
You can do this from within R using system().
On 5/30/07, Gabor Grothendieck [EMAIL PROTECTED] wrote
You can do this from within R using system().
On 5/30/07, Gabor Grothendieck [EMAIL PROTECTED] wrote:
On 5/29/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
OK, I think I get that... do you know which namespace the Sys.setenv()
function affects? Do you know if there are functions in R
You could consider doing this directly with lattice. See:
demo(intervals)
On 5/30/07, Nitin Jain [EMAIL PROTECTED] wrote:
Hello,
I would like to get the scales of y-axes dependent only on the data points in
a particular panel. Have attached a test example below.
When using
Not sure I understand what you want but the clockwise= argument
of pie determines whether the slice is drawn clockwise or counter
clockwise.
On 5/29/07, Adrian Dusa [EMAIL PROTECTED] wrote:
Dear all,
I'd like to produce a simple pie chart for a customer (I know it's bad but
they insist), and
On 5/29/07, Charles C. Berry [EMAIL PROTECTED] wrote:
On Tue, 29 May 2007, Tobin, Jared wrote:
Hello,
I am trying to figure out if there exists some R command that allows one
to be
particularly selective when reading a file. I'm dealing with large
fixed-width data
sets that look
Note that Windows XP has 4 types of environment variables and I suspect
that the problem stems from not taking that into account:
http://www.microsoft.com/technet/scriptcenter/guide/sas_wsh_kmmj.mspx?mfr=true
On 5/29/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
Hi,
I am trying to use R at
would also have no effect -- yet it does.
Any ideas?
Thanks again,
Matt
-Original Message-
From: Gabor Grothendieck [mailto:[EMAIL PROTECTED]
Sent: Tue 5/29/2007 9:49 PM
To: Pettis, Matthew (Thomson)
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] http proxies: setting and unsetting
On 5/29/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
OK, I think I get that... do you know which namespace the Sys.setenv()
function affects? Do you know if there are functions in R that can alter the
user/system/process environment variables?
Use the R Sys.getenv() command to get the
), 6))
u-t(u)
dim(u)
[1] 720 6
u[,2:3] - NA
u[1, 2] - 3
u[2, 1] - NA
idx - colSums(!!u, na.rm = TRUE) 1
u[,idx] - na.approx(u[,idx])
dim(u)
[1] 720 6
Don't know what could be happening to my original data.
Best regards
Antonio
Gabor Grothendieck escribió:
na.approx uses
Here are a couple of solutions:
1. using zoo package
First add Date to the header so there
are the same number of column headers as columns and
then read in using read.zoo. Then aggregate over years
using mean. For more on zoo try library(zoo); vignette(zoo)
and for more on dates see the R
Without any code in your post (see last line of every post to r-help)
its impossible to really know what you are doing but here is an
example:
library(RODBC)
channel - odbcConnect(db01) # existing data base
# add a table with a datetime field
sqlQuery(channel, create table table02 (field01
Here are three ways. The first uses a common
error term and the others separate. They all
give the same coefficient estimates.
Lines - Month ExcessReturn Return STO
8 0.047595875 0.05274292 0.854352503
8 0.016134874 0.049226941 4.399372005
8 -0.000443869 0.004357305 -1.04980297
9
Use the zoo package to represent data like this.
Here time(z) is a vector of the dates and as.yearmon(time(z))
is the year/month of each date. With FUN=head1, ave picks out the first
date in any month and aggregate then aggregates over all
values in the same year/month choosing the first one.
One additional simplification. If we use simplify = FALSE then
tapply won't simplify its answer to numeric and we can
avoid using as.Date in the last solution:
window(z, tapply(time(z), as.yearmon(time(z)), head, 1, simplify = FALSE))
On 5/27/07, Gabor Grothendieck [EMAIL PROTECTED] wrote
to convert it back again. Then
we use window to select those dates.
window(z, as.Date(tapply(time(z), as.yearmon(time(z)), head, 1)))
On 5/27/07, Gabor Grothendieck [EMAIL PROTECTED] wrote:
Use the zoo package to represent data like this.
Here time(z) is a vector of the dates and as.yearmon(time(z
na.approx uses approx and has the same behavior as it. Try this:
library(zoo)
# test data
z - zoo(matrix(1:24, 6))
z[,2:3] - NA
z[1, 2] - 3
z[2, 1] - NA
z
1 1 3 NA 19
2 NA NA NA 20
3 3 NA NA 21
4 4 NA NA 22
5 5 NA NA 23
6 6 NA NA 24
# TRUE for each column that has more than 1
First define a function which is like list() except it ignores all
NULL components. Using that we can write:
list.wo.null - function(...) list(...)[!sapply(list(...), is.null)]
library(lattice)
myhist - function(limits) do.call(histogram, list.wo.null(~ height, singer,
endpoints = if
On 5/27/07, Robert A. LaBudde [EMAIL PROTECTED] wrote:
As I was working through elementary examples, I was using dataset
plasma of package HSAUR.
In performing a logistic regression of the data, and making the
diagnostic plots (R-2.5.0)
data(plasma,package='HSAUR')
plasma_1- glm(ESR ~
On 5/27/07, ronggui [EMAIL PROTECTED] wrote:
Hi,Gabor Grothendieck, Thanks very much.
On 5/27/07, Gabor Grothendieck [EMAIL PROTECTED] wrote:
evalq looks like this:
evalq
function (expr, envir, enclos)
eval.parent(substitute(eval(quote(expr), envir, enclos
evalq looks like this:
evalq
function (expr, envir, enclos)
eval.parent(substitute(eval(quote(expr), envir, enclos)))
environment: namespace:base
so it seems the difference is that
- eval(quote(), envir, enclos) evaluates envir and enclos
in the current frame but
- evalq
Try
?path.expand
On 5/25/07, McGehee, Robert [EMAIL PROTECTED] wrote:
R-Help,
I discovered a mis-feature is ghostscript, which is used by the bitmap
function. It seems that specifying file names in the form ~/abc.png
rather than /home/directory/abc.png causes my GS to crash when I open
the
xlim= can take a list:
# CO2 is built into R
library(lattice)
xlim - rep(list(c(0, 1000), c(0, 2000)), each = 2)
xyplot(uptake ~ conc | Type * Treatment, data = CO2,
scales = list(relation = free), xlim = xlim)
On 5/25/07, Marta Rufino [EMAIL PROTECTED] wrote:
Dear list members,
I
The form of your data is termed wide and you want to reshape it to
long form and use aov with that. This uses the reshape command
to produce the long form. Alternately you could use cast and melt
in the reshape package to do that:
# read data
Lines - subjtherapy t0 t1 t2
1 a
We could do it using either POSIXct or chron:
library(zoo)
# POSIXct
z - zoo(precipitation, as.POSIXct(time, tz = GMT))
aggregate(z, function(x) as.POSIXct(trunc(x, hour)), sum)
# chron
library(chron)
z - zoo(precipitation, as.chron(as.POSIXct(time, tz = GMT))
aggregate(z, function(x)
There was a missing ) on this one. Here it is again:
library(chron)
z - zoo(precipitation, as.chron(as.POSIXct(time, tz = GMT)))
aggregate(z, function(x) chron(trunc(times(x), 01:00:00)), sum)
On 5/24/07, Gabor Grothendieck [EMAIL PROTECTED] wrote:
We could do it using either POSIXct or chron
Use ave. Assuming DF is your 2 column data frame:
ave(DF[,1], DF[,2], FUN = mean)
On 5/22/07, Benoit Chemineau [EMAIL PROTECTED] wrote:
Hello,
I have a basic problem but i can't figure it out with the
table underneath. I would like to compute monthly averages.
I would like to have the
You could use the class dispatching mechanism:
mymodel - function(a, b, method = S) {
.Class - method
NextMethod(mymodel)
}
mymodel.S - function(a, b, method = S) cat(S:, a, b, method, \n)
mymodel.HK - function(a, b, method = S) cat(HK:, a, b, method, \n)
mymodel(1:3, 1:4)
:) ):
model.formula-switch(model.type,S=[s-model formula],HK=[hk-model formula])
model-lm(model.formula)
Gabor Grothendieck wrote:
You could use the class dispatching mechanism:
mymodel - function(a, b, method = S) {
.Class - method
NextMethod(mymodel)
}
mymodel.S
I have not checked your code but that error can stem from an incorrect
gradient.
On 5/19/07, ronggui [EMAIL PROTECTED] wrote:
I try to code the ULS factor analysis descrbied in
ftp://ftp.spss.com/pub/spss/statistics/spss/algorithms/ factor.pdf
# see PP5-6
factanal.fit.uls - function(cmat,
Try this:
with(subset(data, x 0), summary(y + z))
On 5/18/07, Vadim Ogranovich [EMAIL PROTECTED] wrote:
Hi,
When using evalq to evaluate expressions within a say data.frame context I
often wish there was a 'subset' argument, much like in lm() or any ather
advanced regression model. I
Try this. f assigns 1, 2 and 3 to the highest, second highest and third highest
within a category. ave applies f to each category. Finally we convert it to a
factor.
f - function(x) 4 - pmin(3, match(x, sort(x, decreasing = TRUE)))
factor(ave(dfr$var3, dfr$categ, FUN = f), lab = c(low, mid,
$categ, FUN = f), lab = c(low, mid, high))
Also note that the factor labels were arranged so that
low, mid and high correspond to levels 1, 2 and 3
respectively.
On 5/18/07, Gabor Grothendieck [EMAIL PROTECTED] wrote:
Try this. f assigns 1, 2 and 3 to the highest, second highest and third
highest
to
apply this solution to many kinds of recoding situations.
-Lauri
2007/5/18, Gabor Grothendieck [EMAIL PROTECTED]:
There was a problem in the first line in the case that the highest number
is not unique within a category. In this example its not apparent since
that never occurs
: Gabor Grothendieck [EMAIL PROTECTED]
To: Vadim Ogranovich [EMAIL PROTECTED]
Cc: r-help@stat.math.ethz.ch
Sent: Friday, May 18, 2007 9:19:49 AM (GMT-0600) America/Chicago
Subject: Re: [R] subset arg in (modified) evalq
Try this:
with(subset(data, x 0), summary(y + z))
On 5/18/07, Vadim
that will be looked up during its evaluation.
As to checking performance assumptions, you are right, in most cases the
overhead is negligible, but sometimes I work with really big data sets.
Thanks a lot for your help,
Vadim
- Original Message -
From: Gabor Grothendieck [EMAIL PROTECTED
Try this:
library(gtools)
mixedsort(x)
On 5/18/07, Shubha Vishwanath Karanth [EMAIL PROTECTED] wrote:
Hi R,
My csv files are stored in the order, '1abc.csv', '2def.csv',
'3ghi.csv', '10files.csv' in a folder. When I read this into R from
list.files (R command:
In particular, we can use [ directly instead of subset. This is the
same as your function except for the line marked ### :
myfun2 - function() {
foo = data.frame(1:10,10:1)
foos = list(foo)
fooCollumn=2
cFoo = lapply(foos, [, fooCollumn) ###
return(cFoo)
}
On 5/18/07, jiho [EMAIL PROTECTED] wrote:
On 2007-May-18 , at 18:21 , Gabor Grothendieck wrote:
In particular, we can use [ directly instead of subset. This is the
same as your function except for the line marked ### :
myfun2 - function() {
foo = data.frame(1:10,10:1
Please include test data in your posts. We define
sweep.med to perform the sweep on an entire matrix. Then
we lapply f over group.sel where f(g) combines a column of all
g with sweep.med applied to the submatrix of data.mat whose
rows correspond to group.vec of g.
sweep.median2 -
Try this:
lm(Sepal.Length ~., iris[1:3])
# or
cn - c(Sepal.Length, Sepal.Width, Petal.Length)
lm(Sepal.Length ~., iris[cn])
On 5/17/07, Chris Elsaesser [EMAIL PROTECTED] wrote:
New to R; please excuse me if this is a dumb question. I tried to RTFM;
didn't help.
I want to do a series of
On 5/16/07, fatih ozgul [EMAIL PROTECTED] wrote:
Dear R-ians
I have a data frame like
Person_id Date/timeCount
- -- ---
123 20 May 1999 1
123 21 May 1999 3
222 1 Feb 2000 2
222 3 Feb 2000 4
I want
Your call to mvr does not correspond to the documentation. See ?mvr
and try this:
Lines - x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 y1
17 5 77 18 19 24 7 24 24 72 52 100
2 6 72 18 17 15 4 12 18 35 42 97.2
17 2 58 10 5 3 4 3 3 40 28 98
17 2 69 14 13 12 4 6 6 50 37 93
2 3 75 20 38 18 6 12 18 73 67 99
14
On 5/16/07, Marc Schwartz [EMAIL PROTECTED] wrote:
On Wed, 2007-05-16 at 09:25 -0700, new ruser wrote:
I am experimenting with some of the common r functions.
I had a question re:using gsub (or some similar functions) on the
contents of a list.
I want to design a function that looks at
Here is a recursive function you could try. Here f has been defined only to
convert character variables. Modify to suit.
recurse - function(x, f) {
if (length(x) == 0) return(x)
if (is.list(x)) for(i in seq_along(x)) x[[i]] - recurse(x[[i]], f)
else x - f(x)
x
}
f - function(x) if
On 5/16/07, Gabor Grothendieck [EMAIL PROTECTED] wrote:
On 5/16/07, fatih ozgul [EMAIL PROTECTED] wrote:
Dear R-ians
I have a data frame like
Person_id Date/timeCount
- -- ---
123 20 May 1999 1
123 21 May 1999 3
222
1. Use this gsub:
txt - C744=(C627*C177)/100
gsub(\\b|([^[:alnum:]]), \\1 , txt)
and then strsplit or scan as in prior response.
2. If your text consists of valid R expressions then we can use the
R parse function can traverse the tree as shown:
txt - C744=(C627*C177)/100
e - parse(text =
You need complete = TRUE. See ?qr.Q
m - matrix(c(1,0,0,0,1,0,0,0,1,0,0,1), ncol = 3)
y - matrix(c(1,2,3,4,2,3,4,5,1,1,1,1,2,2,2,2), nrow = 4)
t(qr.Q(qr(m), complete = TRUE)) %*% y
[,1] [,2] [,3] [,4]
[1,] -1 -2 -1 -2
[2,] -4 -5 -1 -2
[3,]3412
[4,] -2
On 5/15/07, elyakhlifi mustapha [EMAIL PROTECTED] wrote:
hello,
I have an argument of a the list a like this
a[[18]]
[1] C744=(C627*C177)/100
and I wanna seperate the character and the mathematics symbol to use it like
a formula
and why when I used the strsplit function i obtain as
Try this modification:
chk - function(x) exists(deparse(substitute(x)), parent.env(environment()))
ab - 1
chk(ab)
[1] TRUE
exists(x)
[1] FALSE
chk(x)
[1] FALSE
On 5/15/07, Talbot Katz [EMAIL PROTECTED] wrote:
Hi.
Thanks once more for the swift response. This solution works pretty
201 - 300 of 3333 matches
Mail list logo