On Mar 24, 2014, at 9:02 AM, Tham Tran wrote:
> Dears R Users,
>
> I have another question on function "stack".
>
> Given a data frame like:
> df=data.frame(a=c(3,5),b=c(2,8),a=c(9,1),b=c(6,4),check.names=F)
> a b a b
> 3 2 9 6
> 5 8 1 4
>
I did not create your stack function which woul
I sent that last email too quickly, the duplicate column names cause a
problem when melting. Transposing the data frame first gets around it:
reshape2::melt(t(df))[c('Var1', 'value')]
Var1 value
1a 3
2b 2
3a 9
4b 6
5a 5
6b 8
7a 1
8b
The reshape2 package may be what you're looking for:
http://cran.r-project.org/web/packages/reshape2/index.html
install.packages("reshape2")
reshape2::melt(df)
On 2014-03-24 12:02, Tham Tran wrote:
Dears R Users,
I have another question on function "stack".
Given a data frame like:
df=dat
Dears R Users,
I have another question on function "stack".
Given a data frame like:
df=data.frame(a=c(3,5),b=c(2,8),a=c(9,1),b=c(6,4),check.names=F)
a b a b
3 2 9 6
5 8 1 4
I would like to form a new data frame like:
values ind
1 3 a
2 5 a
3 2 b
4 8 b
Hi,
You may try:
library(reshape2)
res <- setNames(melt(as.matrix(df))[,c(3,2)],c("values","ind"))
res2 <- stack(df, check.names = FALSE)
identical(res,res2)
#[1] TRUE
A.K.
Dears R Users,
I have another question on function "stack".
Given a data frame like:
df=data.frame(a=c(3,5),b=c(2,8)
5 matches
Mail list logo