Re: [R] reshaping data

2012-07-25 Thread AC Del Re
x) > 1) x) > l2 <- do.call(rbind, l2) > l2 > > # Create a new variable > l3 <- lapply(sl, function(x) cbind(x, NEW_VARIABLE=seq_len(nrow(x)))**) > l3 <- do.call(rbind, l3) > l3 > > > Hope this helps, > > Rui Barradas > > Em 25-07-2012 01:59, AC

[R] reshaping data

2012-07-24 Thread AC Del Re
Hi, I am trying to reshape data from a long to wide format but have a specific task that I cannot get to output properly. # SAMPLE DATA; id <- c(1,2,2,3,3,3) time <-c(0,0,5, 0, 2, 10) x <- rnorm(length(id)) long <- data.frame(id,time,x) # To reshape, I would like to exclude 'id' values that have

[R] Removing rows in dataframe w'o duplicated values

2011-11-22 Thread AC Del Re
Hi, Is there an easy way to remove dataframe rows without duplicated values of a specified column ('id')? e.g., dat <- data.frame(id = c(1,1,1,2,3,3), value = c(5,6,7,4,5,4), value2 = c(1,4,3,3,4,3)) dat id value value2 1 1 5 1 2 1 6 4 3 1 7 3 4 2 4 3 5

Re: [R] Take variables in data.frame and create list of matrices

2011-11-03 Thread AC Del Re
Thats a good start but I am looking for more. Specifically (from previous post): 4x4 matrix (based on the maximum number of factor levels in 'o') for each 'id' as a list. Each matrix would have v in the diagonal and r*s*s in the off-diagonal (e.g., .5*2.0814*.1095 = 0.1139), where r is constant (

[R] Take variables in data.frame and create list of matrices

2011-11-03 Thread AC Del Re
Hi, I have this sample data below and would like to create a list of matricies. setseed(1254) id <- c(1,1,1,1 ,2,2,2) o <- as.factor(c(1:4, 1, 3, 4)) r <- rep(.5, 7) v <- rnorm(7) s <- rnorm(7) dat <-data.frame(id, o, r, v, s) dat #> dat # id o r v s # 1 1 0.5 0.7024631 2

Re: [R] selecting first row of a variable with long-format data

2011-09-25 Thread AC Del Re
x, 1)) > id value > 1 1 5 > 2 2 4 > > The formula version of aggregate() requires R-2.11.0 + > > Dennis > > On Sun, Sep 25, 2011 at 1:22 PM, AC Del Re wrote: > > Hi, > > > > I am trying to select the first row of a variable with data in > l

[R] selecting first row of a variable with long-format data

2011-09-25 Thread AC Del Re
Hi, I am trying to select the first row of a variable with data in long-format, e.g., # sample data id <- c(1,1,1,2,2) value <- c(5,6,7,4,5) dat <- data.frame(id, value) dat How can I select/subset the first 'value' for each unique 'id'? Thanks, AC [[alternative HTML version deleted]

[R] Simulating data with conditions

