Re: [R] reshape() not dropping varaibles

2023-12-10 Thread Jeff Newmiller via R-help
It would be nice to see what OP wanted to end up with, but the link contained input data to experiment with. The first problem is that if you are not interested in working with the whole set of columns then you need to only give a data frame with the columns you want to work with: dta.wide <-

Re: [R] reshape() not dropping varaibles

2023-12-10 Thread Bert Gunter
Posting a few rows, say 5, of your data using dput() along with the result that you would like to get for those rows would help get you a quicker and more accurate response, I believe. This is as suggested by the posting guide, linked below, which you should read if you have not already. -- Bert

[R] reshape() not dropping varaibles

2023-12-10 Thread Bob O'Hara
Hi all! I1m trying to re-format some data from long to wide format with reshape(). Specifically, the data has SURVEYDATE, which I want to be in the rows, and COMMON_NAME which should be the columns. The entries should be TOTAL_CATCH. The data has a bunch of other variables, which can be ignored.

Re: [R] Reshape to wide format

2016-12-28 Thread David L Carlson
;year", "month")? --- David L. Carlson Department of Anthropology Texas A&M University From: Miluji Sb [mailto:miluj...@gmail.com] Sent: Thursday, December 22, 2016 8:19 AM To: David L Carlson Cc: Jim Lemon ; r-help mailing list

Re: [R] Reshape to wide format

2016-12-22 Thread Miluji Sb
129 > 9 9 0.000 NA > 1010 0.000 NA > 1111 0.1215360 NA > 1212 0.3886606 NA > > - > David L Carlson > Department of Anthropology > Texas A&M U

Re: [R] Reshape to wide format

2016-12-13 Thread David L Carlson
tment of Anthropology Texas A&M University College Station, TX 77840-4352 -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Jim Lemon Sent: Tuesday, December 13, 2016 2:59 AM To: Miluji Sb; r-help mailing list Subject: Re: [R] Reshape to wide format Hi

Re: [R] Reshape to wide format

2016-12-13 Thread Jim Lemon
Hi Milu, I may have the wrong idea, but is this what you want? temp$ID<-paste(temp$iso3,temp$lon,temp$lat,sep="") library(prettyR) newtemp<-stretch_df(temp,"month","precip")[,c(5,7,8)] names(newtemp)<-c("month",unique(temp$ID)) Jim On Tue, Dec 13, 2016 at 4:10 AM, Miluji Sb wrote: > Dear all,

Re: [R] Reshape to wide format

2016-12-12 Thread Subodh Adhikari
For long to wide, try *dcas*t function in reshape2 package. (*melt* is from wide to long). Subodh On Mon, Dec 12, 2016 at 10:10 AM, Miluji Sb wrote: > [image: Boxbe] Miluji Sb ( > miluj...@gmail.com) is not on your Guest List >

[R] Reshape to wide format

2016-12-12 Thread Miluji Sb
Dear all, I have the following monthly data by coordinates: I would like to reshape this data to wide format so that each column is a coordinate and each row is a month, coordinate1 coordinate2 coordinate3... Month 1 Month 2 Is the best option to concatenate the iso3, lon, and lat variables to

Re: [R] reshape: melt and cast

2015-09-01 Thread Matthew Pickard
Yep, that works. Thanks, Stephen. I should have drawn the parallel with Excel Pivot tables sooner. On Tue, Sep 1, 2015 at 9:36 AM, stephen sefick wrote: > I would make this minimal. In other words, use an example data set, dput, > and use output of dput in a block of reproducible code. I don't u

Re: [R] reshape: melt and cast

2015-09-01 Thread Matt Pickard
Thanks, Stephen. I've looked into the fun.aggregate argument. I don't want to aggregate, so I thought leaving it blank (allowing it to default to NULL) would do that. Here's a corrected post (with further explanation): Hi, I have data that looks like this: >dput(head(ratings)) structure(list(Q

Re: [R] reshape: melt and cast

2015-09-01 Thread stephen sefick
You are welcome. On Tue, Sep 1, 2015 at 10:44 AM, Matthew Pickard < matthew.david.pick...@gmail.com> wrote: > Yep, that works. Thanks, Stephen. I should have drawn the parallel with > Excel Pivot tables sooner. > > On Tue, Sep 1, 2015 at 9:36 AM, stephen sefick wrote: > >> I would make this mini

Re: [R] reshape: melt and cast

