Re: [R] Reshaping Data in R - Transforming Two Columns Into One

2014-03-19 Thread PIKAL Petr
Hi Isn't melt just what you want? melt(mydt) Petr > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of Abraham Mathew > Sent: Tuesday, March 18, 2014 1:59 AM > To: r-help@r-project.org (r-help@r-project.org) > Subject: [R] Resh

Re: [R] Reshaping Data for bi-partite Network Analysis [SOLVED]

2013-04-14 Thread arun
put) #   place #people school home sport beach  # Marc  2    4 0 0   #Joe   0    3 1 5   #Mary  4    0 0 0 A.K. From: sylvain willart To: arun Cc: R help Sent: Saturday, April 13, 2013 5:41 PM Subject: Re: [R] Reshaping Data for

Re: [R] Reshaping Data for bi-partite Network Analysis [SOLVED]

2013-04-13 Thread sylvain willart
Wow ! so many thanks Arun and Rui works like a charm problem solved 2013/4/13 arun > Hi, > Try this; > library(reshape2) > res<-dcast(Input,people~place,value.var="time") > res[is.na(res)]<-0 > res > # people beach home school sport > #1Joe 53 0 1 > #2 Marc 04

Re: [R] Reshaping Data for bi-partite Network Analysis

2013-04-13 Thread Rui Barradas
Hello, With the following the order of both rows and columns will be different than the order of your example output, but the table is basically the same. xtabs(time ~ people + place, data = Input) Hope this helps, Rui Barradas Em 13-04-2013 22:03, sylvain willart escreveu: Hello I have

Re: [R] Reshaping Data for bi-partite Network Analysis

2013-04-13 Thread arun
Hi, Try this; library(reshape2) res<-dcast(Input,people~place,value.var="time") res[is.na(res)]<-0  res #  people beach home school sport #1    Joe 5    3  0 1 #2   Marc 0    4  2 0 #3   Mary 0    0  4 0 #or  xtabs(time~.,Input) #  place #people beach home s

Re: [R] reshaping data

2012-07-25 Thread AC Del Re
Wonderful! thanks, Rui! AC On Tue, Jul 24, 2012 at 10:01 PM, Rui Barradas wrote: > Hello, > > Try the following. > > > # We are going to use this twice > sl <- split(long, long$id) > > # Remove groups with only one row > l2 <- lapply(sl, function(x) if(nrow(x) > 1) x) > l2 <- do.call(rbind, l2)

Re: [R] reshaping data

2012-07-24 Thread Peter Ehlers
On 2012-07-24 22:01, Rui Barradas wrote: Hello, Try the following. # We are going to use this twice sl <- split(long, long$id) # Remove groups with only one row l2 <- lapply(sl, function(x) if(nrow(x) > 1) x) l2 <- do.call(rbind, l2) l2 # Create a new variable l3 <- lapply(sl, function(x) cb

Re: [R] reshaping data

2012-07-24 Thread Rui Barradas
Hello, Try the following. # We are going to use this twice sl <- split(long, long$id) # Remove groups with only one row l2 <- lapply(sl, function(x) if(nrow(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

Re: [R] Reshaping data from long to wide without a "timevar"