2011-05-24 Thread AC Del Re
Hi, I am wanting to simulate data where a percentage of the data has multiple duplicated id variables (with unique values of another factor variable for the dupicated id variables). Im having trouble figuring out an efficent way to do so. For example, consider this mock output [Note: Although the

Re: [R] output without quotes

2010-07-09 Thread AC Del Re
Wonderful, David! Thank you much for your help on this. AC On Fri, Jul 9, 2010 at 6:49 PM, David Winsemius wrote: > > On Jul 9, 2010, at 7:19 PM, Erik Iverson wrote: > > AC Del Re wrote: >> >>> Hi David, >>> I don't have the function in order yet

Re: [R] output without quotes

2010-07-09 Thread AC Del Re
us wrote: > > On Jul 9, 2010, at 3:51 PM, AC Del Re wrote: > > Hi All, >> >> I am interested in printing column names without quotes and am struggling >> to >> do it properly. The tough part is that I am interested in using these >> column >> nam

[R] output without quotes

2010-07-09 Thread AC Del Re
Hi All, I am interested in printing column names without quotes and am struggling to do it properly. The tough part is that I am interested in using these column names for a function within a function (e.g., lm() within a wrapper function). Therefore, cat() doesnt seem appropriate and print() is n

[R] Displaying equations from .Rd files

2010-03-25 Thread AC Del Re
Hi All, > > Attempt #2. any help is much appreciated!: > I am reading through section 2.6 (Mathematics) of the "Writing R > Extensions" manuscript and am wondering where I can find more > examples/documentation on the \deqn{ } function. I would like to learn how > to display equations using th

[R] Displaying equations from .Rd files

2010-03-23 Thread AC Del Re
Hi All, I am reading through section 2.6 (Mathematics) of the "Writing R Extensions" manuscript and am wondering where I can find more examples/documentation on the \deqn{ } function. I would like to learn how to display equations using this function but am not sure how to go about doing it. The

Re: [R] Retaining variable name in a function

2010-03-17 Thread AC Del Re
;- facts(testdata, "b", "newb") > > str(test2) > 'data.frame': 3 obs. of 2 variables: > $ a : num 1 2 3 > $ newb: Factor w/ 2 levels "1","2": 1 1 2 > > Sarah > On Wed, Mar 17, 2010 at 2:23 PM, Henrique Dallazuanna wrote

[R] Retaining variable name in a function

2010-03-17 Thread AC Del Re
Hi All, Im interested in creating a function that will convert a variable within a data.frame to a factor while retaining the original name (yes, I know that I can just: var <-factor(var) but I need it as a function for other purposes). e.g.: # this was an attempt but fails. facts <- function(

Re: [R] ifthen() question -- whoops--ifelse()

2010-03-04 Thread AC Del Re
=st[i]], n.2 = n.2[id==st[i]], cor)[2]) out$n.1[i] <- round(mean(n.1[id==st[i]]),0) out$n.2[i] <- round(mean(n.2[id==st[i]]),0) } return(out) } AC On Thu, Mar 4, 2010 at 9:35 AM, AC Del Re wrote: > Hi All, > > I am using a specialized aggre

[R] ifthen() question

2010-03-04 Thread AC Del Re
Hi All, I am using a specialized aggregation function to reduce a dataset with multiple rows per id down to 1 row per id. My function work perfect when there are >1 id but alters the 'var.g' in undesirable ways when this condition is not met, Therefore, I have been trying ifthen() statements to ke

[R] reducing data.frame

2010-02-24 Thread AC Del Re
Hi All, Is there an easy way to reduce a data.frame to 1 'id' per row while keeping information from the other rows of that same variable, if applicable? e.g.: # data multi[1:15,] id r n wi wi.tau z k alliance a.rater eml treatment outcome o.rater german 1 100 0.2

Re: [R] aggregating using 'with' function

2010-02-21 Thread AC Del Re
(.data), 1),])) >    id mod1  r > 1   1    2  0.295 > 4   4    1  0.640 > 5   5    2  0.490 > 6   6    3 -0.040 > 7   7    1  0.490 > 8   8    2  0.330 > 9   9    3  0.580 > 10 10    1  0.180 > 11 11    2  0.600 > 12 12    3  0.210 >> >> > >

Re: [R] aggregating using 'with' function

2010-02-20 Thread AC Del Re
gt;>    id mod1 r >> 1   1    1  0.98 >> 2   4    1  0.64 >> 3   7    1  0.49 >> 4  10    1  0.18 >> 6   5    2  0.49 >> 7   8    2  0.33 >> 8  11    2  0.60 >> 9   6    3 -0.04 >> 10  9    3  0.58 >> 11 12    3  0.21 >> >

Re: [R] aggregating using 'with' function

2010-02-20 Thread AC Del Re
1    1  0.980 > 2   4    1  0.640 > 3   7    1  0.490 > 4  10    1  0.180 > 5   1    2  0.295 > 6   5    2  0.490 > 7   8    2  0.330 > 8  11    2  0.600 > 9   6    3 -0.040 > 10  9    3  0.580 > 11 12    3  0.210 >> > > > On Sat, Feb 20, 2010 at 6:54 PM,

[R] aggregating using 'with' function

2010-02-20 Thread AC Del Re
Hi All, I am interested in aggregating a data frame based on 2 categories--mean effect size (r) for each 'id's' 'mod1'. The 'with' function works well when aggregating on one category (e.g., based on 'id' below) but doesnt work if I try 2 categories. How can this be accomplished? # sample data i

[R] Replicating output from a function

