Re: [R] Dataframe Manipulation

2017-09-05 Thread Ulrik Stervbo
Hi Hemant, data_help <- data_help %>% # Add a dummy index for each purchase to keep a memory of the purchase since it will dissappear later on. You could also use row number mutate(Purchase_ID = 1:n()) %>% # For each purchase id group_by(Purchase_ID) %>% # Call the split_items function, which retu

Re: [R] Dataframe Manipulation

2017-09-04 Thread Hemant Sain
Hello Ulrik, Can you please explain this code means how and what this code is doing because I'm not able to understand it, if you can explain it i can use it in future by doing some Lil bit manipulation. Thanks data_help <- data_help %>% mutate(Purchase_ID = 1:n()) %>% group_by(Purchase_ID

Re: [R] Dataframe Manipulation

2017-08-31 Thread Ulrik Stervbo
Hi Hemant, the solution is really quite similar, and the logic is identical: library(readr) library(dplyr) library(stringr) library(tidyr) data_help <- read_csv("data_help.csv") cat_help <- read_csv("cat_help.csv") # Helper function to split the Items and create a data_frame split_items <- func

Re: [R] Dataframe Manipulation

2017-08-30 Thread Hemant Sain
by using these two tables we have to create third table in this format where categories will be on the top and transaction will be in the rows, On 30 August 2017 at 16:42, Hemant Sain wrote: > Hello Ulrik, > Can you please once check this code again on the following data set > because it doesn't

Re: [R] Dataframe Manipulation

2017-08-30 Thread Ulrik Stervbo
Hi Hemant, Does this help you along? table_1 <- textConnection("Item_1;Item_2;Item_3 1KG banana;300ML milk;1kg sugar 2Large Corona_Beer;2pack Fries; 2 Lux_Soap;1kg sugar;") table_1 <- read.csv(table_1, sep = ";", na.strings = "", stringsAsFactors = FALSE, check.names = FALSE) table_2 <- textCon

Re: [R] Dataframe Manipulation

2017-08-30 Thread Hemant Sain
Hey PIKAL, It's not a homework neithe that is the real dataset i have signer NDA for my company so that i can share the original data file, Actually I'm working on a market basket analysis task but not able to convert my existing data table to appropriate format so that i can apply Apriori algorith

Re: [R] Dataframe Manipulation

2017-08-30 Thread PIKAL Petr
Hi It seems to me like homework, there is no homework policy on this help list. What do you want to do with your table 3? It seems to me futile. Anyway, some combination of melt, merge, cast and regular expressions could be employed in such task, but it could be rather tricky. But be aware tha

Re: [R] dataframe manipulation

2013-12-13 Thread arun
Hi, Try:  d[match(unique(d$fac),d$fac),] A.K. On Friday, December 13, 2013 4:17 PM, Gang Chen wrote: Suppose I have a dataframe defined as     L3 <- LETTERS[1:3]     (d <- data.frame(cbind(x = 1, y = 1:10), fac = sample(L3, 10, replace = TRUE)))   x  y fac 1  1  1  C 2  1  2  A 3  1  3 

Re: [R] dataframe manipulation

2013-12-13 Thread William Dunlap
-project.org] On > Behalf > Of Gang Chen > Sent: Friday, December 13, 2013 1:35 PM > To: arun > Cc: R help > Subject: Re: [R] dataframe manipulation > > Perfect! Thanks a lot, A.K! > > > On Fri, Dec 13, 2013 at 4:21 PM, arun wrote: > > > > >

Re: [R] dataframe manipulation

2013-12-13 Thread Gang Chen
Another neat solution! Thanks a lot, Sarah! On Fri, Dec 13, 2013 at 4:35 PM, Sarah Goslee wrote: > What about: > > lapply(levels(d$fac), function(x)head(d[d$fac == x,], 1)) > > > Thanks for the reproducible example. If you put set.seed(123) before > the call to sample, then everyone who tries it

Re: [R] dataframe manipulation

2013-12-13 Thread Sarah Goslee
What about: lapply(levels(d$fac), function(x)head(d[d$fac == x,], 1)) Thanks for the reproducible example. If you put set.seed(123) before the call to sample, then everyone who tries it will get the same data frame d. Sarah On Fri, Dec 13, 2013 at 4:15 PM, Gang Chen wrote: > Suppose I have a

Re: [R] dataframe manipulation

2013-12-13 Thread Gang Chen
Perfect! Thanks a lot, A.K! On Fri, Dec 13, 2013 at 4:21 PM, arun wrote: > > > Hi, > Try: > d[match(unique(d$fac),d$fac),] > A.K. > > > On Friday, December 13, 2013 4:17 PM, Gang Chen > wrote: > Suppose I have a dataframe defined as > > L3 <- LETTERS[1:3] > (d <- data.frame(cbind(x

Re: [R] Dataframe manipulation

2013-03-30 Thread englishfellow
Fantastic, thanks alot for that! Take care. Adam. Date: Sat, 30 Mar 2013 01:14:49 -0700 From: ml-node+s789695n466289...@n4.nabble.com To: english.fel...@hotmail.com Subject: Re: Dataframe manipulation Hi Adam, I hope this is what you wanted: dat1<- read.csv("example.csv",sep="\t",s

Re: [R] Dataframe manipulation

2013-03-30 Thread arun
Hi Adam, I hope this is what you wanted: dat1<- read.csv("example.csv",sep="\t",stringsAsFactors=FALSE)  str(dat1) #'data.frame':    102 obs. of  5 variables: # $ species  : chr  "B. barbastrellus" "E. nilssonii" "H. savii" "M. alcathoe" ... # $ period   : chr  "dusk" "dusk" "dusk" "dusk" ... # $

Re: [R] Dataframe manipulation

2007-12-04 Thread Dimitris Rizopoulos
b: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: "David Winsemius" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, December 04, 2007 4:47 PM Subject: Re: [R] Dataframe manipulation &g

Re: [R] Dataframe manipulation

2007-12-04 Thread David Winsemius
"Dimitris Rizopoulos" <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > try this (also look at R-FAQ 7.10): > > sapply(df, function (x) as.numeric(levels(x))[as.integer(x)]) That looks rather dangerous. By the time I saw your suggestion, I had already added an extra variable with: df$tes

Re: [R] Dataframe manipulation

2007-12-04 Thread John Kane
See R-FAQ # 7-11 for the solution. Have a look at http://finzi.psych.upenn.edu/R/Rhelp02a/archive/98227.html for a discussion of this type of problem and ways to get around the issue. --- Antje <[EMAIL PROTECTED]> wrote: > Hello, > > can anybody help me with this problem? > I have a datafram

Re: [R] Dataframe manipulation

2007-12-04 Thread Dimitris Rizopoulos
try this (also look at R-FAQ 7.10): sapply(df, function (x) as.numeric(levels(x))[as.integer(x)]) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: