Hi,
I calculating the output of a function when applied to pairs of row from
a single matrix or dataframe similar to how cor() and pairs() work. This
is the code that I have been using:
pairwise.apply <- function(x, FUN, ...){
n <- nrow(x)
r <- rownames(x)
output <-
There might be a more elegant way of doing this but here is a way of
doing it without reshape().
df <- data.frame( ID=c(1,1,1,1,2,2),
TEST=c("A","A","B","C","B","B"),
RESULT=c(17,12,15,12,8,9) )
df.s <- split( df, df$ID )
out <- sapply( df.s,
FUN
works. So the first thing is to decide where time is being spent.
On Sun, Aug 24, 2008 at 6:35 PM, Adaikalavan Ramasamy
<[EMAIL PROTECTED]> wrote:
Hi,
I calculating the output of a function when applied to pairs of row from a
single matrix or dataframe similar to how cor() and pairs
with(gdsgraph, boxplot(BReT3T5T ~ gds3lev)) is equivalent to
boxplot(gdsgraph$BReT3T5T ~ gdsgraph$gds3lev), so all the terms are found.
gds1lev is not found within the scope of the function gdsbox(). This
function has too many hard codings to be of much use generically.
Consider rewriting it
suggestion, I will play around with it. I guess my concern
is that I need each test result to occupy its own "cell" rather than have
one or more in the same row.
Adaikalavan Ramasamy-2 wrote:
There might be a more elegant way of doing this but here is a way of
doing it wit
Try reading help(hclust) and help(matplot) and run the examples given in
the documentation. If that doesn't work, try posting again with a simple
reproducible example.
Regards, Adai
Marco Chiapello wrote:
Hi all,
I'm trying to do a cluster analysis,but I don't know if it's possible in
the w
Yuan Jian, sending 9 emails within the span of few seconds all with
similar text is very confusing to say the least!
Carl, look up combinations() and permutations() in the gtools package.
For two case scenario, you can use combinations()
v <- c("a","b","c")
library(gtools)
tmp <- co
Have you tried reading some of the material from the BioConductor
workshop http://bioconductor.org/workshops/ ?
Here is a simplistic way of proceeding:
## Calculate pvalues from t-test
p <- apply( mat, function(x) t.test( x ~ cl )$p.value )
## Subset
mat.sub <- mat[ p, ]
## Cluster
heat
It would be useful to have a simplified version of the 'nsu' object.
I am guessing it is a list of some sort (e.g. mean is single value,
quantiles here returns 5 numbers) and not a matrix or dataframe (i.e.
regular array). So you can have several choices here:
1) print nsu to a file. e.g. cat
To stop in Rgui mode, you can try pressing the ESC key. If you are using
within emacs, change to R buffer and try C-c C-c to stop it.
I am not sure how to recover the script (emacs usually makes a .R~
backup). Maybe if you still have the output printed to screen or
terminal make a copy of it
Not very elegant but try:
z <- data.frame(a = 1:5, b=10*(1:5), c = c("a", "a", "b", "b", "b") )
z[ cbind( 1:nrow(z), match( as.character(z$c) , colnames(z) ) ) ]
If you have very few columns, you can use ifelse() too.
Regards, Adai
Gurpal Kalsi wrote:
Hi,
With a data such as:
z = data.f
Your example is too complicated for me. But few points:
1) What do you mean by "instrument"? Do you mean variable?
2) diff(demand) is identical to demand[-1] - demand[-204]
3) system() is a built-in R function, so avoid using it as variable name
4) The variable "yd" is in the eqInvest formula
You might also want to consider using na.string="9" in the scan().
jim holtman wrote:
Here is a faster way of doing the replacement: (provide reproducible
data next time)
x <- matrix(sample(6:9, 64, TRUE), 8)
x
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
[1,]877678
Here is another way based on pasting ids as hinted below:
a <- data.frame(id=c(c("A1","A2","A3","A4","A5"),
c("A3","A2","A3","A4","A5")),
loc=c("B1","B2","B3","B4","B5"),
clm=c(rep(("General"),6),rep("Life",4)))
a$uid <- paste(a$id, ".", a
Hmm, so if read correctly you want to remove exactly duplicated rows. So
maybe try the following to begin with.
duplicated(newdf[ , c("id", "loc", "clm")])
[1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE
TRUE TRUE
Then you can remove the duplicated rows before proceedi
It's a way of extracting from a list. See help("[") or help("Extract")
Regards, Adai
dadrivr wrote:
Great, that works very well. What is the purpose of double brackets vs
single ones? I will remember next time to include a subset of the data, so
that readers can run the script. Thanks again
It's a way of extracting from a list. See help("[") or help("Extract").
dadrivr wrote:
Great, that works very well. What is the purpose of double brackets vs
single ones? I will remember next time to include a subset of the data, so
that readers can run the script. Thanks again for your hel
It would be useful to say which package the object SJ comes from or
provide a more reproducible example.
Assuming that Demand variable is continuous and you are fitting a
standard lm() model, then your results looks suspicious. Where are the
coefficients for Month, Holiday, Season?
Jen-Ch
Try
grep( "\\.x$", c("a.x" ,"b.x","a.xx"),value=TRUE)
The $ means end-of-line (while ^ means start-of-line). And special
characters like dot needs to be escaped twice.
Regards, Adai
Vito Muggeo (UniPa) wrote:
dear all,
This is a probably a silly question.
If I type
> grep("x",c("a.x"
Isn't this more straightforward?
w <- grep("^Ig", vec)
vec[w] <- "0"
Regards, Adai
Giulio Di Giovanni wrote:
Dear all,
I cannot figure out how to solve a small problem (well, not for me), surely
somebody can help me in few seconds.
I have a series of strings in a vector X of t
Not very elegant but this does the trick:
df <- cbind( var1=c(1,3,2,1,2), var2=c(3,1,1,2,3) )
out <- df
out[ which(df==1, arr.ind=T) ] <- "1&1"
out[ which(df==2, arr.ind=T) ] <- "1&2"
out[ which(df==3, arr.ind=T) ] <- "2&2"
outlist <- apply(out, 2, strsplit, split="&")
do.call( "cbind.data.fram
Dear all,
A friend of mine requested me to analyze some data she has generated. I
am hoping for some advice on best way of properly analyzing the data as
I have never worked with such complicated or nested designs.
Here is the setup. She has taken material from 5 animals and each
material is
Dear Julia,
Welcome. It is good that you wish to learn more about R.
R has certainly become very vast in the last few years. Do you wish to
learn R for a particular reason (financial analyses, multivariate,
prediction/classification, genetics)? You might get more targeted
reading materials, b
Season X is taken as the reference category. So the output
"factor(season)y 10.59739" means the feed_intake is higher by 10.59
units in Season Y _compared to_ Season X.
Change your levels in season. E.g.
season <- factor(season, levels=c("Z", "X", "Y")
which means that Z will be taken as th
You can guess by looking at class(g). It is a factor. It is NOT
regressing on the mean of g (i.e. 2.5 and 7.5) and you could have
changed g from (0,5] and (5,10] to A and B with the same results.
Read some books or help(lm) to get an idea of what the outputs mean.
Regards, Adai
newbieR
How about?
eval( D( expression( t^3-6*t^2+5*t+30 ), "t" ) )
David Winsemius wrote:
On Jan 22, 2010, at 6:49 PM, Marlin Keith Cox wrote:
I can plot this just fine:
t<-seq(0,4, by=.1)
y<- t^3-6*t^2+5*t+30
plot(t,y ,xlab="t-values", ylab="f(t)", type="l")
This is the first derivative, how I I
If the columns of all elements of the list are in the same order, then
you can collapse it first and then extract.
out <- do.call("rbind", SPECSHOR_tx_Asfc)
out[ , "Asfc.median"]
Regards, Adai
Ivan Calandra wrote:
Hi everybody!
I have a (stupid) question but I cannot find a way to do
Dear all,
Apologies if this question is bit theoretical and for the longish email.
I am meta-analyzing the coefficients and standard errors from multiple
studies where the raw data is not available.
Each study analyst runs a model that includes an interaction term for,
say, between sex and s
Thanks for providing the example but it would be useful to know who I am
communicating with or from which institute, but nevermind ...
I don't know much about this subject but a quick google search gives me
the following site: http://davidmlane.com/hyperstat/A50760.html
Using the info from th
Dear Melissa,
If Jim's solution doesn't work then for some reason your function is
converting numerical values into either character or factor and I would
suggest you use the colClasses argument to force the right class.
For example,
mat <- read.table( file="lala.txt", sep="\t", row.names=1
I cannot run your example because I cannot identify which package the
function returns is from.
Nonetheless, something like par(mfrow=c(2,3)) should do the trick.
Regards, Adai
On 30/11/2010 14:22, Charles Evans wrote:
After searching multiple combinations of keywords over the past two
days
Here is a possible solution using sweep instead of ave:
df <- data.frame(site = c("a", "a", "a", "b", "b", "b"),
gr = c("total", "x1", "x2", "x1", "total","x2"),
value1 = c(212, 56, 87, 33, 456, 213),
value2 = c(1546, 560, 543, 234, 654,
Many ways of doing this and you have to think about efficiency and
logisitcs of different approaches.
If the data is not large, you can read all n files into a list and then
combine. If data is very large, you may wish to read one file at a time,
combining and then deleting it before reading t
You probably need to look up on how to write functions.
Try
scal.fn <- function(P, R, T){
out <- ( 1/R - T ) / ( P - T )
return(out)
}
Here is a fake example:
df <- cbind.data.frame( P=rnorm(10), R=rnorm(10), T=rnorm(10) )
scal.fn( df$P, df$R, df$T )
Or are you trying to solve other p
lin wrote:
Thanks for the answer!
However, if I would have scal.fn() like below, how would I apply
uniroot() or optimize() or the like?
Best,
PM
On 16/08/10 13:24, Adaikalavan Ramasamy wrote:
You probably need to look up on how to write functions.
Try
scal.fn<- function(P, R, T){
out&l
You can also do meta.summaries() - from rmeta package - followed by a
plot() on the resulting object.
Or for a much more flexible plot try forestplot() function, also from
rmeta package, but this requires a bit of work to set it up.
Regards, Adai
On 24/08/2010 05:50, C.H. wrote:
The correc
If you want to scale within columns, you could try
cbind( scale(df[,1:2]), df[ ,-c(1:2)] )
a b c d
1 -1 -1 7 10
2 0 0 8 11
3 1 1 9 12
and it is data.frame() btw.
On 01/09/2010 15:35, Olga Lyashevska wrote:
Dear all,
I have a dataframe:
df<-dataframe(a=c(1,2,3),b=c(4,5,6),c=c(7,
I would recommend saving the functions into a separate file and then
using source() as bartjoosen suggested.
I do not recommend using save() here because the output is non-readable
(even when using ascii=TRUE option). Which means that you have to load()
it, then copy-and-paste into an editor b
ving them
as an image file in Windows is that you can double-click the file and R will be started with these
objects loaded automatically. Anyway, to save the functions as ASCII files or even write a package
are also good solutions :-)
Regards,
Yihui
On Thu, Sep 11, 2008 at 10:34 PM, Adaikala
A slight variation of what Jorge has proposed is:
f <- function(x) c( mu=mean(x), var=var(x) )
do.call( "rbind", tapply( df$value, df$ID, f ) )
mu var
111 4.33 4.33
138 6.00 4.67
178 5.00 8.00
Regards, Adai
Jorge Ivan Velez wrote:
Dear J
--- On Thu, 9/11/08, Adaikalavan Ramasamy <[EMAIL PROTECTED]> wrote:
From: Adaikalavan Ramasamy <[EMAIL PROTECTED]>
Subject: Re: [R] Calculate mean/var by ID
To: "Jorge Ivan Velez" <[EMAIL PROTECTED]>
Cc: "liujb" <[EMAIL PROTECTED]>, r-help@r-project.org
Da
help(rowttests) says that fac needs to be a factor. So how about ?
m <- matrix( rnorm(30), nc=6 )
genotype <- c("a", "a", "b", "b", "c", "c")
w1 <- which( genotype %in% c("a", "b") )
w2 <- which( genotype %in% c("a", "c") )
w3 <- which( genotype %in% c("b", "c") )
list( ab = rowttes
I just changed the 'at' argument and added an 'xlim' option.
boxplot(len ~ dose, data = ToothGrowth,
boxwex = 0.25, at = 1:3,
subset = which(supp == "VC"), col = "yellow",
main = "Guinea Pigs' Tooth Growth",
xlab = "Vitamin C dose mg",
ylab = "t
It would be useful to have indexed both dataframes with a unique
identifier, such as in rownames etc.
Without that information, you could possibly try to use the same
approach as duplicated() does by "pasting together a character
representation of rows" using "|" (or any other separator).
If I understand you correctly, you already pre-computed the frequencies
and bin widths and want to display them as a histogram. If correct, then
what you are asking for is analogous to what bxp() is to boxplot. I am
not sure if such a function exists.
Instead you can think of the task as drawi
Why not use a script?
I feel that it is much better than using the history via [CTRL]-R in
unix, which also pulls up errorneous commands.
A script is vital for statistical analysis and research where you may
want to or be asked to repeat or reproduce the analysis months later.
Rgui (on wind
Well, I don't see why you need the CTRL-R functionality when you can
just as rapidly and efficiently using SEARCH functionality in scripts
too (CTRL-F in most applications, CTRL-S in emacs etc).
BTW, I am quite familiar with Unix, Linux and Sun Solaris and what
CTRL-R does (yes, I used it fre
Ah, I didn't realize Rterm existed (Start -> Run -> Rterm). It works
with CTRL-R as you said. Thank you!
Regards, Adai
Peter Dalgaard wrote:
Adaikalavan Ramasamy wrote:
...
Anyway, here is how to do what you want:
1) Install bash on your Windows machine - You can use cgywin. O
I agree! The best way to learn (and remember for longer) is to teach
someone else about it.
And there is not reason not to repeat some of the anlysis done on SAS
with R. That way you can verify your outputs or compare the
presentations. If you consistently find differences in the outputs, then
Ramya, you sent four near identical emails with different subject lines.
Since the list is run by unpaid volunteers, please avoid wasting
people's time (and yours too) with such redundancies.
Please read http://www.r-project.org/posting-guide.html and search the
mailing lists and documentation
I guess this would be the fastest way would be:
rs <- rowSums( testDat, na.rm=T)
rs[ which( rowMeans(is.na(testDat)) == 1 ) ] <- NA
since both rowSums and rowMeans are internally coded in C.
Regards, Adai
Doran, Harold wrote:
Say I have the following data:
testDat <- data.frame(A = c(1,N
One way is to keep a copy of the original and then return to it when you
need it.
x <- rnorm(100,1,0.5)
y <- rnorm(100,1,0.5)
plot(x,y,pch=16)
original <- recordPlot()
for( i in 1:10 ){
points( x[i], y[i], pch=19, col="yellow", cex=3)
points( x[i], y[i], pch=16)
Sys.sleep(1)
An example would help.
You generally control the titles using arguments like main, xlab, ylab,
sub in the plotting functions or afterwards using title() function. You
can get the upper/lower case using toupper()/tolower() functions. See
help(par), help(title), help(tolower). Here is an example
First check that your data satisfies the normality assumption. If yes,
then start with the ANOVA test
summary( fit <- aov( genomes ~ clonefed ) )
and *if* you find a significant F-value, you can see which difference is
significant. i.e. post-hoc analysis.
TukeyHSD( fit, "clonefed" )
Y
Perhaps what you want is get().
apple <- rnorm(5)
orange <- runif(5)
fruits <- c("apple", "orange")
fruit.data <- NULL
for( fruit in fruits ){
v <- get(fruit)
fruit.data <- cbind(fruit.data, v)
}
colnames(fruit.data) <- fruits
fruit.data
Here the resulting
What do you mean? If you kill the existing graph, perhaps using
dev.off(), the next plot generated should use default values. Is this
what you want?
Some plotting functions use this at the start before modifying
oldpar <- par(no.readonly=T)
on.exit(par(oldpar))
Regards, Adai
Regards, Adai
Not the most elegant solution but here goes.
df <- data.frame(g=c("g1","g2","g1","g1","g2"),v=c(1,7,3,2,8))
rownames.which.max <- function(m, col){
w <- which.max( m[ , col] )
return( rownames(m)[w] )
}
df.split <-
I don't understand why you need to use a function at all, especially
when all your function arguments are overwritten inside the loop.
Here is a simplified example of what you are doing:
f <- function(x){
x <- 5
print(x)
}
Therefore f(1), f(2), ..., f(1000) etc all gives you the same answer.
Can you give us a simple example which produces the same behavior?
Michael Zak wrote:
Hi there
I have some timeseries data which I plot in a OHLC Plot. In the same
plot I'd like to have the EMA of this timeseries. I tried to add the EMA
point to OHLC with lines(), but this doesn't work. Has
Dear all,
I used the glm.nb with the default values from the MASS package to run a
negative binomial regression. Here is a simple example:
set.seed(123)
y <- c( rep(0, 30), rpois(70, lambda=2) )
smoke <- factor( sample( c("NO", "YES"), 100, replace=T ) )
height <- c( rnorm(30, me
lker wrote:
Adaikalavan Ramasamy imperial.ac.uk> writes:
Dear all,
I used the glm.nb with the default values from the MASS package to run a
negative binomial regression. Here is a simple example:
[snip -- thanks for the example!]
The question now is how do I report the results, say, for height? Do I
Try
x[ !sapply(x, is.null) ]
hadley wickham wrote:
An alternative approach would be to store 0 x 0 matrices instead of
NULLs. This way every object in your list is a consistent type.
Hadley
On Wed, Oct 15, 2008 at 5:23 AM, Muhammad Azam <[EMAIL PROTECTED]> wrote:
Dear friends
There
It sounds like you simply uncompressed your .tar.gz file and then zipped
it up. If so, it should not work correctly.
You need to compile it for windows. Try something like
Rcmd build --binary myRpackageDir
and you may need to include "--force" option in the command above.
Also
63 matches
Mail list logo