Re: [R] facet_wrap(nrow) ignored

2020-09-10 Thread Ulrik Stervbo via R-help
Dear Ivan, I don't think it is possible to force a number of rows - but I'm honestly just guessing. What you can do is to add an empty plot. Here I use cowplot, but gridExtra should also work well. I add an indication of the row number for the plot to the initial data.frame, and loop over

Re: [R] readxl question

2020-08-27 Thread Ulrik Stervbo via R-help
) }, ranges = ranges, .id = "filename") ``` On 2020-08-27 17:33, Ulrik Stervbo via R-help wrote: Hi Thomas, I am not familiar with the use of the range argument, but it seems to me that the cell value becomes the column name. This might be fine, but you might get into trouble if you hav

Re: [R] readxl question

2020-08-27 Thread Ulrik Stervbo via R-help
Hi Thomas, I am not familiar with the use of the range argument, but it seems to me that the cell value becomes the column name. This might be fine, but you might get into trouble if you have repeated cell values since as.data.frame() will fix these. I am also not sure about what you want,

Re: [R] Binomial PCA Using pcr()

2020-08-19 Thread Ulrik Stervbo via R-help
Hi Prasad, I think this might be a problem with the package, and you can try to contact the package author. The error seem to arise because the pcr() cannot find the 'negative-binomial' distribution ``` library(qualityTools) x <- rnbinom(500, mu = 4, size = 100) pcr(x, distribution =

Re: [R] Help with read.csv.sql()

2020-07-29 Thread Ulrik Stervbo via R-help
ear Ulrik, > >On 2020-07-29 17:14 +0200, Ulrik Stervbo via R-help wrote: >> library(readr) >> read_csv( > >This thread was about >sqldf::read.csv.sql ... > >What is the purpose of bringing up >readr::read_csv? I am unfamilliar with >it, s

Re: [R] Help with read.csv.sql()

2020-07-29 Thread Ulrik Stervbo via R-help
You might achieve this using readr: ``` library(readr) lines <- "Id, Date, Time, Quality, Lat, Long STM05-1, 2005/02/28, 17:35, Good, -35.562, 177.158 STM05-1, 2005/02/28, 19:44, Good, -35.487, 177.129 STM05-1, 2005/02/28, 23:01, Unknown, -35.399, 177.064 STM05-1, 2005/03/01,

Re: [R] Help with read.csv.sql()

2020-07-29 Thread Ulrik Stervbo via R-help
You might achieve this using readr: ``` library(readr) lines <- "Id, Date, Time, Quality, Lat, Long STM05-1, 2005/02/28, 17:35, Good, -35.562, 177.158 STM05-1, 2005/02/28, 19:44, Good, -35.487, 177.129 STM05-1, 2005/02/28, 23:01, Unknown, -35.399, 177.064 STM05-1, 2005/03/01,

Re: [R] Dataframe with different lengths

2020-07-29 Thread Ulrik Stervbo via R-help
Hi Pedro, I see you use dplyr and ggplot2. Are you looking for something like this: ``` library(ggplot2) library(dplyr) test_data <- data.frame( year = c(rep("2018", 10), rep("2019", 8), rep("2020", 6)), value = sample(c(1:100), 24) ) test_data <- test_data %>% group_by(year) %>%

Re: [R] Arranging ggplot2 objects with ggplotGrob()

2020-07-29 Thread Ulrik Stervbo via R-help
Then this should work: ``` library(ggplot2) library(cowplot) p1 <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) + geom_point() p2 <- ggplot(iris, aes(x = Petal.Length, y = Petal.Width * 1000)) + geom_point() plot_grid(p1, p2, ncol = 1, align = "hv", rel_heights = c(2, 1), axis =

Re: [R] Arranging ggplot2 objects with ggplotGrob()

2020-07-28 Thread Ulrik Stervbo via R-help
Would this work: ``` library(ggplot2) library(cowplot) p1 <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) + geom_point() p2 <- ggplot(iris, aes(x = Petal.Length, y = Petal.Width * 1000)) + geom_point() plot_grid(p1, p2, ncol = 1, align = "hv", rel_heights = c(2, 1)) ``` Best, Ulrik

Re: [R] Filtering using multiple rows in dplyr

2018-05-31 Thread Ulrik Stervbo via R-help
Hi Sumitrajit, dplyr has a function for this - it's called filter. For each group you can count the number of SNR > 3 (you can use sum on true/false). You can filter on the results directly or add a column as you plan. The latter might make your intention more clear. HTH Ulrik On

Re: [R] removing part of a string

2018-05-21 Thread Ulrik Stervbo
I would use sub("\\(.*\\)", "()", s) It is essentially the same as Rui's suggestion, but I find the purpose to be more clear. It might also be a little more efficient. HTH Ulrik On Mon, 21 May 2018, 15:38 Rui Barradas, wrote: > Hello, > > Try this. > > > ss1 <- "z:f(5,

Re: [R] questions on subscores.

2018-05-14 Thread Ulrik Stervbo
I have no idea, but Google pointed me to this https://cran.r-project.org/web/packages/subscore/index.html Hth Ulrik "Hyunju Kim" schrieb am Di., 15. Mai 2018, 07:21: > > > > Hello, > > > > I want to compute Wainer et al's augmented subscore(2001) using IRT but I >

Re: [R] Quandl data download error

2018-05-14 Thread Ulrik Stervbo
Hi Christofer, it works for me. Perhaps you need up update a package? Best wishes, Ulrik > sessionInfo() R version 3.4.4 (2018-03-15) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 18.04 LTS Matrix products: default BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1 LAPACK:

Re: [R] using apply

2018-05-02 Thread Ulrik Stervbo
Hi Neha, Perhaps merge() from base or join from dplyr is what you are looking for. data. table could also be interesting. Hth Ulrik On Wed, 2 May 2018, 21:28 Neha Aggarwal, wrote: > Hi > > I have 3 dataframes, a,b,c with 0/1 values...i have to check a condition >

Re: [R] Hacked

2018-04-17 Thread Ulrik Stervbo
I asked the moderators about it. This is the reply "Other moderators have looked into this a bit and may be able to shed more light on it. This is a "new" tactic where the spammers appear to reply to the r-help post. They are not, however, going through the r-help server. It also seems that this

Re: [R] Help with R-Calling forth csv.

2018-04-16 Thread Ulrik Stervbo
There are plenty of options for reading csv files. For built-in solutions look at ?read.csv or at read_csv from the package reader. If the measurements are ordered in columns rather than in rows, reading the data can be very slow. HTH Ulrik Mohammad Areida schrieb am Mo.,

Re: [R] regex for "[2440810] / www.tinyurl.com/hgaco4fha3"

2018-02-20 Thread Ulrik Stervbo
Hi Omar, you are almost there but! Your first substitution looks 'www' as the start of the line followed by anything (which then do nothing), so your second substitution removes everything from the first '.' to be found (which is the one after www). What you want to do is x <- "[2440810] /

Re: [R] Help with regular expressions

2018-02-12 Thread Ulrik Stervbo
I think I would replace all , with . and subsequently replace all first . with , using ^\\. x <- gsub(",", ".", x) gsub("^\\.", ",", x) It's not so elegant, but it is easier to understand than backreferences and complex regex. Best, Ulrik On Tue, 13 Feb 2018, 03:38 Boris Steipe,

Re: [R] Newbie wants to compare 2 huge RDSs row by row.

2018-01-28 Thread Ulrik Stervbo
.@tibco.com] > Sent: Saturday, January 27, 2018 4:57 PM > To: Marsh Hardy ARA/RISK > Cc: Ulrik Stervbo; Eric Berger; r-help@r-project.org > Subject: Re: [R] Newbie wants to compare 2 huge RDSs row by row. > > If your two objects have class "data.frame" (look

Re: [R] Newbie wants to compare 2 huge RDSs row by row.

2018-01-27 Thread Ulrik Stervbo
Also, it will be easier to provide helpful information if you'd describe what in your data you want to compare and what you hope to get out of the comparison. Best wishes, Ulrik Eric Berger schrieb am Sa., 27. Jan. 2018, 08:18: > Hi Marsh, > An RDS is not a data

Re: [R] Newbie - Scrape Data From PDFs?

2018-01-23 Thread Ulrik Stervbo
I think I would use pdftk to extract the form data. All subsequent manipulation in R. HTH Ulrik Eric Berger schrieb am Mi., 24. Jan. 2018, 08:11: > Hi Scott, > I have never done this myself but I read something recently on the > r-help distribution that was related. > I

Re: [R] file creating

2017-12-10 Thread Ulrik Stervbo
You could loop over the file names, read each excel file and store the individual data frames in a list using lapply. I prefer to read excel files with the package readxl. The code could be along the lines of library(readxl) my_files <- c("file1", "file2") lapply(my_files, read_excel) HTH

Re: [R] Scatterplot of many variables against a single variable

2017-11-27 Thread Ulrik Stervbo
ggplot and facets might be useful. Ulrik Ismail SEZEN schrieb am Mo., 27. Nov. 2017, 14:06: > > > On 27 Nov 2017, at 13:59, Engin YILMAZ wrote: > > > > Dear Berger and Jim > > > > Can you see my eviews example in the annex? (scattersample.jpg) > >

Re: [R] fill histogram in ggplot

2017-11-07 Thread Ulrik Stervbo
Hi Elahe, You pass 'probable' to the fill aesthetic along the lines of; ggplot(hist) + aes(x=mms, fill = probable) + geom_histogram(binwidth=1) The NAs might give you three and not two colours. I'm guessing you want distinct colours. In this case 'probable' should be a factor and not an

Re: [R] Help in R

2017-11-05 Thread Ulrik Stervbo
And head(test_df$Movie, 10) For function completeness :-) Rui Barradas <ruipbarra...@sapo.pt> schrieb am So., 5. Nov. 2017, 20:56: > Hello, > > Also > > tail(test_df$Movie, 10) > > Hope this helps, > > Rui Barradas > > Em 05-11-2017 19:18, Ulrik

Re: [R] Help in R

2017-11-05 Thread Ulrik Stervbo
R can have a bit of a learning curve... There are several ways to achieve your goal - depending on what you want: test_df <- data.frame(Movie = letters, some.value = rnorm(26)) test_df$Movie[1:10] test_df$Movie[sample(c(1:26), 10)] test_df[sample(c(1:26), 10), ] Do read a tutorial or two on R

Re: [R] Creating Tag

2017-11-01 Thread Ulrik Stervbo
Hi Hermant, It sounds lile grep from base or str_detect from the Stringr package is what you want. Best, Ulrik Hemant Sain schrieb am Mi., 1. Nov. 2017, 08:31: > i want to tag categories to its menuname. > i have a csv containing menu item name and in other csv i have

Re: [R] Regular expression help

2017-10-09 Thread Ulrik Stervbo
Hi Duncan, why not split on / and take the correct elements? It is not as elegant as regex but could do the trick. Best, Ulrik On Mon, 9 Oct 2017 at 17:03 Duncan Murdoch wrote: > I have a file containing "words" like > > > a > > a/b > > a/b/c > > where there may be

Re: [R] example of geom_contour() with function argument

2017-10-09 Thread Ulrik Stervbo
Hi BFD, ?geom_contour() *does* have helpful examples. Your Google-foo is weak: Searching for geom_contour brought me: http://ggplot2.tidyverse.org/reference/geom_contour.html as the first result. HTH Ulrik On Mon, 9 Oct 2017 at 08:04 Big Floppy Dog wrote: > Can someone

Re: [R] how to overlay 2d pdf atop scatter plot using ggplot2

2017-10-08 Thread Ulrik Stervbo
How about geom_contour()? Am So., 8. Okt. 2017, 20:52 schrieb Ranjan Maitra : > Hi, > > I am no expert on ggplot2 and I do not know the answer to your question. I > looked around a bit but could not find an answer right away. But one > possibility could be, if a direct approach

Re: [R] rename multiple files by file.rename or other functions

2017-09-28 Thread Ulrik Stervbo
Hi John, I don't know how to do this with R, but on Linux I'd use rename (or maybe even by hand if it's a one time event). On Windows I believe there is a tool called Bulk Rename. HTH Ulrik On Thu, 28 Sep 2017 at 11:37 John wrote: > Hi, > >I have 50 files whose names

Re: [R] disturbed legend in ggplot2

2017-09-27 Thread Ulrik Stervbo
Hi Troels, Try to move the size argument out of the aesthetic. Best wishes, Ulrik On Mi., 27. Sep. 2017, 08:51 Troels Ring wrote: > Dear friends - below is a subset of a much larger material showing two > ways of generating two "lines". The intention is to have the colour >

Re: [R] Load R data files

2017-09-12 Thread Ulrik Stervbo
at the file was loaded to R. But when I typed the data > name, it says that the not found. > > > *datahs0csv2* > > *Error: object 'datahs0csv2' not found* > > > with many thanks > abou > > On Tue, Sep 12, 2017 at 2:53 PM, Ulrik Stervbo <ulrik.ster..

Re: [R] Load R data files

2017-09-12 Thread Ulrik Stervbo
Hi Abou, You haven't saved the datahs0csv. When you are done manipulating datahs0csv you can use save(datahs0csv, file = 'datahs0csv.rda'). Then you should be able to load the data. HTH Ulrik On Tue, 12 Sep 2017, 20:46 AbouEl-Makarim Aboueissa < abouelmakarim1...@gmail.com> wrote: > Dear All:

Re: [R] Nested loop R code

2017-09-08 Thread Ulrik Stervbo
Hi Hemant, please write to the r-help list in the future. Look at the cut () function to solve your problem. Also, you have a problem in your example - 5 is placed in two different categories. HTH Ulrik On Fri, 8 Sep 2017 at 12:16 Hemant Sain wrote: > i have a vector

Re: [R] Dataframe Manipulation

2017-09-05 Thread Ulrik Stervbo
) > > cat_help %>% gather("Foo", "Item") %>% > filter(!is.na(Item)) %>% > left_join(data_help, by = "Item") %>% > group_by(Foo, Purchase_ID) %>% > summarise(Item = paste(Item, collapse = ", ")) %>% > spread(k

Re: [R] Dataframe Manipulation

2017-08-31 Thread Ulrik Stervbo
are to previous demo data set becaue spiting is getting done on the >> basis of quantity and in real data set quantity is missing. so please use >> following data set and help me out please consider this mail is my final >> email i won't bother you again but its about my job ple

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 <-

Re: [R] Find maxima of a function

2017-08-26 Thread Ulrik Stervbo
e and in 2nd case around 2.1 > according to the plot. > your code will not work in both the scenario > > Regards > Niharika Singhal > > > On Sat, Aug 26, 2017 at 12:47 PM, Ulrik Stervbo <ulrik.ster...@gmail.com> > wrote: > >> Hi, >> >> I once found this

Re: [R] Find maxima of a function

2017-08-26 Thread Ulrik Stervbo
Hi, I once found this somewhere on stackoverflow: values <- rnorm(20, mean = c(2.15,2.0,2.9), sd = c(0.1,0.1,0.1)) v_dens <- density(values) v_dens_y <- v_dens$y r <- rle(v_dens_y) # These functions ignore the extremes if they are the first or last point maxima_index <- which(rep(x =

Re: [R] about multi-optimal points

2017-08-26 Thread Ulrik Stervbo
HI lily, for the colouring of individual points you can set the colour aesthetic. The ID is numeric so ggplot applies a colour scale. If we cast ID to a factor we get the appropriate colouring. test_df <- data.frame(ID = 1:20, v1 = rnorm(20), v2 = rnorm(20), v3 = rnorm(20)) ggplot(data=test_df,

Re: [R] Help Required in looping visuals

2017-08-21 Thread Ulrik Stervbo
Hi Venkat, I must admit I don't understand what you are looking for, but maybe just store the visuals in a named lIst? Also, I have started to use nested data.frames to keep plots together with identifiers of the data sets. The nest and unnest functions are in the tidyr package. It keeps me from

Re: [R] data frame question

2017-08-06 Thread Ulrik Stervbo
Hi Andreas, assuming that the increment is always indicated by the same value (in your example 0), this could work: df$a <- cumsum(seq_along(df$b) %in% which(df$b == 0)) df HTH, Ulrik On Sun, 6 Aug 2017 at 18:06 Bert Gunter wrote: > Your specification is a bit unclear

Re: [R] about saving format

2017-08-05 Thread Ulrik Stervbo
I have no clue how Rstudio saves plots, but when I was writing directly to the pdf plot device I had similar problems. Setting useDingbats = TRUE made everything work well. I think it is more prudent - and less clicking here and there - to save plots from within the script. I imagine this works

Re: [R] define a list with names as variables

2017-08-04 Thread Ulrik Stervbo
Hi Giovani, I would create an unnamed list and set the names after. Best, Ulrik On Fri, 4 Aug 2017 at 12:08 Giovanni Gherdovich wrote: > Hello, > > I'm having troubles defining a list where names are variables (of type > character). Like this, which gives "foo" instead

Re: [R] Restructuring Star Wars data from rwars package

2017-08-04 Thread Ulrik Stervbo
Hi Matt, the usual way would be to use do.call(): .lst <- list(x = list(a = 1, b = 2), y = list(a = 5, b = 8)) do.call(rbind, lapply(.lst, data.frame, stringsAsFactors = FALSE)) however, your list has vectors of unequal lengths making the above fail. You somehow need to get everything to have

Re: [R] fill out a PDF form in R

2017-07-26 Thread Ulrik Stervbo
On second thought, you could also use pdftk to fill out the pdf form with data generated in R. On Wed, 26 Jul 2017 at 14:01 Ulrik Stervbo <ulrik.ster...@gmail.com> wrote: > Hi Elahe, > > I have no clue, but maybe you can dump the data fields using pdftk, and > work with t

Re: [R] fill out a PDF form in R

2017-07-26 Thread Ulrik Stervbo
Hi Elahe, I have no clue, but maybe you can dump the data fields using pdftk, and work with those in R. HTH Ulrik On Wed, 26 Jul 2017 at 13:50 Elahe chalabi via R-help wrote: > Hi all, > > I would like to get ideas about how to fill out a PDF form in R and to > know if

Re: [R] spaghetti plot - urgent

2017-07-19 Thread Ulrik Stervbo
Hi Rosa, You pass a vector to ggplot, which expects a data.frame. I am sure you meant to do this: point7$y_point7 <- point7$beta0_7 + point7$beta1_7*point7$time + point7 $epsilon_7 ggplot(point7, aes(time, y_point7)) + geom_line() HTH Ulrik On Wed, 19 Jul 2017 at 20:37 Rosa Oliveira

Re: [R] Problem in shiny writing a .txt file

2017-07-19 Thread Ulrik Stervbo
Hi Ana, The path is most likely wrong. How does f.texto() know the res.path? Do you manage to remove the old path and create a new one but f.texto() doesn't know? Not reasons for your problem, but curious: Why do you change the working directory? What is the intention behind appending

Re: [R] Arranging column data to create plots

2017-07-16 Thread Ulrik Stervbo
Hi Michael, Try gather from the tidyr package HTH Ulrik Michael Reed via R-help schrieb am So., 16. Juli 2017, 10:19: > Dear All, > > I need some help arranging data that was imported. > > The imported data frame looks something like this (the actual file is > huge, so

Re: [R] Help with R script

2017-07-13 Thread Ulrik Stervbo
rop=FALSE] > > This both assumes and requires that ALL of the rows are structured as in > the example data in the original question. > For example: > if any row is missing the “:”, it will fail. > If the “:” is not followed by a space character it may fail (I have not > checke

Re: [R] Help with R script

2017-07-13 Thread Ulrik Stervbo
Hi Vijayan, one way going about it *could* be this: library(dplyr) library(tidyr) library(purrr) ex_dat <- c("FName: fname1", "Fval: Fval1.name1", "Fval: ", "FName: fname2", "Fval: Fval2.name2", "FName: fname3") data.frame(x = ex_dat) %>% separate(x, c("F1", "F2"), sep = ": ") %>%

Re: [R] PAM Clustering

2017-07-10 Thread Ulrik Stervbo
Hi Sema, read.csv2 use ',' as the decimal separator. Since '.' is used in your file, everything becomes a character which in turn makes pam complain that what you pass to the function isn't numeric. Use read.csv2("data.csv", dec = ".") and it should work. You can also use class(d) to check the

Re: [R] Data import R: some explanatory variables not showing up correctly in summary

2017-06-01 Thread Ulrik Stervbo
Hi Tara, It seems that you categorise and count for each category. Could it be that the method you use puts everything that doesn't match the predefined categories in Other? I'm only guessing because without a minimal reproducible example it's difficult to do anything else. Best wishes Ulrik

Re: [R] organizing data in a matrix avoiding loop

2017-05-26 Thread Ulrik Stervbo
Hi Mario, does acast from the reshape2 package help? dfa<- data.frame(iso_o = letters[c(1, 1:4)], iso_d = letters[6:10], year = c(1985, 1985, 1986, 1987, 1988), flow = c(1,2,3,4, NA)) reshape2::acast(dfa, iso_o ~ iso_d, fun.aggregate = sum, value.var = "flow") HTH Ulrik On Fri, 26 May 2017 at

Re: [R] using "dcast" function ?

2017-05-26 Thread Ulrik Stervbo
It is correct and will produce a data.frame. But I guess the result is not what you intend since the resulting data.frame nothing but NA and Samples in the diagonal: df1 <- data.frame(x = letters[1:5], y = letters[6:10]) reshape2::dcast(df1, x ~ y) You are missing values somewhere. If you want

Re: [R] about combining two dataframes

2017-05-24 Thread Ulrik Stervbo
Hi Lily, maybe you should read up on what bind_rows/bind_cols (or the base functions rbind and cbind) do. bind_cols and cbind will fail in this case because of the different number of rows. bind_rows and rbind will fail because the column names are different - how can R know that month and mon

Re: [R] problem with system.file

2017-05-22 Thread Ulrik Stervbo
What is your version of readxl? In my version 1.0, there is no directory called estdata, but there is one called extdata. However, in that directory there is no file called "results.xlsx" Either it was there once and has now gone missing or "results.xlsx" your own file? It looks like the latter

Re: [R] Randomly select one row by group from a matrix

2017-05-18 Thread Ulrik Stervbo
Hi Marine, your manipulation of the matrix is quite convoluted, and it helps to expand a bit: test_lst <- split(test, test[,c("id")]) test_lst$`1` after splitting, your matrix has gone back to be a plain vector, which makes the sampling fail. The reason is that, a matrix - behind the scenes -

Re: [R] Plotting bar charts by Month

2017-05-13 Thread Ulrik Stervbo
Does scale_x_date(date_breaks = "1 month") do what you want? Ulrik John Kane via R-help schrieb am Sa., 13. Mai 2017, 17:12: > Could we see some sample data? > > > On Tuesday, May 9, 2017 9:55 PM, Jeff Reichman < > reichm...@sbcglobal.net> wrote: > > > r-help > > >

Re: [R] creating a color gradient in geom_ribbon

2017-05-10 Thread Ulrik Stervbo
I haven't tested it but the first thing I'd look at is scale_fill_gradient. HTH Ulrik Jim Lemon schrieb am Do., 11. Mai 2017, 07:22: > Hi Kristi, > It can be done, but it is messy: > > pl = data.frame(Time = 0:10, menle = rnorm(11)) > pl$menlelb = pl$menle -1 >

Re: [R] passing arguments to simple plotting program.

2017-05-09 Thread Ulrik Stervbo
nt in "plot_f1(indata=v5, > n1=114, n2=119, n3=116, fig_descrip=Figure 2” > > Even this call gives the same error: plot_f1(indata=v5, n1=114, n2=119, > n3=116, fig_descrip=Figure) > > > Thanks, > > Gerard > > > > > > > On May 8, 2017, at 11:40 PM, Ul

Re: [R] Joining tables with different order and matched values

2017-05-09 Thread Ulrik Stervbo
wrote: > Could you please teach me about the correct formation of the syntax?. I > have read the help page and other online resources about inner,left, > join but wasn't able to formulate the correct syntax. > > > Sent from my Samsung device > > > Original messa

Re: [R] Joining tables with different order and matched values

2017-05-09 Thread Ulrik Stervbo
Hi Abo, ?merge or the join functions from dplyr. HTH Ulrik On Tue, 9 May 2017 at 06:44 abo dalash wrote: > Hi All .., > > > I have 2 tables and I'm trying to have some information from the 1st table > to appear in the second table with different order. > > > For

Re: [R] passing arguments to simple plotting program.

2017-05-09 Thread Ulrik Stervbo
HI Gerard, You get the literals because the variables are not implicitly expanded - 'Placebo(N=n1) ' is just a string indicating the N = n1. What you want is to use paste() or paste0(): c(paste0("Placebo(N=", n1, ")"), paste0("Low Dose (N=", n2, ")"), paste0("High Dose (N=", n3, ")")) should do

Re: [R] Formatting column displays

2017-05-05 Thread Ulrik Stervbo
Hi Bruce, while working with data I would not touch the formatting of the columns. If knowing the units is important, you can add it to the column name rather than the values of the columns. For presentation purposes - where everything is turned into strings - it is a different story. Once you

Re: [R] Formatting column displays

2017-05-05 Thread Ulrik Stervbo
Hi Bruce, display as in the console or as a table for presentation? For the latter, look at sprintf: sprintf("%,1f", 1) sprintf("%.2f", 2.5678) sprintf("$%.3f", 2.5678) HTH Ulrik On Fri, 5 May 2017 at 14:08 Bruce Ratner PhD wrote: > R-helpers: > I need some references for

Re: [R] Multiple Histograms in R

2017-04-20 Thread Ulrik Stervbo
Hi Prateek, maybe facet_* with ggplot is what you are looking for HTH Ulrik On Thu, 20 Apr 2017 at 13:24 prateek pande wrote: > HI Hasan, > > Thanks for sharing the solution. Really appreciate it. > > But i was reading somewhere that we cannot use par with ggplot 2 . we

Re: [R] problems in vectors of dates_times

2017-04-07 Thread Ulrik Stervbo
Hi Troels, I get no error. I think we need more information to be of any help. Best wishes, Ulrik On Fri, 7 Apr 2017 at 08:17 Troels Ring wrote: > Dear friends - I have further problems handling dates_times, as > demonstrated below where concatenating two formatted vectors

Re: [R] readr to generate tibble from a character matrix

2017-04-06 Thread Ulrik Stervbo
Hi Ben, type.convert should do the trick: m %>% as_tibble() %>% lapply(type.convert) %>% as_tibble() I am not too happy about to double 'as_tibble' but it get the job done. HTH Ulrik On Thu, 6 Apr 2017 at 16:41 Ben Tupper wrote: > Hello, > > I have a workflow

Re: [R] Using R and Python together

2017-03-31 Thread Ulrik Stervbo
'Snakemake' (https://snakemake.readthedocs.io/en/stable/) was created to ease pipelines through different tools so it might be useful. In all honesty I only know of Snakemake, so it might be the completely wrong horse. HTH Ulrik On Fri, 31 Mar 2017 at 06:01 Wensui Liu

Re: [R] Antwort: Re: Way to Plot Multiple Variables and Change Color

2017-03-28 Thread Ulrik Stervbo
Hi Georg, you were on the right path - it is all about scale_fill* The 'problem' as you've discovered is that value is continuous, but applying scale_fill_manual or others (except scale_fill_gradient) expects discrete values. The solution is simply to set the fill with that by using factor():

Re: [R] Way to Plot Multiple Variables and Change Color

2017-03-28 Thread Ulrik Stervbo
Hi Georg, I am a little unsure of what you want to do, but maybe this: mdf <- melt(dfr) d_result <- mdf %>% dplyr::group_by(variable, value) %>% summarise(n = n()) ggplot( d_result, aes(variable, y = n, fill = value)) + geom_bar(stat = "identity") HTH Ulrik On Tue, 28 Mar 2017 at

Re: [R] Looping Through DataFrames with Differing Lenghts

2017-03-28 Thread Ulrik Stervbo
Hi Paul, does this do what you want? exdf1 <- data.frame(Date = c("1985-10-01", "1985-11-01", "1985-12-01", "1986-01-01"), Transits = c(NA, NA, NA, NA)) exdf2 <- data.frame(Date = c("1985-10-01", "1986-01-01"), Transits = c(15, 20)) tmpdf <- subset(exdf1, !Date %in% exdf2$Date) rbind(exdf2,

Re: [R] Looping Through DataFrames with Differing Lenghts

2017-03-27 Thread Ulrik Stervbo
You could use merge() or %in%. Best, Ulrik Mark Sharp schrieb am Mo., 27. März 2017, 22:20: > Make some small dataframes of just a few rows that illustrate the problem > structure. Make a third that has the result you want. You will get an > answer very quickly. Without a

Re: [R] R package

2017-03-23 Thread Ulrik Stervbo
Hi Elahe, maybe the us.cities() in the maps package is what you look for. HTH Ulrik On Thu, 23 Mar 2017 at 11:34 Elahe chalabi via R-help wrote: > Hi all, > > I have a data frame containing serial numbers for US. I also have a column > showing the city in US, now my

Re: [R] string pattern matching

2017-03-22 Thread Ulrik Stervbo
Hi Joe, you could also rethink your pattern: grep("x1 \\+ x2", test, value = TRUE) grep("x1 \\+ x", test, value = TRUE) grep("x1 \\+ x[0-9]", test, value = TRUE) HTH Ulrik On Wed, 22 Mar 2017 at 02:10 Jim Lemon wrote: > Hi Joe, > This may help you: > > test <- c("x1",

Re: [R] find and

2017-03-18 Thread Ulrik Stervbo
Using dplyr: library(dplyr) # Counting unique DF4 %>% group_by(city) %>% filter(length(unique(var)) == 1) # Counting not duplicated DF4 %>% group_by(city) %>% filter(sum(!duplicated(var)) == 1) HTH Ulrik On Sat, 18 Mar 2017 at 15:17 Rui Barradas wrote: >

Re: [R] lagging over consecutive pairs of rows in dataframe

2017-03-17 Thread Ulrik Stervbo
Hi Evan you can easily do this by applying diff() to each exp group. Either using dplyr: library(dplyr) mydata %>% group_by(exp) %>% summarise(difference = diff(rslt)) Or with base R aggregate(mydata, by = list(group = mydata$exp), FUN = diff) HTH Ulrik On Fri, 17 Mar 2017 at 17:34 Evan

Re: [R] ggplot2: Adjusting title and labels

2017-03-16 Thread Ulrik Stervbo
Hi Georg, If you remove the coord_polar, you'll see that the optimal y-value for the labels is between the upper and lower bound of the stacked bar-element. I am not sure it is the most elegant solution, but you can calculate them like this: df <- data.frame(group = c("Male", "Female",

Re: [R] field values from text file to dataframe

2017-03-13 Thread Ulrik Stervbo
I imagine that the FieldStateOption is irrelevant, so you might be able to create a data.frame like this: library(tidyr) fl <- readLines("pdf_dump.txt") fl <- grep("FieldStateOption", fl, value = TRUE, invert = TRUE) field_number <- vector(mode = "integer", length = length(fl)) tmpid <- 0

Re: [R] Extract student ID that match certain criteria

2017-03-13 Thread Ulrik Stervbo
Hi Roslinazairimah, As Bert suggested, you should get acquainted with regular expressions. It can be confusing at times, but pays off in the long run. In your case, the pattern of "^[A-Z]{2}14.*" might work. Best, Ulrik On Mon, 13 Mar 2017 at 06:20 roslinazairimah zakaria

Re: [R] plotting longitudinal data with ggplot

2017-03-11 Thread Ulrik Stervbo
You need to set the aesthetic 'group' to something meaningful, probably ID in this case. HTH Ulrik On Fri, 10 Mar 2017, 19:30 Rayt Chiruka, wrote: > i am trying to convert a dataset from wide to long format using package > tidyr- (seems to have been done) > > wen in try

Re: [R] reading form data from pdf forms

2017-03-11 Thread Ulrik Stervbo
I don't know if there's a pure R option, but i believe pdftk can extract the form data which you can then manipulate in R. Best Ulrik On Sat, 11 Mar 2017, 05:14 Vijayan Padmanabhan, < padmanabhan.vija...@gmail.com> wrote: > Dear R-Help group > Is there any way that I can programmatically

Re: [R] heat maps with qplot

2017-03-10 Thread Ulrik Stervbo
Hi Greg, ?theme You can use the axis.text and axis.title if y and x are to be identical, or axis.text.x, axis.text.y, axis.title.x, axis.title.y if you need different font size. HTH Ulrik On Fri, 10 Mar 2017 at 15:47 greg holly wrote: > Hi all; > > The followings are

Re: [R] restructuring data frame

2017-03-10 Thread Ulrik Stervbo
Hi Petr, maybe library("splitstackshape") cSplit(evid, "V4", "#", direction = "long") or library("tidyr") separate_rows(evid, V4, sep = "#") is helpful. Best, Ulrik On Fri, 10 Mar 2017 at 08:32 PIKAL Petr wrote: Dear all I have some data with following structure

Re: [R] Unable to Load package Rcmdr after installation

2017-03-09 Thread Ulrik Stervbo
is that I tried installing adn loading tve > Hmisc package but wasn't able to do that either. > > > Mensaje original > Asunto: Re: [R] Unable to Load package Rcmdr after installation > De: Ulrik Stervbo > Para: Paul Bernal ,r-help@r-project.org > CC: >

Re: [R] concatenating range of columns in dataframe

2017-03-09 Thread Ulrik Stervbo
Hi Evan, the unite function of the tidyr package achieves the same as Jim suggested, but in perhaps a slightly more readable manner. Ulrik On Fri, 10 Mar 2017 at 07:50 Jim Lemon wrote: > Hi Evan, > How about this: > >

Re: [R] Unable to Load package Rcmdr after installation

2017-03-09 Thread Ulrik Stervbo
Hi Paul, The error tells you, that the 'Hmisc' does not exist on your system. If you install it, everything should work. Use install.packages with dependencies = TRUE to avoid the problem of missing packages. HTH Ulrik On Thu, 9 Mar 2017 at 16:51 Paul Bernal wrote:

Re: [R] Problems outputting ggplot2 graphics to pdf

2017-03-02 Thread Ulrik Stervbo
Hi Hugh, I believe the recommended way of saving ggplots is through ggsave. It defaults to take the latest plot displayed, but you can specify which plot to save by passing the variable to the plot argument. If you need to save multiple plots in one file, you have to create a multipage plot

Re: [R] Averaging without NAs

2017-03-02 Thread Ulrik Stervbo
Hi Elahe, ?mean in particular the na.rm argument. HTH Ulrik On Thu, 2 Mar 2017 at 11:55 ch.elahe via R-help wrote: > Hi all, > > The question seems easy but I could not find an answer for it. I have the > following column in my data frame and I want to take average of

Re: [R] where is .emacs file?

2017-03-01 Thread Ulrik Stervbo
Files starting with dots are hidden files on Mac. The emacs configuration file .emacs should be in your home directory. You can list all files - also the hidden ones - by `ls -a` in your console. I don't use Mac so I can't tell you how to show hidden files in Finder. If you still can't find the

Re: [R] Selecting rows and columns of a data frame using relational operators

2017-02-27 Thread Ulrik Stervbo
Hi Tunga, The function subset() is probably what you are looking for. You might also want to look at a tutorial to understand the R syntax. In addition, calling your data data is not a good idea because of the name clash with the function data(). Hope this helps, Ulrik On Mon, 27 Feb 2017 at

Re: [R] Create gif from series of png files

2017-02-14 Thread Ulrik Stervbo
Hi Shane, Wrong forum. This might be what you are looking for ffmpeg -i %03d.png output.gif Or use the library gganimate. Best Ulrik Shane Carey schrieb am Di., 14. Feb. 2017, 12:08: > Hi, > > I have many png files that I would like to stitch together, in order to >

Re: [R] RStudio: Place for Storing Options

2017-02-09 Thread Ulrik Stervbo
Hi Georg, maybe someone here knows, but I think you are more likely to get answers to Rstudio related questions with RStudio support: https://support.rstudio.com/hc/en-us Best, Ulrik On Thu, 9 Feb 2017 at 12:35 wrote: > Hi All, > > I would like to make a backup of my

Re: [R] can this be simplified with purrr:map or mapply?

2017-01-18 Thread Ulrik Stervbo
If you want to use purrr, you could do fil <- paste0("data",2004:2014,".txt") map_df(fil, read.table, .id = "fil") to get everything in one data frame (I assume all files have the same structure) HTH Ulrik On Wed, 18 Jan 2017 at 16:10 PIKAL Petr wrote: > Hi > > Let me

Re: [R] Error in doc_parse_file

2017-01-07 Thread Ulrik Stervbo
Hi Maicel, Please keep the list in CC. I can't help with read_xml but perhaps someone on the list can. Best, Ulrik On Fri, 6 Jan 2017, 19:03 Maicel Monzon, wrote: > Hi Ulrik, > > > > I meant 'read_xmlmap' was a bug. I did what you told me with all the set > and the

Re: [R] purrr::map and xml2:: read_xml

2017-01-06 Thread Ulrik Stervbo
Hi Maicel, I'm guessing that B works on 50 files, and that A fails because there is no function called 'read_xmlmap'. If the function that you map work well, removing 'dplyr::sample_n(50)' from 'B' should solve the problem. If that is not the case, we need a bit more information. HTH Ulrik On

  1   2   3   >