Re: [R] Convert list of data frames to one data frame
Code below... a) Just because something can be done with dplyr does not mean that is the best way to do it. A solution in the hand is worth two on the Internet, and dplyr is not always the fastest method anyway. b) I highly recommend that you read Hadley Wickham's paper on tidy data [1]. Also, having a group of one or more columns at all times that uniquely identify where the data came from is a "key" to success [2]. c) Please read and follow one of the various online documents about making reproducible examples in R (e.g. [3]). HTML formatting is really a pain (at best... at worst, it corrupts your code) on a plain-text-only list (you have read the Posting Guide, right?). Consider my example below as a model for you to follow in the future, and make sure to set your email program to send plain text. (Obviously your examples don't have to achieve success... but they should bring us up to speed with where you are having troubles IN R.) [1] https://www.jstatsoft.org/article/view/v059i10 [2] http://r4ds.had.co.nz/relational-data.html#keys [3] https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example library(dplyr) #> #> Attaching package: 'dplyr' #> The following objects are masked from 'package:stats': #> #> filter, lag #> The following objects are masked from 'package:base': #> #> intersect, setdiff, setequal, union library(tidyr) # note that these data frames all have character columns # rather than factors, due to the as.is option when the # data are read in. DF1 <- read.table( text = "First Last George Washington ", header=TRUE, as.is = TRUE ) # dput looks ugly but is actually much more practical for # providing R data on the mailing list... here is an example dput( DF1 ) #> structure(list(First = "George", Last = "Washington") #>, .Names = c("First", #> "Last"), class = "data.frame", row.names = c(NA, -1L)) DF2 <- read.table( text = "Start End John Adams ThomasJefferson ", header = TRUE, as.is = TRUE ) DFL <- list( DF1, DF2 ) # DFNames is a set of unique identifiers DFL1 <- data_frame( .DFNames = sprintf( "DF%d", 1:2 ) , data = DFL ) DFL2 <- ( DFL1 %>% mutate( data = lapply( data , function( DF ) { DF[[ ".PK" ]] <- seq.int( nrow( DF )) gather( DF, ".Col", "value", -.PK ) } ) ) %>% unnest %>% spread( .Col, value ) ) DFL2 #> # A tibble: 3 x 6 #> .DFNames .PK End First Last Start #> #> 1 DF1 1 George Washington #> 2 DF2 1 Adams John #> 3 DF2 2 Jefferson Thomas #' Created on 2018-06-29 by the [reprex package](http://reprex.tidyverse.org) (v0.2.0). On Sat, 30 Jun 2018, Ira Sharenow via R-help wrote: Sarah and David, Thank you for your responses.I will try and be clearer. Base R solution: Sarah?smethod worked perfectly Is there a dplyrsolution? START: list of dataframes FINISH: one data frame DETAILS: The initiallist of data frames might have hundreds or a few thousand data frames. Everydata frame will have two columns. The first column will represent first names.The second column will represent last names. The column names are notconsistent. Data frames will most likely have from one to five rows. SUGGESTED STRATEGY:Convert the n by 2 data frames to 1 by 2n data frames. Then somehow do an rbindeven though the number of columns differ from data frame to data frame. EXAMPLE: List with twodata frames # DF1 First Last George Washington # DF2 Start End John Adams Thomas Jefferson # End Result. One dataframe First1 Second1 First2 Second2 George Washington NA NA John Adams Thomas Jefferson DISCUSSION: As mentionedI posted something on Stack Overflow. Unfortunately, my example was not generalenough and so the suggested solutions worked on the easy case which I provided butnot when the names were different. The suggested solution was: library(dplyr) bind_rows(lapply(employees4List,function(x) rbind.data.frame(c(t(x) On this site I pointedout that the inner function: lapply(employees4List, function(x) rbind.data.frame(c(t(x For each data frame correctlyspread the multiple rows into 1 by 2ndata frames. However, the column names were derived from the values and were amess. This caused a problem with bind_rows. I felt that if I knewhow to change all the names of all of the data frames that were created afterlapply, then I could then use bind_rows. So if someone knows how to change allof the names at this intermediate stage, I hope that person will provide thesolution
Re: [R] Convert list of data frames to one data frame
Well, I don't know your constraints, of course; but if I understand correctly, in situations like this, it is usually worthwhile to reconsider your data structure. This is a one-liner if you simply rbind all your data frames into one with 2 columns. Here's an example to indicate how: ## list of two data frames with different column names and numbers of rows: zz <-list(one = data.frame(f=1:3,g=letters[2:4]), two = data.frame(a = 5:9,b = letters[11:15])) ## create common column names and bind them up: do.call(rbind,lapply(zz,function(x){ names(x) <- c("first","last"); x})) Note that the row names of the result tell you which original frame the rows came from. This can also be obtained just from a count of rows (?nrow) of the original list. Apologies if I misunderstand or your query or your constraints make this simple approach impossible. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Fri, Jun 29, 2018 at 5:29 PM, Ira Sharenow via R-help < r-help@r-project.org> wrote: > > Sarah and David, > > Thank you for your responses.I will try and be clearer. > > Base R solution: Sarah’smethod worked perfectly > > Is there a dplyrsolution? > > START: list of dataframes > > FINISH: one data frame > > DETAILS: The initiallist of data frames might have hundreds or a few > thousand data frames. Everydata frame will have two columns. The first > column will represent first names.The second column will represent last > names. The column names are notconsistent. Data frames will most likely > have from one to five rows. > > SUGGESTED STRATEGY:Convert the n by 2 data frames to 1 by 2n data frames. > Then somehow do an rbindeven though the number of columns differ from data > frame to data frame. > > EXAMPLE: List with twodata frames > > # DF1 > > First Last > > George Washington > > > > # DF2 > > Start End > > John Adams > > ThomasJefferson > > > > # End Result. One dataframe > > First1 Second1First2 Second2 > > George Washington NANA > > John AdamsThomasJefferson > > > > DISCUSSION: As mentionedI posted something on Stack Overflow. > Unfortunately, my example was not generalenough and so the suggested > solutions worked on the easy case which I provided butnot when the names > were different. > > The suggested solution was: > > library(dplyr) > > bind_rows(lapply(employees4List,function(x) rbind.data.frame(c(t(x) > > > > On this site I pointedout that the inner function: lapply(employees4List, > function(x) rbind.data.frame(c(t(x > > For each data frame correctlyspread the multiple rows into 1 by 2ndata > frames. However, the column names were derived from the values and were > amess. This caused a problem with bind_rows. > > I felt that if I knewhow to change all the names of all of the data frames > that were created afterlapply, then I could then use bind_rows. So if > someone knows how to change allof the names at this intermediate stage, I > hope that person will provide thesolution. > > In the end a 1 by 2 data frame would have namesFirst1 Second1. A 1 > by 4 data framewould have names First1 Second1First2 > Second2. > > Ira > > > On Friday, June 29, 2018, 12:49:18 PM PDT, David Winsemius < > dwinsem...@comcast.net> wrote: > > > > On Jun 29, 2018, at 7:28 AM, Sarah Goslee > wrote: > > > > Hi, > > > > It isn't super clear to me what you're after. > > Agree. > > Had a different read of ht erequest. Thought the request was for a first > step that "harmonized" the names of the columns and then used > `dplyr::bind_rows`: > > library(dplyr) > newList <- lapply( employees4List, 'names<-', names(employees4List[[1]]) > ) > bind_rows(newList) > > #- > > first1 second1 > 1 Al Jones > 2Al2 Jones > 3Barb Smith > 4Al3 Jones > 5 Barbara Smith > 6 Carol Adams > 7 Al Jones2 > > Might want to wrap suppressWarnings around the right side of that > assignment since there were many warnings regarding incongruent factor > levels. > > -- > David. > > Is this what you intend? > > > >> dfbycol(employees4BList) > > first1 last1 first2 last2 first3 last3 > > 1Al Jones > > 2Al Jones Barb Smith > > 3Al Jones Barb Smith Carol Adams > > 4Al Jones > >> > >> dfbycol(employees4List) > > first1 last1 first2 last2 first3 last3 > > 1Al Jones > > 2Al2 JonesBarb Smith > > 3Al3 Jones Barbara Smith Carol Adams > > 4Al Jones2 > > > > > > If so: > > > > employees4BList = list( > > data.frame(first1 = "Al", second1 = "Jones"), > > data.frame(first1 = c("Al", "Barb"), second1 = c("Jones", "Smith")), > > data.frame(first1 = c("Al", "Barb", "Carol"), second1 = c("Jones", > > "Smith", "Adams")), > > data.frame(first1 = ("Al"), se
Re: [R] Convert list of data frames to one data frame
Sarah and David, Thank you for your responses.I will try and be clearer. Base R solution: Sarah’smethod worked perfectly Is there a dplyrsolution? START: list of dataframes FINISH: one data frame DETAILS: The initiallist of data frames might have hundreds or a few thousand data frames. Everydata frame will have two columns. The first column will represent first names.The second column will represent last names. The column names are notconsistent. Data frames will most likely have from one to five rows. SUGGESTED STRATEGY:Convert the n by 2 data frames to 1 by 2n data frames. Then somehow do an rbindeven though the number of columns differ from data frame to data frame. EXAMPLE: List with twodata frames # DF1 First Last George Washington # DF2 Start End John Adams Thomas Jefferson # End Result. One dataframe First1 Second1 First2 Second2 George Washington NA NA John Adams Thomas Jefferson DISCUSSION: As mentionedI posted something on Stack Overflow. Unfortunately, my example was not generalenough and so the suggested solutions worked on the easy case which I provided butnot when the names were different. The suggested solution was: library(dplyr) bind_rows(lapply(employees4List,function(x) rbind.data.frame(c(t(x) On this site I pointedout that the inner function: lapply(employees4List, function(x) rbind.data.frame(c(t(x For each data frame correctlyspread the multiple rows into 1 by 2ndata frames. However, the column names were derived from the values and were amess. This caused a problem with bind_rows. I felt that if I knewhow to change all the names of all of the data frames that were created afterlapply, then I could then use bind_rows. So if someone knows how to change allof the names at this intermediate stage, I hope that person will provide thesolution. In the end a 1 by 2 data frame would have namesFirst1 Second1. A 1 by 4 data framewould have names First1 Second1 First2 Second2. Ira On Friday, June 29, 2018, 12:49:18 PM PDT, David Winsemius wrote: > On Jun 29, 2018, at 7:28 AM, Sarah Goslee wrote: > > Hi, > > It isn't super clear to me what you're after. Agree. Had a different read of ht erequest. Thought the request was for a first step that "harmonized" the names of the columns and then used `dplyr::bind_rows`: library(dplyr) newList <- lapply( employees4List, 'names<-', names(employees4List[[1]]) ) bind_rows(newList) #- first1 second1 1 Al Jones 2 Al2 Jones 3 Barb Smith 4 Al3 Jones 5 Barbara Smith 6 Carol Adams 7 Al Jones2 Might want to wrap suppressWarnings around the right side of that assignment since there were many warnings regarding incongruent factor levels. -- David. > Is this what you intend? > >> dfbycol(employees4BList) > first1 last1 first2 last2 first3 last3 > 1 Al Jones > 2 Al Jones Barb Smith > 3 Al Jones Barb Smith Carol Adams > 4 Al Jones >> >> dfbycol(employees4List) > first1 last1 first2 last2 first3 last3 > 1 Al Jones > 2 Al2 Jones Barb Smith > 3 Al3 Jones Barbara Smith Carol Adams > 4 Al Jones2 > > > If so: > > employees4BList = list( > data.frame(first1 = "Al", second1 = "Jones"), > data.frame(first1 = c("Al", "Barb"), second1 = c("Jones", "Smith")), > data.frame(first1 = c("Al", "Barb", "Carol"), second1 = c("Jones", > "Smith", "Adams")), > data.frame(first1 = ("Al"), second1 = "Jones")) > > employees4List = list( > data.frame(first1 = ("Al"), second1 = "Jones"), > data.frame(first2 = c("Al2", "Barb"), second2 = c("Jones", "Smith")), > data.frame(first3 = c("Al3", "Barbara", "Carol"), second3 = c("Jones", > "Smith", "Adams")), > data.frame(first4 = ("Al"), second4 = "Jones2")) > > ### > > dfbycol <- function(x) { > x <- lapply(x, function(y)as.vector(t(as.matrix(y > x <- lapply(x, function(y){length(y) <- max(sapply(x, length)); y}) > x <- do.call(rbind, x) > x <- data.frame(x, stringsAsFactors=FALSE) > colnames(x) <- paste0(c("first", "last"), rep(seq(1, ncol(x)/2), each=2)) > x > } > > ### > > dfbycol(employees4BList) > > dfbycol(employees4List) > > On Fri, Jun 29, 2018 at 2:36 AM, Ira Sharenow via R-help > wrote: >> I have a list of data frames which I would like to combine into one data >> frame doing something like rbind. I wish to combine in column order and >> not by names. However, there are issues. >> >> The number of columns is not the same for each data frame. This is an >> intermediate step to a problem and the number of columns could be >> 2,4,6,8,or10. There might be a few thousand data frames. Another problem >> is that the names of the columns produced by the first step are garbage. >> >> Below is a method that I obtained by asking a question on stack >> overflow. Unfortunately, m
Re: [R] [FORGED] Plot multiple time series on a seasonal plot
On 30/06/18 01:41, Jérôme François via R-help wrote: Dear members, I would like to plot a second time series (a forecast) to a seasonal plot made with function seasonplot() from the package forecast. Here is a reproducible example: ts1 <- structure(c(112035, 82, 111015, 109331, 107525, 107749, 111435, 111629, 112462, 112256, 109496, 107917, 108221, 107463, 105960, 103883, 101038, 100056, 101628, 102973, 103371, 102463, 100774, 100718, 100471, 99828, 99365, 98521, 95695, 96443, 96287, 97525, 98293, 98014, 96658, 96736, 96089, 95337, 95382, 92748, 91448, 91560, 92996, 94046, 94128, 93888, 93888, 91091, 91877, 91681, 91045, 89367, 87912), .Tsp = c(2014, 2018.333, 12), class = "ts") ts2 <- structure(c(87867.2152330971, 89713.0862474283, 89600.565347383, 91066.3196835822, 90523.1926861474, 89322.8025396445, 88771.5545520503, 89247.0913151542, 88803.5578121458, 88060.0948570082, 87015.6578227365, 85785.4121532206), .Tsp = c(2018.417, 2019.333, 12), class = "ts") library(forecast)seasonplot(ts1, year.labels = TRUE, year.labels.left = TRUE) How can I add ts2 to the seasonal plot? I would like it to be distinguishable from ts1 (e.g. different color). lines(ts2) doesn't work. Thank you. I don't know anything about forecast/seasonplot. However my experience is that par(new=TRUE) usually rescues one in situations like this. It's a bit shaganappi, but ... seasonplot(ts1, year.labels = TRUE, year.labels.left = TRUE, main="Whatever") OP <- par(new=TRUE,xaxt="n",yaxt="n") seasonplot(ts2, col="red",main="") par(OP) seems to work. It would be nice to have an "add=" argument (defaulting to FALSE, of course) to seasonplot(). cheers, Rolf Turner -- Technical Editor ANZJS Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] trouble with exiting loop if condition is met
Hi Jim & Don, I was trying to use the break command originally before posting but for some reason it was making almost all of the p-values in the replications non significant. I think I am going to change the flow of the loop so I don’t have to use a break, such as the code Jim wrote. Thanks for your detailed response! Kelly > On Jun 28, 2018, at 3:18 PM, Jim Lemon wrote: > > " as sequential observations, it > will only require a minor modification. > > Jim > > On Fri, Jun 29, 2018 at 5:53 AM, Kelly Wu wrote: > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Convert list of data frames to one data frame
> On Jun 29, 2018, at 7:28 AM, Sarah Goslee wrote: > > Hi, > > It isn't super clear to me what you're after. Agree. Had a different read of ht erequest. Thought the request was for a first step that "harmonized" the names of the columns and then used `dplyr::bind_rows`: library(dplyr) newList <- lapply( employees4List, 'names<-', names(employees4List[[1]]) ) bind_rows(newList) #- first1 second1 1 Al Jones 2 Al2 Jones 3Barb Smith 4 Al3 Jones 5 Barbara Smith 6 Carol Adams 7 Al Jones2 Might want to wrap suppressWarnings around the right side of that assignment since there were many warnings regarding incongruent factor levels. -- David. > Is this what you intend? > >> dfbycol(employees4BList) > first1 last1 first2 last2 first3 last3 > 1 Al Jones > 2 Al Jones Barb Smith > 3 Al Jones Barb Smith Carol Adams > 4 Al Jones >> >> dfbycol(employees4List) > first1 last1 first2 last2 first3 last3 > 1 Al Jones > 2Al2 JonesBarb Smith > 3Al3 Jones Barbara Smith Carol Adams > 4 Al Jones2 > > > If so: > > employees4BList = list( > data.frame(first1 = "Al", second1 = "Jones"), > data.frame(first1 = c("Al", "Barb"), second1 = c("Jones", "Smith")), > data.frame(first1 = c("Al", "Barb", "Carol"), second1 = c("Jones", > "Smith", "Adams")), > data.frame(first1 = ("Al"), second1 = "Jones")) > > employees4List = list( > data.frame(first1 = ("Al"), second1 = "Jones"), > data.frame(first2 = c("Al2", "Barb"), second2 = c("Jones", "Smith")), > data.frame(first3 = c("Al3", "Barbara", "Carol"), second3 = c("Jones", > "Smith", "Adams")), > data.frame(first4 = ("Al"), second4 = "Jones2")) > > ### > > dfbycol <- function(x) { > x <- lapply(x, function(y)as.vector(t(as.matrix(y > x <- lapply(x, function(y){length(y) <- max(sapply(x, length)); y}) > x <- do.call(rbind, x) > x <- data.frame(x, stringsAsFactors=FALSE) > colnames(x) <- paste0(c("first", "last"), rep(seq(1, ncol(x)/2), each=2)) > x > } > > ### > > dfbycol(employees4BList) > > dfbycol(employees4List) > > On Fri, Jun 29, 2018 at 2:36 AM, Ira Sharenow via R-help > wrote: >> I have a list of data frames which I would like to combine into one data >> frame doing something like rbind. I wish to combine in column order and >> not by names. However, there are issues. >> >> The number of columns is not the same for each data frame. This is an >> intermediate step to a problem and the number of columns could be >> 2,4,6,8,or10. There might be a few thousand data frames. Another problem >> is that the names of the columns produced by the first step are garbage. >> >> Below is a method that I obtained by asking a question on stack >> overflow. Unfortunately, my example was not general enough. The code >> below works for the simple case where the names of the people are >> consistent. It does not work when the names are realistically not the same. >> >> https://stackoverflow.com/questions/50807970/converting-a-list-of-data-frames-not-a-simple-rbind-second-row-to-new-columns/50809432#50809432 >> >> >> Please note that the lapply step sets things up except for the column >> name issue. If I could figure out a way to change the column names, then >> the bind_rows step will, I believe, work. >> >> So I really have two questions. How to change all column names of all >> the data frames and then how to solve the original problem. >> >> # The non general case works fine. It produces one data frame and I can >> then change the column names to >> >> # c("first1", "last1","first2", "last2","first3", "last3",) >> >> #Non general easy case >> >> employees4BList = list(data.frame(first1 = "Al", second1 = "Jones"), >> >> data.frame(first1 = c("Al", "Barb"), second1 = c("Jones", "Smith")), >> >> data.frame(first1 = c("Al", "Barb", "Carol"), second1 = c("Jones", >> "Smith", "Adams")), >> >> data.frame(first1 = ("Al"), second1 = "Jones")) >> >> employees4BList >> >> bind_rows(lapply(employees4BList, function(x) rbind.data.frame(c(t(x) >> >> # This produces a nice list of data frames, except for the names >> >> lapply(employees4BList, function(x) rbind.data.frame(c(t(x >> >> # This list is a disaster. I am looking for a solution that works in >> this case. >> >> employees4List = list(data.frame(first1 = ("Al"), second1 = "Jones"), >> >> data.frame(first2 = c("Al2", "Barb"), second2 = c("Jones", "Smith")), >> >> data.frame(first3 = c("Al3", "Barbara", "Carol"), second3 = c("Jones", >> "Smith", "Adams")), >> >> data.frame(first4 = ("Al"), second4 = "Jones2")) >> >> bind_rows(lapply(employees4List, function(x) rbind.data.frame(c(t(x) >> >> Thanks. >> >> Ira >> > > -- > Sarah Goslee > http://www.functionaldiversity.org > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PL
Re: [R] Σχετ: x-axis tick marks length in ggplot2
Hello, I don't believe what you want is possible because: axis.ticks.x and axis.ticks.y change the width of the tick marks axis.ticks.length changes the length but there is no x and y axis versions, just a general purpose one. Sorry I couldn't be of much help, Rui Barradas Às 11:01 de 29-06-2018, Maria Lathouri via R-help escreveu: Dear Walter, I tried to use scale_x_continuous but the arguments that I found was to change the labels, the limits and the breaks. I was only able to increase the number of the tick marks. Best,Maria Στις 3:14 μ.μ. Πέμπτη, 28 Ιουνίου 2018, ο/η Walter Pina έγραψε: Dear Maria, you are totally right! Did you tried the scale_x_continuous function and its arguments? RegardsWalter 2018-06-28 8:48 GMT-03:00 'Maria Lathouri' via ggplot2 : Dear Abhimanyu, If I am not mistaken, this online help is to post questions, and if possible, these questions to be answered. NOT for sarcastic and insulting posts. You could have just easily ignored my question. So simple. Kind regards,Maria Στις 12:38 μ.μ. Πέμπτη, 28 Ιουνίου 2018, ο/η Maria Lathouri έγραψε: I am sorry but I didn't get your point. And I am not new in data science!! Maria Στις 11:38 π.μ. Πέμπτη, 28 Ιουνίου 2018, ο/η Abhimanyu Khatry έγραψε: How a beginner can get started on ggplot ? Is it right to start this if someone is new to data science ? On Wed, Jun 27, 2018 at 9:47 PM, 'Maria Lathouri' via ggplot2 wrote: Dear all, I would like to ask if there is a way to increase the length of the tick marks on the x-axis only. I got the code: p+ theme(axis.ticks.length=unit(. 30, "cm")) but this increases the length for both x and y axis; whereas, I would like only on x-axis. Thank you very much in advance. Kind regards, Maria __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Plot multiple time series on a seasonal plot
Dear members, I would like to plot a second time series (a forecast) to a seasonal plot made with function seasonplot() from the package forecast. Here is a reproducible example: ts1 <- structure(c(112035, 82, 111015, 109331, 107525, 107749, 111435, 111629, 112462, 112256, 109496, 107917, 108221, 107463, 105960, 103883, 101038, 100056, 101628, 102973, 103371, 102463, 100774, 100718, 100471, 99828, 99365, 98521, 95695, 96443, 96287, 97525, 98293, 98014, 96658, 96736, 96089, 95337, 95382, 92748, 91448, 91560, 92996, 94046, 94128, 93888, 93888, 91091, 91877, 91681, 91045, 89367, 87912), .Tsp = c(2014, 2018.333, 12), class = "ts") ts2 <- structure(c(87867.2152330971, 89713.0862474283, 89600.565347383, 91066.3196835822, 90523.1926861474, 89322.8025396445, 88771.5545520503, 89247.0913151542, 88803.5578121458, 88060.0948570082, 87015.6578227365, 85785.4121532206), .Tsp = c(2018.417, 2019.333, 12), class = "ts") library(forecast)seasonplot(ts1, year.labels = TRUE, year.labels.left = TRUE) How can I add ts2 to the seasonal plot? I would like it to be distinguishable from ts1 (e.g. different color). lines(ts2) doesn't work. Thank you. Sincerely, Jérôme __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Convert list of data frames to one data frame
Hi, It isn't super clear to me what you're after. Is this what you intend? > dfbycol(employees4BList) first1 last1 first2 last2 first3 last3 1 Al Jones 2 Al Jones Barb Smith 3 Al Jones Barb Smith Carol Adams 4 Al Jones > > dfbycol(employees4List) first1 last1 first2 last2 first3 last3 1 Al Jones 2Al2 JonesBarb Smith 3Al3 Jones Barbara Smith Carol Adams 4 Al Jones2 If so: employees4BList = list( data.frame(first1 = "Al", second1 = "Jones"), data.frame(first1 = c("Al", "Barb"), second1 = c("Jones", "Smith")), data.frame(first1 = c("Al", "Barb", "Carol"), second1 = c("Jones", "Smith", "Adams")), data.frame(first1 = ("Al"), second1 = "Jones")) employees4List = list( data.frame(first1 = ("Al"), second1 = "Jones"), data.frame(first2 = c("Al2", "Barb"), second2 = c("Jones", "Smith")), data.frame(first3 = c("Al3", "Barbara", "Carol"), second3 = c("Jones", "Smith", "Adams")), data.frame(first4 = ("Al"), second4 = "Jones2")) ### dfbycol <- function(x) { x <- lapply(x, function(y)as.vector(t(as.matrix(y x <- lapply(x, function(y){length(y) <- max(sapply(x, length)); y}) x <- do.call(rbind, x) x <- data.frame(x, stringsAsFactors=FALSE) colnames(x) <- paste0(c("first", "last"), rep(seq(1, ncol(x)/2), each=2)) x } ### dfbycol(employees4BList) dfbycol(employees4List) On Fri, Jun 29, 2018 at 2:36 AM, Ira Sharenow via R-help wrote: > I have a list of data frames which I would like to combine into one data > frame doing something like rbind. I wish to combine in column order and > not by names. However, there are issues. > > The number of columns is not the same for each data frame. This is an > intermediate step to a problem and the number of columns could be > 2,4,6,8,or10. There might be a few thousand data frames. Another problem > is that the names of the columns produced by the first step are garbage. > > Below is a method that I obtained by asking a question on stack > overflow. Unfortunately, my example was not general enough. The code > below works for the simple case where the names of the people are > consistent. It does not work when the names are realistically not the same. > > https://stackoverflow.com/questions/50807970/converting-a-list-of-data-frames-not-a-simple-rbind-second-row-to-new-columns/50809432#50809432 > > > Please note that the lapply step sets things up except for the column > name issue. If I could figure out a way to change the column names, then > the bind_rows step will, I believe, work. > > So I really have two questions. How to change all column names of all > the data frames and then how to solve the original problem. > > # The non general case works fine. It produces one data frame and I can > then change the column names to > > # c("first1", "last1","first2", "last2","first3", "last3",) > > #Non general easy case > > employees4BList = list(data.frame(first1 = "Al", second1 = "Jones"), > > data.frame(first1 = c("Al", "Barb"), second1 = c("Jones", "Smith")), > > data.frame(first1 = c("Al", "Barb", "Carol"), second1 = c("Jones", > "Smith", "Adams")), > > data.frame(first1 = ("Al"), second1 = "Jones")) > > employees4BList > > bind_rows(lapply(employees4BList, function(x) rbind.data.frame(c(t(x) > > # This produces a nice list of data frames, except for the names > > lapply(employees4BList, function(x) rbind.data.frame(c(t(x > > # This list is a disaster. I am looking for a solution that works in > this case. > > employees4List = list(data.frame(first1 = ("Al"), second1 = "Jones"), > > data.frame(first2 = c("Al2", "Barb"), second2 = c("Jones", "Smith")), > > data.frame(first3 = c("Al3", "Barbara", "Carol"), second3 = c("Jones", > "Smith", "Adams")), > > data.frame(first4 = ("Al"), second4 = "Jones2")) > > bind_rows(lapply(employees4List, function(x) rbind.data.frame(c(t(x) > > Thanks. > > Ira > -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] inconsistency in list subsetting in R in linux
Read the Value section of ?mclapply. That error is an encapsulated error from the forecast function. I suggest not debugging your code running in parallel... temporarily replace mclapply with lapply to debug so you can step into your worker fictions. You may also want to temporarily reduce the volume of data you are working with. On June 29, 2018 4:19:40 AM PDT, akshay kulkarni wrote: >dear members, >I am using GNU R(R in linux CLI). I am trying to debug a function >called "grand.finalelPf". In the function the following line appears > >> yhpf2 <- mclapply(LYG2[-w], fun = forecast, h = 1) > >I execute the above line in browse[2] prompt. I then type the >following: >Browse[2] > length(yhpf2) > >It also is getting executed with the following output: >[1] 464 > >But when I type this: >Browse[2] > yhpf2[[3]] > >the ouput is this: > >[1] "Error in lapply(X = S, FUN = FUN, ...) : \n argument \"FUN\" is >missing, with no default\n" >attr(,"class") >[1] "try-error" >attr(,"condition") >missing, with no default> >Browse[2] > > >why is this getting outputted instead of a value? Even if all the >yhpf's are NULL, the above is output is weird. > >What is wrong? Why would the output relate to lapply? If the culprit >was mclapply, then why does the line get executed without an error >message? The same function is working perfectly well in windows(I used >parLapply instead of mclapply). >Is this peculiar to R on Linux? Please help > >very many thanks for your time and effort, >Yours sincerely, >AKSHAY M KULKARNI > > > [[alternative HTML version deleted]] > >__ >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code. -- Sent from my phone. Please excuse my brevity. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] inconsistency in list subsetting in R in linux
> args(parallel::mclapply) function (X, FUN, ..., mc.preschedule = TRUE, mc.set.seed = TRUE, mc.silent = FALSE, mc.cores = 1L, mc.cleanup = TRUE, mc.allow.recursive = TRUE) You gave it 'fun=forecast' instead of 'FUN=forecast'. Case matters in R. Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Jun 29, 2018 at 4:19 AM, akshay kulkarni wrote: > dear members, >I am using GNU R(R in linux CLI). I am trying > to debug a function called "grand.finalelPf". In the function the following > line appears > > > yhpf2 <- mclapply(LYG2[-w], fun = forecast, h = 1) > > I execute the above line in browse[2] prompt. I then type the following: > Browse[2] > length(yhpf2) > > It also is getting executed with the following output: > [1] 464 > > But when I type this: > Browse[2] > yhpf2[[3]] > > the ouput is this: > > [1] "Error in lapply(X = S, FUN = FUN, ...) : \n argument \"FUN\" is > missing, with no default\n" > attr(,"class") > [1] "try-error" > attr(,"condition") > with no default> > Browse[2] > > > why is this getting outputted instead of a value? Even if all the yhpf's > are NULL, the above is output is weird. > > What is wrong? Why would the output relate to lapply? If the culprit was > mclapply, then why does the line get executed without an error message? The > same function is working perfectly well in windows(I used parLapply instead > of mclapply). > Is this peculiar to R on Linux? Please help > > very many thanks for your time and effort, > Yours sincerely, > AKSHAY M KULKARNI > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/ > posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Fwd: Quadratic programming, for loop
G'day Maija, On Wed, 27 Jun 2018 08:48:08 +0300 Maija Sirkjärvi wrote: > Thanks for your reply! Unfortunately something is still wrong. > > After the transpose, dvec and Amat are still incompatible. > > > d <- -hsmooth > > dvec <- t(d) > > c <- dvec*Amat > Error in dvec * Amat : non-conformable arrays '*' in R is element-wise multiplication and '%*%' implements matrix/matrix (matrix/vector) multiplication as defined in matrix algebra. I presume you want to use the latter operator here. > Moreover, I don't understand the following: > > > If dvec is of length *J*, then b will be of length J too. > > I believe the length of dvec comes from the number of variables and > the length of b from the number of constraints. In this case they are > not equal. As I said: > > solve.QP solves the quadratic program: > > min(-d^T b + 1/2 b^T D b) > >where A^T b >= b_0. The minimisation is with respect to b. Note that the objective function contains the inner product of d (passed to dvec) and b, so d and b must have the same dimension/length. b contains the parameters/variables over which you want to minimise. b_0 (passed to bvec) depends on the number of constraints. Cheers, Berwin __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Σχετ: x-axis tick marks length in ggplot2
Dear Walter, I tried to use scale_x_continuous but the arguments that I found was to change the labels, the limits and the breaks. I was only able to increase the number of the tick marks. Best,Maria Στις 3:14 μ.μ. Πέμπτη, 28 Ιουνίου 2018, ο/η Walter Pina έγραψε: Dear Maria, you are totally right! Did you tried the scale_x_continuous function and its arguments? RegardsWalter 2018-06-28 8:48 GMT-03:00 'Maria Lathouri' via ggplot2 : Dear Abhimanyu, If I am not mistaken, this online help is to post questions, and if possible, these questions to be answered. NOT for sarcastic and insulting posts. You could have just easily ignored my question. So simple. Kind regards,Maria Στις 12:38 μ.μ. Πέμπτη, 28 Ιουνίου 2018, ο/η Maria Lathouri έγραψε: I am sorry but I didn't get your point. And I am not new in data science!! Maria Στις 11:38 π.μ. Πέμπτη, 28 Ιουνίου 2018, ο/η Abhimanyu Khatry έγραψε: How a beginner can get started on ggplot ? Is it right to start this if someone is new to data science ? On Wed, Jun 27, 2018 at 9:47 PM, 'Maria Lathouri' via ggplot2 wrote: Dear all, I would like to ask if there is a way to increase the length of the tick marks on the x-axis only. I got the code: p+ theme(axis.ticks.length=unit(. 30, "cm")) but this increases the length for both x and y axis; whereas, I would like only on x-axis. Thank you very much in advance. Kind regards, Maria -- -- You received this message because you are subscribed to the ggplot2 mailing list. Please provide a reproducible example: https://github.com/hadley/ devtools/wiki/Reproducibility To post: email ggpl...@googlegroups.com To unsubscribe: email ggplot2+unsubscribe@ googlegroups.com More options: http://groups.google.com/ group/ggplot2 --- You received this message because you are subscribed to the Google Groups "ggplot2" group. To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+unsubscribe@ googlegroups.com. For more options, visit https://groups.google.com/d/ optout. -- -- You received this message because you are subscribed to the ggplot2 mailing list. Please provide a reproducible example: https://github.com/hadley/ devtools/wiki/Reproducibility To post: email ggpl...@googlegroups.com To unsubscribe: email ggplot2+unsubscribe@ googlegroups.com More options: http://groups.google.com/ group/ggplot2 --- You received this message because you are subscribed to the Google Groups "ggplot2" group. To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+unsubscribe@ googlegroups.com. For more options, visit https://groups.google.com/d/ optout. -- -- You received this message because you are subscribed to the ggplot2 mailing list. Please provide a reproducible example: https://github.com/hadley/ devtools/wiki/Reproducibility To post: email ggpl...@googlegroups.com To unsubscribe: email ggplot2+unsubscribe@ googlegroups.com More options: http://groups.google.com/ group/ggplot2 --- You received this message because you are subscribed to the Google Groups "ggplot2" group. To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+unsubscribe@ googlegroups.com. For more options, visit https://groups.google.com/d/ optout. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.