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 a column > containing som

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] Help in R

2017-11-05 Thread Ulrik Stervbo
And head(test_df$Movie, 10) For function completeness :-) Rui Barradas 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 Stervbo escreveu: > > R can

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 integ

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) > > > > Sincerely > > Engin > > Please, use an ima

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 Ulri

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 just did a quick search

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 structure such as a data.frame.

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

2018-01-28 Thread Ulrik Stervbo
From: William Dunlap [wdun...@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&q

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, wrote: > You

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] / ww

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., 16. Apr. 2018, 13:25:

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] 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 > for dataframe a and b and the

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: /u

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 > can't find any packages or re

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, a=3, b=4, c='1:4', d=2)

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 yields a character matrix

Re: [R] problems in vectors of dates_times

2017-04-06 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 of > date_times res

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 can > only use grid ext

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 formatting the disp

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 ar

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

2017-05-08 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] Joining tables with different order and matched values

2017-05-08 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 Example, let's say this is my

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

2017-05-09 Thread Ulrik Stervbo
ach me about the correct formation of the syntax?. I > have read the help page and other online resources about inner,left,&right > join but wasn't able to formulate the correct syntax. > > > Sent from my Samsung device > > > ---- Original message > Fr

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

2017-05-09 Thread Ulrik Stervbo
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, Ulrik Stervbo >

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 > pl$menleub = pl$menle +1 > rg<

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 > > > > Trying to figure out

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

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

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 al

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 1

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 R

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 c

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 = ": ") %>% filter(F2

Re: [R] Help with R script

2017-07-13 Thread Ulrik Stervbo
tst[chk,,drop=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 > che

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 this is example data) >

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 dir(res.pa

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

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 it's possible or not. I

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 wrote: > Hi Elahe, > > I have no clue, but maybe you can dump the data fields using pdftk, and > work with those in R. > > HTH > Ulr

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 th

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 of "world" (the way I >

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 a

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 to me, so I'm not sure t

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] about multi-optimal points

2017-08-25 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] 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 = diff(sign(

Re: [R] Find maxima of a function

2017-08-26 Thread Ulrik Stervbo
; 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 > wrote: > >> Hi, >> >> I once found this somewhere on stackoverflow: >> >> values <- r

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-31 Thread Ulrik Stervbo
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 please help me >> . >> >> Note* th

Re: [R] Dataframe Manipulation

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

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 containing values rangin

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] 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 > wrote: > >

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 > reflect a variable,

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

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 is not possible, t

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 please point me to an ex

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 multiple words on a line (se

Re: [R] An averaged model based on Quartile and Mean of Quartiles

2016-05-21 Thread Ulrik Stervbo
Hi Chalabi, Maybe you can use ddply to look over the intervals and add the means as new colum Best wishes Ulrik David Winsemius schrieb am Sa., 21. Mai 2016 17:16: > > > On May 21, 2016, at 7:41 AM, ch.elahe via R-help > wrote: > > > > Hi all, > > > > Here is my df and I want to make an avera

Re: [R] add value to Bar chart ggplot2

2016-05-27 Thread Ulrik Stervbo
Hi Elahe, maybe this will help: http://stackoverflow.com/questions/6455088/how-to-put-labels-over-geom-bar-in-r-with-ggplot2 or this: http://stackoverflow.com/questions/12018499/how-to-put-labels-over-geom-bar-for-each-bar-in-r-with-ggplot2 Best, Ulrik On Fri, 27 May 2016 at 15:12 ch.elahe via R

Re: [R] add value to Bar chart ggplot2

2016-05-27 Thread Ulrik Stervbo
uot;ch.elahe via R-help" < > r-help@r-project.org> wrote: > >> Thanks Ulrik, >> But in these examples they want to mark the percentage or frequency of plot >> variables, in my case I want to mark the bars with a different variable of >> my df. DO you have any

Re: [R] How to replace all commas with semicolon in a string

2016-05-27 Thread Ulrik Stervbo
use gsub() On Fri, 27 May 2016 at 17:12 Jun Shen wrote: > Dear list, > > Say I have a data frame > > test <- data.frame(C1=c('a,b,c,d'),C2=c('g,h,f')) > > I want to replace the commas with semicolons > > sub(',',';',test$C1) -> test$C1 will only replace the first comma of a > string. > > How do

Re: [R] How to replace all commas with semicolon in a string

2016-05-27 Thread Ulrik Stervbo
or your reply. > > gsub worked for one column! > > If I want to replace the whole data frame, gsub doesn't seem to work. Any > idea > > On Fri, May 27, 2016 at 11:14 AM, Ulrik Stervbo > wrote: > >> use gsub() >> >> On Fri, 27 May 2016 at 17:12 Jun Sh

Re: [R] Extract from a text file

2016-05-30 Thread Ulrik Stervbo
Hi Val, Take a kook at read.table. If for some reason the file dosen't have the same separator between the columns you can use strsplit after loading the file. This might helpyou along getting data into R: http://www.statmethods.net/input/importingdata.html Best On Tue, 31 May 2016, 02:15 Val,

Re: [R] Training set in Self organizing Map

2016-06-01 Thread Ulrik Stervbo
Hi Elahe, if you look at your subdf, you will see that the column Country - which is not numeric - is still present. You might have other non-number columns, but this I cannot tell. scale expects a numeric matrix. You give it a data.frame which is silently cast to a matrix. A matrix can only have

Re: [R] reading data into nested frames

2016-06-02 Thread Ulrik Stervbo
Hi Ed, I'm not sure I understand, but can't you rwad the files one by one and create one data.frane using rbind? Is easy to put do in a loop too. Best wishes, Ulrik On Thu, 2 Jun 2016, 20:23 Ed Siefker, wrote: > I have many data files named like this: > > E11.5-021415-dko-1-1-masked-bottom-a

Re: [R] merging dataframes in a list

2016-06-03 Thread Ulrik Stervbo
You can use ldply in the plyr package to bind all the data.frames together (a regular loop will also work). Afterwards you can summarise using ddply Hope this helps Ulrik Ed Siefker schrieb am Fr., 3. Juni 2016 21:10: > aggregate isn't really what I want. Maybe tapply? I still can't get > it

Re: [R] Knitr R - how to draw plot exactly at place of plot function call in output document?

2016-06-06 Thread Ulrik Stervbo
Hi Michu, What document type do you generate? I usually make just html and have no problems. If you create a pdf, please remember this is done through LaTeX and your problem could arise from the floats of LaTeX. For other output I have no idea. Hope this helps Ulrik Michu Kom schrieb am Mo., 6

Re: [R] Knitr R - how to draw plot exactly at place of plot function call in output document?

2016-06-06 Thread Ulrik Stervbo
> having mixed sections and plots. > > Thank you for your advice, > Michu > > 2016-06-06 10:04 GMT+02:00 Ulrik Stervbo : > >> Hi Michu, >> >> What document type do you generate? I usually make just html and have no >> problems. If you create a pdf, please r

Re: [R] Error: missing value where TRUE/FALSE needed

2016-06-09 Thread Ulrik Stervbo
Dear Shashi, I don't see any code, but I will take a guess anyway: The error tells you that you try to compare a boolean with something that is not (TRUE or FALSE cannot be compared to NA). HTH Ulrik On Thu, 9 Jun 2016 at 08:55 SHASHI SETH wrote: > Hi, > > > > I am getting the following error

Re: [R] problem: the id of the data set

2016-06-09 Thread Ulrik Stervbo
How do you merge the two data.frames? Could it be that you make an outer join? HTH Ulrik On Thu, 9 Jun 2016 at 19:45 Michael Dewey wrote: > Perhaps I do not understand you correctly but why not create a variable > for the id before you merge? > > On 09/06/2016 09:00, 周 可卫 wrote: > > I got the d

Re: [R] inverse table

2016-06-15 Thread Ulrik Stervbo
Hi Patrizio, maybe there is a more efficient way, but you can loop over rows and columns like this ab.recon <- data.frame() ddd.rownames <- rownames(ddd) ddd.colnames <- colnames(ddd) for(cur.row in ddd.rownames){ for(cur.col in ddd.colnames){ times.found <- ddd[cur.row, cur.col] tmp.

Re: [R] check broken links in a column

2016-06-21 Thread Ulrik Stervbo
I don't know about R for this but how about wget: http://www.createdbypete.com/articles/simple-way-to-find-broken-links-with-wget/ You could store the list of links in a file and additionally use the -i flag. HTH Ulrik On Tue, 21 Jun 2016 at 16:47 Jenny Vander Pluym - NOAA Federal < jenny.vander

Re: [R] a new df with one combined column

2016-06-29 Thread Ulrik Stervbo
It looks like the function you are searching for is merge() HTH Ulrik On Wed, 29 Jun 2016 at 15:11 ch.elahe via R-help wrote: > Hi all, > I have this column as a part of df: > > $License : Factor W/384 levels > "41005","41006","41034","41097","41200",... > and I have other column which is

Re: [R] a new df with one combined column

2016-06-29 Thread Ulrik Stervbo
; On Wednesday, June 29, 2016 3:35 PM, Ulrik Stervbo < > ulrik.ster...@gmail.com> wrote: > > > > It looks like the function you are searching for is merge() > > HTH > Ulrik > > > On Wed, 29 Jun 2016 at 15:11 ch.elahe via R-help > wrote: > > Hi all,

Re: [R] Documenting data

2016-06-30 Thread Ulrik Stervbo
Vince Buffalo has covers this nicely in his book "Bioinformatics Data Skills". The original data should stay the original data is immutable and Vince then suggests that you have a text file in your data directory where you explain where the data came from and which scripts you used to create a modi

Re: [R] Difficulty subsetting data frames using logical operators

2016-07-02 Thread Ulrik Stervbo
Hi Giles, Look at ?mean In addition it seems you need to read a few tutorials on R. Several are already mentioned on this list otherwise Google can direct. Hope this helps, Ulrik Giles Bischoff schrieb am Fr., 1. Juli 2016 18:55: > So, I uploaded a data set via my directory using the command

Re: [R] regroup row names

2016-07-03 Thread Ulrik Stervbo
Hi Lily, you can use gsub: df$ID <- gsub("_.*", "", df$ID) HTH Ulrik On Sun, 3 Jul 2016 at 20:16 lily li wrote: > I have a problem in changing row names in a dataframe in R. The first > column is ID, such as aClim_st02, aClim_st03, aClim_st 05, bClim_st01, > bClim_st02, etc. How to rename the

Re: [R] regroup row names

2016-07-03 Thread Ulrik Stervbo
,df$ID), but it does not work. > > > On Sun, Jul 3, 2016 at 12:24 PM, Ulrik Stervbo > wrote: > >> Hi Lily, >> >> you can use gsub: >> >> df$ID <- gsub("_.*", "", df$ID) >> >> HTH >> Ulrik >> >> On S

Re: [R] regroup row names

2016-07-03 Thread Ulrik Stervbo
s characters after using the gsub function. > What is the problem? Thanks again. > > > On Sun, Jul 3, 2016 at 12:41 PM, Ulrik Stervbo > wrote: > >> Hi Lily, >> >> My suggestion should remove the underscore and everything after it, >> leaving just aClim

Re: [R] dplyr : row total for all groups in dplyr summarise

2016-07-04 Thread Ulrik Stervbo
If you want the total number of rows in the original data.frame after counting the rows in each group, you can ungroup and sum the row counts, like: library("dplyr") mtcars %>% group_by (am, gear) %>% summarise (n=n()) %>% mutate(rel.freq = paste0(round(100 * n/sum(n), 0), "%")) %>%

Re: [R] dplyr : row total for all groups in dplyr summarise

2016-07-04 Thread Ulrik Stervbo
That will give you the wrong result when used on summarised data David Winsemius schrieb am Di., 5. Juli 2016 02:10: > I thought there was an nrow() function? > > Sent from my iPhone > > On Jul 4, 2016, at 9:59 AM, Ulrik Stervbo wrote: > > If you want the total number of

Re: [R] dplyr : row total for all groups in dplyr summarise

2016-07-04 Thread Ulrik Stervbo
Yes. But in the sample code the data is summarised. In which case you get 4 rows and not the correct 32. On Tue, 5 Jul 2016, 07:48 David Winsemius, wrote: > nrow(mtcars) > > > Sent from my iPhone > > On Jul 4, 2016, at 9:03 PM, Ulrik Stervbo wrote: > > That will give y

Re: [R] Formatting ggplot2 graph

2016-07-06 Thread Ulrik Stervbo
Hi Georg, Your problem with the geom_text was that you tried to count Var1 in some bins which cannot be defined on characters - the counts you really wanted to use are in Anzahl. This should do what you want: library(ggplot2) freq_ls <- structure(list(Var1 = c("zldkkd", "aakdkdk","aaakdkd", "aai

Re: [R] make a right subset!

2016-07-07 Thread Ulrik Stervbo
Hi Elahe, Use subset and the %in% operator: subset(df2, Serial %in% Matched)[["Count "]] Best wishes, Ulrik On Thu, 7 Jul 2016 at 13:37 ch.elahe via R-help wrote: > Hi all, > I have 2 data frames like the following: > the first one df1: > > 'data.frame': 141obs. of 1 variable: > $Ser

Re: [R] Is there a way to coerce ggplot into using min & max values for x & y axes?

2016-07-11 Thread Ulrik Stervbo
Hi Ken, You can use coord_cartesian() to set axis. Or if it makes sense to your problem you can facet your plot. Hope this helps Ulrik KMNanus schrieb am Di., 12. Juli 2016 01:35: > I’m plotting few dozen variables, doing so because I need to examine them > one at a time. The range of these v

Re: [R] graph: horizontal bar reflecting number of data

2016-07-15 Thread Ulrik Stervbo
Dear Dagmar, must the numberdata be character? Here are tew solutions. The first solution summarise before plotting and the second does everything in the plot library("dplyr") library("ggplot2") datframe <- data.frame(Name=c("Kati","Kati","Kati","Leon","Leon","Leon" ), week =c("1","2", "3", "1",

Re: [R] frequency of items

2016-07-20 Thread Ulrik Stervbo
What you show cannot be a data.frame. Using what you gave, this should help you along: x <- c(11,15,12,25, 11,12, 15,25, 134,45,56, 46, 45,56, 15,12, 66,45,56,24,14,11,25,12,134) table(x) On Wed, 20 Jul 2016 at 11:44 Jim Lemon wrote: > Oops, didn't translate that function correctly: > > has_val

Re: [R] Please assist me to download this data

2016-07-25 Thread Ulrik Stervbo
The easiest might be to download the entire dataset and filter it appropriately. If I follow your link and press Download, I get the option to "Download Complete NAV Report in Text Format" and will result in this: http://portal.amfiindia.com/NAVReport.aspx?type=0 It is not the easiest format to ge

Re: [R] Please assist me to download this data

2016-07-25 Thread Ulrik Stervbo
I am aware of that link and this is a > good option. However with this approach, I can not get Data > historically. I would like to create some TS in R for each MF there. > > Any other idea? > > Thanks, > > On Tue, Jul 26, 2016 at 12:53 AM, Ulrik Stervbo > wrote: > &g

Re: [R] Error when installing packages

2016-07-26 Thread Ulrik Stervbo
Hi Georg, excel.link and installr: as far as I can tell from CRAN, excel.link and installr are for windows OS only 1-5: you are installing packages that are wrappers to system function/programms. They must be present on your system first. 2: Maybe Weka is missing in the path? Is your java excutab

Re: [R] Spread data.frame on 2 variables

2016-07-28 Thread Ulrik Stervbo
Hi Georg, it's hard to tell without a reproducible example. Should spread really merge elements? Does spread know anything about CustID? Maybe you need to make a useful key of the CustIDs first and spread on that? Maybe I'm all off, because I'm really just guessing. Best, Ulrik On Thu, 28 Jul

Re: [R] Reduce woes

2016-07-28 Thread Ulrik Stervbo
Hi Stefan, in that case,lapply(data, length) should do the trick. Best wishes, Ulrik On Thu, 28 Jul 2016 at 12:57 Stefan Kruger wrote: > David - many thanks for your response. > > What I tried to do was to turn > > data <- list(one = c(1, 1), three = c(3), two = c(2, 2)) > > into > > result <-

Re: [R] Spread data.frame on 2 variables

2016-07-28 Thread Ulrik Stervbo
into wide > form and keep all but missing value information. > > Did I explain my problem in a comprehensible way? Are there any further > questions? > > Kind regards > > Georg > > > > > > Von:Ulrik Stervbo > An: g.maub...@weinwolf.de, r-help@

Re: [R] Colour gradients in ggtern

2016-08-02 Thread Ulrik Stervbo
Hi Jake, maybe you can just revet the colours given to the scale: scale_colour_gradientn(colours = rev(rainbow(5.5))) Best, Ulrik On Tue, 2 Aug 2016 at 16:41 Jake William Andrae wrote: > Hello, > > This is my first time posting to the r-help mailing list and I'm a > relative amateur using R,

Re: [R] how to plot annual values directly

2016-08-03 Thread Ulrik Stervbo
You could use dplyr: library(plyr) ddply(df, .variables = "year", summarise, mean.precip = mean(precip)) Hope this helps Ulrik On Wed, 3 Aug 2016 at 17:29 lily li wrote: > I meant that my dataframe has daily data, but how to plot annual mean/sum > directly? Thanks. > > On Wed, Aug 3, 2016 at

Re: [R] plot many dfs in ggplot

2016-08-03 Thread Ulrik Stervbo
Not quite - this works: rbind(df1, df2, df3, df1, df2, df3) Or if the have your data.frames in a list, use do.call: df.lst <- list(df1, df2, df3, df1, df2, df3) do.call(rbind, df.lst) You might take a look at the facet functionality in ggplot once you are ready to build your plots. Best, Ulrik

  1   2   3   >