t.org)
> Subject: [R] Reshaping Data in R - Transforming Two Columns Into One
>
> I have the following data frame. Using the stringr package, I've
> attempted
> to map the url's to some specific elements that are in each url. I then
> used the reshape package to join tw
I have the following data frame. Using the stringr package, I've attempted
to map the url's to some specific elements that are in each url. I then
used the reshape package to join two different data frames. The next step
is to transform the two columns in the mydt data frame (forester and
customer_
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
0
>
> A.K.
>
>
>
>
> From: sylvain willart
> To: r-help ; sylvain willart <
> sylvain.will...@gmail.com>
> Sent: Saturday, April 13, 2013 5:03 PM
> Subject: [R] Reshaping Data for bi-partite Network Analysis
>
>
> He
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
eople beach home school sport
# Joe 5 3 0 1
# Marc 0 4 2 0
# Mary 0 0 4 0
A.K.
From: sylvain willart
To: r-help ; sylvain willart
Sent: Saturday, April 13, 2013 5:03 PM
Subject: [R] Reshaping Data for bi
Hello
I have a dataset of people spending time in places. But most people don't
hang out in all the places.
it looks like:
> Input<-data.frame(people=c("Marc","Marc","Joe","Joe","Joe","Mary"),
+ place=c("school","home","home","sport","beach","school"),
+ time=c(2,4,3,1,
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)
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
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
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
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
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
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 "
Hello All,
I was wondering if it's possible to reshape data from long to wide in R without
using a "timevar". I've pasted some sample data below along with some code. The
data are sorted by Subject and Drug. I want to transpose the Drug variable into
multiple columns in alphabetical order.
My
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.
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')
>
>
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
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.
Below is an example of the columns of a
I have the following data (see RawData using dput below)
How do I get it in the following 3 column format (CO2 measurements are the
elements of the original data frame). I'm sure the package reshape is where
I should look, but I haven't figured out how.
Thanks ahead of time
Month Year CO2
J
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
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 again to the array (or list, doesn't matter) of matrices form.
However when using xtabs function it orders my rows alphabetically and
apparentl
e, split = "_", names =
c("begin.end","t")))
m.dat$variable <- NULL
dat.final <- cast(m.dat, ... ~ begin.end)
Hope it helps,
Ista
>
> --- On Mon, 7/19/10, Thomas Jensen wrote:
>
>> From: Thomas Jensen
>> Subject: [R] Reshaping data
>>
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
gt; From: Thomas Jensen
> Subject: [R] Reshaping data
> To: R-help@r-project.org
> Received: Monday, July 19, 2010, 6:48 PM
> Dear All,
>
> I have some data in the following shape:
>
> ID
> begin_t1 end_t1
> begin_t2 end_t2
> Thomas
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
Dear All,
I have some data in the following shape:
ID begin_t1end_t1 begin_t2end_t2
Thomas 11/03/0413/05/0604/02/0716/05/08
... ... ... ...
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
> -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
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
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
Hello,
I am a relatively new R-user who has a lot to learn. I have a large dataset
that is in the following dataframe format:
red A B C
green D
blueE F
Where red, green and blue are "species" names and A, B and C are observations
(corresponding to DNA sequen
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
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
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 (
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
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),
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
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 be like
Var1 X Y Z
A 1 2 3
B 4 5 6
Any help would be greatly appreciated,
Kim
[[alternative HTML version deleted]]
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
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
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
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:00", "11:30:00", "13:30:00", "15:30:00")
> shows <- c("Red Dwarf", "Being Human", "Doctor Who")
>
> df1 <- data.frame(Date = dates[1], Time = times[1], Sh
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
Hi all,
I have a dataframe that has one observation per case.
for example:
CaseStartyear Endyear
A 1979 1989
B 1950 1955
I would like to create a dataframe in which each case has
multiple observations corresponding to the start and end
Hi all,
I have a matrix of correlation values between all pairwise comparison in
an experiment. For example, I have 2 time points (1,2) each in
triplicate. Thus, I have the following matrix
1-1
1-2
1-3
2-1
2-2
2-3
1-1
NA
...
...
...
...
...
1-2
...
NA
...
...
...
...
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
> # 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
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) <-
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:
>
> #
> #
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:
#
# data in its original shape:
indiv <- rep(c("A","B"),c(10,10))
le
51 matches
Mail list logo