Displaying 20 results from an estimated 4000 matches similar to: "using ddply but preserving some of the outside data"
2009 Jun 22
3
Calculating "row standard deviations"
Hi R-helpers,
I have been struggling with calculating row and column statistics,
e.g. standard deviation.
I know that
> datac$Mean<-rowMeans(datac,na.rm=TRUE)
will give me row means.
I have tried to replicate those row means with the apply function:
> datac$Mean2<-apply(datac,2,mean)
so that I can replace the function argument with "sd" (instead of
mean) to get standard
2011 Aug 06
1
help with predict for cr model using rms package
Dear list,
I'm currently trying to use the rms package to get predicted ordinal
responses from a conditional ratio model. As you will see below, my
model seems to fit well to the data, however, I'm having trouble
getting predicted mean (or fitted) ordinal response values using the
predict function. I have a feeling I'm missing something simple,
however I haven't been able to
2011 Aug 16
4
a question about lm on t-test.
Hi all:
I have a question about lm on t-test.
data(sleep)
I wanna perform t-test to test the difference between the 2 groups:
I can use:
t.test(extra~group)
The t.test result shows that:t = -1.8608; mean1=0.75,mean2=2.33
But I still wanna use:
summary(lm(extra~group))
Intercept=0.75,which is mean1,just the same as t.test.
group2=1.58 means the difference of the 2 groups,so
2010 Nov 23
1
Barplot and plot means with confidence intervals in the same plot
I want to obtain a barplot with error bars and a mean plot with error bars
with other scale on the left in the same plot. I need help to get the same
x axis (centered) when overlay two plots (barplot2 and plotCI (or
lineplot.CI) with errorbars), with diferent y axis. I use par (new=T) but
the X axis names are not centered with the figures.
An example of my data:
1999 Mar 07
1
ANOVA f-test
I have a rather basic question. How can I get R to generate a ANOVA table
and a f-value for a hypothesis test such as:
Data: group1 values: 5.2 4.5 6.0 6.1 6.7 5.8
group2 values: 6.5 8.0 6.1 7.5 5.9 5.6
...
H0: mean1 = mean2 = mean3 = mean4
HA: at least two means different
where I want to evaluate using a f test statistic?
F = MSTr/MSE
I'd like a table similar to one that
2010 Dec 06
3
[plyr] Question regarding ddply: use of .(as.name(varname)) and varname in ddply function
Dear R-Helpers:
I am using trying to use *ddply* to extract min and max of a particular
column in a data.frame. I am using two different forms of the function:
## var_name_to_split is a string -- something like "var1" which is the name
of a column in data.frame
ddply( df, .(as.name(var_name_to_split)), function(x) c(min(x[ , 3] , max(x[
, 3]))) ## fails with an error - case 1
ddply(
2010 Apr 07
1
unexpected behaviour with ddply and colwise
Hi,
I am confused by results from:
> ddply(aa, names(aa), colwise(sum))
I thought ddply was just calling colwise(sum)() with each column.
However ddply() returns a 13 x 5 result !!
The general result I expected is similar to that of apply() , or
using colwise(sum)() alone. Shouldn't ddply() produce the same ?
Thanks in advance for your help,
- Stuart Andrews
>
2011 Jun 21
4
ddply to count frequency of combinations
I have a dataframe df with two columns x and y. I want to count the number
of times a unique x, y combination occurs.
For example
x<- c(1,2,3,4,5,1,2,3,4)
y<- c(1,2,3,4,5,1,2,4,1)
df<-as.data.frame(cbind(x, y))
#what is the correct way to use ddply for this example?
ddply(df, c('x','y', summarize, ??)
#desired output -- format and order doesn't matter
# (x, y)
2011 May 11
3
ddply with mean and max...
I'm trying to use ddply to compute summary statistics for many variables
splitting on the variable site. however, it seems to work fine for mean() but
if i use max() or min() things fall apart. whats going on?
test.set<-data.frame(site=1:10,x=.Random.seed[1:100],y=rnorm(100))
means<-ddply(test.set,.(site),mean)
means
site x y
1 1 -97459496 -0.14826303
2
2010 Oct 20
1
Generate variable with Bivariate Normal Distribution
Dear All
I want to generate variable with Bivariate Normal Distribution by
use mean1 = a, variance1 = b, mean2 = c, variance2 = d, rho = e.
How I can do this.
Many Thanks.
IRD
[[alternative HTML version deleted]]
2009 Nov 19
1
ddply function nesting problems
While putting my R code into functions, I've encountered a ddply function nesting issue and need a bit of advice on the proper way to fix it.? I've tried several approahces, but neither worked and I need to have the ability to include the "cut", "range", and "fullseq" methods within ddply.? (For a bit of that explanation refer to
2011 Aug 24
3
ddply from plyr package - any alternatives?
Hello everyone,
I was asked to repost this again, sorry for any inconvenience.
I'm looking replacement for ddply function from plyr package.
Function allows to apply function by category stored in any column/columns.
Regular loops or lapplys slow down greatly because my unique combination
count exceeds 9000. Is there any available solution which allow me to apply
function by category?
2012 Jul 24
1
Function for ddply
Hello, all. I'm new to R and just beginning to learn to write functions. I
know I'm out of my depth posting here, and I'm sure my issue is mundane.
But here goes. I'm analyzing the American National Election Study (nes),
looking at mean values of a numeric dep_var (environ.therm) across values
of a factor (partyid3). I use ddply from plyr and wtd.mean from Hmisc. The
nes requires a
2012 May 29
2
a question about "by" and "ddply"
Hi all,
I have a data set (df, n=10 for the sake of simplicity here) where I have two continuous variables (age and weight) and I also have a grouping variable (group, with two levels). I want to run correlations for each group separately (kind of similar to "split file" in SPSS). I've been experimenting with different functions, and I was able to do this correctly using ddply
2012 May 05
1
Correct use of ddply with own function
Hi,
I am really confused how ddply work, so maybe you can help me.
I created a function that sorts a vector etc.
fn <- function(x){
x1 <- sort(x)
x2 <- seq(length(x))
x3 <- x2/max(x2)
df <- data.frame(x1,x2,x3)
df
}
Probably this is not the best form of the function, but at least it produces what I want (data to plot a cumulative count curve).
This function works on a
2010 Jun 01
1
data frame manipulation ddply
Dear group,
Here is my data frame:
futures <-
structure(list(DESCRIPTION = c("CORN Jul/10", "CORN Jul/10",
"CORN Jul/10", "CORN Jul/10", "CORN Jul/10", "LIVE CATTLE Aug/10",
"LIVE CATTLE Aug/10", "SUGAR NO.11 Jul/10", "SUGAR NO.11 Jul/10",
"SUGAR NO.11 Jul/10", "SUGAR NO.11
2012 Mar 03
3
Using ddply within a function by argument transfer
An embedded and charset-unspecified text was scrubbed...
Name: inte tillg?nglig
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120303/a62e41f2/attachment.pl>
2003 Dec 04
6
get mean of several rows
Dear all!
After hours of trying around, I gave up:
I have a 2-dimensional array, and I know how to split it into its rows
and how to get the mean for every row using 'sapply'.
But what I want is to calculate the mean over the first n rows, and then
the second n rows, etc., so that I get a vector like:
v == mean1(row 1:5), mean2(row6:10),...
(trivial, you might say. I find it rather
2011 Aug 23
3
ddply - how to transform df column "in place"
Dear R-users,
I am trying to get the plyr syntax right, without much success.
Given:
d<- data.frame(cbind(x=1,y=seq(20100801,20100830,1)))
names(d)<-c("first", "daterep")
d2<-d
# I can convert the daterep column in place the classic way:
d$daterep<-as.Date(strptime(d$daterep, format="%Y%m%d"))
# How to do it the plyr way?
ddply(d2,
2012 Sep 06
1
use of ddply() within function
Dear all,
I am encountering problems with the application of ddply within the body of a self-defined function.
The script is the following:
moncostcarmoto <- function(costtype){
costaux_result <- data.frame()
for (purp in PURPcount){for (per in PERcount){
costcarin =