Re: [R] reshape a dataset

2014-08-15 Thread sohail13
Great! Thanks Sent from my LG G Flex, an AT&T 4G LTE smartphone -- Original message-- From: Jorge I Velez Date: Fri, Aug 15, 2014 8:54 AM To: Sohail Khan; Cc: Jim Lemon;R Help; Subject:Re: [R] reshape a dataset If that's the case, you could do the following: d <- with(skd

Re: [R] reshape a dataset

2014-08-15 Thread Jorge I Velez
If that's the case, you could do the following: d <- with(skdat, table(ID, lettertag)) d <- data.frame(cbind(ID = rownames(d), d)) rownames(d) <- NULL d HTH, Jorge.- On Fri, Aug 15, 2014 at 8:22 PM, Sohail Khan wrote: > Thanks Jim and Jorge, > Clever solutions, the final output is a list. >

Re: [R] reshape a dataset

2014-08-15 Thread Jim Lemon
On Fri, 15 Aug 2014 06:22:53 AM Sohail Khan wrote: > Thanks Jim and Jorge, > Clever solutions, the final output is a list. > How do I covert it back a dataframe? > -Sohail > as.data.frame(newskdat) or for Jorge's as.data.frame(res) Jim __ R-help@r-pr

Re: [R] reshape a dataset

2014-08-15 Thread Sohail Khan
Thanks Jim and Jorge, Clever solutions, the final output is a list. How do I covert it back a dataframe? -Sohail On Fri, Aug 15, 2014 at 5:37 AM, Jorge I Velez wrote: > Dear Sohail, > > Using Jim's data set skdat, two more options would be > > # first option > d <- with(skdat, table(ID, lettert

Re: [R] reshape a dataset

2014-08-15 Thread Jorge I Velez
Dear Sohail, Using Jim's data set skdat, two more options would be # first option d <- with(skdat, table(ID, lettertag)) names <- colnames(d) d <- c(list(rownames(d)), lapply(1:ncol(d), function(i) as.numeric(d[,i]))) names(d) <- c('ID', names) d # second option d <- with(skdat, table(ID, letter

Re: [R] reshape a dataset

2014-08-15 Thread Jim Lemon
On Thu, 14 Aug 2014 06:08:51 PM Sohail Khan wrote: > Hi > I have data set as follows: > A 92315 A 35018 A 56710 B 52700 B 92315 B 15135 C 35018 C 52700 > I would like to transform this data set into: > ID 92315 35018 56710 52700 15135 A 1 1 1 0 0 B 1 0 0 1 1 C 0 1 0 1 0 > I looked i

[R] reshape a dataset

2014-08-15 Thread Sohail Khan
Hi I have data set as follows: A 92315 A 35018 A 56710 B 52700 B 92315 B 15135 C 35018 C 52700 I would like to transform this data set into: ID 92315 35018 56710 52700 15135 A 1 1 1 0 0 B 1 0 0 1 1 C 0 1 0 1 0 I looked into reshape package to no avail. I would appreciate any suggestio