Re: [R] reshaping data

2012-07-25 Thread AC Del Re
(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 Del Re escreveu: Hi, I am trying to reshape data from a long to wide format but have a specific

[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 NO

[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

[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

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] 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]]

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

2011-09-25 Thread AC Del Re
The formula version of aggregate() requires R-2.11.0 + Dennis On Sun, Sep 25, 2011 at 1:22 PM, AC Del Re de...@wisc.edu wrote: 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

[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

Re: [R] output without quotes

2010-07-10 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 dwinsem...@comcast.netwrote: 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 but the names will be going

[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

Re: [R] output without quotes

2010-07-09 Thread AC Del Re
...@comcast.netwrote: 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 names for a function within a function (e.g., lm() within

[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 this

[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

[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 -

Re: [R] Retaining variable name in a function

2010-03-17 Thread AC Del Re
Dallazuanna www...@gmail.comwrote: Try this: transform(DF, newA = factor(a), a = NULL) On Wed, Mar 17, 2010 at 4:06 PM, AC Del Re de...@wisc.edu wrote: Hi All, Im interested in creating a function that will convert a variable within a data.frame to a factor while retaining the original

[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

[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

Re: [R] aggregating using 'with' function

2010-02-21 Thread AC Del Re
10    1  0.180 11 11    2  0.600 12 12    3  0.210 On Sat, Feb 20, 2010 at 9:50 PM, AC Del Re acde...@gmail.com wrote: OK, this is great, Jim. Last question: How about if I want the 1 copy of each id to be selected randomly versus taking the first one? AC On Sat, Feb 20, 2010 at 8:37

[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

Re: [R] aggregating using 'with' function

2010-02-20 Thread AC Del Re
  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, AC Del Re de...@wisc.edu wrote: Hi All, I am interested in aggregating a data frame

Re: [R] aggregating using 'with' function

2010-02-20 Thread AC Del Re
11 12    3  0.21 On Sat, Feb 20, 2010 at 8:07 PM, AC Del Re de...@wisc.edu wrote: Perfect! Thanks Jim. Do you know how I could then reduce the data even further? Specifically, reducing it to 1 id per row? In this dataset, id 1 would have one row eliminated. Assume the data is much larger

[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

[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

[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)

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 d.rizopou...@erasmusmc.nl wrote: try this: MRfit - function (...) {    models - list(...)    do.call(anova, models) } I hope it helps. Best, Dimitris AC Del Re wrote: Hi All, I am

Re: [R] Data.frame manipulation

2010-01-29 Thread AC Del Re
1 wai Any help is much appreciated! AC Del Re [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting

Re: [R] Data.frame manipulation

2010-01-28 Thread AC Del Re
don't: with(x, aggregate(es, list(id, mod1), mean)) Group.1 Group.2x 1 3 1 0.20 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 acde

Re: [R] Data.frame manipulation

2010-01-28 Thread AC Del Re
wai 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 HTML version deleted]] __ R-help@r

Re: [R] Data.frame manipulation

2010-01-27 Thread AC Del Re
# 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 help is much appreciated! AC Del Re

[R] Data.frame manipulation

2010-01-27 Thread AC Del Re
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 help is much appreciated! AC Del Re [[alternative HTML version deleted

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,

[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

[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,cbt)

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 spec...@stat.berkeley.eduwrote: AC - The easiest way I can think of is to create a time variable, so reshape will know which observation