[R] Package ‘FAdist’ - Log-Pearson Type III Distribution
Dear Sir, I am referring to your package "FAdist". I wish to know how to estimate the parameters of the distribution - "Log-Pearson Type III Distribution"? Will it be possible for you to guide me or inform the package in R, I can use to estimate the parameters. Regards Katherine [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] lmomco - Three-Parameter Pearson 5 Distribution
Dear R forum, I am bit confused and please guide me - (1) Is "Pearson Type III Distribution" as given in lmomco package same as Three Parameter Pearson 5 Distribution? If not, how do I estimate the parameters of Three Parameter Pearson 5 Distribution? (2) Is there any other R forum dealing with only Statistical queries? Kindly guide Regards Katherine [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] Better way of writing R code
Dear Sir, Thanks a lot for your great help. Do appreciate it a lot. In my earlier mail, where I had attached some files, I have realized yesterday that instead of sending the R code customized by me based on your guidance, I had by mistake attached the contents of email. I do apologize to you for the same. Thanks once again and sorry for the inconvenience caused by me. Regards Katherine --- On Fri, 5/4/13, Adams, Jean wrote: From: Adams, Jean Subject: Re: [R] Better way of writing R code To: "Katherine Gobin" Cc: "R help" Date: Friday, 5 April, 2013, 2:40 PM Katherine, To preserve the original order, you could create a new variable for the currency data frame (BEFORE the merges), then use this variable to reorder at the end. currency_df$orig.order <- 1:dim(currency_df)[1] You can do another merge for the other currency, you just need to specify the columns that you want to merge by. The rate information will be called rate.x for the first currency (from the first merge) and rate.y for the other currency (from the second merge). both2 <- merge(both, rate_df, by.x=c("other_currency", "tenor"), by.y=c("currency", "tenor"), all.x=TRUE) Then reorder. both2 <- both2[order(both2$orig.order), ] Jean On Thu, Apr 4, 2013 at 3:19 AM, Katherine Gobin wrote: Dear Mr Adams, I sincerely apologize for taking the liberty of writing to you. I wholeheartedly thank you for the wonderful solution you had provided me yesterday. I have customized the R code you had provided and it's yielding the results. I can't imagine me repeating the 1 lines code after receving such a powerful solution from you. In future it will save lots of efforts from my side as I always deal with such situation. There is one small problem though - I am dealing with pair of currencies e.g. currency other_currency transaction USD EURO Buy USD CAD Buy GBP CHF Sell SEK USD Buy The R code gives me the currency rates (w.r.t. appropriate "tenor"), however, I need the corresponding rates pertaining to the other currency too i.e. in the first case, the maturity period applicable is one month so the R - code gives me one month LIBOR wr.t. USD, but I need the corresponding one month LIBOR w.r.t. the other currency i.e. EURO in this case. I tried to improve upon the merge statement and used "?merge", but couldn't. Another problem is the order of the original portfolio is not mainteained , but I think I can manage the order. With warm regards Katherine --- On Wed, 3/4/13, Adams, Jean wrote: From: Adams, Jean Subject: Re: [R] Better way of writing R code To: "Katherine Gobin" Cc: "R help" Date: Wednesday, 3 April, 2013, 2:08 PM Katherine, You don't need to convert rate_df into tabular form. You just need to categorize each row in currency_df into a "tenor". Then you can merge the two data frames (by currency and tenor). For example ... # convert dates to R dates, to calculate the number of days to maturity# I am assuming this is the number of days from the current date to the maturity date currency_df$maturity <- as.Date(currency_df$maturity_date, "%d/%m/%Y")currency_df$current <- as.Date(currency_df$current_date, "%d/%m/%Y")currency_df$days2mature <- as.numeric(currency_df$maturity - currency_df$current) # categorize the number of days to maturity as you wish# you may need to change the breaks= option to suit your needs# read about the cut function to make sure you get the cut points included in the proper category, ?cut currency_df$tenor <- cut(currency_df$days2mature, breaks=c(0, 1, 7, 14, seq(from=30.5, length=12, by=30.5)),labels=c("1 day", "1 week", "2 weeks", "1 month", paste(2:12, "months"))) # merge the currency_df and rate_df# this will work better with real data, since the example data you provided didn't have matching tenorsboth <- merge(currency_df, rate_df, all.x=TRUE) Jean On Wed, Apr 3, 2013 at 5:21 AM, Katherine Gobin wrote: Dear R forum, (Pl note this is not a finance problem) I have two data.frames as currency_df = data.frame(current_date = c("3/4/2013", "3/4/2013", "3/4/2013", "3/4/2013"), issue_date = c("27/11/2012", "9/12/2012", "14/01/2013", "28/02/2013"), maturity_date = c("27/04/2013", "3/5/2013", "14/6/2013", "28/06/2013"), currency = c("USD", "USD", "GBP", "SEK"), other_currency = c("EURO", "CAD", "CHF", "USD"), transaction = c("Buy", "Buy", "Sell", "Buy"), units_currency = c(10, 25000, 15, 4), units_other_currency = c(78000, 25350, 99200, 6150)) rate_df = data.frame(date = c("28/3/2013","27/3/2013","26/3/2013","25/3/2013","28/3/2013","27/3/2013","26/3/2013", "25/3/2013","28/3/2013","27/3/2013","26/3/2013","25/3/2013","28/3/2013","27/3/2013","26/3/2013", "25/3/2013","28/3/2013","27/3/2013","26/3/2013","25/3/2013","28
[R] Plotting a curve for a Holling Type III Functional Response
Hey, So I have a scatter plot and I am trying to plot a curve to fit the data based on a Holling Type III functional response. My function is this: nll2<-function(a,b) { conefun<-(a*DBH^2)/(b^2+DBH^2) nlls2<-dnbinom(x=cones ,size=DBH, mu=conefun,log=TRUE) -sum(nlls) } and my plot is this: plot (DBH,cones) DBH is on the x-axis and cones is on the y-axis. How do I get the curve for my function onto the scatterplot? -- View this message in context: http://r.789695.n4.nabble.com/Plotting-a-curve-for-a-Holling-Type-III-Functional-Response-tp4663556.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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] Multiple subsetting of a dataframe based on many conditions
Hello Everybody, I'm working with a dataframe that has 18 columns. I would like to subset the data in one of these columns, "present", according to combinations of data in six of the other columns within the data frame and then save this into a text file. The columns I would like to use to subset "present" are: * answer (1:4) [answer takes the values 1 to 4] *p.num (1:18) * session (1:2) * count (1:8) * type (1:3) So there are a total of 3456 possible subsetting combinations. At present, I have been using the following and manually changing the values in each line and re-running the code. input<-subset(input, answer==1) input.s2g<-subset(input, p.num == 1) input.s2g<-subset(input.s2g, session == "S2") input.s2g<-subset(input.s2g, count==8) input.s2g<-subset(input.s2g, type==1) write.table(s2g, file = "1_1_S2_8_1", sep = "\t", col.names = F, row.names = F) But this takes me hours and is obviously prone to error. There must be an easier way? Thanks for any help! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] error message sending question to the list
There is much wisdom in the Posting Guide mentioned in the footer of every email on this list. One pearl is the request to send your email in text format, not HTML. How you do this is specific to your email program, so we cannot help you, but Google is your friend. As to your message, requests for help debugging long complicated algorithms is frowned upon here and are likely to be ignored. Don't ask us to do your work for you... isolate your problem to at most two dozen lines of code and include 10-50 rows of sample data, and be specific about what is working and what is not. --- Jeff NewmillerThe . . Go Live... DCN:Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Stat Tistician wrote: >Hi, >I tried to send several questions to the lists (both normal R and >R-Sig-Finance), but everytime I look them up in the archives my >messages >end up with the following > >"An embedded and charset-unspecified text was scrubbed... > >for example see my post here: > >https://stat.ethz.ch/pipermail/r-sig-finance/2013q2/011496.html > > >This one was a real important for me. Can subscribers still read it? >Shall >I repost, how can I post correctly? > >Thanks > > [[alternative HTML version deleted]] > >__ >R-help@r-project.org mailing list >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-help@r-project.org mailing list 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] Mutliple subsetting of a dataframe based on many conditions
Hi, May be this helps: input1<- data.frame(answer=rep(1:4,times=18),p.number=rep(1:18,each=4),session=rep(1:2,each=36),count=rep(1:8,each=9),type=rep(1:3,each=24)) input2<- data.frame(answer=rep(1:4,times=18),p.number=rep(1:18,each=4),session=rep(1:2,each=36),count=rep(1:8,each=9),type=rep(1:3,each=24)) inputNew<- rbind(input1,input2) indx1<- apply(inputNew,1,paste0,collapse="") res<- lapply(split(indx1,indx1),function(x) inputNew[apply(inputNew,1,paste0,collapse="")%in%x,]) res[1:4] #$`110252` # answer p.number session count type #37 1 10 2 5 2 #109 1 10 2 5 2 #$`1` # answer p.number session count type #1 1 1 1 1 1 #73 1 1 1 1 1 #$`111252` # answer p.number session count type #41 1 11 2 5 2 #113 1 11 2 5 2 #$`112252` # answer p.number session count type #45 1 12 2 5 2 #117 1 12 2 5 2 A.K. Currently I have a dataframe with 18 columns. I would like to subset the data in one of these columns, "present", according to combinations of data in six of the other columns within the data frame and then save this into a text file. The columns I would like to use to subset "present" are: * answer (1:4) [answer takes the values 1 to 4] *p.num (1:18) * session (1:2) * count (1:8) * type (1:3) So there are a total of 3456 possible subsetting combinations. At present, I have been using the following and manually changing the values in each line and re-running the code. input<-subset(input, answer==1) input.s2g<-subset(input, p.num == 1) input.s2g<-subset(input.s2g, session == "S2") input.s2g<-subset(input.s2g, count==8) input.s2g<-subset(input.s2g, type==1) write.table(s2g, file = "1_1_S2_8_1", sep = "\t", col.names = F, row.names = F) But this takes hours and is obviously prone to error. There must be an easier way? Thanks for the help! __ R-help@r-project.org mailing list 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] Graphic window dimensions
On 06.04.2013 08:53, Eva Prieto Castro wrote: Dear all, I have a doubt: if I run windows(width=8.27, height=11.69), the size of an A4 paper, does it work correctly in all screens? Correctly: yes, but not as you expect. It keeps the aspect ration but in a smaller size if the screen is smaller than the size you specified. Or does it depend on the inches of my screen?. Yes. I ask you about this question because I need to make the user see a graph in the graph window and he must be able to save the graph as a pdf (using the Rgui menu) and the result must be a pdf with A4 size. Why not use pdf() directly? Anyway, you can dev.print(pdf, file="test.pdf", width=8.27, height=11.69) Best, Uwe Ligges Thank you in advance. Regards, Eva [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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-help@r-project.org mailing list 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] ad.test parameters
On 06.04.2013 09:45, iritgur wrote: Hi all, i have 2 cumulative (F(x)) distribution function that not defined in R. i want to make anderson darling goodness of fit test to first function (function 1) to check if it behaves as the other distributed function(function 2) You mean you have observations from such distributions, I guess, otherwise you do not need a test to find out. how can i insert my 2 unknown by R function to ad.test()? ad.test from which package? If nortest: That's not appropriate here. See the adk package. Uwe Ligges Regards, Irit -- View this message in context: http://r.789695.n4.nabble.com/ad-test-parameters-tp4663500.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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-help@r-project.org mailing list 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] Fw: Reversing data transformation
On 06.04.2013 22:21, Beatriz González Domínguez wrote: From: aguitatie...@hotmail.com Sent: Friday, April 05, 2013 11:47 PM To: r-help@r-project.org ; R Help Subject: Reversing data transformation Hi everybody, I would be very grateful if you could give me your thoughts on the following issue. I need to perform Box-Cox (bcPower€Â�) transformation on my data. To do this, I calculated lambda using the function '€Â�powerTransform'€Â�. powerTransform(data) We get: Error: could not find function "powerTransform" so that fucntion appears to be from some not mentioned package. However, I got an error message when performing this function: Convergence failure: return code = 52 I was told by John Fox that the nature of my data was probably causing the problem so I applied the following transformation: powerTransform(1e7*(data - 0.99*(min(data [1] > And it worked! However, now when I try to check the normality of my data, shapiro.test(data) I get a new warning message: Error in shapiro.test(data) : ifault=6. This should not happen I think this may be solved by removing the transformation I applied previously in [1], but I’m not sure how to do it properly. Could anyone give me some advice? MY DATA: c(0.000103113, 0.000102948, 0.000104001, 0.000103794, 0.000104628, 9.2765e-05, 9.4296e-05, 9.5025e-05, 9.4978e-05, 9.8821e-05, 9.7586e-05, 9.6285e-05, 0.00010158, 0.000100919, 0.000103535, 0.000103321, 0.000102842, 0.000102315, 0.0001033, 0.000103691, 0.000102689, 0.000103248, 0.000101216, 0.000103127, 0.000103439, 0.000102818, 0.000103482, 0.00010227, 0.000104264, 0.000104672, 0.000104586, 0.000104516, 0.000104585, 0.000103804, 0.000103702, 0.000103405, 0.000104815, 0.000101718, 0.000101792, 0.000103273, 0.000102942, 0.000102522, 0.000103149, 0.0001036995, 0.0001039735, 0.0001014877, 0.000102796) shapiro.test on this data works for me: Shapiro-Wilk normality test data: data W = 0.7314, p-value = 6.243e-08 Best, Uwe Ligges Thanks a lot!! Bea [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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-help@r-project.org mailing list 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] categorized complete list of R commands?
Dear Rees Morrison, Re: > Franklin, I am very impressed. I ran your code and am amazed at the output. > I want to use it in my efforts to figure out which are the most widely used > functions, so that I can concentrate on understanding those basics reasonably > well. > > May I ask you two few questions? > > What additional code would create a table output, with the function name in > the left column, sorted alphabetically within a pattern, and the pattern of > the function in the column to the right. Users could then sort by those > patterns, rename some to suit themselves, etc. > That would be handy, indeed, as well as in which package each function resides. However, my own motive was that if you know the existence and exact name of (seemingly) relevant functions, you can find the full syntax etc. throught R's built-in help system. I'm not sure whether this would be simple, because "grep" yields a variable number of hits, which must then be combined with a fixed string value. I'll think about it. > Second, I assume this function searches base only? Could you add a parameter > to the function so that it would search other, installed packages, such as > Hmisc or stringr or plyr? If so, the table (or your output) would need to > identify the package. > search() gives a list of attached packages, so if you load all packages of your interest you 'll get all relevant functions. > Third, the patterns might usefully include wd, str, and names. Certainly; for others it might be model, summary etc. Users can extend the pattern list or load them from a text file, e.g. patterns = read.csv(file.choose()) > > I did not want to post this on R-Help because that site is much too > intimidating for a newcomer. In that regard, Hadley Wickham sent the .csv > file where he compiled the base functions and stats functions. I have done > one of my own, but it is not as comprehensive, but goes beyond base. > In my opinion it's better to CC the r-help, because someone in the vast R community might come up with a faster, or better, solution. > Much obliged. > > Rees > > -- > Rees Morrison > General Counsel Metrics, LLC (management consulting and data analytics) > 4 Hawthorne Ave. > Princeton, NJ 08540-3840 USA > (973) 568-9110 > Hosts www.lawdepartmentmanagementblog.com > Best wishes, Franklin Bretschneider -- Dept Biologie Kruytgebouw W711 Padualaan 8 3584 CH Utrecht The Netherlands [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] Replace missing value within group with non-missing value
> Anyway, try replacing the lapply instruction with this. > > tmp <- lapply(sp, function(x){ > idx <- which(!is.na(x$mth))[1] > if(length(idx) > 0) > x$mth <- x$mth[idx] > x > }) Note that which(anyLogicalVector)[1] always has length 1, because of the subscript [1], so the 'if' statement may as well be omitted. There are 2 cases the above code does not detect or deal with. (a) nrow(x)==0 (b) all(is.na(x$mth)) (c) length(which(is.na(x$mth))) > 1 Case (a) causes the function to stop in way you saw: > f <- function(x) { # the function passed to lapply +idx <- which(!is.na(x$mth))[1] +if (length(idx) > 0) + x$mth <- x$mth[idx] +x + } > f(data.frame(mth=integer())) Error in `$<-.data.frame`(`*tmp*`, "mth", value = NA_integer_) : replacement has 1 rows, data has 0 but (b) and (c) may indicate some errors in your data and cause some surprises down the line. > f(data.frame(mth=c(NA,NA))) mth 1 NA 2 NA > f(data.frame(mth=c(NA,2,3))) mth 1 2 2 2 3 2 You could have your code check whether there is exactly one non-missing value for mth in each non-empty group and warn if that assumption is not true for some group (but also return some reasonable result)? The following does that: f2 <- function (x) { idx <- !is.na(x$mth) # logical vector with length nrow(x) nNotNA <- sum(idx) if (nNotNA > 1) { warning("more than one non-missing mth value in group, using the first") idx[cumsum(idx) > 1] <- FALSE } else if (nrow(x) > 0 && nNotNA == 0) { warning("no non-missing values in group, all mth values will be NA") idx[1] <- TRUE } x$mth <- x$mth[idx] x } The error messages do not say where in 'sp' the problem arose. You could change your lapply call so the group number was in the warning: lapply(seq_along(sp), function(i) { x <- sp[[i]] ... same code as in f2, but add the group number, i, to the end of warnings ... warning("more than one ... in group number", i) ... }) Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf > Of Rui Barradas > Sent: Saturday, April 06, 2013 10:24 AM > To: Leask, Graham > Cc: r-help@r-project.org > Subject: Re: [R] Replace missing value within group with non-missing value > > Hello, > > I've just run my code with your data and found no error. Anyway, try > replacing the lapply instruction with this. > > > tmp <- lapply(sp, function(x){ > idx <- which(!is.na(x$mth))[1] > if(length(idx) > 0) > x$mth <- x$mth[idx] > x > }) > > > Rui Barradas > > Em 06-04-2013 18:12, Leask, Graham escreveu: > > Hi Arun, > > > > How odd. Directly pasting the code from your email precisely repeats the > > error. > > See below. Any thoughts on the cause of this anomaly? > > > >> dput(head(dat,50)) > > structure(list(dn = c(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, > > 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, > > 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4), obs = c(1, 1, > > 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, > > 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, > > 8, 8, 8, 8, 9, 9), choice = c(0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, > > 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, > > 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0), br = c(1, > > 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, > > 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, > > 2, 3, 4, 5, 6, 1, 2), mth = c(NA, NA, NA, NA, NA, 487, NA, NA, > > 488, NA, NA, NA, NA, NA, NA, NA, NA, 488, NA, NA, 489, NA, NA, > > NA, NA, NA, NA, NA, NA, 489, NA, NA, NA, NA, NA, 489, NA, NA, > > NA, NA, NA, 490, NA, NA, NA, NA, NA, 491, NA, NA)), .Names = c("dn", > > "obs", "choice", "br", "mth"), row.names = c("1", "2", "3", "4", > > "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", > > "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", > > "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", > > "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", > > "49", "50"), class = "data.frame") > >> sp <- split(dat, list(dat$dn, dat$obs)) > >> names(sp) <- NULL > >> tmp <- lapply(sp, function(x){ > > + idx <- which(!is.na(x$mth))[1] > > + x$mth <- x$mth[idx] > > + x > > + }) > > Error in `$<-.data.frame`(`*tmp*`, "mth", value = NA_real_) : > >replacement has 1 rows, data has 0 > >> head(do.call(rbind, tmp),7) > > Error in do.call(rbind, tmp) : object 'tmp' not found > > > > Best wishes > > > > > > Graham > > > > -Original Message- > > From: arun [mailto:smartpink...@yahoo.com] > > Sent: 06 April 2013 17:25 > > To: Leask,
Re: [R] Data normalization
Hello, See ?scale scale(DATA) # mean 0, unit variance Hope this helps, Rui Barradas Em 06-04-2013 21:21, Beatriz González Domínguez escreveu: Dear all, I’m finding difficulties to normalize this data. Could you provide some input? DATA: c(0.000103113, 0.000102948, 0.000104001, 0.000103794, 0.000104628, 9.2765e-05, 9.4296e-05, 9.5025e-05, 9.4978e-05, 9.8821e-05, 9.7586e-05, 9.6285e-05, 0.00010158, 0.000100919, 0.000103535, 0.000103321, 0.000102842, 0.000102315, 0.0001033, 0.000103691, 0.000102689, 0.000103248, 0.000101216, 0.000103127, 0.000103439, 0.000102818, 0.000103482, 0.00010227, 0.000104264, 0.000104672, 0.000104586, 0.000104516, 0.000104585, 0.000103804, 0.000103702, 0.000103405, 0.000104815, 0.000101718, 0.000101792, 0.000103273, 0.000102942, 0.000102522, 0.000103149, 0.0001036995, 0.0001039735, 0.0001014877, 0.000102796) Greatly appreciated!! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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-help@r-project.org mailing list 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] list of distance matrices
Hi, Try this: set.seed(25) el<-as.data.frame(matrix(sample(1:50,75*124,replace=TRUE),ncol=75)) lst1<-lapply(el,function(x) dist(x)) set.seed(28) q<-as.data.frame(matrix(sample(1:50,75*124,replace=TRUE),ncol=75)) q<-dist(q) library(ade4) res<- lapply(lst1,function(x) mantel.rtest(q,x,nrepet=) Though, I am getting warnings() for this test (which I am not sure). A.K. - Original Message - From: eliza botto To: "r-help@r-project.org" Cc: Sent: Saturday, April 6, 2013 4:01 PM Subject: [R] list of distance matrices Dear UseRs, i want to apply mantel test by comparing a list of 124 distance matrices with a reference distance matrix "q". The list of distance matrices was created by the following command.. u<-lapply(el, function(x) dist(x)) where "el" is a data frame of 75 columns and 124 rows. Therefore, the list of distances matrices, made out of it should have 75 elements each containing 124 rows and 124 columns. I, unsuccessfully, tried the following command >mantel.rtest(as.dist(q), lapply(el, function(x) dist(x)), nrepet = ) Do you have any clue?? Thanks in advance Eliza [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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-help@r-project.org mailing list 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] [R-SIG-Finance] error message sending question to the list
Post in plain text (not HTML) which is a choice within your email client. And please (!!) don't post the same question to multiple lists. If your question is off-topic, the list membership will redirect as needed. Double posting simply wasted the community's energies by duplicating responses. Michael On Apr 6, 2013, at 3:42 PM, Stat Tistician wrote: > Hi, > I tried to send several questions to the lists (both normal R and > R-Sig-Finance), but everytime I look them up in the archives my messages > end up with the following > > "An embedded and charset-unspecified text was scrubbed... > > for example see my post here: > > https://stat.ethz.ch/pipermail/r-sig-finance/2013q2/011496.html > > > This one was a real important for me. Can subscribers still read it? Shall > I repost, how can I post correctly? > > Thanks > >[[alternative HTML version deleted]] > See -- HTML! > ___ > r-sig-fina...@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-sig-finance > -- Subscriber-posting only. If you want to post, subscribe first. > -- Also note that this is not the r-help list where general R questions > should go. __ R-help@r-project.org mailing list 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] error message sending question to the list
Hi, I tried to send several questions to the lists (both normal R and R-Sig-Finance), but everytime I look them up in the archives my messages end up with the following "An embedded and charset-unspecified text was scrubbed... for example see my post here: https://stat.ethz.ch/pipermail/r-sig-finance/2013q2/011496.html This one was a real important for me. Can subscribers still read it? Shall I repost, how can I post correctly? Thanks [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] Data normalization
Dear all, Iâm finding difficulties to normalize this data. Could you provide some input? DATA: c(0.000103113, 0.000102948, 0.000104001, 0.000103794, 0.000104628, 9.2765e-05, 9.4296e-05, 9.5025e-05, 9.4978e-05, 9.8821e-05, 9.7586e-05, 9.6285e-05, 0.00010158, 0.000100919, 0.000103535, 0.000103321, 0.000102842, 0.000102315, 0.0001033, 0.000103691, 0.000102689, 0.000103248, 0.000101216, 0.000103127, 0.000103439, 0.000102818, 0.000103482, 0.00010227, 0.000104264, 0.000104672, 0.000104586, 0.000104516, 0.000104585, 0.000103804, 0.000103702, 0.000103405, 0.000104815, 0.000101718, 0.000101792, 0.000103273, 0.000102942, 0.000102522, 0.000103149, 0.0001036995, 0.0001039735, 0.0001014877, 0.000102796) Greatly appreciated!! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] Fw: Reversing data transformation
From: aguitatie...@hotmail.com Sent: Friday, April 05, 2013 11:47 PM To: r-help@r-project.org ; R Help Subject: Reversing data transformation Hi everybody, I would be very grateful if you could give me your thoughts on the following issue. I need to perform Box-Cox (bcPowerÂÂ) transformation on my data. To do this, I calculated lambda using the function 'ÂÂpowerTransform'ÂÂ. powerTransform(data) However, I got an error message when performing this function: Convergence failure: return code = 52 I was told by John Fox that the nature of my data was probably causing the problem so I applied the following transformation: powerTransform(1e7*(data - 0.99*(min(data [1] And it worked! However, now when I try to check the normality of my data, shapiro.test(data) I get a new warning message: Error in shapiro.test(data) : ifault=6. This should not happen I think this may be solved by removing the transformation I applied previously in [1], but Iâm not sure how to do it properly. Could anyone give me some advice? MY DATA: c(0.000103113, 0.000102948, 0.000104001, 0.000103794, 0.000104628, 9.2765e-05, 9.4296e-05, 9.5025e-05, 9.4978e-05, 9.8821e-05, 9.7586e-05, 9.6285e-05, 0.00010158, 0.000100919, 0.000103535, 0.000103321, 0.000102842, 0.000102315, 0.0001033, 0.000103691, 0.000102689, 0.000103248, 0.000101216, 0.000103127, 0.000103439, 0.000102818, 0.000103482, 0.00010227, 0.000104264, 0.000104672, 0.000104586, 0.000104516, 0.000104585, 0.000103804, 0.000103702, 0.000103405, 0.000104815, 0.000101718, 0.000101792, 0.000103273, 0.000102942, 0.000102522, 0.000103149, 0.0001036995, 0.0001039735, 0.0001014877, 0.000102796) Thanks a lot!! Bea [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] Matrix reduction
On 06-04-2013, at 22:01, Bert Gunter wrote: > ?chol > > ##also > Quite true and therefore: ?backsolve # forwardsolve and ?qr # qr.solve So there's a lot to choose from. Berend > -- Bert > > On Sat, Apr 6, 2013 at 11:12 AM, Berend Hasselman wrote: >> >> On 06-04-2013, at 19:58, Angelo Scozzarella Tiscali >> wrote: >> >>> Well, I mean to use the elimination method to transform the matrix, for >>> example, of the coefficients of a linear equations system. >>> >>> AS >>> >> >> >> Well if you only need to solve a linear equation system have a look at solve. >> If you have a special system (banded,tridiagonal) then limSolve may help. >> If you need the LU decomposition itself use package Matrix and look at >> denseLU. >> >> Berend >> >> __ >> R-help@r-project.org mailing list >> 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. > > > > -- > > Bert Gunter > Genentech Nonclinical Biostatistics > > Internal Contact Info: > Phone: 467-7374 > Website: > http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ R-help@r-project.org mailing list 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] Matrix reduction
?chol ##also -- Bert On Sat, Apr 6, 2013 at 11:12 AM, Berend Hasselman wrote: > > On 06-04-2013, at 19:58, Angelo Scozzarella Tiscali > wrote: > >> Well, I mean to use the elimination method to transform the matrix, for >> example, of the coefficients of a linear equations system. >> >> AS >> > > > Well if you only need to solve a linear equation system have a look at solve. > If you have a special system (banded,tridiagonal) then limSolve may help. > If you need the LU decomposition itself use package Matrix and look at > denseLU. > > Berend > > __ > R-help@r-project.org mailing list > 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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ R-help@r-project.org mailing list 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] list of distance matrices
Dear UseRs, i want to apply mantel test by comparing a list of 124 distance matrices with a reference distance matrix "q". The list of distance matrices was created by the following command.. u<-lapply(el, function(x) dist(x)) where "el" is a data frame of 75 columns and 124 rows. Therefore, the list of distances matrices, made out of it should have 75 elements each containing 124 rows and 124 columns. I, unsuccessfully, tried the following command >mantel.rtest(as.dist(q), lapply(el, function(x) dist(x)), nrepet = ) Do you have any clue?? Thanks in advance Eliza [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] manipulating R contingency tables
Hi, You could also do: tbl1[,-match("B2",colnames(tbl1))] # gts #labels A1 G3 # 1 21 120 # 2 23 0 #or tbl1[,!grepl("B2",colnames(tbl1))] # gts #labels A1 G3 # 1 21 120 # 2 23 0 If you need to remove columns that contains 0 along with removing a specific column. tbl1[,!grepl("B2",colnames(tbl1)) & colSums(tbl1==0)==0] # 1 2 #21 23 tbl1[,colSums(tbl1==0)==0] # gts #labels A1 B2 # 1 21 127 # 2 23 112 A.K. - Original Message - From: arun To: Abhishek Pratap Cc: R help Sent: Saturday, April 6, 2013 11:45 AM Subject: Re: [R] manipulating R contingency tables Hi, Try this: tbl1<- structure(c(21L, 23L, 127L, 112L, 120L, 0L), .Dim = 2:3, .Dimnames = structure(list( labels = c(1, 2), gts = c("A1", "B2", "G3")), .Names = c("labels", "gts")), class = "table") dat1<-as.data.frame(tbl1,stringsAsFactors=FALSE) dat2<-dat1[dat1$gts!="B2" & dat1$Freq!=0,] library(reshape2) dcast(dat2,labels~gts,value.var="Freq") # labels A1 G3 #1 1 21 120 #2 2 23 NA A.K. - Original Message - From: Abhishek Pratap To: "r-help@r-project.org" Cc: Sent: Saturday, April 6, 2013 2:55 AM Subject: [R] manipulating R contingency tables Hi Guys I am back with another thing that's puzzling me. I am creating contingency tables but then I want to filter out certain columns and also find if any entry in the table is 0. Example: gts labels A1 B2 G3 1 21 127 120 2 23 112 0 Here I want to remove B2 column from this table and also if any entry is 0 in this case G3 second row. Missing out on how to do this in an efficient manner as I have to do this millions of times for my data. Thanks! -Abhi [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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-help@r-project.org mailing list 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] Replace missing value within group with non-missing value
Hi Arun, Thank you to yourself and Rui. The solution that you provided does indeed work. I greatly appreciate your help. Best wishes Graham -Original Message- From: arun [mailto:smartpink...@yahoo.com] Sent: 06 April 2013 19:20 To: Leask, Graham Cc: R help; Rui Barradas Subject: Re: [R] Replace missing value within group with non-missing value Hi, dat<- read.csv("test1.csv",sep=",",stringsAsFactors=FALSE) sp <- split(dat, list(dat$dn, dat$obs)) sp1<-sp[lapply(sp,nrow)!=0] #added here names(sp1) <- NULL tmp<- lapply(sp1,function(x){ idx<- which(!is.na(x$mth))[1] x$mth<- x$mth[idx] x } ) res<- do.call(rbind,tmp) row.names(res)<-1:nrow(res) dim(res) #[1] 1200 6 dim(dat) #[1] 1200 6 head(res) # X dn obs choice br mth #1 1 4 1 0 1 487 #2 2 4 1 0 2 487 #3 3 4 1 0 3 487 #4 4 4 1 0 4 487 #5 5 4 1 0 5 487 #6 6 4 1 1 6 487 A.K. - Original Message - From: "Leask, Graham" To: Rui Barradas Cc: arun ; "r-help@r-project.org" Sent: Saturday, April 6, 2013 1:44 PM Subject: RE: [R] Replace missing value within group with non-missing value Hi Rui, I have just pasted this direct and rerun. I still get the same error. I am running this on the full length dataset. dim [1] 255030 5 I attach the first few rows of the file. Error pasted below. I am using version 2.15.2 on a windows 7 machine. > sp <- split(dat, list(dat$dn, dat$obs)) > names(sp) <- NULL > tmp <- lapply(sp, function(x){ + idx <- which(!is.na(x$mth))[1] + if(length(idx) > 0) + x$mth <- x$mth[idx] + x + }) Error in `$<-.data.frame`(`*tmp*`, "mth", value = NA_real_) : replacement has 1 rows, data has 0 > do.call(rbind,tmp) Error in do.call(rbind, tmp) : object 'tmp' not found Any thoughts on what could be causing this anomaly? -Original Message- From: Rui Barradas [mailto:ruipbarra...@sapo.pt] Sent: 06 April 2013 18:24 To: Leask, Graham Cc: arun; r-help@r-project.org Subject: Re: [R] Replace missing value within group with non-missing value Hello, I've just run my code with your data and found no error. Anyway, try replacing the lapply instructi on with this. tmp <- lapply(sp, function(x){ idx <- which(!is.na(x$mth))[1] if(length(idx) > 0) x$mth <- x$mth[idx] x }) Rui Barradas Em 06-04-2013 18:12, Leask, Graham escreveu: > Hi Arun, > > How odd. Directly pasting the code from your email precisely repeats the > error. > See below. Any thoughts on the cause of this anomaly? > >> dput(head(dat,50)) > structure(list(dn = c(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, > 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, > 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4), obs = c(1, 1, 1, 1, 1, 1, 2, 2, 2, > 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, > 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9), choice = c(0, > 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, > 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, > 1, 0, 0), br = c(1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, > 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, > 6, 1, 2, 3, 4, 5, 6, 1, 2), mth = c(NA, NA, NA, NA, NA, 487, NA, NA, > 488, NA, NA, NA, NA, NA, NA, NA, NA, 488, NA, NA, 489, NA, NA, NA, NA, > NA, NA, NA, NA, 489, NA, NA, NA, NA, NA, 489, NA, NA, NA, NA, NA, 490, > NA, NA, NA, NA, NA, 491, NA, NA)), .Names = c("dn", "obs", "choice", > "br", "mth"), row.names = c("1", "2", "3", "4", "5", "6", "7", "8", > "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", > "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", > "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", > "43", "44", "45", "46", "47", "48", "49", "50"), class = "data.frame") >> sp <- split(dat, list(dat$dn, dat$obs)) >> names(sp) <- NULL >> tmp <- lapply(sp, function(x){ > + idx <- which(!is.na(x$mth))[1] > + x$mth <- x$mth[idx] > + x > + }) > Error in `$<-.data.frame`(`*tmp*`, "mth", value = NA_real_) : > replacement has 1 rows, data has 0 >> head(do.call(rbind, tmp),7) > Error in do.call(rbind, tmp) : object 'tmp' not found > > Best wishes > > > Graham > > -Original Message- > From: arun [mailto:smartpink...@yahoo.com] > Sent: 06 April 2013 17:25 > To: Leask, Graham > Cc: Rui Barradas > Subject: Re: [R] Replace missing value within group with non-missing > value > > Hello, > By running Rui's code, I am getting this: > sp <- split(dat, list(dat$dn, dat$obs)) > names(sp) <- NULL > tmp <- lapply(sp, function(x){ > idx <- which(!is.na(x$mth))[1] > x$mth <- x$mth[idx] > x > }) > head(do.call(rbind, tmp),7) > dn obs choice br mth > 1 4 1 0 1 487 > 2 4 1 0 2 487 > 3 4 1 0 3 487 > 4 4 1 0 4 487 > 5 4 1 0 5 487 > 6 4 1 1 6 487 > 7 4 2 0 1
Re: [R] arrange data
Hi, You could also do this with: dat2<- dat1 dat2[]<-lapply(dat1,function(x) c(x[!is.na(x)],x[is.na(x)])) row.names(res1)<- row.names(dat2) identical(dat2,res1) #[1] TRUE For your new question: test<- data.frame(medrw1) row.names(test) [1] "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12" [13] "13" "14" "15" "16" "17" "18" "19" "20" "21" "22" "23" "24" [25] "25" "26" "27" "28" "29" "30" "31" "32" "33" "34" "35" "36" [37] "37" "38" "39" "40" "41" "42" "43" "44" "45" "46" "47" "48" [49] "49" "50" "51" "52" "53" "54" "55" "56" "57" "58" "59" "60" [61] "61" "62" "63" "64" "65" "66" "67" "68" "69" "70" "71" "72" [73] "73" "74" "75" "76" "77" "78" "79" "80" "81" "82" "83" "84" [85] "85" "86" "87" "88" "89" "90" "91" "92" "93" "94" "95" "96" [97] "97" "98" "99" "100" "101" "102" "103" "104" "105" "106" "107" "108" [109] "109" "110" "111" "112" "113" "114" "115" "116" "117" "118" "119" "120" [121] "121" "122" "123" "124" "125" "126" "127" "128" "129" "130" "131" "132" [133] "133" "134" "135" "136" "137" "138" "139" "140" test$newCol<- row.names(test) test1<-test[,c(2:1)] head(test1) # newCol medrw1 #1 1 1.499 #2 2 1.209 #3 3 1.400 #4 4 1.590 #5 5 1.463 #6 6 1.771 A.K. From: catalin roibu To: arun Sent: Saturday, April 6, 2013 2:27 PM Subject: Re: [R] arrange data It is not for this case. I want to create a growth mean by row and compare with another serie mean. medrw1 <- apply(res,1,median,na.rm=TRUE) test<-cbind(medrw1) in this case I want to create a new column at first position which contain this seq(). This column I want to set as row.names. Thank you very much! On 6 April 2013 21:24, arun wrote: > > > >From: catalin roibu >To: arun >Sent: Saturday, April 6, 2013 1:43 PM >Subject: Re: [R] arrange data > > >I want a column with seq(1,nrow(res),by=1) and set this column as row.names. > > >Thank you very much! > > > >On 6 April 2013 20:41, arun wrote: > > >>> >> From: catalin roibu >>To: arun >>Sent: Saturday, April 6, 2013 1:20 PM >> >>Subject: Re: [R] arrange data >> >> >>It is perfect! Thank you very much! A last question if you don't mind. How >>can add in the first position a new column ( from 1 to max row length) which >>I use as rowname? >> >> >> >>> >>>On 6 April 2013 20:06, arun wrote: >>> >>> lst1<-lapply(dat1,function(x) x[!is.na(x)]) res<-as.data.frame(sapply(lst1,function(x) c(x,rep(NA,max(sapply(lst1,length))-length(x)) ))) head(res) # 1B 2B 4B 1A 2A 4A 5B 5A C31A C31B C34A C34B C35A #1 2.518 2.357 1.499 3.647 1.890 2.249 2.896 2.175 0.452 1.177 0.344 0.612 1.722 #2 2.796 2.759 1.032 3.763 1.182 2.291 2.417 2.597 1.033 0.831 0.351 0.509 1.102 #3 4.012 2.878 1.126 3.236 1.431 2.635 2.952 2.483 0.679 0.484 0.704 0.461 1.400 #4 3.611 2.094 1.043 3.032 1.835 3.019 1.590 2.269 0.901 0.576 1.008 0.879 2.222 #5 2.970 1.371 1.486 1.817 1.884 2.557 1.768 1.463 0.466 0.378 0.708 0.862 1.840 #6 4.687 1.042 1.252 3.495 2.540 2.592 1.179 1.860 0.608 0.314 0.721 0.624 1.927 # C35B C37A C37B C36A C36B C32A C32B C33A C33B C39B #1 2.482 0.996 0.898 0.179 1.148 2.637 2.917 1.440 1.487 1.291 #2 1.061 1.243 1.078 1.167 1.209 2.770 2.325 2.006 1.886 0.655 #3 1.350 0.999 0.992 1.629 1.551 1.996 2.444 1.261 1.343 0.790 #4 1.952 1.227 1.447 1.067 2.252 2.220 1.635 1.085 1.367 0.633 #5 2.343 1.049 1.285 1.299 1.182 2.976 2.106 1.388 2.253 0.630 #6 2.104 1.771 1.204 1.540 1.203 2.847 2.200 2.563 2.348 0.493 nrow(res) #[1] 140 If you wanted to have the same number of rows as dat1: nrow(dat1) #[1] 145 new1<-as.data.frame(matrix(NA,ncol=23,nrow=5)) colnames(new1)<- colnames(res) res1<- rbind(res,new1) nrow(res1) #[1] 145 A.K. >> > __ R-help@r-project.org mailing list 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] Replace missing value within group with non-missing value
Hello, With the attached file, I could reproduce the error but I think the added line does the trick. Rui Barradas Em 06-04-2013 19:20, arun escreveu: Hi, dat<- read.csv("test1.csv",sep=",",stringsAsFactors=FALSE) sp <- split(dat, list(dat$dn, dat$obs)) sp1<-sp[lapply(sp,nrow)!=0] #added here names(sp1) <- NULL tmp<- lapply(sp1,function(x){ idx<- which(!is.na(x$mth))[1] x$mth<- x$mth[idx] x } ) res<- do.call(rbind,tmp) row.names(res)<-1:nrow(res) dim(res) #[1] 12006 dim(dat) #[1] 12006 head(res) # X dn obs choice br mth #1 1 4 1 0 1 487 #2 2 4 1 0 2 487 #3 3 4 1 0 3 487 #4 4 4 1 0 4 487 #5 5 4 1 0 5 487 #6 6 4 1 1 6 487 A.K. - Original Message - From: "Leask, Graham" To: Rui Barradas Cc: arun ; "r-help@r-project.org" Sent: Saturday, April 6, 2013 1:44 PM Subject: RE: [R] Replace missing value within group with non-missing value Hi Rui, I have just pasted this direct and rerun. I still get the same error. I am running this on the full length dataset. dim [1] 255030 5 I attach the first few rows of the file. Error pasted below. I am using version 2.15.2 on a windows 7 machine. sp <- split(dat, list(dat$dn, dat$obs)) names(sp) <- NULL tmp <- lapply(sp, function(x){ + idx <- which(!is.na(x$mth))[1] + if(length(idx) > 0) + x$mth <- x$mth[idx] + x + }) Error in `$<-.data.frame`(`*tmp*`, "mth", value = NA_real_) : replacement has 1 rows, data has 0 do.call(rbind,tmp) Error in do.call(rbind, tmp) : object 'tmp' not found Any thoughts on what could be causing this anomaly? -Original Message- From: Rui Barradas [mailto:ruipbarra...@sapo.pt] Sent: 06 April 2013 18:24 To: Leask, Graham Cc: arun; r-help@r-project.org Subject: Re: [R] Replace missing value within group with non-missing value Hello, I've just run my code with your data and found no error. Anyway, try replacing the lapply instructi on with this. tmp <- lapply(sp, function(x){ idx <- which(!is.na(x$mth))[1] if(length(idx) > 0) x$mth <- x$mth[idx] x }) Rui Barradas Em 06-04-2013 18:12, Leask, Graham escreveu: Hi Arun, How odd. Directly pasting the code from your email precisely repeats the error. See below. Any thoughts on the cause of this anomaly? dput(head(dat,50)) structure(list(dn = c(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4), obs = c(1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9), choice = c(0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0), br = c(1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2), mth = c(NA, NA, NA, NA, NA, 487, NA, NA, 488, NA, NA, NA, NA, NA, NA, NA, NA, 488, NA, NA, 489, NA, NA, NA, NA, NA, NA, NA, NA, 489, NA, NA, NA, NA, NA, 489, NA, NA, NA, NA, NA, 490, NA, NA, NA, NA, NA, 491, NA, NA)), .Names = c("dn", "obs", "choice", "br", "mth"), row.names = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50"), class = "data.frame") sp <- split(dat, list(dat$dn, dat$obs)) names(sp) <- NULL tmp <- lapply(sp, function(x){ + idx <- which(!is.na(x$mth))[1] + x$mth <- x$mth[idx] + x + }) Error in `$<-.data.frame`(`*tmp*`, "mth", value = NA_real_) : replacement has 1 rows, data has 0 head(do.call(rbind, tmp),7) Error in do.call(rbind, tmp) : object 'tmp' not found Best wishes Graham -Original Message- From: arun [mailto:smartpink...@yahoo.com] Sent: 06 April 2013 17:25 To: Leask, Graham Cc: Rui Barradas Subject: Re: [R] Replace missing value within group with non-missing value Hello, By running Rui's code, I am getting this: sp <- split(dat, list(dat$dn, dat$obs)) names(sp) <- NULL tmp <- lapply(sp, function(x){ idx <- which(!is.na(x$mth))[1] x$mth <- x$mth[idx] x }) head(do.call(rbind, tmp),7) dn obs choice br mth 1 4 1 0 1 487 2 4 1 0 2 487 3 4 1 0 3 487 4 4 1 0 4 487 5 4 1 0 5 487 6 4 1 1 6 487 7 4 2 0 1 488 Couldn't reproduce the error you cited. A.K. - Original Message - From: "Leask, Graham" To: Rui Barradas Cc: "r-help@r-project.org" Sent: Saturday, April 6, 2013 12:16 PM Subject: Re: [R] Replace missing value within group with non-missing value Hi Rui, Data as follows structure(list(dn = c(4,
Re: [R] Replace missing value within group with non-missing value
Hi, dat<- read.csv("test1.csv",sep=",",stringsAsFactors=FALSE) sp <- split(dat, list(dat$dn, dat$obs)) sp1<-sp[lapply(sp,nrow)!=0] #added here names(sp1) <- NULL tmp<- lapply(sp1,function(x){ idx<- which(!is.na(x$mth))[1] x$mth<- x$mth[idx] x } ) res<- do.call(rbind,tmp) row.names(res)<-1:nrow(res) dim(res) #[1] 1200 6 dim(dat) #[1] 1200 6 head(res) # X dn obs choice br mth #1 1 4 1 0 1 487 #2 2 4 1 0 2 487 #3 3 4 1 0 3 487 #4 4 4 1 0 4 487 #5 5 4 1 0 5 487 #6 6 4 1 1 6 487 A.K. - Original Message - From: "Leask, Graham" To: Rui Barradas Cc: arun ; "r-help@r-project.org" Sent: Saturday, April 6, 2013 1:44 PM Subject: RE: [R] Replace missing value within group with non-missing value Hi Rui, I have just pasted this direct and rerun. I still get the same error. I am running this on the full length dataset. dim [1] 255030 5 I attach the first few rows of the file. Error pasted below. I am using version 2.15.2 on a windows 7 machine. > sp <- split(dat, list(dat$dn, dat$obs)) > names(sp) <- NULL > tmp <- lapply(sp, function(x){ + idx <- which(!is.na(x$mth))[1] + if(length(idx) > 0) + x$mth <- x$mth[idx] + x + }) Error in `$<-.data.frame`(`*tmp*`, "mth", value = NA_real_) : replacement has 1 rows, data has 0 > do.call(rbind,tmp) Error in do.call(rbind, tmp) : object 'tmp' not found Any thoughts on what could be causing this anomaly? -Original Message- From: Rui Barradas [mailto:ruipbarra...@sapo.pt] Sent: 06 April 2013 18:24 To: Leask, Graham Cc: arun; r-help@r-project.org Subject: Re: [R] Replace missing value within group with non-missing value Hello, I've just run my code with your data and found no error. Anyway, try replacing the lapply instructi on with this. tmp <- lapply(sp, function(x){ idx <- which(!is.na(x$mth))[1] if(length(idx) > 0) x$mth <- x$mth[idx] x }) Rui Barradas Em 06-04-2013 18:12, Leask, Graham escreveu: > Hi Arun, > > How odd. Directly pasting the code from your email precisely repeats the > error. > See below. Any thoughts on the cause of this anomaly? > >> dput(head(dat,50)) > structure(list(dn = c(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, > 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, > 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4), obs = c(1, 1, > 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, > 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, > 8, 8, 8, 8, 9, 9), choice = c(0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, > 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, > 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0), br = c(1, > 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, > 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, > 2, 3, 4, 5, 6, 1, 2), mth = c(NA, NA, NA, NA, NA, 487, NA, NA, > 488, NA, NA, NA, NA, NA, NA, NA, NA, 488, NA, NA, 489, NA, NA, > NA, NA, NA, NA, NA, NA, 489, NA, NA, NA, NA, NA, 489, NA, NA, > NA, NA, NA, 490, NA, NA, NA, NA, NA, 491, NA, NA)), .Names = c("dn", > "obs", "choice", "br", "mth"), row.names = c("1", "2", "3", "4", > "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", > "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", > "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", > "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", > "49", "50"), class = "data.frame") >> sp <- split(dat, list(dat$dn, dat$obs)) >> names(sp) <- NULL >> tmp <- lapply(sp, function(x){ > + idx <- which(!is.na(x$mth))[1] > + x$mth <- x$mth[idx] > + x > + }) > Error in `$<-.data.frame`(`*tmp*`, "mth", value = NA_real_) : > replacement has 1 rows, data has 0 >> head(do.call(rbind, tmp),7) > Error in do.call(rbind, tmp) : object 'tmp' not found > > Best wishes > > > Graham > > -Original Message- > From: arun [mailto:smartpink...@yahoo.com] > Sent: 06 April 2013 17:25 > To: Leask, Graham > Cc: Rui Barradas > Subject: Re: [R] Replace missing value within group with non-missing value > > Hello, > By running Rui's code, I am getting this: > sp <- split(dat, list(dat$dn, dat$obs)) > names(sp) <- NULL > tmp <- lapply(sp, function(x){ > idx <- which(!is.na(x$mth))[1] > x$mth <- x$mth[idx] > x > }) > head(do.call(rbind, tmp),7) > dn obs choice br mth > 1 4 1 0 1 487 > 2 4 1 0 2 487 > 3 4 1 0 3 487 > 4 4 1 0 4 487 > 5 4 1 0 5 487 > 6 4 1 1 6 487 > 7 4 2 0 1 488 > > Couldn't reproduce the error you cited. > A.K. > > > > > - Original Message - > From: "Leask, Graham" > To: Rui Barradas > Cc: "r-help@r-project.org" > Sent: Saturday, April 6, 2013 12:16 PM > Subject: Re: [R] Replace missing value within group with non-missing value > > Hi Rui, > > Data as follows > > structure(list(dn = c(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
Re: [R] Matrix reduction
On 06-04-2013, at 19:58, Angelo Scozzarella Tiscali wrote: > Well, I mean to use the elimination method to transform the matrix, for > example, of the coefficients of a linear equations system. > > AS > Well if you only need to solve a linear equation system have a look at solve. If you have a special system (banded,tridiagonal) then limSolve may help. If you need the LU decomposition itself use package Matrix and look at denseLU. Berend __ R-help@r-project.org mailing list 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] Matrix reduction
Well, I mean to use the elimination method to transform the matrix, for example, of the coefficients of a linear equations system. AS Il giorno 06/apr/2013, alle ore 19:43, Angelo Scozzarella Tiscali ha scritto: > Hi everyone, > > I asked myself if exists a way to get a rows (or columns) matrix reduction > with R. > My goal is for education. > > Thanks in advance > > AS > __ > R-help@r-project.org mailing list > 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-help@r-project.org mailing list 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] Matrix reduction
Incomprehensible. Define:"matrix reduction" . Perhaps: ?qr ?svd ## and links therein. -- Bert On Sat, Apr 6, 2013 at 10:43 AM, Angelo Scozzarella Tiscali wrote: > Hi everyone, > > I asked myself if exists a way to get a rows (or columns) matrix reduction > with R. > My goal is for education. > > Thanks in advance > > AS > __ > R-help@r-project.org mailing list > 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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ R-help@r-project.org mailing list 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] Replace missing value within group with non-missing value
Hi Rui, I have just pasted this direct and rerun. I still get the same error. I am running this on the full length dataset. dim [1] 255030 5 I attach the first few rows of the file. Error pasted below. I am using version 2.15.2 on a windows 7 machine. > sp <- split(dat, list(dat$dn, dat$obs)) > names(sp) <- NULL > tmp <- lapply(sp, function(x){ + idx <- which(!is.na(x$mth))[1] + if(length(idx) > 0) + x$mth <- x$mth[idx] + x + }) Error in `$<-.data.frame`(`*tmp*`, "mth", value = NA_real_) : replacement has 1 rows, data has 0 > do.call(rbind,tmp) Error in do.call(rbind, tmp) : object 'tmp' not found Any thoughts on what could be causing this anomaly? -Original Message- From: Rui Barradas [mailto:ruipbarra...@sapo.pt] Sent: 06 April 2013 18:24 To: Leask, Graham Cc: arun; r-help@r-project.org Subject: Re: [R] Replace missing value within group with non-missing value Hello, I've just run my code with your data and found no error. Anyway, try replacing the lapply instructi on with this. tmp <- lapply(sp, function(x){ idx <- which(!is.na(x$mth))[1] if(length(idx) > 0) x$mth <- x$mth[idx] x }) Rui Barradas Em 06-04-2013 18:12, Leask, Graham escreveu: > Hi Arun, > > How odd. Directly pasting the code from your email precisely repeats the > error. > See below. Any thoughts on the cause of this anomaly? > >> dput(head(dat,50)) > structure(list(dn = c(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, > 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, > 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4), obs = c(1, 1, > 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, > 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, > 8, 8, 8, 8, 9, 9), choice = c(0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, > 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, > 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0), br = c(1, > 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, > 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, > 2, 3, 4, 5, 6, 1, 2), mth = c(NA, NA, NA, NA, NA, 487, NA, NA, > 488, NA, NA, NA, NA, NA, NA, NA, NA, 488, NA, NA, 489, NA, NA, > NA, NA, NA, NA, NA, NA, 489, NA, NA, NA, NA, NA, 489, NA, NA, > NA, NA, NA, 490, NA, NA, NA, NA, NA, 491, NA, NA)), .Names = c("dn", > "obs", "choice", "br", "mth"), row.names = c("1", "2", "3", "4", > "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", > "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", > "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", > "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", > "49", "50"), class = "data.frame") >> sp <- split(dat, list(dat$dn, dat$obs)) >> names(sp) <- NULL >> tmp <- lapply(sp, function(x){ > + idx <- which(!is.na(x$mth))[1] > + x$mth <- x$mth[idx] > + x > + }) > Error in `$<-.data.frame`(`*tmp*`, "mth", value = NA_real_) : >replacement has 1 rows, data has 0 >> head(do.call(rbind, tmp),7) > Error in do.call(rbind, tmp) : object 'tmp' not found > > Best wishes > > > Graham > > -Original Message- > From: arun [mailto:smartpink...@yahoo.com] > Sent: 06 April 2013 17:25 > To: Leask, Graham > Cc: Rui Barradas > Subject: Re: [R] Replace missing value within group with non-missing value > > Hello, > By running Rui's code, I am getting this: > sp <- split(dat, list(dat$dn, dat$obs)) > names(sp) <- NULL > tmp <- lapply(sp, function(x){ > idx <- which(!is.na(x$mth))[1] > x$mth <- x$mth[idx] > x > }) > head(do.call(rbind, tmp),7) > dn obs choice br mth > 1 4 1 0 1 487 > 2 4 1 0 2 487 > 3 4 1 0 3 487 > 4 4 1 0 4 487 > 5 4 1 0 5 487 > 6 4 1 1 6 487 > 7 4 2 0 1 488 > > Couldn't reproduce the error you cited. > A.K. > > > > > - Original Message - > From: "Leask, Graham" > To: Rui Barradas > Cc: "r-help@r-project.org" > Sent: Saturday, April 6, 2013 12:16 PM > Subject: Re: [R] Replace missing value within group with non-missing value > > Hi Rui, > > Data as follows > > structure(list(dn = c(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, > 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, > 4, 4, 4, 4, 4, 4), obs = c(1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, > 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, > 8, 8, 8, 8, 8, 9, 9), choice = c(0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, > 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, > 1, 0, 0, 0, 0, 0, 1, 0, 0), br = c(1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, > 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, > 5, 6, 1, 2, 3, 4, 5, 6, 1, 2), mth = c(NA, NA, NA, NA, NA, 487, NA, NA, 488, > NA, NA, NA, NA, NA, NA, NA, NA, 488, NA, NA, 489, NA, NA, NA, NA, NA,
[R] Matrix reduction
Hi everyone, I asked myself if exists a way to get a rows (or columns) matrix reduction with R. My goal is for education. Thanks in advance AS __ R-help@r-project.org mailing list 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] Image segmentation
I've recently had a reason to work a little with image segmentation too, and in addition to EBImage, you should look at biOps. You can learn a lot by studying these packages. Bryan On Apr 6, 2013, at 10:04 AM, Eder Paulo wrote: > Hello, > > Thanks for replying me! > > I was investigating the EBImage package and actually > there is a algorithm for image segmentation. But I think this algorithm is not > automated enough for me and maybe to work with multispectral remote sensing > image when I want to segment the whole image. The algorithm does not look for > “seeds” automatically and I think there is not possibility to segment color > images. > > I am looking for an algorithm similar to that > implemented in Spring software (developed at INPE) or what Multiresolution > Segmentation algorithm does in eCognition software (eCognition, 2012). This > algorithm > was described by Baatz and Schäpe (2000). > > Now I will see the second option that Susen sent me (http://www.itk.org/). > But I would like something in R, that I can see the > script and in a language that I already know a bit. But the main reason of > looking for something in R is the presence of other statistic tools not found > in SPRING, eCOGNITION etc. > > > Baatz, M., & Schäpe, A. > (2000). Multiresolution segmentation—An optimization approach for high > qualitymulti-scale image segmentation. Angewandte Geographische > Informationsverarbeitung XII. Beiträge zum AGIT-Symposium Salzburg, 200, > 12–23. > > eCognition (2012). Definiens > eCognition developer 8.7 user guide. > > > Thanks, > > Eder Paulo Moreira > > Master Student in Remote Sensing > > National Institute For Space Research - Brazil > >> Subject: Re: [R] Image segmentation >> From: dwinsem...@comcast.net >> Date: Mon, 1 Apr 2013 18:42:40 -0700 >> CC: r-help@r-project.org >> To: eder...@hotmail.com >> >> >> On Apr 1, 2013, at 7:50 AM, Eder Paulo wrote: >> >>> Hi, >>> >>> I work with >>> remote sensing in Brazil. I would like to know if there is any algorithm or >>> package that does image segmentation by region growing in R. >>> >> >> It's possible that there is a domain of investigation where the phrase " >> image segmentation by region growing" would be specific enough to offer >> advice, but it's certainly outside my experience. I would advise being >> somewhat more expansive when describing your requirements in future postings >> to this generalist audience. You might want to look at the CRAN Task Views: >> (first hit with Google if you search on that phrase). The Task Views used to >> be countable on one hand but now threaten to extend beyond a full page. I >> believe you will find the MedicalImaging or Spatial Views have pointers to >> tools with image analysis functions. The MedicalImaging View also has a link >> to: http://www.bioconductor.org/packages/release/bioc/html/EBImage.html >> >> >> -- >> David Winsemius >> Alameda, CA, USA >> > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > 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-help@r-project.org mailing list 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] Cannot scale data
Hello, Can't you simply call svm() with scale = FALSE ? If the variable is constant, it cannot be scaled to unit variance (and zero mean). Hope this helps, Rui Barradas Em 06-04-2013 17:19, Nicolás Sánchez escreveu: Hello! I have this error in R: In svm.default(x, y, scale = scale, ..., na.action = na.action) : Variable(s) ‘X.11.’ constant. Cannot scale data. Of course, I have a column of 25 rows where the values are always 0. Why it is not possible to have a column with 0? I need this column because is a feature from a patient. Is there any way to solve this error? Thanks in advance! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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-help@r-project.org mailing list 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] Replace missing value within group with non-missing value
Hello, I've just run my code with your data and found no error. Anyway, try replacing the lapply instruction with this. tmp <- lapply(sp, function(x){ idx <- which(!is.na(x$mth))[1] if(length(idx) > 0) x$mth <- x$mth[idx] x }) Rui Barradas Em 06-04-2013 18:12, Leask, Graham escreveu: Hi Arun, How odd. Directly pasting the code from your email precisely repeats the error. See below. Any thoughts on the cause of this anomaly? dput(head(dat,50)) structure(list(dn = c(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4), obs = c(1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9), choice = c(0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0), br = c(1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2), mth = c(NA, NA, NA, NA, NA, 487, NA, NA, 488, NA, NA, NA, NA, NA, NA, NA, NA, 488, NA, NA, 489, NA, NA, NA, NA, NA, NA, NA, NA, 489, NA, NA, NA, NA, NA, 489, NA, NA, NA, NA, NA, 490, NA, NA, NA, NA, NA, 491, NA, NA)), .Names = c("dn", "obs", "choice", "br", "mth"), row.names = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50"), class = "data.frame") sp <- split(dat, list(dat$dn, dat$obs)) names(sp) <- NULL tmp <- lapply(sp, function(x){ + idx <- which(!is.na(x$mth))[1] + x$mth <- x$mth[idx] + x + }) Error in `$<-.data.frame`(`*tmp*`, "mth", value = NA_real_) : replacement has 1 rows, data has 0 head(do.call(rbind, tmp),7) Error in do.call(rbind, tmp) : object 'tmp' not found Best wishes Graham -Original Message- From: arun [mailto:smartpink...@yahoo.com] Sent: 06 April 2013 17:25 To: Leask, Graham Cc: Rui Barradas Subject: Re: [R] Replace missing value within group with non-missing value Hello, By running Rui's code, I am getting this: sp <- split(dat, list(dat$dn, dat$obs)) names(sp) <- NULL tmp <- lapply(sp, function(x){ idx <- which(!is.na(x$mth))[1] x$mth <- x$mth[idx] x }) head(do.call(rbind, tmp),7) dn obs choice br mth 1 4 1 0 1 487 2 4 1 0 2 487 3 4 1 0 3 487 4 4 1 0 4 487 5 4 1 0 5 487 6 4 1 1 6 487 7 4 2 0 1 488 Couldn't reproduce the error you cited. A.K. - Original Message - From: "Leask, Graham" To: Rui Barradas Cc: "r-help@r-project.org" Sent: Saturday, April 6, 2013 12:16 PM Subject: Re: [R] Replace missing value within group with non-missing value Hi Rui, Data as follows structure(list(dn = c(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4), obs = c(1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9), choice = c(0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0), br = c(1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2), mth = c(NA, NA, NA, NA, NA, 487, NA, NA, 488, NA, NA, NA, NA, NA, NA, NA, NA, 488, NA, NA, 489, NA, NA, NA, NA, NA, NA, NA, NA, 489, NA, NA, NA, NA, NA, 489, NA, NA, NA, NA, NA, 490, NA, NA, NA, NA, NA, 491, NA, NA)), .Names = c("dn", "obs", "choice", "br", "mth"), row.names = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"! , "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50"), class = "data.frame") Best wishes Graham -Original Message- From: Rui Barradas [mailto:ruipbarra...@sapo.pt] Sent: 06 April 2013 16:32 To: Leask, Graham Cc: r-help@r-project.org Subject: Re: [R] Replace missing value within group with non-missing value Hello, Can't you post a data example? If your dataset is named 'dat' use dput(head(dat, 50)) # paste the output of this in a post Rui Barradas Em 06-04-2013 15:34, Leask, Graham escreveu: Hi Rui, Thank you for your suggestion which is very much appreciated. Unfortunately running this code produces the following error. error in '$<-.data.frame' ('*tm
Re: [R] Replace missing value within group with non-missing value
Hi David, Thank you for your suggestion unfortunately it yields an incorrect result. Within a choice set the mth should be identical. > head(dat) dn obs choice br mth 1 4 1 0 1 487 2 4 1 0 2 488 3 4 1 0 3 488 4 4 1 0 4 488 5 4 1 0 5 488 6 4 1 1 6 487 Best wishes Graham -Original Message- From: David Winsemius [mailto:dwinsem...@comcast.net] Sent: 06 April 2013 17:46 To: David Winsemius Cc: Leask, Graham; r-help@r-project.org Subject: Re: [R] Replace missing value within group with non-missing value On Apr 6, 2013, at 9:26 AM, David Winsemius wrote: > > On Apr 6, 2013, at 9:16 AM, Leask, Graham wrote: > >> Hi Rui, >> >> Data as follows >> >> structure(list(dn = c(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, >> 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, >> 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4), obs = c(1, 1, 1, 1, 1, 1, 2, 2, 2, >> 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, >> 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9), choice = c(0, >> 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, >> 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, >> 1, 0, 0), br = c(1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, >> 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, >> 5, 6, 1, 2, 3, 4, 5, 6, 1, 2), mth = c(NA, NA, NA, NA, NA, 487, NA, >> NA, 488, NA, NA, NA, NA, NA, NA, NA, NA, 488, NA, NA, 489, NA, NA, >> NA, NA, NA, NA, NA, NA, 489, NA, NA, NA, NA, NA, 489, NA, NA, NA, NA, >> NA, 490, NA, NA, NA, NA, NA, 491, NA, NA)), .Names = c("dn", "obs", >> "choice", "br", "mth"), row.names = c("1", "2", "3", "4", "5", "6", >> "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", >> "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", >> "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", >> "41", "42", "43", "44", "45", "46", "47", "48", "49", "50"), class = >> "data.frame") >> > > Looks like a job for na.locf in the zoo package: > > require(zoo) > # will fail if first value is NA so either this ... > dat$mth[-(1:5)] <- na.locf(dat$mth[-(1:5)]) # ... or this: > dat$mth <- na.locf(dat$mth, na.rm=FALSE) If on the other hand you wnated cases to be be handled within individual values of "obs" then you could do this to the categories of obs where there was a value to replace (omitting the last two rows): dat$mth[-(49:50)] <- ave(dat$mth[-(49:50)] , dat$obs, FUN=function(m) {m[is.na(m)] <- m[!is.na(m)]; m } ) If there were more than one choice in a category you might need to pick the first or the last. > > -- > David. > >> Best wishes >> >> >> Graham >> >> -Original Message- >> From: Rui Barradas [mailto:ruipbarra...@sapo.pt] >> Sent: 06 April 2013 16:32 >> To: Leask, Graham >> Cc: r-help@r-project.org >> Subject: Re: [R] Replace missing value within group with non-missing >> value >> >> Hello, >> >> Can't you post a data example? If your dataset is named 'dat' use >> >> dput(head(dat, 50)) # paste the output of this in a post >> >> >> Rui Barradas >> >> Em 06-04-2013 15:34, Leask, Graham escreveu: >>> Hi Rui, >>> >>> Thank you for your suggestion which is very much appreciated. Unfortunately >>> running this code produces the following error. >>> >>> error in '$<-.data.frame' ('*tmp*', "mth", value = NA_real_) : >>>replacement has 1 rows, data has 0 >>> >>> I'm sure there must be an elegant solution to this problem? >>> >>> Best wishes >>> >>> >>> >>> Graham >>> >>> On 6 Apr 2013, at 12:15, "Rui Barradas" wrote: >>> Hello, That's not a very good way of posting your data, preferably paste the output of ?dput in a post. Some thing along the lines of the following might do what you want. It seems that the groups are established by 'dn' and 'obs' numbers. If so, try # Make up some data dat <- data.frame(dn = 4, obs = rep(1:5, each = 6), mth = NA) dat$mth[6] <- 487 dat$mth[9] <- 488 dat$mth[18] <- 488 dat$mth[21] <- 489 dat$mth[30] <- 489 sp <- split(dat, list(dat$dn, dat$obs)) names(sp) <- NULL tmp <- lapply(sp, function(x){ idx <- which(!is.na(x$mth))[1] x$mth <- x$mth[idx] x }) do.call(rbind, tmp) Hope this helps, Rui Barradas Em 06-04-2013 11:33, Leask, Graham escreveu: > Dear List members > > I have a large dataset organised in choice groups see sample below > > > +-+ > | dn obs choice acid br date cdate > situat~n mth year set | > > |--
Re: [R] Array analogue of row and col
slice.index() in base On 4/2/2013 9:53 AM, Enrico Bibbona wrote: Great! Thanks a lot, Enrico 2013/4/2 Duncan Murdoch On 02/04/2013 6:36 AM, Enrico Bibbona wrote: Is there any function that extends to multidimentional arrays the functionalities of "row" and "col" which are just defined for matrices? Thanks, Enrico Bibbona Not as far as I know, but there are a lot of functions in packages. You could write your own something like this. I've skipped any error checking; you'll want to add that. indices <- function(a, which) { d <- dim(a) prod_before <- prod(d[seq_len(which-1)]) result <- rep(seq_len(d[which]), each=prod_before, length.out = prod(d)) dim(result) <- d result } Then indices(a, 1) gives an array of the same shape as a where entry i, j, k, ... is i, indices(a, 2) has entry i,j,k, ... equal to j, etc. Duncan Murdoch [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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-help@r-project.org mailing list 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] Array analogue of row and col
slice.index() in base On 4/2/2013 6:36 AM, Enrico Bibbona wrote: Is there any function that extends to multidimentional arrays the functionalities of "row" and "col" which are just defined for matrices? Thanks, Enrico Bibbona [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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-help@r-project.org mailing list 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] Replace missing value within group with non-missing value
Hi Arun, How odd. Directly pasting the code from your email precisely repeats the error. See below. Any thoughts on the cause of this anomaly? > dput(head(dat,50)) structure(list(dn = c(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4), obs = c(1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9), choice = c(0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0), br = c(1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2), mth = c(NA, NA, NA, NA, NA, 487, NA, NA, 488, NA, NA, NA, NA, NA, NA, NA, NA, 488, NA, NA, 489, NA, NA, NA, NA, NA, NA, NA, NA, 489, NA, NA, NA, NA, NA, 489, NA, NA, NA, NA, NA, 490, NA, NA, NA, NA, NA, 491, NA, NA)), .Names = c("dn", "obs", "choice", "br", "mth"), row.names = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50"), class = "data.frame") > sp <- split(dat, list(dat$dn, dat$obs)) > names(sp) <- NULL > tmp <- lapply(sp, function(x){ + idx <- which(!is.na(x$mth))[1] + x$mth <- x$mth[idx] + x + }) Error in `$<-.data.frame`(`*tmp*`, "mth", value = NA_real_) : replacement has 1 rows, data has 0 > head(do.call(rbind, tmp),7) Error in do.call(rbind, tmp) : object 'tmp' not found Best wishes Graham -Original Message- From: arun [mailto:smartpink...@yahoo.com] Sent: 06 April 2013 17:25 To: Leask, Graham Cc: Rui Barradas Subject: Re: [R] Replace missing value within group with non-missing value Hello, By running Rui's code, I am getting this: sp <- split(dat, list(dat$dn, dat$obs)) names(sp) <- NULL tmp <- lapply(sp, function(x){ idx <- which(!is.na(x$mth))[1] x$mth <- x$mth[idx] x }) head(do.call(rbind, tmp),7) dn obs choice br mth 1 4 1 0 1 487 2 4 1 0 2 487 3 4 1 0 3 487 4 4 1 0 4 487 5 4 1 0 5 487 6 4 1 1 6 487 7 4 2 0 1 488 Couldn't reproduce the error you cited. A.K. - Original Message - From: "Leask, Graham" To: Rui Barradas Cc: "r-help@r-project.org" Sent: Saturday, April 6, 2013 12:16 PM Subject: Re: [R] Replace missing value within group with non-missing value Hi Rui, Data as follows structure(list(dn = c(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4), obs = c(1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9), choice = c(0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0), br = c(1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2), mth = c(NA, NA, NA, NA, NA, 487, NA, NA, 488, NA, NA, NA, NA, NA, NA, NA, NA, 488, NA, NA, 489, NA, NA, NA, NA, NA, NA, NA, NA, 489, NA, NA, NA, NA, NA, 489, NA, NA, NA, NA, NA, 490, NA, NA, NA, NA, NA, 491, NA, NA)), .Names = c("dn", "obs", "choice", "br", "mth"), row.names = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50"), class = "data.frame") Best wishes Graham -Original Message- From: Rui Barradas [mailto:ruipbarra...@sapo.pt] Sent: 06 April 2013 16:32 To: Leask, Graham Cc: r-help@r-project.org Subject: Re: [R] Replace missing value within group with non-missing value Hello, Can't you post a data example? If your dataset is named 'dat' use dput(head(dat, 50)) # paste the output of this in a post Rui Barradas Em 06-04-2013 15:34, Leask, Graham escreveu: > Hi Rui, > > Thank you for your suggestion which is very much appreciated. Unfortunately > running this code produces the following error. > > error in '$<-.data.frame' ('*tmp*', "mth", value = NA_real_) : > replacement has 1 rows, data has 0 > > I'm sure there must be an elegant solution to this problem? > > Best wishes > > > > Graham > > On 6 Apr 2013, at 12:15, "Rui Barradas" wrote: > >> Hello, >> >> That's not a very good way of posting your data, preferably paste the output >> of ?dput in a post. >> Som
Re: [R] arrange data
lst1<-lapply(dat1,function(x) x[!is.na(x)]) res<-as.data.frame(sapply(lst1,function(x) c(x,rep(NA,max(sapply(lst1,length))-length(x)) ))) head(res) # 1B 2B 4B 1A 2A 4A 5B 5A C31A C31B C34A C34B C35A #1 2.518 2.357 1.499 3.647 1.890 2.249 2.896 2.175 0.452 1.177 0.344 0.612 1.722 #2 2.796 2.759 1.032 3.763 1.182 2.291 2.417 2.597 1.033 0.831 0.351 0.509 1.102 #3 4.012 2.878 1.126 3.236 1.431 2.635 2.952 2.483 0.679 0.484 0.704 0.461 1.400 #4 3.611 2.094 1.043 3.032 1.835 3.019 1.590 2.269 0.901 0.576 1.008 0.879 2.222 #5 2.970 1.371 1.486 1.817 1.884 2.557 1.768 1.463 0.466 0.378 0.708 0.862 1.840 #6 4.687 1.042 1.252 3.495 2.540 2.592 1.179 1.860 0.608 0.314 0.721 0.624 1.927 # C35B C37A C37B C36A C36B C32A C32B C33A C33B C39B #1 2.482 0.996 0.898 0.179 1.148 2.637 2.917 1.440 1.487 1.291 #2 1.061 1.243 1.078 1.167 1.209 2.770 2.325 2.006 1.886 0.655 #3 1.350 0.999 0.992 1.629 1.551 1.996 2.444 1.261 1.343 0.790 #4 1.952 1.227 1.447 1.067 2.252 2.220 1.635 1.085 1.367 0.633 #5 2.343 1.049 1.285 1.299 1.182 2.976 2.106 1.388 2.253 0.630 #6 2.104 1.771 1.204 1.540 1.203 2.847 2.200 2.563 2.348 0.493 nrow(res) #[1] 140 If you wanted to have the same number of rows as dat1: nrow(dat1) #[1] 145 new1<-as.data.frame(matrix(NA,ncol=23,nrow=5)) colnames(new1)<- colnames(res) res1<- rbind(res,new1) nrow(res1) #[1] 145 A.K. From: catalin roibu To: arun Sent: Saturday, April 6, 2013 12:52 PM Subject: Re: [R] arrange data it is ok, but I want for all rows not only for 2, like in my example. Thank you very much! On 6 April 2013 19:47, arun wrote: > >Hi, >Try this: >#dat1 is dataset >indx<-apply(dat1,2,function(x) head(which(!is.na(x)),2)) >res<-as.data.frame(sapply(seq_len(ncol(indx)),function(i) dat2[indx[,i],i])) > colnames(res)<- colnames(dat1) > res ># 1B 2B 4B 1A 2A 4A 5B 5A C31A C31B C34A C34B >C35A >#1 2.518 2.357 1.499 3.647 1.890 2.249 2.896 2.175 0.452 1.177 0.344 0.612 >1.722 >#2 2.796 2.759 1.032 3.763 1.182 2.291 2.417 2.597 1.033 0.831 0.351 0.509 >1.102 > # C35B C37A C37B C36A C36B C32A C32B C33A C33B C39B >#1 2.482 0.996 0.898 0.179 1.148 2.637 2.917 1.440 1.487 1.291 >#2 1.061 1.243 1.078 1.167 1.209 2.770 2.325 2.006 1.886 0.655 > > >#or just > res2<-sapply(dat1,function(x) head(x[!is.na(x)],2)) >res2 ># 1B 2B 4B 1A 2A 4A 5B 5A C31A C31B C34A C34B >#[1,] 2.518 2.357 1.499 3.647 1.890 2.249 2.896 2.175 0.452 1.177 0.344 0.612 >#[2,] 2.796 2.759 1.032 3.763 1.182 2.291 2.417 2.597 1.033 0.831 0.351 0.509 > # C35A C35B C37A C37B C36A C36B C32A C32B C33A C33B C39B >#[1,] 1.722 2.482 0.996 0.898 0.179 1.148 2.637 2.917 1.440 1.487 1.291 >#[2,] 1.102 1.061 1.243 1.078 1.167 1.209 2.770 2.325 2.006 1.886 0.655 > > >A.K. > > >- Original Message - > >From: catalin roibu >To: r-help@r-project.org >Cc: >Sent: Saturday, April 6, 2013 10:28 AM >Subject: [R] arrange data > > >Hello all! >I have a problem to arrange data in another form. My initial data is like >this: >'data.frame': 421 obs. of 58 variables: >$ 01A: num NA NA NA NA NA NA NA NA NA NA ... >$ 01B: num NA NA NA NA NA NA NA NA NA NA ... >$ 03A: num NA NA NA NA NA NA NA NA NA NA ... >$ 03B: num NA NA NA NA NA NA NA NA NA NA ... >$ 05A: num NA NA NA NA NA NA NA NA NA NA ... >$ 05B: num NA NA NA NA NA NA NA 3.64 2.48 1.87 ... >$ 07A: num NA NA NA NA NA NA NA NA NA NA ... >$ 07B: num NA NA NA NA NA NA NA NA NA NA ... >$ 10A: num NA NA NA NA NA NA NA NA NA NA ... >$ 10B: num NA NA NA NA NA NA NA NA NA NA ... >$ 12A: num NA NA NA NA NA NA NA NA NA NA ... >$ 12B: num NA NA NA NA NA NA NA NA NA NA ... >$ 14A: num NA NA NA NA NA NA NA NA NA NA ... >$ 14B: num NA NA NA NA NA NA NA NA NA NA ... >$ 16A: num NA NA NA NA NA NA NA NA NA NA ... >$ 16B: num NA NA NA NA NA NA NA NA NA NA ... >$ 17A: num NA NA NA NA NA NA NA NA NA NA ... >$ 17B: num NA NA NA NA NA NA NA NA NA NA ... >$ 20A: num NA NA NA NA NA NA NA NA NA NA ... >$ 20B: num 0.85 0.77 0.62 0.86 0.97 0.6 0.33 0.58 0.54 0.88 ... >$ 22A: num NA NA NA NA NA NA NA NA NA NA ... >$ 22B: num NA NA NA NA NA NA NA NA NA NA ... >$ 23A: num NA NA NA NA NA NA NA NA NA NA ... >$ 23B: num NA NA NA NA NA NA NA NA NA NA ... >$ 25A: num NA NA NA NA NA NA NA NA NA NA ... >$ 25B: num NA NA NA NA NA NA NA NA NA NA ... >$ 28A: num NA NA NA NA NA NA NA NA NA NA ... >$ 28B: num NA NA NA NA NA NA NA NA NA NA ... >$ 31A: num NA NA NA NA NA NA NA NA NA NA ... >$ 31B: num NA NA NA NA NA NA NA NA NA NA ... >$ 32A: num NA NA NA NA NA NA NA NA NA 1.19 ... >$ 32B: num NA NA NA NA NA NA NA NA NA NA ... >$ 34A: num NA NA NA NA NA NA NA NA NA NA ... >$ 34B: num NA NA NA NA NA NA NA NA NA NA ... >$ 36A: num NA NA NA NA NA NA NA NA NA NA ... >$ 36B: num NA NA NA NA NA NA NA NA NA NA ... >$ 42A: num NA NA NA NA NA NA NA NA NA NA ... >$ 42B: num NA NA NA NA NA NA NA NA NA NA ... >$ 44A: num NA NA NA NA NA NA NA
Re: [R] arrange data
Hi, Try this: #dat1 is dataset indx<-apply(dat1,2,function(x) head(which(!is.na(x)),2)) res<-as.data.frame(sapply(seq_len(ncol(indx)),function(i) dat2[indx[,i],i])) colnames(res)<- colnames(dat1) res # 1B 2B 4B 1A 2A 4A 5B 5A C31A C31B C34A C34B C35A #1 2.518 2.357 1.499 3.647 1.890 2.249 2.896 2.175 0.452 1.177 0.344 0.612 1.722 #2 2.796 2.759 1.032 3.763 1.182 2.291 2.417 2.597 1.033 0.831 0.351 0.509 1.102 # C35B C37A C37B C36A C36B C32A C32B C33A C33B C39B #1 2.482 0.996 0.898 0.179 1.148 2.637 2.917 1.440 1.487 1.291 #2 1.061 1.243 1.078 1.167 1.209 2.770 2.325 2.006 1.886 0.655 #or just res2<-sapply(dat1,function(x) head(x[!is.na(x)],2)) res2 # 1B 2B 4B 1A 2A 4A 5B 5A C31A C31B C34A C34B #[1,] 2.518 2.357 1.499 3.647 1.890 2.249 2.896 2.175 0.452 1.177 0.344 0.612 #[2,] 2.796 2.759 1.032 3.763 1.182 2.291 2.417 2.597 1.033 0.831 0.351 0.509 # C35A C35B C37A C37B C36A C36B C32A C32B C33A C33B C39B #[1,] 1.722 2.482 0.996 0.898 0.179 1.148 2.637 2.917 1.440 1.487 1.291 #[2,] 1.102 1.061 1.243 1.078 1.167 1.209 2.770 2.325 2.006 1.886 0.655 A.K. - Original Message - From: catalin roibu To: r-help@r-project.org Cc: Sent: Saturday, April 6, 2013 10:28 AM Subject: [R] arrange data Hello all! I have a problem to arrange data in another form. My initial data is like this: 'data.frame': 421 obs. of 58 variables: $ 01A: num NA NA NA NA NA NA NA NA NA NA ... $ 01B: num NA NA NA NA NA NA NA NA NA NA ... $ 03A: num NA NA NA NA NA NA NA NA NA NA ... $ 03B: num NA NA NA NA NA NA NA NA NA NA ... $ 05A: num NA NA NA NA NA NA NA NA NA NA ... $ 05B: num NA NA NA NA NA NA NA 3.64 2.48 1.87 ... $ 07A: num NA NA NA NA NA NA NA NA NA NA ... $ 07B: num NA NA NA NA NA NA NA NA NA NA ... $ 10A: num NA NA NA NA NA NA NA NA NA NA ... $ 10B: num NA NA NA NA NA NA NA NA NA NA ... $ 12A: num NA NA NA NA NA NA NA NA NA NA ... $ 12B: num NA NA NA NA NA NA NA NA NA NA ... $ 14A: num NA NA NA NA NA NA NA NA NA NA ... $ 14B: num NA NA NA NA NA NA NA NA NA NA ... $ 16A: num NA NA NA NA NA NA NA NA NA NA ... $ 16B: num NA NA NA NA NA NA NA NA NA NA ... $ 17A: num NA NA NA NA NA NA NA NA NA NA ... $ 17B: num NA NA NA NA NA NA NA NA NA NA ... $ 20A: num NA NA NA NA NA NA NA NA NA NA ... $ 20B: num 0.85 0.77 0.62 0.86 0.97 0.6 0.33 0.58 0.54 0.88 ... $ 22A: num NA NA NA NA NA NA NA NA NA NA ... $ 22B: num NA NA NA NA NA NA NA NA NA NA ... $ 23A: num NA NA NA NA NA NA NA NA NA NA ... $ 23B: num NA NA NA NA NA NA NA NA NA NA ... $ 25A: num NA NA NA NA NA NA NA NA NA NA ... $ 25B: num NA NA NA NA NA NA NA NA NA NA ... $ 28A: num NA NA NA NA NA NA NA NA NA NA ... $ 28B: num NA NA NA NA NA NA NA NA NA NA ... $ 31A: num NA NA NA NA NA NA NA NA NA NA ... $ 31B: num NA NA NA NA NA NA NA NA NA NA ... $ 32A: num NA NA NA NA NA NA NA NA NA 1.19 ... $ 32B: num NA NA NA NA NA NA NA NA NA NA ... $ 34A: num NA NA NA NA NA NA NA NA NA NA ... $ 34B: num NA NA NA NA NA NA NA NA NA NA ... $ 36A: num NA NA NA NA NA NA NA NA NA NA ... $ 36B: num NA NA NA NA NA NA NA NA NA NA ... $ 42A: num NA NA NA NA NA NA NA NA NA NA ... $ 42B: num NA NA NA NA NA NA NA NA NA NA ... $ 44A: num NA NA NA NA NA NA NA NA NA NA ... $ 44B: num NA NA NA NA NA NA NA NA NA NA ... $ 47A: num NA NA NA NA NA NA NA NA NA NA ... $ 47B: num NA NA NA NA NA NA NA NA NA NA ... $ 48A: num NA NA NA NA NA NA NA NA NA NA ... $ 48B: num NA NA NA NA NA NA NA NA NA NA ... $ 50A: num NA NA NA NA NA NA NA NA NA NA ... $ 50B: num NA NA NA NA NA NA NA NA NA NA ... $ 52A: num NA NA NA NA NA NA NA NA NA NA ... $ 52B: num NA NA NA NA NA NA NA NA NA NA ... $ 55A: num NA NA NA NA NA NA NA NA NA NA ... $ 55B: num NA NA NA NA NA NA NA NA NA NA ... $ 56A: num NA NA NA NA NA NA NA NA NA NA ... $ 56B: num NA NA NA NA NA NA NA NA NA NA ... $ 59A: num NA NA NA NA NA NA NA NA NA NA ... $ 59B: num NA NA NA NA NA NA NA NA NA NA ... $ 40A: num NA NA NA NA 2.93 3.38 3.19 3.62 2.55 1.69 ... $ 40B: num NA NA NA NA NA NA NA NA NA NA ... $ 39A: num NA NA NA NA NA NA NA NA NA NA ... $ 39B: num NA NA NA NA NA NA NA NA NA NA ... I want to arrange them like this> row.names 01A 02A.. 1 first value first value 2 second value second value 3 4 .. max(nrow) Thank you very much! -- --- Catalin-Constantin ROIBU Lecturer PhD, Forestry engineer Forestry Faculty of Suceava Str. Universitatii no. 13, Suceava, 720229, Romania office phone +4 0230 52 29 78, ext. 531 mobile phone +4 0745 53 18 01 +4 0766 71 76 58 FAX: +4 0230 52 16 64 silvic.usv.ro [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] Replace missing value within group with non-missing value
On Apr 6, 2013, at 9:26 AM, David Winsemius wrote: > > On Apr 6, 2013, at 9:16 AM, Leask, Graham wrote: > >> Hi Rui, >> >> Data as follows >> >> structure(list(dn = c(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, >> 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, >> 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4), obs = c(1, 1, >> 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, >> 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, >> 8, 8, 8, 8, 9, 9), choice = c(0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, >> 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, >> 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0), br = c(1, >> 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, >> 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, >> 2, 3, 4, 5, 6, 1, 2), mth = c(NA, NA, NA, NA, NA, 487, NA, NA, >> 488, NA, NA, NA, NA, NA, NA, NA, NA, 488, NA, NA, 489, NA, NA, >> NA, NA, NA, NA, NA, NA, 489, NA, NA, NA, NA, NA, 489, NA, NA, >> NA, NA, NA, 490, NA, NA, NA, NA, NA, 491, NA, NA)), .Names = c("dn", >> "obs", "choice", "br", "mth"), row.names = c("1", "2", "3", "4", >> "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", >> "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", >> "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", >> "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", >> "49", "50"), class = "data.frame") >> > > Looks like a job for na.locf in the zoo package: > > require(zoo) > # will fail if first value is NA so either this ... > dat$mth[-(1:5)] <- na.locf(dat$mth[-(1:5)]) > # ... or this: > dat$mth <- na.locf(dat$mth, na.rm=FALSE) If on the other hand you wnated cases to be be handled within individual values of "obs" then you could do this to the categories of obs where there was a value to replace (omitting the last two rows): dat$mth[-(49:50)] <- ave(dat$mth[-(49:50)] , dat$obs, FUN=function(m) {m[is.na(m)] <- m[!is.na(m)]; m } ) If there were more than one choice in a category you might need to pick the first or the last. > > -- > David. > >> Best wishes >> >> >> Graham >> >> -Original Message- >> From: Rui Barradas [mailto:ruipbarra...@sapo.pt] >> Sent: 06 April 2013 16:32 >> To: Leask, Graham >> Cc: r-help@r-project.org >> Subject: Re: [R] Replace missing value within group with non-missing value >> >> Hello, >> >> Can't you post a data example? If your dataset is named 'dat' use >> >> dput(head(dat, 50)) # paste the output of this in a post >> >> >> Rui Barradas >> >> Em 06-04-2013 15:34, Leask, Graham escreveu: >>> Hi Rui, >>> >>> Thank you for your suggestion which is very much appreciated. Unfortunately >>> running this code produces the following error. >>> >>> error in '$<-.data.frame' ('*tmp*', "mth", value = NA_real_) : >>>replacement has 1 rows, data has 0 >>> >>> I'm sure there must be an elegant solution to this problem? >>> >>> Best wishes >>> >>> >>> >>> Graham >>> >>> On 6 Apr 2013, at 12:15, "Rui Barradas" wrote: >>> Hello, That's not a very good way of posting your data, preferably paste the output of ?dput in a post. Some thing along the lines of the following might do what you want. It seems that the groups are established by 'dn' and 'obs' numbers. If so, try # Make up some data dat <- data.frame(dn = 4, obs = rep(1:5, each = 6), mth = NA) dat$mth[6] <- 487 dat$mth[9] <- 488 dat$mth[18] <- 488 dat$mth[21] <- 489 dat$mth[30] <- 489 sp <- split(dat, list(dat$dn, dat$obs)) names(sp) <- NULL tmp <- lapply(sp, function(x){ idx <- which(!is.na(x$mth))[1] x$mth <- x$mth[idx] x }) do.call(rbind, tmp) Hope this helps, Rui Barradas Em 06-04-2013 11:33, Leask, Graham escreveu: > Dear List members > > I have a large dataset organised in choice groups see sample below > > > +-+ > | dn obs choice acid br date cdate > situat~n mth year set | > > |-| > 1. | 4 10 LOSEC1. . > . . 1 | > 2. | 4 10NEXIUM2. . > . . 1 | > 3. | 4 10PARIET3. . > . . 1 | > 4. | 4 10 PROTIUM4. . > . . 1 | > 5. | 4 10ZANTAC5. . >
Re: [R] Replace missing value within group with non-missing value
Probably not very R-ish but it works (your data in a dataframe called "x"), if I understand your question right: # replace NA with 0 x$mth <- ifelse( is.na( x$mth ), 0, x$mth ) # loop through observation numbers and replace 0 with the month no for( i in unique( x$obs ) ) x$mth[ x$obs == i ] <- max( x$mth[ x$obs == i ] ) Rgds, Rainer > x dn obs choice br mth 1 4 1 0 1 487 2 4 1 0 2 487 3 4 1 0 3 487 4 4 1 0 4 487 5 4 1 0 5 487 6 4 1 1 6 487 7 4 2 0 1 488 8 4 2 0 2 488 9 4 2 1 3 488 10 4 2 0 4 488 11 4 2 0 5 488 12 4 2 0 6 488 13 4 3 0 1 488 14 4 3 0 2 488 15 4 3 0 3 488 16 4 3 0 4 488 17 4 3 0 5 488 18 4 3 1 6 488 19 4 4 0 1 489 20 4 4 0 2 489 21 4 4 1 3 489 22 4 4 0 4 489 23 4 4 0 5 489 24 4 4 0 6 489 25 4 5 0 1 489 26 4 5 0 2 489 27 4 5 0 3 489 28 4 5 0 4 489 29 4 5 0 5 489 30 4 5 1 6 489 31 4 6 0 1 489 32 4 6 0 2 489 33 4 6 0 3 489 34 4 6 0 4 489 35 4 6 0 5 489 36 4 6 1 6 489 37 4 7 0 1 490 38 4 7 0 2 490 39 4 7 0 3 490 40 4 7 0 4 490 41 4 7 0 5 490 42 4 7 1 6 490 43 4 8 0 1 491 44 4 8 0 2 491 45 4 8 0 3 491 46 4 8 0 4 491 47 4 8 0 5 491 48 4 8 1 6 491 49 4 9 0 1 0 50 4 9 0 2 0 On Saturday 06 April 2013 16:16:16 Leask, Graham wrote: > Hi Rui, > > Data as follows > > structure(list(dn = c(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, > 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, > 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4), obs = c(1, 1, > 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, > 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, > 8, 8, 8, 8, 9, 9), choice = c(0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, > 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, > 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0), br = c(1, > 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, > 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, > 2, 3, 4, 5, 6, 1, 2), mth = c(NA, NA, NA, NA, NA, 487, NA, NA, > 488, NA, NA, NA, NA, NA, NA, NA, NA, 488, NA, NA, 489, NA, NA, > NA, NA, NA, NA, NA, NA, 489, NA, NA, NA, NA, NA, 489, NA, NA, > NA, NA, NA, 490, NA, NA, NA, NA, NA, 491, NA, NA)), .Names = c("dn", > "obs", "choice", "br", "mth"), row.names = c("1", "2", "3", "4", > "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", > "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", > "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", > "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", > "49", "50"), class = "data.frame") > > Best wishes > > > Graham > > -Original Message- > From: Rui Barradas [mailto:ruipbarra...@sapo.pt] > Sent: 06 April 2013 16:32 > To: Leask, Graham > Cc: r-help@r-project.org > Subject: Re: [R] Replace missing value within group with non-missing value > > Hello, > > Can't you post a data example? If your dataset is named 'dat' use > > dput(head(dat, 50)) # paste the output of this in a post > > > Rui Barradas > > Em 06-04-2013 15:34, Leask, Graham escreveu: > > Hi Rui, > > > > Thank you for your suggestion which is very much appreciated. Unfortunately > > running this code produces the following error. > > > > error in '$<-.data.frame' ('*tmp*', "mth", value = NA_real_) : > > replacement has 1 rows, data has 0 > > > > I'm sure there must be an elegant solution to this problem? > > > > Best wishes > > > > > > > > Graham > > > > On 6 Apr 2013, at 12:15, "Rui Barradas" wrote: > > > >> Hello, > >> > >> That's not a very good way of posting your data, preferably paste the > >> output of ?dput in a post. > >> Some thing along the lines of the following might do what you want. > >> It seems that the groups are established by 'dn' and 'obs' numbers. > >> If so, try > >> > >> > >> # Make up some data > >> dat <- data.frame(dn = 4, obs = rep(1:5, each = 6), mth = NA) > >> dat$mth[6] <- 487 dat$mth[9] <- 488 dat$mth[18] <- 488 dat$mth[21] <- > >> 489 dat$mth[30] <- 489 > >> > >> > >> sp <- split(dat, list(dat$dn, dat$obs)) > >> names(sp) <- NULL > >> tmp <- lapply(sp, function(x){ > >> idx <- which(!is.na(x$mth))[1] > >> x$mth <- x$mth[idx] > >> x > >> }) > >> do.call(rbind, tmp) > >> > >> > >> Hope this helps, > >> > >> Rui Barradas > >> > >> > >> Em 06-04-2013 11:33, Leask, Graham escreveu: > >>> Dear List members > >>> > >>> I have a large dataset organised in choice groups see sample below > >>> > >>> > >>> +-+ > >>> | dn obs cho
Re: [R] arrange data
If you want to reorder the column names of your data frame, try (it would have been nice if you provided a subset of your data with 'dput'): # create the order of the new columns indx <- order(substring(colnnames(df), 3, 3) , substring(colnames(df), 1, 2) ) df <- df[, indx] On Sat, Apr 6, 2013 at 10:28 AM, catalin roibu wrote: > Hello all! > I have a problem to arrange data in another form. My initial data is like > this: > 'data.frame': 421 obs. of 58 variables: > $ 01A: num NA NA NA NA NA NA NA NA NA NA ... > $ 01B: num NA NA NA NA NA NA NA NA NA NA ... > $ 03A: num NA NA NA NA NA NA NA NA NA NA ... > $ 03B: num NA NA NA NA NA NA NA NA NA NA ... > $ 05A: num NA NA NA NA NA NA NA NA NA NA ... > $ 05B: num NA NA NA NA NA NA NA 3.64 2.48 1.87 ... > $ 07A: num NA NA NA NA NA NA NA NA NA NA ... > $ 07B: num NA NA NA NA NA NA NA NA NA NA ... > $ 10A: num NA NA NA NA NA NA NA NA NA NA ... > $ 10B: num NA NA NA NA NA NA NA NA NA NA ... > $ 12A: num NA NA NA NA NA NA NA NA NA NA ... > $ 12B: num NA NA NA NA NA NA NA NA NA NA ... > $ 14A: num NA NA NA NA NA NA NA NA NA NA ... > $ 14B: num NA NA NA NA NA NA NA NA NA NA ... > $ 16A: num NA NA NA NA NA NA NA NA NA NA ... > $ 16B: num NA NA NA NA NA NA NA NA NA NA ... > $ 17A: num NA NA NA NA NA NA NA NA NA NA ... > $ 17B: num NA NA NA NA NA NA NA NA NA NA ... > $ 20A: num NA NA NA NA NA NA NA NA NA NA ... > $ 20B: num 0.85 0.77 0.62 0.86 0.97 0.6 0.33 0.58 0.54 0.88 ... > $ 22A: num NA NA NA NA NA NA NA NA NA NA ... > $ 22B: num NA NA NA NA NA NA NA NA NA NA ... > $ 23A: num NA NA NA NA NA NA NA NA NA NA ... > $ 23B: num NA NA NA NA NA NA NA NA NA NA ... > $ 25A: num NA NA NA NA NA NA NA NA NA NA ... > $ 25B: num NA NA NA NA NA NA NA NA NA NA ... > $ 28A: num NA NA NA NA NA NA NA NA NA NA ... > $ 28B: num NA NA NA NA NA NA NA NA NA NA ... > $ 31A: num NA NA NA NA NA NA NA NA NA NA ... > $ 31B: num NA NA NA NA NA NA NA NA NA NA ... > $ 32A: num NA NA NA NA NA NA NA NA NA 1.19 ... > $ 32B: num NA NA NA NA NA NA NA NA NA NA ... > $ 34A: num NA NA NA NA NA NA NA NA NA NA ... > $ 34B: num NA NA NA NA NA NA NA NA NA NA ... > $ 36A: num NA NA NA NA NA NA NA NA NA NA ... > $ 36B: num NA NA NA NA NA NA NA NA NA NA ... > $ 42A: num NA NA NA NA NA NA NA NA NA NA ... > $ 42B: num NA NA NA NA NA NA NA NA NA NA ... > $ 44A: num NA NA NA NA NA NA NA NA NA NA ... > $ 44B: num NA NA NA NA NA NA NA NA NA NA ... > $ 47A: num NA NA NA NA NA NA NA NA NA NA ... > $ 47B: num NA NA NA NA NA NA NA NA NA NA ... > $ 48A: num NA NA NA NA NA NA NA NA NA NA ... > $ 48B: num NA NA NA NA NA NA NA NA NA NA ... > $ 50A: num NA NA NA NA NA NA NA NA NA NA ... > $ 50B: num NA NA NA NA NA NA NA NA NA NA ... > $ 52A: num NA NA NA NA NA NA NA NA NA NA ... > $ 52B: num NA NA NA NA NA NA NA NA NA NA ... > $ 55A: num NA NA NA NA NA NA NA NA NA NA ... > $ 55B: num NA NA NA NA NA NA NA NA NA NA ... > $ 56A: num NA NA NA NA NA NA NA NA NA NA ... > $ 56B: num NA NA NA NA NA NA NA NA NA NA ... > $ 59A: num NA NA NA NA NA NA NA NA NA NA ... > $ 59B: num NA NA NA NA NA NA NA NA NA NA ... > $ 40A: num NA NA NA NA 2.93 3.38 3.19 3.62 2.55 1.69 ... > $ 40B: num NA NA NA NA NA NA NA NA NA NA ... > $ 39A: num NA NA NA NA NA NA NA NA NA NA ... > $ 39B: num NA NA NA NA NA NA NA NA NA NA ... > I want to arrange them like this> > row.names 01A 02A.. > 1 first value first value > 2 second value second value > 3 > 4 > .. > max(nrow) > > Thank you very much! > > -- > --- > Catalin-Constantin ROIBU > Lecturer PhD, Forestry engineer > Forestry Faculty of Suceava > Str. Universitatii no. 13, Suceava, 720229, Romania > office phone +4 0230 52 29 78, ext. 531 > mobile phone +4 0745 53 18 01 >+4 0766 71 76 58 > FAX:+4 0230 52 16 64 > silvic.usv.ro > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > 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. > -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] Replace missing value within group with non-missing value
On Apr 6, 2013, at 9:16 AM, Leask, Graham wrote: > Hi Rui, > > Data as follows > > structure(list(dn = c(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, > 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, > 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4), obs = c(1, 1, > 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, > 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, > 8, 8, 8, 8, 9, 9), choice = c(0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, > 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, > 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0), br = c(1, > 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, > 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, > 2, 3, 4, 5, 6, 1, 2), mth = c(NA, NA, NA, NA, NA, 487, NA, NA, > 488, NA, NA, NA, NA, NA, NA, NA, NA, 488, NA, NA, 489, NA, NA, > NA, NA, NA, NA, NA, NA, 489, NA, NA, NA, NA, NA, 489, NA, NA, > NA, NA, NA, 490, NA, NA, NA, NA, NA, 491, NA, NA)), .Names = c("dn", > "obs", "choice", "br", "mth"), row.names = c("1", "2", "3", "4", > "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", > "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", > "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", > "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", > "49", "50"), class = "data.frame") > Looks like a job for na.locf in the zoo package: require(zoo) # will fail if first value is NA so either this ... dat$mth[-(1:5)] <- na.locf(dat$mth[-(1:5)]) # ... or this: dat$mth <- na.locf(dat$mth, na.rm=FALSE) -- David. > Best wishes > > > Graham > > -Original Message- > From: Rui Barradas [mailto:ruipbarra...@sapo.pt] > Sent: 06 April 2013 16:32 > To: Leask, Graham > Cc: r-help@r-project.org > Subject: Re: [R] Replace missing value within group with non-missing value > > Hello, > > Can't you post a data example? If your dataset is named 'dat' use > > dput(head(dat, 50)) # paste the output of this in a post > > > Rui Barradas > > Em 06-04-2013 15:34, Leask, Graham escreveu: >> Hi Rui, >> >> Thank you for your suggestion which is very much appreciated. Unfortunately >> running this code produces the following error. >> >> error in '$<-.data.frame' ('*tmp*', "mth", value = NA_real_) : >> replacement has 1 rows, data has 0 >> >> I'm sure there must be an elegant solution to this problem? >> >> Best wishes >> >> >> >> Graham >> >> On 6 Apr 2013, at 12:15, "Rui Barradas" wrote: >> >>> Hello, >>> >>> That's not a very good way of posting your data, preferably paste the >>> output of ?dput in a post. >>> Some thing along the lines of the following might do what you want. >>> It seems that the groups are established by 'dn' and 'obs' numbers. >>> If so, try >>> >>> >>> # Make up some data >>> dat <- data.frame(dn = 4, obs = rep(1:5, each = 6), mth = NA) >>> dat$mth[6] <- 487 dat$mth[9] <- 488 dat$mth[18] <- 488 dat$mth[21] <- >>> 489 dat$mth[30] <- 489 >>> >>> >>> sp <- split(dat, list(dat$dn, dat$obs)) >>> names(sp) <- NULL >>> tmp <- lapply(sp, function(x){ >>>idx <- which(!is.na(x$mth))[1] >>>x$mth <- x$mth[idx] >>>x >>>}) >>> do.call(rbind, tmp) >>> >>> >>> Hope this helps, >>> >>> Rui Barradas >>> >>> >>> Em 06-04-2013 11:33, Leask, Graham escreveu: Dear List members I have a large dataset organised in choice groups see sample below +-+ | dn obs choice acid br date cdate situat~n mth year set | |-| 1. | 4 10 LOSEC1. . . . 1 | 2. | 4 10NEXIUM2. . . . 1 | 3. | 4 10PARIET3. . . . 1 | 4. | 4 10 PROTIUM4. . . . 1 | 5. | 4 10ZANTAC5. . . . 1 | |-| 6. | 4 11 ZOTON6 23aug2000 01:00:00 23aug2000 NS 487 2000 1 | 7. | 4 20 LOSEC1. . . . 2 | 8. | 4 20NEXIUM2. . . . 2 | 9. | 4 21PARIET3 25sep2000 01:00:00 25sep2000 L 488 2000 2 | 10. | 4 2
[R] Cannot scale data
Hello! I have this error in R: In svm.default(x, y, scale = scale, ..., na.action = na.action) : Variable(s) X.11. constant. Cannot scale data. Of course, I have a column of 25 rows where the values are always 0. Why it is not possible to have a column with 0? I need this column because is a feature from a patient. Is there any way to solve this error? Thanks in advance! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] Replace missing value within group with non-missing value
Hi Rui, Data as follows structure(list(dn = c(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4), obs = c(1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9), choice = c(0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0), br = c(1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2), mth = c(NA, NA, NA, NA, NA, 487, NA, NA, 488, NA, NA, NA, NA, NA, NA, NA, NA, 488, NA, NA, 489, NA, NA, NA, NA, NA, NA, NA, NA, 489, NA, NA, NA, NA, NA, 489, NA, NA, NA, NA, NA, 490, NA, NA, NA, NA, NA, 491, NA, NA)), .Names = c("dn", "obs", "choice", "br", "mth"), row.names = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50"), class = "data.frame") Best wishes Graham -Original Message- From: Rui Barradas [mailto:ruipbarra...@sapo.pt] Sent: 06 April 2013 16:32 To: Leask, Graham Cc: r-help@r-project.org Subject: Re: [R] Replace missing value within group with non-missing value Hello, Can't you post a data example? If your dataset is named 'dat' use dput(head(dat, 50)) # paste the output of this in a post Rui Barradas Em 06-04-2013 15:34, Leask, Graham escreveu: > Hi Rui, > > Thank you for your suggestion which is very much appreciated. Unfortunately > running this code produces the following error. > > error in '$<-.data.frame' ('*tmp*', "mth", value = NA_real_) : > replacement has 1 rows, data has 0 > > I'm sure there must be an elegant solution to this problem? > > Best wishes > > > > Graham > > On 6 Apr 2013, at 12:15, "Rui Barradas" wrote: > >> Hello, >> >> That's not a very good way of posting your data, preferably paste the output >> of ?dput in a post. >> Some thing along the lines of the following might do what you want. >> It seems that the groups are established by 'dn' and 'obs' numbers. >> If so, try >> >> >> # Make up some data >> dat <- data.frame(dn = 4, obs = rep(1:5, each = 6), mth = NA) >> dat$mth[6] <- 487 dat$mth[9] <- 488 dat$mth[18] <- 488 dat$mth[21] <- >> 489 dat$mth[30] <- 489 >> >> >> sp <- split(dat, list(dat$dn, dat$obs)) >> names(sp) <- NULL >> tmp <- lapply(sp, function(x){ >> idx <- which(!is.na(x$mth))[1] >> x$mth <- x$mth[idx] >> x >> }) >> do.call(rbind, tmp) >> >> >> Hope this helps, >> >> Rui Barradas >> >> >> Em 06-04-2013 11:33, Leask, Graham escreveu: >>> Dear List members >>> >>> I have a large dataset organised in choice groups see sample below >>> >>> >>> +-+ >>> | dn obs choice acid br date cdate >>> situat~n mth year set | >>> >>> |-| >>>1. | 4 10 LOSEC1. . >>> . . 1 | >>>2. | 4 10NEXIUM2. . >>> . . 1 | >>>3. | 4 10PARIET3. . >>> . . 1 | >>>4. | 4 10 PROTIUM4. . >>> . . 1 | >>>5. | 4 10ZANTAC5. . >>> . . 1 | >>> >>> |-| >>>6. | 4 11 ZOTON6 23aug2000 01:00:00 23aug2000 >>> NS 487 2000 1 | >>>7. | 4 20 LOSEC1. . >>> . . 2 | >>>8. | 4 20NEXIUM2. . >>> . . 2 | >>>9. | 4 21PARIET3 25sep2000 01:00:00 25sep2000 >>>L 488 2000 2 | >>> 10. | 4 20 PROTIUM4. . >>>. . 2 | >>> >>> |-| >>> 11. | 4 20ZANTAC5. . >>>. . 2 | >>> 12. | 4 20 ZOTON6. . >>>. . 2 | >>> 13. | 4 30
Re: [R] Replace missing value within group with non-missing value
Hi Rui, Data as follows. These data are arranged in choice sets of 6. head(dat,50) dn obs choice br mth 1 4 1 0 1 NA 2 4 1 0 2 NA 3 4 1 0 3 NA 4 4 1 0 4 NA 5 4 1 0 5 NA 6 4 1 1 6 487 7 4 2 0 1 NA 8 4 2 0 2 NA 9 4 2 1 3 488 10 4 2 0 4 NA 11 4 2 0 5 NA 12 4 2 0 6 NA 13 4 3 0 1 NA 14 4 3 0 2 NA 15 4 3 0 3 NA 16 4 3 0 4 NA 17 4 3 0 5 NA 18 4 3 1 6 488 19 4 4 0 1 NA 20 4 4 0 2 NA 21 4 4 1 3 489 22 4 4 0 4 NA 23 4 4 0 5 NA 24 4 4 0 6 NA 25 4 5 0 1 NA 26 4 5 0 2 NA 27 4 5 0 3 NA 28 4 5 0 4 NA 29 4 5 0 5 NA 30 4 5 1 6 489 31 4 6 0 1 NA 32 4 6 0 2 NA 33 4 6 0 3 NA 34 4 6 0 4 NA 35 4 6 0 5 NA 36 4 6 1 6 489 37 4 7 0 1 NA 38 4 7 0 2 NA 39 4 7 0 3 NA 40 4 7 0 4 NA 41 4 7 0 5 NA 42 4 7 1 6 490 43 4 8 0 1 NA 44 4 8 0 2 NA 45 4 8 0 3 NA 46 4 8 0 4 NA 47 4 8 0 5 NA 48 4 8 1 6 491 49 4 9 0 1 NA 50 4 9 0 2 NA Best wishes Graham -Original Message- From: Rui Barradas [mailto:ruipbarra...@sapo.pt] Sent: 06 April 2013 16:32 To: Leask, Graham Cc: r-help@r-project.org Subject: Re: [R] Replace missing value within group with non-missing value Hello, Can't you post a data example? If your dataset is named 'dat' use dput(head(dat, 50)) # paste the output of this in a post Rui Barradas Em 06-04-2013 15:34, Leask, Graham escreveu: > Hi Rui, > > Thank you for your suggestion which is very much appreciated. Unfortunately > running this code produces the following error. > > error in '$<-.data.frame' ('*tmp*', "mth", value = NA_real_) : > replacement has 1 rows, data has 0 > > I'm sure there must be an elegant solution to this problem? > > Best wishes > > > > Graham > > On 6 Apr 2013, at 12:15, "Rui Barradas" wrote: > >> Hello, >> >> That's not a very good way of posting your data, preferably paste the output >> of ?dput in a post. >> Some thing along the lines of the following might do what you want. >> It seems that the groups are established by 'dn' and 'obs' numbers. >> If so, try >> >> >> # Make up some data >> dat <- data.frame(dn = 4, obs = rep(1:5, each = 6), mth = NA) >> dat$mth[6] <- 487 dat$mth[9] <- 488 dat$mth[18] <- 488 dat$mth[21] <- >> 489 dat$mth[30] <- 489 >> >> >> sp <- split(dat, list(dat$dn, dat$obs)) >> names(sp) <- NULL >> tmp <- lapply(sp, function(x){ >> idx <- which(!is.na(x$mth))[1] >> x$mth <- x$mth[idx] >> x >> }) >> do.call(rbind, tmp) >> >> >> Hope this helps, >> >> Rui Barradas >> >> >> Em 06-04-2013 11:33, Leask, Graham escreveu: >>> Dear List members >>> >>> I have a large dataset organised in choice groups see sample below >>> >>> >>> +-+ >>> | dn obs choice acid br date cdate >>> situat~n mth year set | >>> >>> |-| >>>1. | 4 10 LOSEC1. . >>> . . 1 | >>>2. | 4 10NEXIUM2. . >>> . . 1 | >>>3. | 4 10PARIET3. . >>> . . 1 | >>>4. | 4 10 PROTIUM4. . >>> . . 1 | >>>5. | 4 10ZANTAC5. . >>> . . 1 | >>> >>> |-| >>>6. | 4 11 ZOTON6 23aug2000 01:00:00 23aug2000 >>> NS 487 2000 1 | >>>7. | 4 20 LOSEC1. . >>> . . 2 | >>>8. | 4 20NEXIUM2. . >>> . . 2 | >>>9. | 4 21PARIET3 25sep2000 01:00:00 25sep2000 >>>L 488 2000 2 | >>> 10. | 4 20 PROTIUM4. . >>>. . 2 | >>> >>> |-| >>> 11. | 4 20ZANTAC5. . >>>. . 2 | >>> 12. | 4 20 ZOTON6. . >>>. . 2 | >>> 13. |
Re: [R] arrange data
On Apr 6, 2013, at 7:28 AM, catalin roibu wrote: > Hello all! > I have a problem to arrange data in another form. My initial data is like > this: > 'data.frame': 421 obs. of 58 variables: > $ 01A: num NA NA NA NA NA NA NA NA NA NA ... > $ 01B: num NA NA NA NA NA NA NA NA NA NA ... > $ 03A: num NA NA NA NA NA NA NA NA NA NA ... > $ 03B: num NA NA NA NA NA NA NA NA NA NA ... > $ 05A: num NA NA NA NA NA NA NA NA NA NA ... > $ 05B: num NA NA NA NA NA NA NA 3.64 2.48 1.87 ... > $ 07A: num NA NA NA NA NA NA NA NA NA NA ... > $ 07B: num NA NA NA NA NA NA NA NA NA NA ... > $ 10A: num NA NA NA NA NA NA NA NA NA NA ... > $ 10B: num NA NA NA NA NA NA NA NA NA NA ... > $ 12A: num NA NA NA NA NA NA NA NA NA NA ... > $ 12B: num NA NA NA NA NA NA NA NA NA NA ... > $ 14A: num NA NA NA NA NA NA NA NA NA NA ... > $ 14B: num NA NA NA NA NA NA NA NA NA NA ... > $ 16A: num NA NA NA NA NA NA NA NA NA NA ... > $ 16B: num NA NA NA NA NA NA NA NA NA NA ... > $ 17A: num NA NA NA NA NA NA NA NA NA NA ... > $ 17B: num NA NA NA NA NA NA NA NA NA NA ... > $ 20A: num NA NA NA NA NA NA NA NA NA NA ... > $ 20B: num 0.85 0.77 0.62 0.86 0.97 0.6 0.33 0.58 0.54 0.88 ... > $ 22A: num NA NA NA NA NA NA NA NA NA NA ... > $ 22B: num NA NA NA NA NA NA NA NA NA NA ... > $ 23A: num NA NA NA NA NA NA NA NA NA NA ... > $ 23B: num NA NA NA NA NA NA NA NA NA NA ... > $ 25A: num NA NA NA NA NA NA NA NA NA NA ... > $ 25B: num NA NA NA NA NA NA NA NA NA NA ... > $ 28A: num NA NA NA NA NA NA NA NA NA NA ... > $ 28B: num NA NA NA NA NA NA NA NA NA NA ... > $ 31A: num NA NA NA NA NA NA NA NA NA NA ... > $ 31B: num NA NA NA NA NA NA NA NA NA NA ... > $ 32A: num NA NA NA NA NA NA NA NA NA 1.19 ... > $ 32B: num NA NA NA NA NA NA NA NA NA NA ... > $ 34A: num NA NA NA NA NA NA NA NA NA NA ... > $ 34B: num NA NA NA NA NA NA NA NA NA NA ... > $ 36A: num NA NA NA NA NA NA NA NA NA NA ... > $ 36B: num NA NA NA NA NA NA NA NA NA NA ... > $ 42A: num NA NA NA NA NA NA NA NA NA NA ... > $ 42B: num NA NA NA NA NA NA NA NA NA NA ... > $ 44A: num NA NA NA NA NA NA NA NA NA NA ... > $ 44B: num NA NA NA NA NA NA NA NA NA NA ... > $ 47A: num NA NA NA NA NA NA NA NA NA NA ... > $ 47B: num NA NA NA NA NA NA NA NA NA NA ... > $ 48A: num NA NA NA NA NA NA NA NA NA NA ... > $ 48B: num NA NA NA NA NA NA NA NA NA NA ... > $ 50A: num NA NA NA NA NA NA NA NA NA NA ... > $ 50B: num NA NA NA NA NA NA NA NA NA NA ... > $ 52A: num NA NA NA NA NA NA NA NA NA NA ... > $ 52B: num NA NA NA NA NA NA NA NA NA NA ... > $ 55A: num NA NA NA NA NA NA NA NA NA NA ... > $ 55B: num NA NA NA NA NA NA NA NA NA NA ... > $ 56A: num NA NA NA NA NA NA NA NA NA NA ... > $ 56B: num NA NA NA NA NA NA NA NA NA NA ... > $ 59A: num NA NA NA NA NA NA NA NA NA NA ... > $ 59B: num NA NA NA NA NA NA NA NA NA NA ... > $ 40A: num NA NA NA NA 2.93 3.38 3.19 3.62 2.55 1.69 ... > $ 40B: num NA NA NA NA NA NA NA NA NA NA ... > $ 39A: num NA NA NA NA NA NA NA NA NA NA ... > $ 39B: num NA NA NA NA NA NA NA NA NA NA ... > I want to arrange them like this> > row.names 01A 02A.. > 1 first value first value > 2 second value second value > 3 > 4 > .. > max(nrow) I don't think the question is clear, but perhaps you just wnat to transpose this dataframe? If that is the goal, then look at: ?t > [[alternative HTML version deleted]] (By the mail-list software) > -- David Winsemius Alameda, CA, USA __ R-help@r-project.org mailing list 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] manipulating R contingency tables
Hi, Try this: tbl1<- structure(c(21L, 23L, 127L, 112L, 120L, 0L), .Dim = 2:3, .Dimnames = structure(list( labels = c(1, 2), gts = c("A1", "B2", "G3")), .Names = c("labels", "gts")), class = "table") dat1<-as.data.frame(tbl1,stringsAsFactors=FALSE) dat2<-dat1[dat1$gts!="B2" & dat1$Freq!=0,] library(reshape2) dcast(dat2,labels~gts,value.var="Freq") # labels A1 G3 #1 1 21 120 #2 2 23 NA A.K. - Original Message - From: Abhishek Pratap To: "r-help@r-project.org" Cc: Sent: Saturday, April 6, 2013 2:55 AM Subject: [R] manipulating R contingency tables Hi Guys I am back with another thing that's puzzling me. I am creating contingency tables but then I want to filter out certain columns and also find if any entry in the table is 0. Example: gts labels A1 B2 G3 1 21 127 120 2 23 112 0 Here I want to remove B2 column from this table and also if any entry is 0 in this case G3 second row. Missing out on how to do this in an efficient manner as I have to do this millions of times for my data. Thanks! -Abhi [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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-help@r-project.org mailing list 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] Replace missing value within group with non-missing value
Hello, Can't you post a data example? If your dataset is named 'dat' use dput(head(dat, 50)) # paste the output of this in a post Rui Barradas Em 06-04-2013 15:34, Leask, Graham escreveu: Hi Rui, Thank you for your suggestion which is very much appreciated. Unfortunately running this code produces the following error. error in '$<-.data.frame' ('*tmp*', "mth", value = NA_real_) : replacement has 1 rows, data has 0 I'm sure there must be an elegant solution to this problem? Best wishes Graham On 6 Apr 2013, at 12:15, "Rui Barradas" wrote: Hello, That's not a very good way of posting your data, preferably paste the output of ?dput in a post. Some thing along the lines of the following might do what you want. It seems that the groups are established by 'dn' and 'obs' numbers. If so, try # Make up some data dat <- data.frame(dn = 4, obs = rep(1:5, each = 6), mth = NA) dat$mth[6] <- 487 dat$mth[9] <- 488 dat$mth[18] <- 488 dat$mth[21] <- 489 dat$mth[30] <- 489 sp <- split(dat, list(dat$dn, dat$obs)) names(sp) <- NULL tmp <- lapply(sp, function(x){ idx <- which(!is.na(x$mth))[1] x$mth <- x$mth[idx] x }) do.call(rbind, tmp) Hope this helps, Rui Barradas Em 06-04-2013 11:33, Leask, Graham escreveu: Dear List members I have a large dataset organised in choice groups see sample below +-+ | dn obs choice acid br date cdate situat~n mth year set | |-| 1. | 4 10 LOSEC1. . . . 1 | 2. | 4 10NEXIUM2. . . . 1 | 3. | 4 10PARIET3. . . . 1 | 4. | 4 10 PROTIUM4. . . . 1 | 5. | 4 10ZANTAC5. . . . 1 | |-| 6. | 4 11 ZOTON6 23aug2000 01:00:00 23aug2000 NS 487 2000 1 | 7. | 4 20 LOSEC1. . . . 2 | 8. | 4 20NEXIUM2. . . . 2 | 9. | 4 21PARIET3 25sep2000 01:00:00 25sep2000 L 488 2000 2 | 10. | 4 20 PROTIUM4. . . . 2 | |-| 11. | 4 20ZANTAC5. . . . 2 | 12. | 4 20 ZOTON6. . . . 2 | 13. | 4 30 LOSEC1. . . . 3 | 14. | 4 30NEXIUM2. . . . 3 | 15. | 4 30PARIET3. . . . 3 | |-| 16. | 4 30 PROTIUM4. . . . 3 | 17. | 4 30ZANTAC5. . . . 3 | 18. | 4 31 ZOTON6 20sep2000 00:00:00 20sep2000 R 488 2000 3 | 19. | 4 40 LOSEC1. . . . 4 | 20. | 4 40NEXIUM2. . . . 4 | |-| 21. | 4 41PARIET3 27oct2000 00:00:00 27oct2000 NL 489 2000 4 | 22. | 4 40 PROTIUM4. . . . 4 | 23. | 4 40ZANTAC5. . . . 4 | 24. | 4 40 ZOTON6. . . . 4 | 25. | 4 50 LOSEC1. . . . 5 | |-| 26. | 4 50NEXIUM2. . . . 5 | 27. | 4 50PARIE
Re: [R] Image segmentation
Hello, Thanks for replying me! I was investigating the EBImage package and actually there is a algorithm for image segmentation. But I think this algorithm is not automated enough for me and maybe to work with multispectral remote sensing image when I want to segment the whole image. The algorithm does not look for seeds automatically and I think there is not possibility to segment color images. I am looking for an algorithm similar to that implemented in Spring software (developed at INPE) or what Multiresolution Segmentation algorithm does in eCognition software (eCognition, 2012). This algorithm was described by Baatz and Schäpe (2000). Now I will see the second option that Susen sent me (http://www.itk.org/). But I would like something in R, that I can see the script and in a language that I already know a bit. But the main reason of looking for something in R is the presence of other statistic tools not found in SPRING, eCOGNITION etc. Baatz, M., & Schäpe, A. (2000). Multiresolution segmentationAn optimization approach for high qualitymulti-scale image segmentation. Angewandte Geographische Informationsverarbeitung XII. Beiträge zum AGIT-Symposium Salzburg, 200, 1223. eCognition (2012). Definiens eCognition developer 8.7 user guide. Thanks, Eder Paulo Moreira Master Student in Remote Sensing National Institute For Space Research - Brazil > Subject: Re: [R] Image segmentation > From: dwinsem...@comcast.net > Date: Mon, 1 Apr 2013 18:42:40 -0700 > CC: r-help@r-project.org > To: eder...@hotmail.com > > > On Apr 1, 2013, at 7:50 AM, Eder Paulo wrote: > > > Hi, > > > > I work with > > remote sensing in Brazil. I would like to know if there is any algorithm or > > package that does image segmentation by region growing in R. > > > > It's possible that there is a domain of investigation where the phrase " > image segmentation by region growing" would be specific enough to offer > advice, but it's certainly outside my experience. I would advise being > somewhat more expansive when describing your requirements in future postings > to this generalist audience. You might want to look at the CRAN Task Views: > (first hit with Google if you search on that phrase). The Task Views used to > be countable on one hand but now threaten to extend beyond a full page. I > believe you will find the MedicalImaging or Spatial Views have pointers to > tools with image analysis functions. The MedicalImaging View also has a link > to: http://www.bioconductor.org/packages/release/bioc/html/EBImage.html > > > -- > David Winsemius > Alameda, CA, USA > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] Text Encoding
On Apr 5, 2013, at 11:30 AM, Emily Ottensmeyer wrote: > Dear R-Help, > > I am using the RDF package/ R 2.14 with the RDF package to download data > from a website, and then use R to manipulate it. > > Text on the website is UTF-8. The RDF package's rdf_load command is > converting it into a different encoding, which converts non-ASCII > characters to unicode codes. > > On the webpage/sparql RDF: "4.5µg of cDNA was used" > > In R, the RDF triple gives: "4.5\\u00B5g of cDNA was used" > > I can't seem to convert it back from \\u00B5 into "µ". > > I've tried iconv with various settings without success: >> iconv(test, "latin1", "UTF-8") > [1] "4.5\\u00B5g of cDNA was used" > > And, I tried Encoding, to see if I could figure that out, but it returns > "unknown" on my string. >> Encoding(test) > [1] "unknown" > On my device entering this: "4.5\\u00B5g of cDNA was used" ... returns [1] "4.5\\u00B5g of cDNA was used" But entering: "4.5\u00B5g of cDNA was used" returns: [1] "4.5µg of cDNA was used" > nchar("4.5\\u00B5g of cDNA was used") [1] 27 > nchar("4.5\u00B5g of cDNA was used") [1] 22 So the doubled "\" is really a single character in the first case and has no effect in escaping the next four hex digits but "\u00B5" in the second case is a correct "micro-character" (for my setup with my fonts) If this is a systematic problem then you should contact the maintainer with a full problem description and a link to the website. If this is just a one-off problem just remove the extraneous backslash. -- David. > sessionInfo() R version 3.0.0 RC (2013-03-31 r62463) Platform: x86_64-apple-darwin10.8.0 (64-bit) locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 > Anyone have any ideas on how to correct/convert the text encoding? > > > Thanks! > -Emily > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > 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. David Winsemius Alameda, CA, USA __ R-help@r-project.org mailing list 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] Replace missing value within group with non-missing value
Hi Rui, Thank you for your suggestion which is very much appreciated. Unfortunately running this code produces the following error. error in '$<-.data.frame' ('*tmp*', "mth", value = NA_real_) : replacement has 1 rows, data has 0 I'm sure there must be an elegant solution to this problem? Best wishes Graham On 6 Apr 2013, at 12:15, "Rui Barradas" wrote: > Hello, > > That's not a very good way of posting your data, preferably paste the output > of ?dput in a post. > Some thing along the lines of the following might do what you want. It seems > that the groups are established by 'dn' and 'obs' numbers. If so, try > > > # Make up some data > dat <- data.frame(dn = 4, obs = rep(1:5, each = 6), mth = NA) > dat$mth[6] <- 487 > dat$mth[9] <- 488 > dat$mth[18] <- 488 > dat$mth[21] <- 489 > dat$mth[30] <- 489 > > > sp <- split(dat, list(dat$dn, dat$obs)) > names(sp) <- NULL > tmp <- lapply(sp, function(x){ >idx <- which(!is.na(x$mth))[1] >x$mth <- x$mth[idx] >x >}) > do.call(rbind, tmp) > > > Hope this helps, > > Rui Barradas > > > Em 06-04-2013 11:33, Leask, Graham escreveu: >> Dear List members >> >> I have a large dataset organised in choice groups see sample below >> >> >> +-+ >> | dn obs choice acid br date cdate >> situat~n mth year set | >> >> |-| >> 1. | 4 10 LOSEC1. . >>. . 1 | >> 2. | 4 10NEXIUM2. . >>. . 1 | >> 3. | 4 10PARIET3. . >>. . 1 | >> 4. | 4 10 PROTIUM4. . >>. . 1 | >> 5. | 4 10ZANTAC5. . >>. . 1 | >> >> |-| >> 6. | 4 11 ZOTON6 23aug2000 01:00:00 23aug2000 >> NS 487 2000 1 | >> 7. | 4 20 LOSEC1. . >>. . 2 | >> 8. | 4 20NEXIUM2. . >>. . 2 | >> 9. | 4 21PARIET3 25sep2000 01:00:00 25sep2000 >> L 488 2000 2 | >> 10. | 4 20 PROTIUM4. . >> . . 2 | >> >> |-| >> 11. | 4 20ZANTAC5. . >> . . 2 | >> 12. | 4 20 ZOTON6. . >> . . 2 | >> 13. | 4 30 LOSEC1. . >> . . 3 | >> 14. | 4 30NEXIUM2. . >> . . 3 | >> 15. | 4 30PARIET3. . >> . . 3 | >> >> |-| >> 16. | 4 30 PROTIUM4. . >> . . 3 | >> 17. | 4 30ZANTAC5. . >> . . 3 | >> 18. | 4 31 ZOTON6 20sep2000 00:00:00 20sep2000 >> R 488 2000 3 | >> 19. | 4 40 LOSEC1. . >> . . 4 | >> 20. | 4 40NEXIUM2. . >> . . 4 | >> >> |-| >> 21. | 4 41PARIET3 27oct2000 00:00:00 27oct2000 >>NL 489 2000 4 | >> 22. | 4 40 PROTIUM4. . >> . . 4 | >> 23. | 4 40ZANTAC5. . >> . . 4 | >> 24. | 4 40 ZOTON6. . >> . . 4 | >> 25. | 4 50 LOSEC1. . >> . . 5 | >> >> |-| >> 26. | 4 50NEXIUM2. .
[R] arrange data
Hello all! I have a problem to arrange data in another form. My initial data is like this: 'data.frame': 421 obs. of 58 variables: $ 01A: num NA NA NA NA NA NA NA NA NA NA ... $ 01B: num NA NA NA NA NA NA NA NA NA NA ... $ 03A: num NA NA NA NA NA NA NA NA NA NA ... $ 03B: num NA NA NA NA NA NA NA NA NA NA ... $ 05A: num NA NA NA NA NA NA NA NA NA NA ... $ 05B: num NA NA NA NA NA NA NA 3.64 2.48 1.87 ... $ 07A: num NA NA NA NA NA NA NA NA NA NA ... $ 07B: num NA NA NA NA NA NA NA NA NA NA ... $ 10A: num NA NA NA NA NA NA NA NA NA NA ... $ 10B: num NA NA NA NA NA NA NA NA NA NA ... $ 12A: num NA NA NA NA NA NA NA NA NA NA ... $ 12B: num NA NA NA NA NA NA NA NA NA NA ... $ 14A: num NA NA NA NA NA NA NA NA NA NA ... $ 14B: num NA NA NA NA NA NA NA NA NA NA ... $ 16A: num NA NA NA NA NA NA NA NA NA NA ... $ 16B: num NA NA NA NA NA NA NA NA NA NA ... $ 17A: num NA NA NA NA NA NA NA NA NA NA ... $ 17B: num NA NA NA NA NA NA NA NA NA NA ... $ 20A: num NA NA NA NA NA NA NA NA NA NA ... $ 20B: num 0.85 0.77 0.62 0.86 0.97 0.6 0.33 0.58 0.54 0.88 ... $ 22A: num NA NA NA NA NA NA NA NA NA NA ... $ 22B: num NA NA NA NA NA NA NA NA NA NA ... $ 23A: num NA NA NA NA NA NA NA NA NA NA ... $ 23B: num NA NA NA NA NA NA NA NA NA NA ... $ 25A: num NA NA NA NA NA NA NA NA NA NA ... $ 25B: num NA NA NA NA NA NA NA NA NA NA ... $ 28A: num NA NA NA NA NA NA NA NA NA NA ... $ 28B: num NA NA NA NA NA NA NA NA NA NA ... $ 31A: num NA NA NA NA NA NA NA NA NA NA ... $ 31B: num NA NA NA NA NA NA NA NA NA NA ... $ 32A: num NA NA NA NA NA NA NA NA NA 1.19 ... $ 32B: num NA NA NA NA NA NA NA NA NA NA ... $ 34A: num NA NA NA NA NA NA NA NA NA NA ... $ 34B: num NA NA NA NA NA NA NA NA NA NA ... $ 36A: num NA NA NA NA NA NA NA NA NA NA ... $ 36B: num NA NA NA NA NA NA NA NA NA NA ... $ 42A: num NA NA NA NA NA NA NA NA NA NA ... $ 42B: num NA NA NA NA NA NA NA NA NA NA ... $ 44A: num NA NA NA NA NA NA NA NA NA NA ... $ 44B: num NA NA NA NA NA NA NA NA NA NA ... $ 47A: num NA NA NA NA NA NA NA NA NA NA ... $ 47B: num NA NA NA NA NA NA NA NA NA NA ... $ 48A: num NA NA NA NA NA NA NA NA NA NA ... $ 48B: num NA NA NA NA NA NA NA NA NA NA ... $ 50A: num NA NA NA NA NA NA NA NA NA NA ... $ 50B: num NA NA NA NA NA NA NA NA NA NA ... $ 52A: num NA NA NA NA NA NA NA NA NA NA ... $ 52B: num NA NA NA NA NA NA NA NA NA NA ... $ 55A: num NA NA NA NA NA NA NA NA NA NA ... $ 55B: num NA NA NA NA NA NA NA NA NA NA ... $ 56A: num NA NA NA NA NA NA NA NA NA NA ... $ 56B: num NA NA NA NA NA NA NA NA NA NA ... $ 59A: num NA NA NA NA NA NA NA NA NA NA ... $ 59B: num NA NA NA NA NA NA NA NA NA NA ... $ 40A: num NA NA NA NA 2.93 3.38 3.19 3.62 2.55 1.69 ... $ 40B: num NA NA NA NA NA NA NA NA NA NA ... $ 39A: num NA NA NA NA NA NA NA NA NA NA ... $ 39B: num NA NA NA NA NA NA NA NA NA NA ... I want to arrange them like this> row.names 01A 02A.. 1 first value first value 2 second value second value 3 4 .. max(nrow) Thank you very much! -- --- Catalin-Constantin ROIBU Lecturer PhD, Forestry engineer Forestry Faculty of Suceava Str. Universitatii no. 13, Suceava, 720229, Romania office phone +4 0230 52 29 78, ext. 531 mobile phone +4 0745 53 18 01 +4 0766 71 76 58 FAX:+4 0230 52 16 64 silvic.usv.ro [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] Reversing data transformation
Sorry --failed to cc the list. -- Bert On Fri, Apr 5, 2013 at 9:29 PM, Bert Gunter wrote: Have you tried plotting your data?! >library(lattice) >densityplot(yourdata) Forget tests of normality -- they are a BAD idea, despite what the statistics textbooks say (IMHO obviously) -- and focus on what the data are trying to tell you, which sure ain't that they are a sample from a normal distribution! Subject matter knowledge and problem context -- and probably explicit knowledge of how the data were produced -- are probably essential. -- Bert > > On Fri, Apr 5, 2013 at 3:47 PM, Beatriz González Domínguez > wrote: >> Hi everybody, >> >> I would be very grateful if you could give me your thoughts on the following >> issue. >> >> I need to perform Box-Cox (bcPower€ ) transformation on my data. To do >> this, I calculated lambda using the function '€ powerTransform'€ . >> powerTransform(data) >> However, I got an error message when performing this function: >> Convergence failure: return code = 52 >> I was told by John Fox that the nature of my data was probably causing the >> problem so I applied the following transformation: >> powerTransform(1e7*(data - 0.99*(min(data [1] >> And it worked! However, now when I try to check the normality of my data, >> shapiro.test(data) >> I get a new warning message: >> Error in shapiro.test(data) : >> ifault=6. This should not happen >> I think this may be solved by removing the transformation I applied >> previously in [1], but I’m not sure how to do it properly. >> >> Could anyone give me some advice? >> >> MY DATA: > c(0.000103113, 0.000102948, 0.000104001, 0.000103794, 0.000104628, > 9.2765e-05, 9.4296e-05, 9.5025e-05, 9.4978e-05, 9.8821e-05, 9.7586e-05, > 9.6285e-05, 0.00010158, 0.000100919, 0.000103535, 0.000103321, > 0.000102842, 0.000102315, 0.0001033, 0.000103691, 0.000102689, > 0.000103248, 0.000101216, 0.000103127, 0.000103439, 0.000102818, > 0.000103482, 0.00010227, 0.000104264, 0.000104672, 0.000104586, > 0.000104516, 0.000104585, 0.000103804, 0.000103702, 0.000103405, > 0.000104815, 0.000101718, 0.000101792, 0.000103273, 0.000102942, > 0.000102522, 0.000103149, 0.0001036995, 0.0001039735, 0.0001014877, > 0.000102796) >> >> Thanks a lot!! >> >> Bea >> >> >> >> >> [[alternative HTML version deleted]] >> >> >> __ >> R-help@r-project.org mailing list >> 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. >> > > > > -- > > Bert Gunter > Genentech Nonclinical Biostatistics > > Internal Contact Info: > Phone: 467-7374 > Website: > http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ R-help@r-project.org mailing list 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] How to plot several years data with date information by months?
Le 06/04/13 10:00, ZhaoXing a écrit : Hi, all I have a medium sized data, 6 years. Each observation is a case with a date variable, such as '2004-08-02'. Some of the months didn't occur a case. I want to plot the 6 years data by month, and the Y_axis is the freqency of cases for each month, meaning 12*6=72 bars or points in the figure. I though of a method, 1st, using the months function, then ploting. But I need to assign zero to the months without case. And a lot of other manipulations. Is there any simpler way to complete this? or just a simple function exists? Thanks in advance ZhaoXing Sorry, I completely overlooked your question. Here is a better answer. Sincerely Marc # I generate dummy data x <- seq(from=as.Date("2000-01-01"), to=as.Date("2006-12-31"), by="1 day") y <- sample(0:10, 2557, replace=TRUE) t <- y + sample(5:20, 2557, replace=TRUE) dt <- data.frame(d = x, obs = y, total=t) # I erase some data; sometimes full month is erased dt <- dt[c(20:156, 300:900, 1200:2557),] # I begin here # I generate a variable with all the months x2 <- seq(from=as.Date("2000-01-01"), to=as.Date("2006-12-31"), by="1 month") # I add this variable with all the months to the available data to have information also for missing months dt <- rbind(dt, data.frame(d=x2, obs = rep(NA, length(x2)), total=rep(NA, length(x2 # I sum month per month o1 <- with(dt, rowsum(obs, format(d,"%Y-%m"), na.rm=TRUE)) o2 <- with(dt, rowsum(total, format(d,"%Y-%m"), na.rm=TRUE)) # If total for a month is 0, I replace it with NA o1[o2==0] <- NA o2[o2==0] <- NA # proportion y <- o1/o2 # plot plot(x2, y, bty="n", type="p", xaxt="n", las=1) axis(1, at=seq(from=as.Date("2000-01-01"), to=as.Date("2006-12-31"), by="1 month"), label=FALSE) axis(1, at=seq(from=as.Date("2000-01-01"), to=as.Date("2006-12-31"), by="1 year"), lwd.ticks=2, label=FALSE, lwd=0) axis(1, at=seq(from=as.Date("2000-07-01"), to=as.Date("2006-12-31"), by="1 year"), lwd.ticks=0, label=c(2000:2006), lwd=0) -- __ Marc Girondot, Pr Laboratoire Ecologie, Systématique et Evolution Equipe de Conservation des Populations et des Communautés CNRS, AgroParisTech et Université Paris-Sud 11 , UMR 8079 Bâtiment 362 91405 Orsay Cedex, France Tel: 33 1 (0)1.69.15.72.30 Fax: 33 1 (0)1.69.15.73.53 e-mail: marc.giron...@u-psud.fr Web: http://www.ese.u-psud.fr/epc/conservation/Marc.html Skype: girondot __ R-help@r-project.org mailing list 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] Replace missing value within group with non-missing value
Hello, That's not a very good way of posting your data, preferably paste the output of ?dput in a post. Some thing along the lines of the following might do what you want. It seems that the groups are established by 'dn' and 'obs' numbers. If so, try # Make up some data dat <- data.frame(dn = 4, obs = rep(1:5, each = 6), mth = NA) dat$mth[6] <- 487 dat$mth[9] <- 488 dat$mth[18] <- 488 dat$mth[21] <- 489 dat$mth[30] <- 489 sp <- split(dat, list(dat$dn, dat$obs)) names(sp) <- NULL tmp <- lapply(sp, function(x){ idx <- which(!is.na(x$mth))[1] x$mth <- x$mth[idx] x }) do.call(rbind, tmp) Hope this helps, Rui Barradas Em 06-04-2013 11:33, Leask, Graham escreveu: Dear List members I have a large dataset organised in choice groups see sample below +-+ | dn obs choice acid br date cdate situat~n mth year set | |-| 1. | 4 10 LOSEC1. . . . 1 | 2. | 4 10NEXIUM2. . . . 1 | 3. | 4 10PARIET3. . . . 1 | 4. | 4 10 PROTIUM4. . . . 1 | 5. | 4 10ZANTAC5. . . . 1 | |-| 6. | 4 11 ZOTON6 23aug2000 01:00:00 23aug2000 NS 487 2000 1 | 7. | 4 20 LOSEC1. . . . 2 | 8. | 4 20NEXIUM2. . . . 2 | 9. | 4 21PARIET3 25sep2000 01:00:00 25sep2000 L 488 2000 2 | 10. | 4 20 PROTIUM4. . . . 2 | |-| 11. | 4 20ZANTAC5. . . . 2 | 12. | 4 20 ZOTON6. . . . 2 | 13. | 4 30 LOSEC1. . . . 3 | 14. | 4 30NEXIUM2. . . . 3 | 15. | 4 30PARIET3. . . . 3 | |-| 16. | 4 30 PROTIUM4. . . . 3 | 17. | 4 30ZANTAC5. . . . 3 | 18. | 4 31 ZOTON6 20sep2000 00:00:00 20sep2000 R 488 2000 3 | 19. | 4 40 LOSEC1. . . . 4 | 20. | 4 40NEXIUM2. . . . 4 | |-| 21. | 4 41PARIET3 27oct2000 00:00:00 27oct2000 NL 489 2000 4 | 22. | 4 40 PROTIUM4. . . . 4 | 23. | 4 40ZANTAC5. . . . 4 | 24. | 4 40 ZOTON6. . . . 4 | 25. | 4 50 LOSEC1. . . . 5 | |-| 26. | 4 50NEXIUM2. . . . 5 | 27. | 4 50PARIET3. . . . 5 | 28. | 4 50 PROTIUM4. . . . 5 | 29. | 4 50ZANTAC5. . . . 5 | 30. | 4 51 ZOTON6 23oct2000 03:00:00 23oct2000 NS 489 2000 5 | I wish to fill in the missing values in each choice set - delineated by dn (Doctor) obs (Observation number) and choices (1 to 6). For each choice se
[R] Value at Risk using a volatility model?
Hi, I want to calculate the Value at Risk with using some distirbutions and a volatility model. I use the following data(http://uploadeasy.net/upload/cdm3n.rar) which are losses (negative returns) of a company of approx. the last 10 years. So I want to calculated the Value at Risk, this is nothing else than the quantile. Since I have losses I consider the right tail of the distribution. Consider a first simple example, I assume the returns to follow a normal distribution with mean zero and a volatility, which is estimated for each day with a volatility model. Let's use a simple volatility model: The empirical standard deviation of the last 10 days. So I calculate the standard deviation of the first ten days and this is my estimate for the 11th day and so on, until the end of my data. So I assume for each day a normal distribution with mean zero and a sigma estimated by the voaltility mdoel. So I use this estimated sigma to calculate the quantile, which gives me the Value at Risk. The code would be: volatility<-0 quantile<-0 for(i in 11:length(dat)){ volatility[i]<-sd(dat[(i-10):(i-1)]) } for(i in 1:length(dat)){ quantile[i]<-qnorm(0.975,mean=0,sd=volatility[i]) } # the first quantile value is the VaR for the 11th date #plot the volatility plot(c(1:length(volatility)),volatility,type="l") #add VaR lines(quantile,type="l",col="red") So in this case I understand everything and I can implement this. But now comes my problem: I want to use a t-distribution with paramters mu, nu and beta or even a generalized hyperbolic distribution. So in this case, I don't know how to plug in the estimates for sigma, since there is no sigma in the paramters? How can I implement the volatility model and e.g. the generalized hyperbolic distribution in this case to calculate the Value at Risk? Thanks [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] Replace missing values within a group with the non-missing value
I have a large dataset organised in choice groups see below. Each choice represents a separate occasion with 1 product chosen out of the 6 offered.        +-+     | dn  obs  choice     acid  br                date      cdate  situat~n  mth  year  set |     |-|  1. | 4    1       0    LOSEC   1                   .          .               .     .    1 |  2. | 4    1       0   NEXIUM   2                   .          .               .     .    1 |  3. | 4    1       0   PARIET   3                   .          .               .     .    1 |  4. | 4    1       0  PROTIUM   4                   .          .               .     .    1 |  5. | 4    1       0   ZANTAC   5                   .          .               .     .    1 |     |-|  6. | 4    1       1    ZOTON   6  23aug2000 01:00:00  23aug2000        NS  487  2000    1 |  7. | 4    2       0    LOSEC   1                   .          .               .     .    2 |  8. | 4    2       0   NEXIUM   2                   .          .               .     .    2 |  9. | 4    2       1   PARIET   3  25sep2000 01:00:00  25sep2000         L  488  2000    2 | 10. | 4    2       0  PROTIUM   4                   .          .               .     .    2 |     |-| 11. | 4    2       0   ZANTAC   5                   .          .               .     .    2 | 12. | 4    2       0    ZOTON   6                   .          .               .     .    2 | 13. | 4    3       0    LOSEC   1                   .          .               .     .    3 | 14. | 4    3       0   NEXIUM   2                   .          .               .     .    3 | 15. | 4    3       0   PARIET   3                   .          .               .     .    3 |     |-| 16. | 4    3       0  PROTIUM   4                   .          .               .     .    3 | 17. | 4    3       0   ZANTAC   5                   .          .               .     .    3 | 18. | 4    3       1    ZOTON   6  20sep2000 00:00:00  20sep2000         R  488  2000    3 | 19. |  4    4       0    LOSEC   1                   .          .               .     .    4 |  I wish to fill in the missing values in each choice set â delineated by dn (Doctor) obs (Observation number) and choices (1 to 6). For each choice set one choice is chosen which contains full time information for that choice set ie in set 1 choice 6 was chosen and shows the month 487. The other 5 choices show mth as missing. I want to fill these with the correct mth.  Clearly on different occasions the date will differ but each choice set has only one date.  Is there a simple elegant way to do this in R? Kind regards Graham [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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, reprod
Re: [R] manipulating R contingency tables
Hello, Try the following. The first function removes a column(s) from the table, and the secondd all rows and columns with zero elements in them. fun1 <- function(x, col) x[, -which(colnames(x) %in% col)] fun2 <- function(x){ idx <- which(x == 0, arr.ind = TRUE) x[-idx[, 1], -idx[, 2]] } Hope this helps, Rui Barradas Em 06-04-2013 07:55, Abhishek Pratap escreveu: Hi Guys I am back with another thing that's puzzling me. I am creating contingency tables but then I want to filter out certain columns and also find if any entry in the table is 0. Example: gts labels A1 B2 G3 121 127 120 223 112 0 Here I want to remove B2 column from this table and also if any entry is 0 in this case G3 second row. Missing out on how to do this in an efficient manner as I have to do this millions of times for my data. Thanks! -Abhi [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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-help@r-project.org mailing list 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] Replace missing value within group with non-missing value
Dear List members I have a large dataset organised in choice groups see sample below +-+ | dn obs choice acid br date cdate situat~n mth year set | |-| 1. | 4 10 LOSEC1. . . . 1 | 2. | 4 10NEXIUM2. . . . 1 | 3. | 4 10PARIET3. . . . 1 | 4. | 4 10 PROTIUM4. . . . 1 | 5. | 4 10ZANTAC5. . . . 1 | |-| 6. | 4 11 ZOTON6 23aug2000 01:00:00 23aug2000 NS 487 2000 1 | 7. | 4 20 LOSEC1. . . . 2 | 8. | 4 20NEXIUM2. . . . 2 | 9. | 4 21PARIET3 25sep2000 01:00:00 25sep2000 L 488 2000 2 | 10. | 4 20 PROTIUM4. . . . 2 | |-| 11. | 4 20ZANTAC5. . . . 2 | 12. | 4 20 ZOTON6. . . . 2 | 13. | 4 30 LOSEC1. . . . 3 | 14. | 4 30NEXIUM2. . . . 3 | 15. | 4 30PARIET3. . . . 3 | |-| 16. | 4 30 PROTIUM4. . . . 3 | 17. | 4 30ZANTAC5. . . . 3 | 18. | 4 31 ZOTON6 20sep2000 00:00:00 20sep2000 R 488 2000 3 | 19. | 4 40 LOSEC1. . . . 4 | 20. | 4 40NEXIUM2. . . . 4 | |-| 21. | 4 41PARIET3 27oct2000 00:00:00 27oct2000 NL 489 2000 4 | 22. | 4 40 PROTIUM4. . . . 4 | 23. | 4 40ZANTAC5. . . . 4 | 24. | 4 40 ZOTON6. . . . 4 | 25. | 4 50 LOSEC1. . . . 5 | |-| 26. | 4 50NEXIUM2. . . . 5 | 27. | 4 50PARIET3. . . . 5 | 28. | 4 50 PROTIUM4. . . . 5 | 29. | 4 50ZANTAC5. . . . 5 | 30. | 4 51 ZOTON6 23oct2000 03:00:00 23oct2000 NS 489 2000 5 | I wish to fill in the missing values in each choice set - delineated by dn (Doctor) obs (Observation number) and choices (1 to 6). For each choice set one choice is chosen which contains full time information for that choice set ie in set 1 choice 6 was chosen and shows the month 487. The other 5 choices show mth as missing. I want to fill these with the correct mth. I am sure there must be an elegant way to do this in R? Best wishes Graham [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] How to plot several years data with date information by months?
Le 06/04/13 10:00, ZhaoXing a écrit : Hi, all I have a medium sized data, 6 years. Each observation is a case with a date variable, such as '2004-08-02'. Some of the months didn't occur a case. I want to plot the 6 years data by month, and the Y_axis is the freqency of cases for each month, meaning 12*6=72 bars or points in the figure. I though of a method, 1st, using the months function, then ploting. But I need to assign zero to the months without case. And a lot of other manipulations. Is there any simpler way to complete this? or just a simple function exists? Thanks in advance ZhaoXing __ Do you want something like this ? x <- seq(from=as.Date("2000-01-01"), to=as.Date("2006-12-31"), by="1 day") y <- sin(1:length(x))+1 plot(x, y, bty="n", type="l", xaxt="n", las=1) axis(1, at=seq(from=as.Date("2000-01-01"), to=as.Date("2006-12-31"), by="1 month"), label=FALSE) axis(1, at=seq(from=as.Date("2000-01-01"), to=as.Date("2006-12-31"), by="1 year"), lwd.ticks=2, label=c(2000:2006)) Sincerely Marc -- __ Marc Girondot, Pr Laboratoire Ecologie, Systématique et Evolution Equipe de Conservation des Populations et des Communautés CNRS, AgroParisTech et Université Paris-Sud 11 , UMR 8079 Bâtiment 362 91405 Orsay Cedex, France Tel: 33 1 (0)1.69.15.72.30 Fax: 33 1 (0)1.69.15.73.53 e-mail: marc.giron...@u-psud.fr Web: http://www.ese.u-psud.fr/epc/conservation/Marc.html Skype: girondot __ R-help@r-project.org mailing list 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] Text Encoding
Le vendredi 05 avril 2013 à 14:30 -0400, Emily Ottensmeyer a écrit : > Dear R-Help, > > I am using the RDF package/ R 2.14 with the RDF package to download data > from a website, and then use R to manipulate it. > > Text on the website is UTF-8. The RDF package's rdf_load command is > converting it into a different encoding, which converts non-ASCII > characters to unicode codes. > > On the webpage/sparql RDF: "4.5g of cDNA was used" > > In R, the RDF triple gives: "4.5\\u00B5g of cDNA was used" > > I can't seem to convert it back from \\u00B5 into "". Beware that \\u00B5 is the micro sign (greek letter mu), not "". This is probably an important information... > I've tried iconv with various settings without success: > > iconv(test, "latin1", "UTF-8") > [1] "4.5\\u00B5g of cDNA was used" \\u00B5 looks like UTF-16, not UTF-8. Does this work? iconv(test, "UTF-16", "UTF-8") > And, I tried Encoding, to see if I could figure that out, but it returns > "unknown" on my string. > > Encoding(test) > [1] "unknown" > > > Anyone have any ideas on how to correct/convert the text encoding? Can you provide us the file, or at least the required parts of it? You can also try loading the file using xmlParse() from the XML package. Regards __ R-help@r-project.org mailing list 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] ad.test parameters
Hi all, i have 2 cumulative (F(x)) distribution function that not defined in R. i want to make anderson darling goodness of fit test to first function (function 1) to check if it behaves as the other distributed function(function 2) how can i insert my 2 unknown by R function to ad.test()? Regards, Irit -- View this message in context: http://r.789695.n4.nabble.com/ad-test-parameters-tp4663500.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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] retrieveing value from KS test
thank you. it helps! -- View this message in context: http://r.789695.n4.nabble.com/retrieveing-value-from-KS-test-tp4663439p4663499.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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] Graphic window dimensions
Dear all, I have a doubt: if I run windows(width=8.27, height=11.69), the size of an A4 paper, does it work correctly in all screens? Or does it depend on the inches of my screen?. I ask you about this question because I need to make the user see a graph in the graph window and he must be able to save the graph as a pdf (using the Rgui menu) and the result must be a pdf with A4 size. Thank you in advance. Regards, Eva [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] How to plot several years data with date information by months?
Hi, all I have a medium sized data, 6 years. Each observation is a case with a date variable, such as '2004-08-02'. Some of the months didn't occur a case. I want to plot the 6 years data by month, and the Y_axis is the freqency of cases for each month, meaning 12*6=72 bars or points in the figure. I though of a method, 1st, using the months function, then ploting. But I need to assign zero to the months without case. And a lot of other manipulations. Is there any simpler way to complete this? or just a simple function exists? Thanks in advance ZhaoXing __ R-help@r-project.org mailing list 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.