2012-03-21 Thread Paul Miller
Hello All, Tried some more Internet searches and came to the conclusion that one probably does need to create a "timevar" before reshaping from long to wide. Below is some code that creates the "timevar" and transposes the data. connection <- textConnection(" 005 1 Gemcitabine 005 2 Erlotinib

Re: [R] Reshaping data from long to wide without a "timevar"

2012-03-20 Thread Paul Miller
Erlotinib, Paclitaxel" instead of "Gemcitabine, Paclitaxel, Erlotinib". That's what I mean when I say I want the columns in alphabetical order. Thanks, Paul --- On Tue, 3/20/12, R. Michael Weylandt wrote: > From: R. Michael Weylandt > Subject: Re: [R] Reshaping data

Re: [R] Reshaping data from long to wide without a "timevar"

2012-03-20 Thread R. Michael Weylandt
If I understand you right, library(reshape2) dcast(melt(TestData, id.var = "Subject", measure.var = "Drug"), Subject ~ value) Michael On Tue, Mar 20, 2012 at 9:50 AM, Paul Miller wrote: > Hello All, > > I was wondering if it's possible to reshape data from long to wide in R > without using a "

Re: [R] Reshaping data from wide to tall format for multilevel modeling

2011-09-08 Thread Jim Lemon
On 09/08/2011 12:02 AM, dadrivr wrote: Hi, I'm trying to reshape my data set from wide to tall format for multilevel modeling. Unfortunately, the function I typically use (make.univ from the multilevel package) does not appear to work with unbalanced data frames, which is what I'm dealing with.

Re: [R] reshaping data

2011-09-07 Thread B77S
The terminology (melt, cast, recast) just isn't intuitive to me; but I understand how to use melt now. Thanks! Justin Haynes wrote: > > look at the melt function in reshape, specifically ?melt.data.frame > > require(reshape) > Raw.melt<-melt(RawData,id.vars='Year',variable_name='Month') > >

Re: [R] reshaping data

2011-09-07 Thread Justin Haynes
look at the melt function in reshape, specifically ?melt.data.frame require(reshape) Raw.melt<-melt(RawData,id.vars='Year',variable_name='Month') there is an additional feature in the melt function for handling na values. names(Raw.melt)[3]<-'CO2' > head(Raw.melt) Year MonthCO2 1 1958

Re: [R] Reshaping data with xtabs reorders my rows

2011-06-15 Thread filip.biele...@rega.kuleuven.be
Dnia 2011-06-15, o godz. 12:05:01 Jim Lemon napisał(a): > On 06/15/2011 06:46 PM, filip.biele...@rega.kuleuven.be wrote: > > Dear, > > > > I have a data frame melted from a list of matrices (melt from > > reshape package), then I impute some missing values and then want > > to tabulate the data a

Re: [R] Reshaping data

2010-07-20 Thread Ista Zahn
On Tue, Jul 20, 2010 at 3:30 AM, John Kane wrote: > Assuming your data is in data.frame xx > > > library(reshape) > mm1 <- melt(xx, id=c("ID")) > cast(mm1, ID  ~ variable ) > =

Re: [R] Reshaping data

2010-07-20 Thread Thomas Jensen
Hi Dennis, Thanks for the answer, it works perfectly for two time intervals, but if I add a third interval like this: ID begin_t1end_t1 begin_t2end_t2 begin_t3end_t3 Thomas 11/03/0413/05/0604/02/071

Re: [R] Reshaping data

2010-07-19 Thread John Kane
Assuming your data is in data.frame xx library(reshape) mm1 <- melt(xx, id=c("ID")) cast(mm1, ID ~ variable ) = --- On Mon, 7/19/10, Thomas Jensen wrote: > From: Thomas Jens

Re: [R] Reshaping data

2010-07-19 Thread Dennis Murphy
Hi: Here's one solution using function reshape() in the stats package (adapted from an R-help solution by Thomas Lumley on Nov. 26, 2002): d <- read.table(textConnection(" + ID begin_t1end_t1 begin_t2 end_t2 + Thomas 11/03/0413/05/06

Re: [R] reshaping data

2010-05-21 Thread Mia Bengtsson
ilto:r-help-boun...@r-project.org] On Behalf Of Mia Bengtsson >> Sent: Friday, May 21, 2010 3:39 AM >> To: Dennis Murphy; Henrique Dallazuanna >> Cc: r-help@r-project.org >> Subject: Re: [R] reshaping data >> >> Thank you Dennis and Henrique for your help! >> >&g

Re: [R] reshaping data

2010-05-21 Thread William Dunlap
> -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Mia Bengtsson > Sent: Friday, May 21, 2010 3:39 AM > To: Dennis Murphy; Henrique Dallazuanna > Cc: r-help@r-project.org > Subject: Re: [R] reshaping data

Re: [R] reshaping data

2010-05-21 Thread Mia Bengtsson
Thank you Dennis and Henrique for your help! Both solutions work! I just need to find a way of removing the empty "cells" from the final "long" dataframe since they are not NAs. Maybe there is an easier way of doing this of the data is not treated as a dataframe? The original data file that is

Re: [R] reshaping data

2010-05-20 Thread Henrique Dallazuanna
Try this: x_long <- reshape(x, direction = 'long', varying = 2:4, sep = '', idvar = 'V1', timevar = 'V') subset(x_long[order(x_long$V1),], V != "") On Thu, May 20, 2010 at 2:13 PM, Mia Bengtsson wrote: > Hello, > > I am a relatively new R-user who has a lot to learn. I have a large dataset > tha

Re: [R] reshaping data

2010-03-31 Thread David Winsemius
On Mar 31, 2010, at 2:37 PM, Kim Jung Hwa wrote: Thanks Henrique and Stephan for your reply! Henrique, I'm planning to do some arthitmetic operations on tranformed (matrix) data and then would like to convert it back to original format (as a data frame)... is there an equivalent easy command

Re: [R] reshaping data

2010-03-31 Thread Henrique Dallazuanna
Try: as.data.frame(with(x, tapply(Val, list(Var1, Var2), sum))) On Wed, Mar 31, 2010 at 3:37 PM, Kim Jung Hwa wrote: > Thanks Henrique and Stephan for your reply! > > Henrique, I'm planning to do some arthitmetic operations on tranformed > (matrix) data and then would like to convert it back t

Re: [R] reshaping data

