4, 2013 3:47 PM
Subject: Re: [R] question: data.frame data conversion
Hello,
You're insisting in as.data.frame(cbind(...)). Don't do that. Just see
the difference:
z = data.frame(x, y)
str(z)
'data.frame': 8 obs. of 2 variables:
$ x: Factor w/ 3 levels "a",&qu
y
1 a1
2 a 1.2
3 a 1.1
4 b 1.01
5 b 1.03
6 b1
7 c2
8 c3
-Original Message-
From: Rui Barradas [mailto:ruipbarra...@sapo.pt]
Sent: Sunday, August 04, 2013 1:57 PM
To: Brijesh Gulati
Cc: r-help@r-project.org
Subject: Re: [R] question: data.frame data conversion
Hello,
t; "b" "b" "b" "c" "c" "1" ...
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : chr [1:2] "x" "y"
A.K.
- Original Message -
From: Brijesh Gulati
To: 'arun'
Cc: 'R help'
ent: Sunday, August 4, 2013 8:49 AM
Subject: [R] question: data.frame data conversion
Hello, I have a data.frame with repeating rows and corresponding value. For
instance, "z" will be an example of that.
x = c("a","a", "a", "b","b",&qu
#actually, this would be more compact
data.frame(split(z[,-1],z$x))
A.K.
- Original Message -
From: arun
To: Brijesh Gulati
Cc: R help
Sent: Sunday, August 4, 2013 1:27 PM
Subject: Re: [R] question: data.frame data conversion
Hi,
May be:
z<-data.frame(x,y,stringsAsFactors=FA
1.2, 1.1, 1.01, 1.03, 1.0, 2.0, 3.0)
z = as.data.frame(cbind(x,y))
> z
xy
1 a1
2 a 1.2
3 a 1.1
4 b 1.01
5 b 1.03
6 b1
7 c2
8 c3
-Original Message-----
From: arun [mailto:smartpink...@yahoo.com]
Sent: Sunday, August 04, 2013 1:30 PM
To: Brijesh Gulati
Cc: R
ppreciated.
x = c("a","a", "a", "b","b","b", "c", "c")
y = c(1.0, 1.2, 1.1, 1.01, 1.03, 1.0, 2.0, 3.0)
z = as.data.frame(cbind(x,y))
x y
1 a1
2 a 1.2
3 a 1.1
4 b 1.01
5 b 1.03
6 b1
7 c2
8 c
Hello,
First of all, do _not_ create a data frame with
as.data.frame(cbind(...))
Instead, use
z = data.frame(x, y)
As for your question, try the following.
library(reshape2)
fun <- function(z){
zs <- split(z, x)
n <- length(zs)
m <- nrow(zs[[1]])
zz <- cbind(
Hello, I have a data.frame with repeating rows and corresponding value. For
instance, "z" will be an example of that.
x = c("a","a", "a", "b","b","b")
y = c(1.0, 1.2, 1.1, 1.01, 1.03, 1.0)
z = as.data.frame(cbind(x,y))
> z
xy
1 a1
2 a 1.2
3 a 1.1
4 b 1.01
5 b 1.03
9 matches
Mail list logo