2015-09-01 Thread stephen sefick
I would make this minimal. In other words, use an example data set, dput, and use output of dput in a block of reproducible code. I don't understand exactly what you want, but does sum work? If there is more than one record for a given set of factors the sum is the sum of the counts. If only one re

Re: [R] reshape: melt and cast

2015-08-31 Thread stephen sefick
This is very hard to read. Please use dput to provide data. I believe the answer is in the manual. Look at the aggregation function argument. Please excuse my brevity; this message was sent from my telephone. On Sep 1, 2015 12:11 AM, "Matt Pickard" wrote: > Hi, > > I have data that looks like th

[R] reshape: melt and cast

2015-08-31 Thread Matt Pickard
Hi, I have data that looks like this: *> head(ratings) QCode PID RaterName SI1 SI2 SI3 SI4 SI5 SI6 SI7 SI8 SI9 SI10 SI111 GUILT 1123 cwormhoudt 2 2 3 1 1 1 3 3 3 212 LOVE 1123 cwormhoudt 1 2 3 2 1 1 1 1 11 33 GUILT 1136 cwormhoudt 1 2

Re: [R] reshape a data frame

2015-06-04 Thread David L Carlson
Anthropology Texas A&M University College Station, TX 77840-4352 -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Bert Gunter Sent: Thursday, June 4, 2015 8:58 AM To: javascriptart25 Cc: r-help@r-project.org Subject: Re: [R] reshape a data frame

Re: [R] reshape a data frame

2015-06-04 Thread Bert Gunter
Yes. This is basic stuff, and it seems unnecessary to run to packages for it, Knowledge of base R should suffice. It would appear that the OP would benefit by going through an R tutorial or two. Slightly more economical and more general -- and trickier -- than explicit concatenation, which could g

Re: [R] reshape a data frame

2015-06-03 Thread javascriptart25
You can change ex <- data.frame("gIN" = gIN, "bc1" = bc1, "bc2"=bc2, "group" = group) to ex <- data.frame("gIN" = c(gIN,gIN), "bcX" = c(bc1,bc2), "group" = c(group,group)) On Wed, Jun 3, 2015 at 2:27 PM, hedelhusk [via R] < ml-node+s789695n4708145...@n4.nabble.com> wrote: > Hello, > > I would

Re: [R] reshape a data frame

2015-06-03 Thread Jon BR
I found the gather function from the tidyr package, which worked nicely: gather(ex,bcX,value, bc1:bc2) gIN group bcX value 1 A_1 A bc1 1219.79 2 A_2 A bc1 1486.84 3 A_3 A bc1 1255.80 4 A_4 A bc1 941.87 5 B_1 B bc1 588.19 6 B_2 B bc1

Re: [R] reshape a data frame

2015-06-03 Thread John Kane
...@gmail.com > Sent: Wed, 3 Jun 2015 18:25:02 -0400 > To: r-help@r-project.org > Subject: Re: [R] reshape a data frame > > I found the gather function from the tidyr package, which worked nicely: > > gather(ex,bcX,value, bc1:bc2) >gIN group bcX value > 1 A_1

[R] reshape a data frame