2010-03-31 Thread Kim Jung Hwa
Actually, apart from melt() in reshape package. On Wed, Mar 31, 2010 at 2:37 PM, Kim Jung Hwa wrote: > Thanks Henrique and Stephan for your reply! > > Henrique, I'm planning to do some arthitmetic operations on tranformed > (matrix) data and then would like to convert it back to original format (

Re: [R] reshaping data

2010-03-31 Thread Kim Jung Hwa
Thanks Henrique and Stephan for your reply! Henrique, I'm planning to do some arthitmetic operations on tranformed (matrix) data and then would like to convert it back to original format (as a data frame)... is there an equivalent easy command for this too? Thanks, On Wed, Mar 31, 2010 at 2:26 PM

Re: [R] reshaping data

2010-03-31 Thread Stephan Kolassa
Hi Kim, look at the reshape() command with direction="wide". Or at the reshape package. HTH, Stephan Kim Jung Hwa schrieb: Hi All, Can someone help me reshape following data: Var1 Var2 Val A X 1 A Y 2 A Z 3 B X 4 B Y 5 B Z 6 to some kind of matrix/tabular format (preferably as a matrix),

Re: [R] reshaping data

2010-03-31 Thread Henrique Dallazuanna
Try this: xtabs(Val ~ Var1 + Var2, data = x) On Wed, Mar 31, 2010 at 3:23 PM, Kim Jung Hwa wrote: > Hi All, > > Can someone help me reshape following data: > > Var1 Var2 Val > A X 1 > A Y 2 > A Z 3 > B X 4 > B Y 5 > B Z 6 > > to some kind of matrix/tabular format (preferably as a matrix), may b

Re: [R] Reshaping data with xtabs giving me 'extra' data

2010-01-20 Thread Henrique Dallazuanna
You can use this instead: with(do.call(rbind, df.list), tapply(Score, list(Date, Show, Time), invisible)) On Wed, Jan 20, 2010 at 3:02 PM, Tony B wrote: > Thank you for taking the time to reply Henrique. Although your > solution does take away the zeroes and replaces them with NA's (which > i pr

Re: [R] Reshaping data with xtabs giving me 'extra' data

2010-01-20 Thread Tony B
Thank you for taking the time to reply Henrique. Although your solution does take away the zeroes and replaces them with NA's (which i prefer), it unfortunately seems to reduce all of the other scores to just '1': > x <- with(do.call(rbind, df.list), tapply(Score, list(Date, Show, Time), > length

Re: [R] Reshaping data with xtabs giving me 'extra' data

2010-01-20 Thread Henrique Dallazuanna
Try with tapply: with(do.call(rbind, df.list), tapply(Score, list(Date, Time, Show), length)) On Wed, Jan 20, 2010 at 10:20 AM, Tony B wrote: > Dear all, > > Lets say I have several data frames as follows: > >> set.seed(42) >> dates <- as.Date(c("2010-01-19", "2010-01-20")) >> times <- c("09:30

Re: [R] reshaping data

2009-11-24 Thread Henrique Dallazuanna
Try this; with(x, data.frame(Case = rep(Case, (Endyear - Startyear) + 1), Year = unlist(mapply(seq, Startyear, Endyear On Tue, Nov 24, 2009 at 4:14 PM, Joseph Magagnoli wrote: > Hi all, > I have a dataframe that has one observation per case. > for example: > > Case

Re: [R] reshaping data frame

2008-02-22 Thread ahimsa campos-arceiz
Dear Chuck, John, Vikas, and useRs, thank you very much for your great suggestions. I received three replies providing different ways to reshape my original data.frame (original question at the bottom). There are however some discrepancies in their results (most likely because I didn't explain my

Re: [R] reshaping data frame

2008-02-21 Thread Vikas Rawal
> # 2. create one new row for each case in level.1 and level.2 > > # the new reshaped data.frame would should look like this: > > # indiv factorcovar case.id > # A level.1 4.6141051 > # A level.1 4.6141052 > # A level.2 31.0644051 > # A level.2 31.064405

Re: [R] reshaping data frame

2008-02-21 Thread John Kane
Here is a very clumsy way to do it but I think it works fact1 <- rep("level.1", length(mydat[,1])) fact2 <- rep("level.2", length(mydat[,1])) lels <- c(fact1,fact2) nams <- c("indiv", "case.id", "covar") set1 <- mydat[, c(1,2,3)] ; names(set1) <- nams set2 <- mydat[,c(1, 4,5)] ; names(set2) <-

Re: [R] reshaping data frame

2008-02-20 Thread Chuck Cleland
On 2/20/2008 1:14 PM, ahimsa campos-arceiz wrote: > Dear all, > > I'm having a few problems trying to reshape a data frame. I tried with > reshape{stats} and melt{reshape} but I was missing something. Any help is > very welcome. Please find details below: > > # > #