2010-02-17 Thread AC Del Re
Hi All, I have a function that is used with data frames having multiple id's per row and it aggregates the data down to 1 id per row. It also randomly selects one of the within-id values of a variable (mod), which often differ within-id. Assume this data frame (below) is much larger and I want to

Re: [R] creating functions question

2010-02-15 Thread AC Del Re
Perfect! Thank you, Dimitris. AC On Mon, Feb 15, 2010 at 1:45 PM, Dimitris Rizopoulos wrote: > try this: > > MRfit <- function (...) { >    models <- list(...) >>    do.call(anova, models) >> } >> >> >> I hope it helps. >> >>

[R] creating functions question

2010-02-15 Thread AC Del Re
Hi All, I am interested in creating a function that will take x number of lm objects and automate the comparison of each model (using anova). Here is a simple example (the actual function will involve more than what Im presenting but is irrelevant for the example): # sample data: id<-rep(1:20)

[R] R-Commander plug-in difficulties

2010-02-15 Thread AC Del Re
Hi All, I have recently created an Rcmdr plugin package and it passed all the checks and was uploaded to CRAN. I then downloaded it from CRAN and tried running it from my local R program and received this error: ... Error in f(libname, pkgname) : could not find function "getRcmdr" Error in librar

Re: [R] Data.frame manipulation

2010-01-29 Thread AC Del Re
3 0.21 wai > > > > > 6 3 0.31 wai > > > > > > > > > > # I would like to reduce the entire data.frame like this: > > > > > > E.g. aggregate > > > > > > a

Re: [R] Data.frame manipulation

2010-01-28 Thread AC Del Re
egards > Petr > > > > > > > id es mod1 mod2 > > > > > > 1 .30 2wai > > > 2 .15 4other > > > 3 .20 1 itas > > > > > > # If possible, I would also like the option of this (collapsing on

Re: [R] Data.frame manipulation

2010-01-28 Thread AC Del Re
> 2 1 2 0.30 > 3 2 4 0.15 > > ddply() is a little less painless and sorts the output for you > automatically. > > HTH, > Dennis > > On Wed, Jan 27, 2010 at 7:34 PM, AC Del Re wrote: > >> Hi All, >> >> I'm cond

[R] Data.frame manipulation

2010-01-27 Thread AC Del Re
wai 2 .15 4other 3 .20 1 itas # If possible, I would also like the option of this (collapsing on id and mod2): id es mod1 mod2 1 .30 2wai 2 0.1 4 other 2 0.2 4calpas 3 0.1 1 itas 3 0.251 wai Any

Re: [R] Data.frame manipulation

2010-01-27 Thread AC Del Re
psing on id and > mod2): > > id es mod1 mod2 > 1 .30 2wai > 2 0.1 4 other > 2 0.2 4calpas > 3 0.1 1 itas > 3 0.251 wai > > Any help is much appreciated! > > AC Del Re > [[alternative

Re: [R] reshape question

2009-11-25 Thread AC Del Re
Thanks for your help on this Hadley and David! Dennis Murphy also had a good solution (changing list(data.out2[-1])...etc to names(data.out2[-1]}...): > data.out3 <- reshape(data.out2, direction = 'long', varying = names(data.out2[-1]), + idvar = 'id') > data.out4 <- split(data.out3, da

[R] reshape question

2009-11-24 Thread AC Del Re
Hi All, I am wanting to convert a data.frame from a wide format to a long format (with >1 variable) and am having difficulties. Any help is appreciated! #current wide format > head(data.out2) id rater.1 n.1 rater.2 n.2 rater.3 n.3 rater.4 n.4 11 11 0.118 79NA NA

Re: [R] Row to Column help

2009-10-04 Thread AC Del Re
> > Wonderful, Phil! Your suggestion produced the exact format I desired. > Thank you kindly, > AC Del Re > > > On Sun, Oct 4, 2009 at 2:03 PM, Phil Spector wrote: > >> AC - >> The easiest way I can think of is to create a time variable, >> so res

[R] Row to Column help

2009-10-04 Thread AC Del Re
Dear R Community, I am attempting to transpose a dataset from rows to columns but am stuck. I have tried using reshape() with little luck, possibly due to the categorical nature of the data. For example: id<-c(1,2,2,3,3,3) author<-c("j","k","k","l","l","l") tmt<-c("cbt","act","dbt","act","act","cb