Many thanks to all, the first 3 solutions worked nicely but I did not get
around to tweaking properly the others. It's really nice to get thing going
in a "one liner" or about... Again greatly appreciated. Cheers!
--
View this message in context:
http://r.789695.n4.nabble.com/Simple-but-elusive-e
Try this:
transform(tmp[rep(seq(nrow(tmp)), as.numeric(tmp$V4)),], V4 = 1)
On Tue, Mar 29, 2011 at 3:15 PM, jjap wrote:
> Dear R-users,
>
> This should be simple but still eludes me:
>
> Given the following
> tmp<-as.data.frame(matrix(c(44, 10, "abc", 1, 44, 10, "def", 1, 44, 12,
> "abc", 2), 3,
p@r-project.org
> Subject: [R] Simple but elusive - expand back from counts
>
> Dear R-users,
>
> This should be simple but still eludes me:
>
> Given the following
> tmp<-as.data.frame(matrix(c(44, 10, "abc", 1, 44, 10, "def", 1, 44, 12,
>
On Tue, Mar 29, 2011 at 11:15:33AM -0700, jjap wrote:
> Dear R-users,
>
> This should be simple but still eludes me:
>
> Given the following
> tmp<-as.data.frame(matrix(c(44, 10, "abc", 1, 44, 10, "def", 1, 44, 12,
> "abc", 2), 3, 4, byrow=T))
>
> I want to expand the data to the following form
Hi,
You can use rep() to repeat the appropriate rows as in V4. For example:
tmp[rep(rownames(tmp), tmp$V4), ]
V1 V2 V3 V4
1 44 10 abc 1
2 44 10 def 1
3 44 12 abc 2
3.1 44 12 abc 2
if you wanted, you could then reset the row names to NULL to get 1, 2,
3, 4 rather than 3, 3.1
row
Dear R-users,
This should be simple but still eludes me:
Given the following
tmp<-as.data.frame(matrix(c(44, 10, "abc", 1, 44, 10, "def", 1, 44, 12,
"abc", 2), 3, 4, byrow=T))
I want to expand the data to the following form:
V1 V2 V3 V4
1 44 10 abc 1
2 44 10 def 1
3 44 12 abc 1
4 44 12 a
,2,3)
>
> Thanks, Shubha
>
> -Original Message-
> From: Doran, Harold [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, July 23, 2008 6:47 PM
> To: Shubha Vishwanath Karanth; [EMAIL PROTECTED]
> Subject: RE: [R] Simple... but...
>
> x <- c(1,3,5)
>
john seers (IFR) wrote:
>
>
>
>
> This is definitely the best way:
>
> c(lapply(1:length(x), function(i, x, y) c(x[i], y[i]), x, y),
> recursive=TRUE)
>
>
>
you'd better test it yourself; it simply won't do the job -- you get a
list of vectors, no?
(hint: replace the initial 'c' with 'unlis
ROTECTED]
>> Sent: Wednesday, July 23, 2008 9:17 AM
>> To: Doran, Harold; [EMAIL PROTECTED]
>> Subject: RE: [R] Simple... but...
>>
>> OK,
>>
>> Let x=c(4,2,2)
>> y=c(1,5,3)
>>
>> My result should be c(4,1,2,5,2,3)
>>
>> Th
On Wed, 23 Jul 2008, Shubha Vishwanath Karanth wrote:
If
x=c(1,3,5)
y=c(2,4,6)
I need a vector which is c(1,2,3,4,5,6) from x and y.
I am assuming that you want to interleave the vectors, but that is not the
only algorithm giving that result.
How do I do it? I mean the best way
as.
Shubha Vishwanath Karanth wrote:
> Hi R,
>
>
>
> If
>
> x=c(1,3,5)
>
> y=c(2,4,6)
>
>
>
> I need a vector which is c(1,2,3,4,5,6) from x and y.
>
>
>
> How do I do it? I mean the best way
>
>
... but seriously, rbind(x,y)[1:6] is one concise way to do it (x and y
are bound into rows i
Doran, Harold air.org> writes:
>
> Shubba
>
> I'm confused. Your first post said the result should be c(1,2,3,4,5,6)
> when x and y are combined. The code I sent does that. But here you say
> your result should be c(4,1,2,5,2,3).
>
> What do you want your result to actually be?
>
I think
>
> What do you want your result to actually be?
>
>> -Original Message-
>> From: Shubha Vishwanath Karanth [mailto:[EMAIL PROTECTED]
>> Sent: Wednesday, July 23, 2008 9:17 AM
>> To: Doran, Harold; [EMAIL PROTECTED]
>> Subject: RE: [R] Simple... but...
&
Try c(rbind(x, y))
On Wed, Jul 23, 2008 at 8:54 AM, Shubha Vishwanath Karanth
<[EMAIL PROTECTED]> wrote:
> Hi R,
>
>
>
> If
>
> x=c(1,3,5)
>
> y=c(2,4,6)
>
>
>
> I need a vector which is c(1,2,3,4,5,6) from x and y.
>
>
>
> How do I do it? I mean the best way
>
>
>
> Thanks, Shubha
>
>
>
> Thi
On 23-Jul-08 12:54:49, Shubha Vishwanath Karanth wrote:
> Hi R,
> If
> x=c(1,3,5)
> y=c(2,4,6)
>
> I need a vector which is c(1,2,3,4,5,6) from x and y.
> How do I do it? I mean the best way
> Thanks, Shubha
Your query is ambiguous, in that it is not clear whether you want
a) The elements of
> x <- c(1,3,5)
> y <- c(2,4,6)
> xy <- sort(c(x,y))
-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Shubha Vishwanath Karanth
Sent: Wednesday, July 23, 2008 8:55 AM
To: [EMAIL PROTECTED]
Subject: [R] Simple... but...
Hi R,
If
x=c
Hi Shubha,
Assuming you are after ordering by position in x and y (and not
values), how about
as.vector(t(cbind(x, y)))
HTH,
Jim Porzak
Responsys, Inc.
San Francisco, CA
http://www.linkedin.com/in/jimporzak
On Wed, Jul 23, 2008 at 5:54 AM, Shubha Vishwanath Karanth
<[EMAIL PROTECTED]> wrote:
>
+32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
http://perswww.kuleuven.be/dimitris_rizopoulos/
- Original Message -
From: "Shubha Vishwanath Karanth" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, July 23, 2008 2:54 P
G'day Shubha,
On Wed, 23 Jul 2008 18:24:49 +0530
"Shubha Vishwanath Karanth" <[EMAIL PROTECTED]> wrote:
> Hi R,
>
>
>
> If
>
> x=c(1,3,5)
>
> y=c(2,4,6)
>
>
>
> I need a vector which is c(1,2,3,4,5,6) from x and y.
>
>
>
> How do I do it? I mean the best way
R> as.vector(rbind
-
Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Namens Shubha Vishwanath Karanth
Verzonden: woensdag 23 juli 2008 14:55
Aan: [EMAIL PROTECTED]
Onderwerp: [R] Simple... but...
Hi R,
If
x=c(1,3,5)
y=c(2,4,6)
I need a vector which is c(1,2,3,4,5,6) from x and y.
How do I do it? I mean
How about this
as.vector(t(cbind(x,y)))
> -Original Message-
> From: Shubha Vishwanath Karanth [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, July 23, 2008 9:17 AM
> To: Doran, Harold; [EMAIL PROTECTED]
> Subject: RE: [R] Simple... but...
>
> OK,
>
> Let x
]
Subject: [R] Simple... but...
Hi R,
If
x=c(1,3,5)
y=c(2,4,6)
I need a vector which is c(1,2,3,4,5,6) from x and y.
How do I do it? I mean the best way
Thanks, Shubha
This e-mail may contain confidential and/or privileged
i...{{dropped:13
OK,
Let x=c(4,2,2)
y=c(1,5,3)
My result should be c(4,1,2,5,2,3)
Thanks, Shubha
-Original Message-
From: Doran, Harold [mailto:[EMAIL PROTECTED]
Sent: Wednesday, July 23, 2008 6:47 PM
To: Shubha Vishwanath Karanth; [EMAIL PROTECTED]
Subject: RE: [R] Simple... but...
x <-
Z=NULL;for (i in 1:3) Z=c(Z,c(x[i],y[i]))
On Wed, Jul 23, 2008 at 8:54 AM, Shubha Vishwanath Karanth
<[EMAIL PROTECTED]> wrote:
> Hi R,
>
>
>
> If
>
> x=c(1,3,5)
>
> y=c(2,4,6)
>
>
>
> I need a vector which is c(1,2,3,4,5,6) from x and y.
>
>
>
> How do I do it? I mean the best way
>
>
>
> Th
Shubha Vishwanath Karanth wrote:
> Hi R,
>
>
>
> If
>
> x=c(1,3,5)
>
> y=c(2,4,6)
>
>
>
> I need a vector which is c(1,2,3,4,5,6) from x and y.
>
>
>
> How do I do it? I mean the best way
>
>
>
the absolutely best way is:
?c
vQ
__
R-hel
x <- c(1,3,5)
y <- c(2,4,6)
sort(c(x,y))
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Shubha
> Vishwanath Karanth
> Sent: Wednesday, July 23, 2008 8:55 AM
> To: [EMAIL PROTECTED]
> Subject: [R] Simple... but..
]
Subject: [R] Simple... but...
Hi R,
If
x=c(1,3,5)
y=c(2,4,6)
I need a vector which is c(1,2,3,4,5,6) from x and y.
How do I do it? I mean the best way
Thanks, Shubha
This e-mail may contain confidential and/or privileged
i...{{dropped:13
ath Karanth [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, July 23, 2008 9:17 AM
> To: Doran, Harold; [EMAIL PROTECTED]
> Subject: RE: [R] Simple... but...
>
> OK,
>
> Let x=c(4,2,2)
> y=c(1,5,3)
>
> My result should be c(4,1,2,5,2,3)
>
> Thanks, Shubha
If I understand:
sort(c(x,y))
or if you want combine the elements:
as.vector(mapply(c, x, y))
On Wed, Jul 23, 2008 at 9:54 AM, Shubha Vishwanath Karanth
<[EMAIL PROTECTED]> wrote:
> Hi R,
>
>
>
> If
>
> x=c(1,3,5)
>
> y=c(2,4,6)
>
>
>
> I need a vector which is c(1,2,3,4,5,6) from x and y.
>
Hi R,
If
x=c(1,3,5)
y=c(2,4,6)
I need a vector which is c(1,2,3,4,5,6) from x and y.
How do I do it? I mean the best way
Thanks, Shubha
This e-mail may contain confidential and/or privileged i...{{dropped:13}}
__
R-help@r-proje
30 matches
Mail list logo