2015-06-03 Thread Jon BR
Hello, I would like to ask for some advice in reformatting a data frame such as the following one: gIN <- c("A_1","A_2","A_3","A_4","B_1","B_2") bc1 <- c(1219.79, 1486.84, 1255.80, 941.87, 588.19, 304.02) bc2 <- c(319.79, 186.84, 125.80, 94.87, 1008.19, 314.02) group <- c("A","A","A","A","B","B"

Re: [R] reshape data frame when one column has unequal number of entries

2015-04-23 Thread Dimitri Liakhovitski
mitri > Liakhovitski > Sent: Thursday, 23 April 2015 23:15 > To: r-help > Subject: [R] reshape data frame when one column has unequal number of > entries > > Hello! > > I have my data frame x with 2 character columns: > > x <- data.frame(a = numeric(), b =

Re: [R] reshape data frame when one column has unequal number of entries

2015-04-23 Thread PIKAL Petr
f Maybe you want to remove extra white space form your values. It is mentioned somewhere in help pages to regular expressions Cheers Petr > -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Dimitri > Liakhovitski > Sent: Thursday, April 23,

Re: [R] reshape data frame when one column has unequal number of entries

2015-04-23 Thread Duncan Mackay
351 Email: home: mac...@northnet.com.au -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Dimitri Liakhovitski Sent: Thursday, 23 April 2015 23:15 To: r-help Subject: [R] reshape data frame when one column has unequal number of entries Hello! I have my

[R] reshape data frame when one column has unequal number of entries

2015-04-23 Thread Dimitri Liakhovitski
Hello! I have my data frame x with 2 character columns: x <- data.frame(a = numeric(), b = I(list())) x[1:3,"a"] = 1:3 x[[1, "b"]] <- "a, b, c" x[[2, "b"]] <- "d, e" x[[3, "b"]] <- "f" x$a = as.character(x$a) x$b = as.character(x$b) x str(x) I need to produce this data frame: 1 a 1 b 1 c 2

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

Re: [R] Reshape large Data Frame to new format

2014-04-30 Thread Arunkumar Srinivasan
al Message----- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of arun > Sent: Monday, March 24, 2014 9:57 AM > To: r-help@r-project.org > Cc: Dark > Subject: Re: [R] Reshape large Data Frame to new format > > Hi, > In your 

Re: [R] Reshape large Data Frame to new format

2014-03-24 Thread David Carlson
l Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of arun Sent: Monday, March 24, 2014 9:57 AM To: r-help@r-project.org Cc: Dark Subject: Re: [R] Reshape large Data Frame to new format Hi, In your 'resultData", some observations seems to be omitte

Re: [R] Reshape large Data Frame to new format

2014-03-24 Thread arun
Hi, In your 'resultData", some observations seems to be omitted. with(rawData,tapply(codes, PersonID,FUN=function(x) x))$Person3  #[1] 56177 61704 70879 69033 87224 68670 65602 25476 81209 62086 35492 39771 #[13] 14380 43858 53679 78023 43785 69884 12840 54021 resultData[4,] #  PersonId Code1 Code

[R] Reshape large Data Frame to new format

2014-03-24 Thread Dark
Hi R-experts, I have a data.frame that I want to reshape to a certain format so I can use it in a tool for further analysis. Basicly I have a very long list with IDs of persons and their codes. I create a row for every person with 25 of their codes. I a person has more then 25 codes, I want to ad

Re: [R] reshape non-square matrix

2014-03-04 Thread Jeff Newmiller
On Tue, 4 Mar 2014, Chirag Gupta wrote: Jeff This works fine for smaller ones but I have a big dataframe. Its ~35000 X 30. When I try this command, it says "Using  as id variables". Thank you. You asked for a solution regarding a matrix. Now you talk about data frames. And in responding to

Re: [R] reshape non-square matrix

2014-03-04 Thread Chirag Gupta
Jeff This works fine for smaller ones but I have a big dataframe. Its ~35000 X 30. When I try this command, it says "Using as id variables". Thank you. On Sat, Mar 1, 2014 at 12:38 AM, Jeff Newmiller wrote: > library(reshape2) > mx <- matrix( 1:12, nrow=3 ) > mxdf <- melt( mx ) > names( mxdf

Re: [R] reshape non-square matrix

2014-03-04 Thread arun
Hi, You didn't provide any reproducible example to start with. Using Jeff's example mx <- matrix( 1:12, nrow=3 ) dimnames(mx) <- list(1:nrow(mx),1:ncol(mx)) ## setNames(as.data.frame.table(mx),c("m","n","value"))   m n value 1  1 1 1 2  2 1 2 3  3 1 3 4  1 2 4 5  2 2 5 6 

Re: [R] reshape non-square matrix

2014-03-04 Thread Chirag Gupta
This takes away names of all the variables On Sat, Mar 1, 2014 at 9:30 AM, arun wrote: > > > Hi, > You could try: > #If mat1 is the matrix > dimnames(mat1) <- list(1:nrow(mat1),1:ncol(mat1)) > setNames(as.data.frame.table(mat1),c("m","n","value")) > A.K. > > > On Friday, February 28, 2014 11:40

Re: [R] reshape non-square matrix

2014-03-01 Thread arun
Hi, You could try: #If mat1 is the matrix dimnames(mat1) <- list(1:nrow(mat1),1:ncol(mat1)) setNames(as.data.frame.table(mat1),c("m","n","value")) A.K. On Friday, February 28, 2014 11:40 PM, Chirag Gupta wrote: Hi list I have a matrix of size m x n (m and n are different, hence non square!)

Re: [R] reshape non-square matrix

2014-02-28 Thread Jeff Newmiller
library(reshape2) mx <- matrix( 1:12, nrow=3 ) mxdf <- melt( mx ) names( mxdf ) <- c( "m", "n", "value" ) --- Jeff NewmillerThe . . Go Live... DCN:Basics: ##.#. ##.#. L

Re: [R] reshape non-square matrix

2014-02-28 Thread Rolf Turner
On 01/03/14 14:49, Chirag Gupta wrote: Hi list I have a matrix of size m x n (m and n are different, hence non square!) I want to melt it in such a way that I get a df of 3 columns. m ,n Surely you mean i, j (i = 1, ..., m), j = 1, ..., n). and cell value in the original matrix. Yes:

[R] reshape non-square matrix

2014-02-28 Thread Chirag Gupta
Hi list I have a matrix of size m x n (m and n are different, hence non square!) I want to melt it in such a way that I get a df of 3 columns. m ,n and cell value in the original matrix. Any suggestions? -- *Chirag Gupta* Department of Crop, Soil, and Environmental Sciences, 115 Plant Sciences

Re: [R] reshape data frame

2013-11-18 Thread tsippel
Thanks, that seems to work. On Fri, Nov 15, 2013 at 10:26 PM, arun kirshna [via R] < ml-node+s789695n4680556...@n4.nabble.com> wrote: > Hi, > > Try: > var1 <- load("reshape_data.frame.RData") > ##It is better not to name the objects with function names. > dat1 <- data > reshape1 <- reshape > na

Re: [R] reshape

2013-11-17 Thread arun
Hi Felipe, You may try ?mutate() with ?ddply() from library(plyr) library(plyr) library(reshape2) res <- dcast(ddply(z,.(week),mutate,ID=seq_along(week)),ID~week,value.var="length")[,-1] If you have multiple years, probably you may need: z1 <- z ##using the same example z1[,1] <- gsub("(.\\/.*\

Re: [R] reshape

2013-11-17 Thread arun
Felipe, I get the results like this by running the code: z <-read.table(text="date week length 7/13/2010 28 34 7/13/2010 28 35 7/14/2010 28 35 7/14/2010 28 35 7/14/2010 28 36 7/14/2010 28 36 7/20/2010 29 31 7/16/2010 29 34 7/18/2010 29 34 7/18/2010 29 34 7/21/2010 29 35 7/20/2010 29 36 7/21/2010 2

Re: [R] reshape data frame

2013-11-15 Thread arun
Hi, Try: var1 <- load("reshape_data.frame.RData") ##It is better not to name the objects with function names. dat1 <- data  reshape1 <- reshape names(dat1)[grep("X\\d+",names(dat1))] <- gsub("[[:alpha:]]","X_",names(dat1)[grep("X\\d+",names(dat1))]) res1 <- reshape(dat1,direction="long",varying=7

Re: [R] Reshape

2013-10-16 Thread arun
HI, A minor change to make it a bit more generic.  res <- reshape(ddply(df,.(Person), mutate,id=((seq_along(Person)-1)%%2+1)),idvar=c("Person","Date"),timevar="id",direction="wide")   colnames(res)[3:4] <- paste0("Amt",1:2)  rownames(res) <- 1:nrow(res) In cases like: df1 <- rbind(df,data.frame(

Re: [R] Reshape

2013-10-16 Thread arun
Hi, Try: library(plyr)  res <- reshape(ddply(df,.(Person),mutate,id=rep(1:2,length(Person)/2)),idvar=c("Person","Date"),timevar="id",direction="wide")  colnames(res)[3:4] <- paste0("Amt",1:2) rownames(res) <- 1:nrow(res)   res #  Person   Date Amt1 Amt2 #1  1 12/01/2012  100   10 #2 

[R] Reshape

2013-10-16 Thread Kimberly Harris-McCoy
Hello, I have data frame like the one created below, ##input data Person <- c(1,1,1,1,1,1,2,2) Amount <- c(100,10,100,10,100,10,50,150) Date <- c("12/01/2012", "12/01/2012", "01/01/2013","01/01/2013","02/01/2013","02/01/2013","12/01/2012","12/01/2012") df <- data.frame(Person,Amount,Date)

Re: [R] Reshape problem

2013-09-30 Thread arun
Hi, May be this helps. dat1<- structure(list(trialnumber = 1:9, Control = c(0L, 1L, 0L, 0L, 1L, 0L, 1L, 0L, 0L), HC = c(0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 1L ), LC = c(1L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L), pleasantness = c(3L, 3L, 2L, 2L, 3L, 4L, 3L, 3L, 2L)), .Names = c("trialnumber", "Control", "H

Re: [R] Reshape

2013-07-30 Thread Jim Lemon
On 07/30/2013 11:41 PM, Dominic Roye wrote: Hello, I try out to create a new form from the below data.frame. I would like to have this form: V3 Santiago Ourense VigoFerrol 2013-07-04 2013-07-04 07:01:04 .. How ca

Re: [R] Reshape

2013-07-30 Thread arun
lt;-dcast(sunrise,V3~day_frac,value.var="time") res  #     V3  Ferrol Ourense    Santiago #1 2013-07-04 2013-07-04 06:57:38 2013-07-04 07:00:05 2013-07-04 07:01:04 #2 2013-07-05 2013-07-05 06:58:16 2013-07-05 07:00:41 2013-07-05 07:01:41 #3 2013-07-06

Re: [R] Reshape

2013-07-30 Thread John Kane
To: r-help@r-project.org > Subject: [R] Reshape > > Hello, > > I try out to create a new form from the below data.frame. > > I would like to have this form: > > V3 Santiago Ourense VigoFerr

[R] Reshape

2013-07-30 Thread Dominic Roye
Hello, I try out to create a new form from the below data.frame. I would like to have this form: V3 Santiago Ourense VigoFerrol 2013-07-04 2013-07-04 07:01:04 .. How can i get this? > str(sunrise) 'data.frame': 24

Re: [R] Reshape or Plyr?

2013-04-22 Thread Law, Jason
vironmental Services Water Pollution Control Laboratory 6543 N Burlington Avenue Portland, OR 97203-5452 503-823-1038 jason@portlandoregon.gov -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Bruce Miller Sent: Saturday, April 20, 2013

Re: [R] Reshape or Plyr?

2013-04-21 Thread arun
To: arun Cc: Sent: Sunday, April 21, 2013 6:18 PM Subject: Re: [R] Reshape or Plyr? Hi Arun, Your first example is what looks like the correct one but needs the Location_name as in your 2nd example. I do want to group by "Location_name". The full data set will include up to 100 L

Re: [R] Reshape or Plyr?

2013-04-21 Thread Arhopala
Hi Bruce It sounds like the aggregate function is what you need. Here's an example using the ChickWeight dataset in R: chick.agg<-aggregate(ChickWeight[,c('weight', 'Time')], by = ChickWeight[c('Chick','Diet')], sum) weight.time<-chick.agg$weight/chick.agg$Time chick.agg.df<-data.frame(chick.

Re: [R] Reshape or Plyr?

2013-04-21 Thread arun
ot;Std_AI"), class = "data.frame", row.names = c(NA, -42L)) library(plyr) res<- mutate(ddply(dat1,.(SPEC_CODE,Location_name),function(x) colSums(x[,-c(1:3,6)])),SumAIbySumST=Survey_Time/AI,Std.SumAIbySumST=10*SumAIbySumST) res #   SPEC_CODE    Location_name Survey_Time AI SumAI

Re: [R] Reshape or Plyr?

2013-04-21 Thread arun
10  3.846154 From: Bruce Miller To: arun Sent: Sunday, April 21, 2013 4:19 PM Subject: Re: [R] Reshape or Plyr? Hi Arun, This looks good; however the not quite correct yet. Looks like the mutate option may be a good place to start. Sorry I did not clearly exp

[R] Reshape or Plyr?

2013-04-20 Thread Bruce Miller
H all, I have relative abundance data from >100 sites. This is from acoustic monitoring and usually the data is for 2-3 nights but in some cases my be longer like months or years for each location.. The data output from my management data base is proved by species by night for each location so

Re: [R] reshape

2013-03-13 Thread arun
Hi Elisa, You need to check your data.  For some 'st', the data is repeated/duplicated (I am assuming, didn't check it) especially for a particular year. dat1<-read.csv("elisa.csv",sep="\t") dat1$st<- as.character(dat1$st)  str(dat1) #'data.frame':    506953 obs. of  5 variables: # $ st   :

Re: [R] reshape help

2013-02-04 Thread arun
   0     0         1            0              1      1   #pneumonia #1         0 #2         1 #3         0 A.K. - Original Message - From: Robert Strother To: r-help@r-project.org Cc: Sent: Monday, February 4, 2013 3:16 AM Subject: [R] reshape help Dear R users - I have a list of patie

Re: [R] reshape help

2013-02-04 Thread Eik Vettorazzi
Hi Robert, how about this? tmp<-read.table(text="ID Dx Anausea Adiabetes Akidney_failure Aheart_attack Afever Bfever Bpneumonia Bheart_attack Bnausea Bcough Ckidney_failure Cnausea Cfoot_pain",header=T) data.frame(cbind(ID=levels(tmp$ID),(tabl

Re: [R] reshape

2012-11-13 Thread David Winsemius
as a matrix: > newmat<-do.call(rbind,strsplit(as.character(dat1[[1]]),split=":")) > n12<-2400-as.numeric(newmat[,2]) > newmat2<-cbind(newmat,n12) > colnames(newmat2)[1:2]<-c("Variable","n11") > A.K. > > > - Original Message

Re: [R] reshape

2012-11-13 Thread Flavio Barros
(newmat[,2]) > newmat2<-cbind(newmat,n12) > colnames(newmat2)[1:2]<-c("Variable","n11") > A.K. > > > > > > > - Original Message - > From: farnoosh sheikhi > To: "r-help@R-project.org" > Cc: > Sent: Monday, Novembe

Re: [R] reshape

2012-11-12 Thread arun
uot;Variable","n11") A.K. ----- Original Message - From: farnoosh sheikhi To: "r-help@R-project.org" Cc: Sent: Monday, November 12, 2012 5:52 PM Subject: [R] reshape Hi, I have a R output that looks as follow: Rad:0 Rad1:2 Rad3:3 I want to make a new

[R] reshape

2012-11-12 Thread farnoosh sheikhi
Hi, I have a R output that looks as follow: Rad:0 Rad1:2 Rad3:3 I want to make a new matrix that looks like : sample size is 2400 Variable    n11  n12 Rad            0     2400-0=2400 Rad1          2       2400-2 Rad3  3      2400-3   Thanks a lot for your time and help:) Best,Farnoosh Sheikhi

[R] reshape and geeglm problem

2012-09-07 Thread Lilia Verchinina
Dear R users, could you please help me figure out why I am getting an error? Initially my data looks like this: > attributes(compl)$names [1] "UserID" "compl_bin" "Sex.x" "PHQ_base" "PHQ_Surv1" "PHQ_Surv2" "PHQ_Surv3" [8] "PHQ_Surv4" "EFE"

Re: [R] reshape cast to a sparse matrix?

2012-08-16 Thread Martin Maechler
> Yin Aphinyanaphongs > on Tue, 14 Aug 2012 09:13:21 -0400 writes: > I am using the reshape package to convert a series of > values into a binary matrix. The binary matrix is very > sparse with many zeros and I'd like to use cast to > generate a sparse matrix using any

[R] reshape cast to a sparse matrix?

2012-08-14 Thread Yin Aphinyanaphongs
I am using the reshape package to convert a series of values into a binary matrix. The binary matrix is very sparse with many zeros and I'd like to use cast to generate a sparse matrix using any of the sparse matrix packages of choice. Is there functionality to support this use? Are there strategi

Re: [R] reshape -> reshape 2: function cast changed?

2012-07-25 Thread arun
ill = fill,    drop = drop, value.var = value.var) 1: dcast(dfmmelt, variable ~ Species, value.var = "value", max) The output seems to be correct. A.K. - Original Message - From: Johannes Radinger To: r-help@r-project.org Cc: Sent: Wednesday, July 25, 2012 6:14 AM Subj

Re: [R] reshape -> reshape 2: function cast changed?

2012-07-25 Thread Jeff Newmiller
Not really answering your posed question, but a) reshape2 uses dcast and acast b) The "cast" step of "melt-cast-melt" can invoke plyr, and it seems like MCM is just a very inefficient way for you to get at the plyr functionality. Perhaps you should take a more direct route to your goal? ---

[R] reshape -> reshape 2: function cast changed?

2012-07-25 Thread Johannes Radinger
Hi, I used to use reshape and moved to reshape2 (R 2.15.1). Now I tried some of my older scripts and was surprised that my cast function wasn't working like before. What I did/want to do: 1) Melt a dataframe based on a vector specifying column names as measure.vars. Thats working so far: dfm <-

Re: [R] reshape

2012-06-21 Thread nrm2010
Hello, Jim, Thank you for the new version. I'm still verifying that everything is running correctly with the real data but it looks good so far. Thank you very much for your assistance. grep syntax is a bit mysterious... Toby On Wed, 20 Jun 2012 16:58:44 -0700 jim holtman wrote

Re: [R] reshape

2012-06-21 Thread arun
7,10)]) colnames(toynew)<-c(colnames(toymeltVWC2),"type2","value2") It's kind of an ugly way of arriving at the result and it may not be helpful in real data. A.K. - Original Message - From: jim holtman To: nrm2010 Cc: r-help Sent: Wednesday, June 20,

Re: [R] reshape

2012-06-20 Thread jim holtman
Something got lost in the transmission since the '\\' were replaced with '\' I will try gain with the data: (also attached as a text file) require(reshape2) toy <- data.frame(year = rep(2007:2008,each = 20), month = rep(1:5,each = 4, length = 40), day = rep(1:2,each = 2,length = 40), hhmm = re

Re: [R] reshape

2012-06-20 Thread nrm2010
=c(rep("B",80),rep("T",80)), > Subject=c(rep(1,40),rep(2,40),rep(1,40),rep(2,40))) > toynewTair<-data.frame(dat3,toymelt2) > > Hope this helps. > > A.K. > > > > - Original Message - > From: nrm2010 > To: r-help &

Re: [R] reshape

2012-06-20 Thread nrm2010
Still working on it...to get your original suggestion to run, I "escaped" (doubled) the backslashes, so instead of x$type <- sub("\..*$", "", x$variable) which generated the error message Error: '\.' is an unrecognized escape in character string starting "\." I tried x$type <- sub("\\..*$", "", x

Re: [R] reshape

2012-06-20 Thread arun
),rep("T",80)), Subject=c(rep(1,40),rep(2,40),rep(1,40),rep(2,40))) toynewTair<-data.frame(dat3,toymelt2) Hope this helps. A.K. ----- Original Message - From: nrm2010 To: r-help Cc: Sent: Wednesday, June 20, 2012 12:08 PM Subject: [R] reshape Hello, helpeRs, I am attempting to

Re: [R] reshape

2012-06-20 Thread jim holtman
Is this closer using the same data: > dcast(x, year+month+day+hhmm+group+number ~ type, mean) year month day hhmm group number Tair VWC 1 2007 1 1 1100 B 1 0.285404913 1.4337114478 2 2007 1 1 1100 B 2 -0.899893189 1.1004122756 3 2007

Re: [R] reshape

2012-06-20 Thread nrm2010
Thank you, but it doesn't quite. It still needs a new column for each measurement type, i.e., a VWC column that contains the VWC measurements for each subject within group at each time point and a Tair column that contains the Tair measurements for each subject within group at each time point

Re: [R] reshape

2012-06-20 Thread jim holtman
will this do it for you: > require(reshape2) > toy <- data.frame(year = rep(2007:2008,each = 20), month = rep(1:5,each = 4, > length = 40), + day = rep(1:2,each = 2,length = 40), hhmm = rep(1100:1101,length = 40), plot = rep(1,40), + trt=rep(4,40), VWC.B1 = rnorm(40), VWC.B2 = rnorm(40), VWC.T1

[R] reshape

2012-06-20 Thread nrm2010
Hello, helpeRs, I am attempting to reshape (either base R or package reshape) multiple .csv spreadsheets from a very unfortunate wide format to long format.  Each spreadsheet looks something like this, after being read in to R: toy <- data.frame(year = rep(2007:2008,each = 20), month = rep(1:5

Re: [R] Reshape from long to wide

2012-03-21 Thread aly
Thanks a lot, I tried one of the ways you guys showed me and it totally work. Just for fun, I tried all the others and with some modifications here and there they work fine too. It was time consuming but definitely worth as a good learning experience. Thanks again -- View this message in context

Re: [R] Reshape from long to wide

2012-03-20 Thread Tyler Rinker
]) Cheers,Tyler > From: jorgeivanve...@gmail.com > Date: Tue, 20 Mar 2012 00:29:08 -0400 > To: alyaba...@gmail.com > CC: r-help@r-project.org > Subject: Re: [R] Reshape from long to wide > > Hi aly, > > Try > > # your data > x <- structure(list(family = c(14L, 1

Re: [R] Reshape from long to wide

2012-03-19 Thread Gabor Grothendieck
On Mon, Mar 19, 2012 at 7:01 PM, aly wrote: > > Hi, > > I'm a total beginner in R and this question is probably very simple but I've > spent hours reading about it and can't find the answer. I'm trying to > reshape a data table from long to wide format. I've tried reshape() and > cast() but I get

Re: [R] Reshape from long to wide

2012-03-19 Thread Jorge I Velez
Hi aly, Try # your data x <- structure(list(family = c(14L, 14L, 15L, 15L, 17L, 17L, 18L, 18L, 20L, 20L, 24L, 24L, 25L, 25L, 27L, 27L, 28L, 28L, 29L, 29L ), length = c(18L, 7L, 7L, 21L, 50L, 21L, 36L, 21L, 36L, 42L, 56L, 42L, 43L, 56L, 15L, 42L, 7L, 42L, 56L, 49L)), .Names = c("family", "length")

[R] Reshape from long to wide

2012-03-19 Thread aly
Hi, I'm a total beginner in R and this question is probably very simple but I've spent hours reading about it and can't find the answer. I'm trying to reshape a data table from long to wide format. I've tried reshape() and cast() but I get error messages every time and I can't figure why. In my da

[R] Reshape data frame with dcast and melt

2012-03-19 Thread mails
Hello, I implemented two functions reshape_long and reshape_wide (see full working example below) to reshape data frames. I created several small examples and the two functions seemed to work properly. However, using the reshape_wide function on my real data sets (about 200.000 to 300.000 rows) fa

Re: [R] Reshape question

2012-03-06 Thread David Winsemius
On Mar 6, 2012, at 3:00 PM, David Perlman wrote: I have a data frame in wide format. There are six variables that represent two factors in long format 3x2, Valence and Temperature: head(dpts) File Subj Time Group PainNeg.hot PainNeg.warm SociNeg.hot SociNeg.warm Positiv.hot

[R] Reshape question

2012-03-06 Thread David Perlman
I have a data frame in wide format. There are six variables that represent two factors in long format 3x2, Valence and Temperature: > head(dpts) File Subj Time Group PainNeg.hot PainNeg.warm SociNeg.hot SociNeg.warm Positiv.hot Positiv.warm Errors 1 WB101_1_1_dp.txt 1011 MN

Re: [R] reshape dataframe to array (pivot table)

2012-01-25 Thread Johannes Radinger
> An: Johannes Radinger > CC: "r-help@r-project.org" > Betreff: Re: [R] reshape dataframe to array (pivot table) > Hi, > > I wouldn't know how to fill the data into the array form you want, but > you can get the aggregated data with > > dfm <-

Re: [R] reshape dataframe to array (pivot table)

2012-01-24 Thread Jean V Adams
Johannes Radinger wrote on 01/24/2012 10:15:29 AM: > Hello, > > I would like to reshape a dataframe into an array. This is kind a > similar task as Excel performs with a Pivot table. To illustrate it: > > LOC <- factor(c(1,2,2,3,1,1)) > SPEC1 <- c(0,0,23,0,12,11) > SPEC2 <- c(1,2,0,0,0,4) > >

Re: [R] reshape dataframe to array (pivot table)

2012-01-24 Thread Rainer Schuermann
Hi, I wouldn't know how to fill the data into the array form you want, but you can get the aggregated data with dfm <- melt( df ) dfc <- cast( dfm, LOC ~ variable, sum ) > dfc LOC SPEC1 SPEC2 1 123 5 2 223 2 3 3 0 0 Hope this helps as a first step! Rgds, Raine

[R] reshape dataframe to array (pivot table)

2012-01-24 Thread Johannes Radinger
Hello, I would like to reshape a dataframe into an array. This is kind a similar task as Excel performs with a Pivot table. To illustrate it: LOC <- factor(c(1,2,2,3,1,1)) SPEC1 <- c(0,0,23,0,12,11) SPEC2 <- c(1,2,0,0,0,4) df <- data.frame(LOC,SPEC1,SPEC2) # original dataframe a <- array(NA,d

Re: [R] Reshape with multiple aggregate functions

2012-01-18 Thread David Winsemius
On Jan 18, 2012, at 4:06 AM, pengcafe wrote: I have a data frame and I would like to reshape it to wide format while at the same time applying different aggregate functions to each column AND at times multiple aggregate functions: test1 = data.frame( id = c(rep('101',8),rep('102',8)

Re: [R] Reshape with multiple aggregation functions

2012-01-18 Thread Jean V Adams
dimitris fekas wrote on 01/18/2012 03:21:44 AM: > I have a data frame and I would like to reshape it to wide format > while at the same time applying different aggregate functions to > each column AND at times multiple aggregate functions: > > test1 = data.frame( > id = c(rep('101',

Re: [R] Reshape with multiple aggregation functions

2012-01-18 Thread pengcafe
Hello, and thanks for your answer, I have melted the data already and can reshape it with cast alright, but I still can find no way to provide a list of aggregate functions per column, nor multiple aggregate functions for some of them (i.e. mean AND stdev) -- View this message in context: http:

  1   2   3   4   >