[R] Dropping predictor variables based on adjusted R square
Hello experts, I have recently (1month) started using R. Earlier I was using SAS to work on analytic assignments. In SAS there is an option - forward selection, backward selection, step wise selection where in it removes the least impacting predictor variable from the set of variables based on adjusted r square and leaves us with the highest impacting variables to predict. Is there any similar functionality or function in R studio. Kindly suggest. Thanks. -- View this message in context: http://r.789695.n4.nabble.com/Dropping-predictor-variables-based-on-adjusted-R-square-tp4707186.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Counting consecutive events in R
Hi, I have the following dataframe structure(list(Type = c(QRS, QRS, QRS, QRS, QRS, QRS, QRS, QRS, QRS, QRS, QRS, QRS, RR, RR, RR, PP, PP, PP, PP, PP, PP, PP, PP, PP, QTc, QTc, QTc, QTc, QTc, QTc, QTc, QTc, QTc, QTc, QTc, QTc, QTc, QTc, QTc), Time_Point_Start = c(2015-04-01 14:57:15.0.0312, 2015-04-01 14:57:15.0.7839, 2015-04-01 14:57:16.0.5343, 2015-04-01 14:57:17.0.2573, 2015-04-01 14:57:18.0.0234, 2015-04-01 14:57:18.0.7722, 2015-04-01 14:57:19.0.5265, 2015-04-01 14:57:24.0.0195, 2015-04-01 14:57:24.0.7839, 2015-04-01 14:57:25.0.5343, 2015-04-01 14:57:26.0.2768, 2015-04-01 14:57:27.0.0273, 2015-04-01 14:58:03.0.0702, 2015-04-01 14:58:03.0.8190, 2015-04-01 14:58:04.0.5694, 2015-04-01 14:57:58.0.4134, 2015-04-01 14:57:59.0.1637, 2015-04-01 14:57:59.0.9126, 2015-04-01 14:58:00.0.6630, 2015-04-01 14:58:01.0.4134, 2015-04-01 14:58:02.0.1637, 2015-04-01 14:58:02.0.9126, 2015-04-01 14:58:03.0.6630, 2015-04-01 14:58:04.0.4134, 2015-04-01 14:57:07.0.4212, 2015-04-01 14:57:08.0.1715, 2015-04-01 14:57:08.0.9204, 2015-04-01 14:57:09.0.6864, 2015-04-01 14:57:10.0.4368, 2015-04-01 14:57:11.0.1871, 2015-04-01 14:57:11.0.9360, 2015-04-01 14:57:12.0.6591, 2015-04-01 14:57:13.0.4251, 2015-04-01 14:57:14.0.1754, 2015-04-01 14:57:14.0.9243, 2015-04-01 14:57:15.0.6903, 2015-04-01 14:57:16.0.4407, 2015-04-01 14:57:17.0.1676, 2015-04-01 14:57:17.0.9321), Time_Point_End = c(2015-04-01 14:57:15.0.0858, 2015-04-01 14:57:15.0.8346, 2015-04-01 14:57:16.0.6006, 2015-04-01 14:57:17.0.0351, 2015-04-01 14:57:18.0.1403, 2015-04-01 14:57:18.0.8385, 2015-04-01 14:57:19.0.5889, 2015-04-01 14:57:24.0.0858, 2015-04-01 14:57:24.0.8346, 2015-04-01 14:57:25.0.5772, 2015-04-01 14:57:26.0.3939, 2015-04-01 14:57:27.0.0936, 2015-04-01 14:58:03.0.8190, 2015-04-01 14:58:04.0.5694, 2015-04-01 14:58:05.0.3197, 2015-04-01 14:57:59.0.1637, 2015-04-01 14:57:59.0.9126, 2015-04-01 14:58:00.0.6630, 2015-04-01 14:58:01.0.4134, 2015-04-01 14:58:02.0.1637, 2015-04-01 14:58:02.0.9126, 2015-04-01 14:58:03.0.6630, 2015-04-01 14:58:04.0.4134, 2015-04-01 14:58:05.0.1793, 2015-04-01 14:57:07.0.8775, 2015-04-01 14:57:08.0.6435, 2015-04-01 14:57:09.0.3705, 2015-04-01 14:57:10.0.1209, 2015-04-01 14:57:10.0.8697, 2015-04-01 14:57:11.0.6201, 2015-04-01 14:57:12.0.3861, 2015-04-01 14:57:13.0.1364, 2015-04-01 14:57:13.0.8853, 2015-04-01 14:57:14.0.6513, 2015-04-01 14:57:15.0.4017, 2015-04-01 14:57:16.0.1248, 2015-04-01 14:57:16.0.9165, 2015-04-01 14:57:17.0.6162, 2015-04-01 14:57:18.0.3900), Value = c(0.0546, 0.0507, 0.0663, 0.0936, 0.117, 0.0663, 0.0624, 0.0663, 0.0507, 0.0429, 0.117, 0.0663, 0.7488, 0.7488, 0.7488, 0.7488, 0.7488, 0.7488, 0.7488, 0.7488, 0.7488, 0.7488, 0.7488, 0.7644, 0.033103481, 0.034056449, 0.032367699, 0.031000613, 0.031405867, 0.031241866, 0.032367699, 0.034337907, 0.033125921, 0.034337907, 0.034337907, 0.031241866, 0.034337907, 0.032367699, 0.032930616), Score = c(0L, 0L, 0L, 0L, 3L, 0L, 0L, 0L, 0L, 0L, 3L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 2L, 2L, 2L, 2L, 0L, 0L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), Type_Desc = c(NA, NA, NA, NA, 1L, NA, NA, NA, NA, NA, 1L, NA, NA, NA, NA, NA, NA, 1L, 1L, 1L, 1L, 1L, NA, NA, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), Pat_id = c(4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L)), .Names = c(Type, Time_Point_Start, Time_Point_End, Value, Score, Type_Desc, Pat_id), class = data.frame, row.names = c(NA, -39L)) For each unique value in column 'Type' , I want to check for consecutive 5 rows (if any) of 'Score' 0. Now, if there are five consecutive rows with Score 0 and 'Type_Desc' = 0, then we print Type_low , else if 'Type_Desc' = 1, we print Type_high. The search should end once 5 consecutive rows have been found. So, for this data frame we will have two statements as follows, 1.PP_high (reason - consecutive 5 rows of score 0 and 'Type_Desc' = 1 ) 2.QTc_low (reason - consecutive 5 rows of score 0 and 'Type_Desc' = 0 ) How can this problem tackled in R? Thanks, Abhinaba [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] binding two lists of lists of dataframes together
Hi David, Understood. I've done a lot of work around this structure, but if there isn't anyway to change it back to the original structure then I'll work around it. Could you possibly show me how to add colnames to list3a? c(id,WgtBand,Wgt,Held,LID,Issuer,Bid,Offer) these would be repeated once for each V1,V2,V3. Thank you again for all the help! It's much appreciated! Vince Subject: Re: [R] binding two lists of lists of dataframes together From: dwinsem...@comcast.net Date: Wed, 13 May 2015 15:51:47 -0700 CC: r-help@r-project.org To: newrnew...@hotmail.com On May 13, 2015, at 2:01 PM, Vin Cheng wrote: Hi David, I tried both solutions you provided(lapply(dlist, function(x) rbind(x,x) ) Map( rbind, smaller, smaller)) and they seem to transpose and reshape the data into a different structure. Whenever I added the str - I only get a NULL. I believe you are misrepresenting my suggestion. I suggested that you coerce each of the items in those lists to data.frames with appropriate column names before applying rbind.data.frame Those list1 and list2 examples appear to me as pathologically deformed. They claim to be data.tables but they have no self referential pointers, suggesting to me that they are not data.tables, and they have no column names suggesting not either data.table, nor data.frame. class(list1) [1] data.table data.frame class(list2) [1] data.table data.frame You basically want a list of the same general structure as list1 where all the elements in list two at the same position and depth have been concatenated? Yes - that sounds exactly right. Fix up the data.structures, first. Then use Map(rbind, ...) as described previously. list1a - lapply(list1, function(x) setNames( data.frame(x), paste0(V, seq(length(x)) ) ) ) list2a - lapply(list2, function(x) setNames( data.frame(x), paste0(V, seq(length(x)) ) )) list3a - Map( rbind.data.frame, list1a, list2a) str(list3a) List of 3 $ V1:'data.frame': 22 obs. of 8 variables: ..$ V1: int [1:22] 15 19 28 9 17 3 11 21 7 8 ... ..$ V2: num [1:22] 1 1 2 3 4 5 6 7 8 9 ... ..$ V3: num [1:22] NaN NaN NA NA NA NA NA NA NA NA ... ..$ V4: num [1:22] 0 0 0 0 0 0 0 0 0 0 ... ..$ V5: Factor w/ 29 levels ID1,ID10,ID11,..: 7 11 21 29 9 23 3 14 27 28 ... ..$ V6: Factor w/ 29 levels Issuer1,Issuer10,..: 7 11 21 29 9 23 3 14 27 28 ... ..$ V7: num [1:22] 99.5 95.5 99.5 100 98.5 ... ..$ V8: num [1:22] 0.4 0.55 0.4 0.4 0.5 0.45 0.4 0.45 0.6 0.4 ... $ V2:'data.frame': 22 obs. of 8 variables: ..$ V1: int [1:22] 10 29 5 19 28 3 10 12 1 21 ... ..$ V2: num [1:22] 1 1 2 3 4 5 6 7 8 9 ... ..$ V3: num [1:22] NaN NaN NA NA NA NA NA NA NA NA ... ..$ V4: num [1:22] 0 0 0 0 0 0 0 0 0 0 ... ..$ V5: Factor w/ 29 levels ID1,ID10,ID11,..: 2 22 25 11 21 23 2 4 1 14 ... ..$ V6: Factor w/ 29 levels Issuer1,Issuer10,..: 2 22 25 11 21 23 2 4 1 14 ... ..$ V7: num [1:22] 98.5 100.2 99 95.5 99.5 ... ..$ V8: num [1:22] 0.6 0.4 0.45 0.55 0.4 0.45 0.6 0.55 0.5 0.45 ... $ V3:'data.frame': 22 obs. of 8 variables: ..$ V1: int [1:22] 21 28 3 7 25 25 15 13 3 20 ... ..$ V2: num [1:22] 1 1 2 3 4 5 6 7 8 9 ... ..$ V3: num [1:22] NaN NaN NA NA NA NA NA NA NA NA ... ..$ V4: num [1:22] 0 0 0 0 0 0 0 0 0 0 ... ..$ V5: Factor w/ 29 levels ID1,ID10,ID11,..: 14 21 23 27 18 18 7 5 23 13 ... ..$ V6: Factor w/ 29 levels Issuer1,Issuer10,..: 14 21 23 27 18 18 7 5 23 13 ... ..$ V7: num [1:22] 98 99.5 99.6 99.8 99.4 ... ..$ V8: num [1:22] 0.45 0.4 0.45 0.6 0.4 0.4 0.4 0.4 0.45 0.3 .. -- David I've created new input(list1,list2) and desired output(list3) examples below. I hope this makes the request a lot clearer. Not sure if this helpful, but I found this bit of script and it keeps V1,V2,V3 separate and keeps each set of observations as vectors, but it doesn't concatenate the v1 observations with v2 observations together. sample.list - list(list1,list2) library(data.table) nr - nrow(sample.list[[1]]) fastbind.ith.rows - function(i) rbindlist(lapply(sample.list, [, i, TRUE)) fastbound - lapply(1:nr, fastbind.ith.rows) Link: http://stackoverflow.com/questions/4863341/fast-vectorized-merge-of-list-of-data-frames-by-row Thank you again! Vince Please find below the structure for list1, list2, and the desired output list3: list1-structure(list( V1 = list(c(15L, 19L, 28L, 9L, 17L, 3L, 11L, 21L,7L, 8L, 11L, 13L), c(1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11), c(NaN,NaN, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), structure(c(7L, 11L, 21L, 29L, 9L, 23L, 3L, 14L, 27L, 28L, 3L, 5L), .Label = c(ID1, ID10, ID11, ID12, ID13, ID14, ID15, ID16, ID17, ID18, ID19, ID2, ID20, ID21, ID22, ID23, ID24, ID25, ID26, ID27, ID28, ID29, ID3, ID4, ID5, ID6, ID7, ID8, ID9), class = factor),
Re: [R] Dropping predictor variables based on adjusted R square
Hi Shiv82, For a start, look at the step function in the stats package. There are a number of functions in other packages that offer different variable selection procedures. Jim On Thu, May 14, 2015 at 9:35 PM, Shivi82 shivibha...@ymail.com wrote: Hello experts, I have recently (1month) started using R. Earlier I was using SAS to work on analytic assignments. In SAS there is an option - forward selection, backward selection, step wise selection where in it removes the least impacting predictor variable from the set of variables based on adjusted r square and leaves us with the highest impacting variables to predict. Is there any similar functionality or function in R studio. Kindly suggest. Thanks. -- View this message in context: http://r.789695.n4.nabble.com/Dropping-predictor-variables-based-on-adjusted-R-square-tp4707186.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Need help with lm function on MAC OS X. R version - 3.2.0
I Have a data frame named BSE and CP is my independent variable and here;s the error I get if I try to run an lm function any idea whats wrong P.S - all my data is in numeric except company which is a factor. I have 2700 row and 450 variable P.P.S - I have no missing data, I have 0 in Empty field. BSE_Reg - lm(CP ~.-company, data = bse) Error in `contrasts-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : contrasts can be applied only to factors with 2 or more levels BSE_Reg - lm(CP ~., data = bse) Error in `contrasts-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : contrasts can be applied only to factors with 2 or more levels Error in as.character(tools:::httpdPort) : cannot coerce type 'closure' to vector of type 'character' Error in as.character(tools:::httpdPort) : cannot coerce type 'closure' to vector of type 'character' Error in as.character(tools:::httpdPort) : cannot coerce type 'closure' to vector of type 'character' Error in as.character(tools:::httpdPort) : cannot coerce type 'closure' to vector of type 'character' R.Version() $platform [1] x86_64-apple-darwin13.4.0 $arch [1] x86_64 $os [1] darwin13.4.0 $system [1] x86_64, darwin13.4.0 $status [1] $major [1] 3 $minor [1] 2.0 $year [1] 2015 $month [1] 04 $day [1] 16 $`svn rev` [1] 68180 $language [1] R $version.string [1] R version 3.2.0 (2015-04-16) $nickname [1] Full of Ingredients [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] create a vector from several data frames
Dear r-users, suppose that I have 20 data frames df1, df2, ..., df20 (one for each different location) with the same column names and column types (the first column contains a date, the others are numeric) like day tmax tmin 2015-05-10 20 10 2015-05-11 21 12 2015-05-12 17 9 2015-05-13 24 13 2015-05-14 25 18 I need to create a vector tmax_all of length 20 with the tmax referred to a particular day (let's say 2015-05-14). I would first build a new data frame tmax_df - Reduce(function(x, y) merge(x, y, by=day), list(df1[ , c(day, tmax)], df2[ , c(day, tmax)], ..., df20[ , c(day, tmax)])) and then select the row of tmax_df where day is the day I want to. Is there an easiest way? Is it possible to create straightforward this vector without passing through the merge of all the data frames? Thank you for your help Stefano AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere informazioni confidenziali, pertanto è destinato solo a persone autorizzate alla ricezione. I messaggi di posta elettronica per i client di Regione Marche possono contenere informazioni confidenziali e con privilegi legali. Se non si è il destinatario specificato, non leggere, copiare, inoltrare o archiviare questo messaggio. Se si è ricevuto questo messaggio per errore, inoltrarlo al mittente ed eliminarlo completamente dal sistema del proprio computer. Ai sensi dell’art. 6 della DGR n. 1394/2008 si segnala che, in caso di necessità ed urgenza, la risposta al presente messaggio di posta elettronica può essere visionata da persone estranee al destinatario. IMPORTANT NOTICE: This e-mail message is intended to be received only by persons entitled to receive the confidential information it may contain. E-mail messages to clients of Regione Marche may contain information that is confidential and legally privileged. Please do not read, copy, forward, or store this message unless you are an intended recipient of it. If you have received this message in error, please forward it to the sender and delete it completely from your computer system. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Counting consecutive events in R
Assuming I understand the problem correctly, you want to check for runs of at least length five where both Score and Test_desc assume particular values. You don't care where they are or what other data are associated, you just want to know if at least one such run exists in your data frame. Here's a function that does that: checkruns - function(testdata) { test1 - ifelse(testdata$Score 0 testdata$Type_Desc == 1 !is.na(testdata$Type_Desc), 1, 0) test0 - ifelse(testdata$Score 0 testdata$Type_Desc == 0 !is.na(testdata$Type_Desc), 1, 0) test1.rle - rle(test1) test0.rle - rle(test0) if(any(test1.rle$lengths = 5 test1.rle$values == 1)) cat(Type_high\n) if(any(test0.rle$lengths = 5 test0.rle$values == 1)) cat(Type_low\n) invisible() } Sarah On Thu, May 14, 2015 at 8:16 AM, Abhinaba Roy abhinabaro...@gmail.com wrote: Hi, I have the following dataframe structure(list(Type = c(QRS, QRS, QRS, QRS, QRS, QRS, QRS, QRS, QRS, QRS, QRS, QRS, RR, RR, RR, PP, PP, PP, PP, PP, PP, PP, PP, PP, QTc, QTc, QTc, QTc, QTc, QTc, QTc, QTc, QTc, QTc, QTc, QTc, QTc, QTc, QTc), Time_Point_Start = c(2015-04-01 14:57:15.0.0312, 2015-04-01 14:57:15.0.7839, 2015-04-01 14:57:16.0.5343, 2015-04-01 14:57:17.0.2573, 2015-04-01 14:57:18.0.0234, 2015-04-01 14:57:18.0.7722, 2015-04-01 14:57:19.0.5265, 2015-04-01 14:57:24.0.0195, 2015-04-01 14:57:24.0.7839, 2015-04-01 14:57:25.0.5343, 2015-04-01 14:57:26.0.2768, 2015-04-01 14:57:27.0.0273, 2015-04-01 14:58:03.0.0702, 2015-04-01 14:58:03.0.8190, 2015-04-01 14:58:04.0.5694, 2015-04-01 14:57:58.0.4134, 2015-04-01 14:57:59.0.1637, 2015-04-01 14:57:59.0.9126, 2015-04-01 14:58:00.0.6630, 2015-04-01 14:58:01.0.4134, 2015-04-01 14:58:02.0.1637, 2015-04-01 14:58:02.0.9126, 2015-04-01 14:58:03.0.6630, 2015-04-01 14:58:04.0.4134, 2015-04-01 14:57:07.0.4212, 2015-04-01 14:57:08.0.1715, 2015-04-01 14:57:08.0.9204, 2015-04-01 14:57:09.0.6864, 2015-04-01 14:57:10.0.4368, 2015-04-01 14:57:11.0.1871, 2015-04-01 14:57:11.0.9360, 2015-04-01 14:57:12.0.6591, 2015-04-01 14:57:13.0.4251, 2015-04-01 14:57:14.0.1754, 2015-04-01 14:57:14.0.9243, 2015-04-01 14:57:15.0.6903, 2015-04-01 14:57:16.0.4407, 2015-04-01 14:57:17.0.1676, 2015-04-01 14:57:17.0.9321), Time_Point_End = c(2015-04-01 14:57:15.0.0858, 2015-04-01 14:57:15.0.8346, 2015-04-01 14:57:16.0.6006, 2015-04-01 14:57:17.0.0351, 2015-04-01 14:57:18.0.1403, 2015-04-01 14:57:18.0.8385, 2015-04-01 14:57:19.0.5889, 2015-04-01 14:57:24.0.0858, 2015-04-01 14:57:24.0.8346, 2015-04-01 14:57:25.0.5772, 2015-04-01 14:57:26.0.3939, 2015-04-01 14:57:27.0.0936, 2015-04-01 14:58:03.0.8190, 2015-04-01 14:58:04.0.5694, 2015-04-01 14:58:05.0.3197, 2015-04-01 14:57:59.0.1637, 2015-04-01 14:57:59.0.9126, 2015-04-01 14:58:00.0.6630, 2015-04-01 14:58:01.0.4134, 2015-04-01 14:58:02.0.1637, 2015-04-01 14:58:02.0.9126, 2015-04-01 14:58:03.0.6630, 2015-04-01 14:58:04.0.4134, 2015-04-01 14:58:05.0.1793, 2015-04-01 14:57:07.0.8775, 2015-04-01 14:57:08.0.6435, 2015-04-01 14:57:09.0.3705, 2015-04-01 14:57:10.0.1209, 2015-04-01 14:57:10.0.8697, 2015-04-01 14:57:11.0.6201, 2015-04-01 14:57:12.0.3861, 2015-04-01 14:57:13.0.1364, 2015-04-01 14:57:13.0.8853, 2015-04-01 14:57:14.0.6513, 2015-04-01 14:57:15.0.4017, 2015-04-01 14:57:16.0.1248, 2015-04-01 14:57:16.0.9165, 2015-04-01 14:57:17.0.6162, 2015-04-01 14:57:18.0.3900), Value = c(0.0546, 0.0507, 0.0663, 0.0936, 0.117, 0.0663, 0.0624, 0.0663, 0.0507, 0.0429, 0.117, 0.0663, 0.7488, 0.7488, 0.7488, 0.7488, 0.7488, 0.7488, 0.7488, 0.7488, 0.7488, 0.7488, 0.7488, 0.7644, 0.033103481, 0.034056449, 0.032367699, 0.031000613, 0.031405867, 0.031241866, 0.032367699, 0.034337907, 0.033125921, 0.034337907, 0.034337907, 0.031241866, 0.034337907, 0.032367699, 0.032930616), Score = c(0L, 0L, 0L, 0L, 3L, 0L, 0L, 0L, 0L, 0L, 3L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 2L, 2L, 2L, 2L, 0L, 0L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), Type_Desc = c(NA, NA, NA, NA, 1L, NA, NA, NA, NA, NA, 1L, NA, NA, NA, NA, NA, NA, 1L, 1L, 1L, 1L, 1L, NA, NA, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), Pat_id = c(4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L)), .Names = c(Type, Time_Point_Start, Time_Point_End, Value, Score, Type_Desc, Pat_id), class = data.frame, row.names = c(NA, -39L)) For each unique value in column 'Type' , I want to check for consecutive 5 rows (if any) of 'Score' 0. Now, if there are five consecutive rows with Score 0 and 'Type_Desc' = 0, then we print Type_low , else if 'Type_Desc' = 1, we print Type_high. The search should end once 5 consecutive rows have been found. So, for this data frame we will have two statements as
Re: [R] Plotting times at night and getting plot limits correct
I might do it this way using Jim's sample data: epoch - as.POSIXct( 1970-01-01 ) # any date you like dta - data.frame( Timestamps = epoch + as.difftime( ifelse( Times = 5/24 , Times , Times + 1 ) , units=days ) , Thing=Thing ) brks - epoch + as.difftime( seq( 5, 29, 1 ), units=hours ) plot( Thing ~ Timestamps, dta, xaxt=n, xlim=c( min(brks), max(brks) ) ) axis.POSIXct( 1, at=brks, format=%H:%M ) or, using ggplot2 instead of base graphics: library(ggplot2) library(scales) ggplot( dta, aes( x=Timestamps, y=Thing ) ) + geom_point() + scale_x_datetime( breaks=brks , limits=c( min(brks), max(brks) ) , labels=date_format(%H:%M) ) + theme( axis.text.x = element_text( angle = 90, hjust = 1 ) ) On Thu, 14 May 2015, Jim Lemon wrote: Hi Bob, Given the other answers I may be off target, but perhaps this will help: # create two nights worth of data Times-strptime( paste(c(2015-05-13,2015-05-14),paste(rep(c(18:23,0:6),2),:30:00,sep=)), %Y-%m-%d %H:%M:%S) # telescope the two nights into repeated hours Hours-strptime(format(Times,%H:%M:%S),%H:%M:%S) # get a measure that can be checked for the correct output calls_per_hour-sample(10:100,length(Hours)) # plot the repeated values - looks okay plot(Hours,calls_per_hour) # now calculate the mean values for each hourly measurement mean_calls_per_hour-by(calls_per_hour,as.character(Hours),mean) # plot the means, making sure that the orders match plot(sort(unique(Hours)),mean_calls_per_hour) Jim On Wed, May 13, 2015 at 1:20 AM, Richard M. Heiberger r...@temple.edu wrote: Try this. From the full data-time value subtract 18:00:00. This places the times you are interested in into the range 00:00:00 - 12:00:00 Remove the date from these adjusted date-time values and plot y against the new times. Take control of the tick-labels and display 18:00 - 0600 instead of the default 00:00 - 12:00 Rich On Tue, May 12, 2015 at 10:34 AM, Bob O'Hara rni@gmail.com wrote: I'm helping colleagues with analysis of frog calls at night, and they want to plot call statistics against time. This means we hit a problem: we want the x-axis to start at (say) 18:00 and end at (say) 06:00. I'm reluctant to use the date as well, because we have data from several dates, but only want to plot against time of day. Here's some code to illustrate the problem (don't worry about the data being outside the range of the plot: this is only for illustration). library(chron) Times - chron(times.=paste(c(18:23,0:9),:30:00, sep=)) Thing - rnorm(length(Times)) # just something for the y-axis plot(Times,Thing) # x-axis wrong plot(Times,Thing, xlim=chron(times.=c(05:00:00, 18:00:00))) # x-axis right plot(Times,Thing, xlim=chron(times.=c(18:00:00, 05:00:00))) # would like this to work... Can anyone suggest a solution? Bob -- Bob O'Hara Biodiversity and Climate Research Centre Senckenberganlage 25 D-60325 Frankfurt am Main, Germany Tel: +49 69 798 40226 Mobile: +49 1515 888 5440 WWW: http://www.bik-f.de/root/index.php?page_id=219 Blog: http://occamstypewriter.org/boboh/ Journal of Negative Results - EEB: www.jnr-eeb.org __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained,
Re: [R] Counting consecutive events in R
I normally use rle() for these problems, see ?rle. for instance, k - rbinom(999, 1, .5) series - function(run) { r - rle(run)ser - which(r$lengths 5 r$values) } series(k) returns the indices of consecutive runs that have length 5 or longer. Abhinaba Roy abhinabaro...@gmail.com [Thu, May 14, 2015 at 02:16:31PM CEST]: Hi, I have the following dataframe structure(list(Type = c(QRS, QRS, QRS, QRS, QRS, QRS, QRS, QRS, QRS, QRS, QRS, QRS, RR, RR, RR, PP, PP, PP, PP, PP, PP, PP, PP, PP, QTc, QTc, QTc, QTc, QTc, QTc, QTc, QTc, QTc, QTc, QTc, QTc, QTc, QTc, QTc), Time_Point_Start = c(2015-04-01 14:57:15.0.0312, 2015-04-01 14:57:15.0.7839, 2015-04-01 14:57:16.0.5343, 2015-04-01 14:57:17.0.2573, 2015-04-01 14:57:18.0.0234, 2015-04-01 14:57:18.0.7722, 2015-04-01 14:57:19.0.5265, 2015-04-01 14:57:24.0.0195, 2015-04-01 14:57:24.0.7839, 2015-04-01 14:57:25.0.5343, 2015-04-01 14:57:26.0.2768, 2015-04-01 14:57:27.0.0273, 2015-04-01 14:58:03.0.0702, 2015-04-01 14:58:03.0.8190, 2015-04-01 14:58:04.0.5694, 2015-04-01 14:57:58.0.4134, 2015-04-01 14:57:59.0.1637, 2015-04-01 14:57:59.0.9126, 2015-04-01 14:58:00.0.6630, 2015-04-01 14:58:01.0.4134, 2015-04-01 14:58:02.0.1637, 2015-04-01 14:58:02.0.9126, 2015-04-01 14:58:03.0.6630, 2015-04-01 14:58:04.0.4134, 2015-04-01 14:57:07.0.4212, 2015-04-01 14:57:08.0.1715, 2015-04-01 14:57:08.0.9204, 2015-04-01 14:57:09.0.6864, 2015-04-01 14:57:10.0.4368, 2015-04-01 14:57:11.0.1871, 2015-04-01 14:57:11.0.9360, 2015-04-01 14:57:12.0.6591, 2015-04-01 14:57:13.0.4251, 2015-04-01 14:57:14.0.1754, 2015-04-01 14:57:14.0.9243, 2015-04-01 14:57:15.0.6903, 2015-04-01 14:57:16.0.4407, 2015-04-01 14:57:17.0.1676, 2015-04-01 14:57:17.0.9321), Time_Point_End = c(2015-04-01 14:57:15.0.0858, 2015-04-01 14:57:15.0.8346, 2015-04-01 14:57:16.0.6006, 2015-04-01 14:57:17.0.0351, 2015-04-01 14:57:18.0.1403, 2015-04-01 14:57:18.0.8385, 2015-04-01 14:57:19.0.5889, 2015-04-01 14:57:24.0.0858, 2015-04-01 14:57:24.0.8346, 2015-04-01 14:57:25.0.5772, 2015-04-01 14:57:26.0.3939, 2015-04-01 14:57:27.0.0936, 2015-04-01 14:58:03.0.8190, 2015-04-01 14:58:04.0.5694, 2015-04-01 14:58:05.0.3197, 2015-04-01 14:57:59.0.1637, 2015-04-01 14:57:59.0.9126, 2015-04-01 14:58:00.0.6630, 2015-04-01 14:58:01.0.4134, 2015-04-01 14:58:02.0.1637, 2015-04-01 14:58:02.0.9126, 2015-04-01 14:58:03.0.6630, 2015-04-01 14:58:04.0.4134, 2015-04-01 14:58:05.0.1793, 2015-04-01 14:57:07.0.8775, 2015-04-01 14:57:08.0.6435, 2015-04-01 14:57:09.0.3705, 2015-04-01 14:57:10.0.1209, 2015-04-01 14:57:10.0.8697, 2015-04-01 14:57:11.0.6201, 2015-04-01 14:57:12.0.3861, 2015-04-01 14:57:13.0.1364, 2015-04-01 14:57:13.0.8853, 2015-04-01 14:57:14.0.6513, 2015-04-01 14:57:15.0.4017, 2015-04-01 14:57:16.0.1248, 2015-04-01 14:57:16.0.9165, 2015-04-01 14:57:17.0.6162, 2015-04-01 14:57:18.0.3900), Value = c(0.0546, 0.0507, 0.0663, 0.0936, 0.117, 0.0663, 0.0624, 0.0663, 0.0507, 0.0429, 0.117, 0.0663, 0.7488, 0.7488, 0.7488, 0.7488, 0.7488, 0.7488, 0.7488, 0.7488, 0.7488, 0.7488, 0.7488, 0.7644, 0.033103481, 0.034056449, 0.032367699, 0.031000613, 0.031405867, 0.031241866, 0.032367699, 0.034337907, 0.033125921, 0.034337907, 0.034337907, 0.031241866, 0.034337907, 0.032367699, 0.032930616), Score = c(0L, 0L, 0L, 0L, 3L, 0L, 0L, 0L, 0L, 0L, 3L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 2L, 2L, 2L, 2L, 0L, 0L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), Type_Desc = c(NA, NA, NA, NA, 1L, NA, NA, NA, NA, NA, 1L, NA, NA, NA, NA, NA, NA, 1L, 1L, 1L, 1L, 1L, NA, NA, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), Pat_id = c(4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L)), .Names = c(Type, Time_Point_Start, Time_Point_End, Value, Score, Type_Desc, Pat_id), class = data.frame, row.names = c(NA, -39L)) For each unique value in column 'Type' , I want to check for consecutive 5 rows (if any) of 'Score' 0. Now, if there are five consecutive rows with Score 0 and 'Type_Desc' = 0, then we print Type_low , else if 'Type_Desc' = 1, we print Type_high. The search should end once 5 consecutive rows have been found. So, for this data frame we will have two statements as follows, 1.PP_high (reason - consecutive 5 rows of score 0 and 'Type_Desc' = 1 ) 2.QTc_low (reason -
[R] specific package to laply
Hi, I have a batch jobs problem for parallel code without sudo. When I try to send a package to the different nodes, as follows: .libPaths( c(.libPaths(), /my/first/library, /my/second/library) ) library(foreach) library(iterators) library(parallel) library(doParallel) library(rvest) cl - makeCluster(detectCores()) registerDoParallel(cl) sites - paste0(https://www.site,1:2,.com;) html0 - foreach(i=sites,.packages='rvest') %dopar% html(i) I get the following output: Error in e$fun(obj, substitute(ex), parent.frame(), e$data) : worker initialization failed: there is no package called ‘rvest’ Calls: %dopar% - Anonymous Presumably, I need a way to export my .libPaths() to the nodes. Any suggestions? Thanks, Benjamin [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] specific package to laply
I suggest you post using plain text to minimize communication problems on this list. I use the clusterEvalQ and cluster export functions to setup the slave processes before I start processing. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. 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. On May 14, 2015 11:01:50 AM PDT, Benjamin hess...@gmail.com wrote: Hi, I have a batch jobs problem for parallel code without sudo. When I try to send a package to the different nodes, as follows: .libPaths( c(.libPaths(), /my/first/library, /my/second/library) ) library(foreach) library(iterators) library(parallel) library(doParallel) library(rvest) cl - makeCluster(detectCores()) registerDoParallel(cl) sites - paste0(https://www.site,1:2,.com;) html0 - foreach(i=sites,.packages='rvest') %dopar% html(i) I get the following output: Error in e$fun(obj, substitute(ex), parent.frame(), e$data) : worker initialization failed: there is no package called ‘rvest’ Calls: %dopar% - Anonymous Presumably, I need a way to export my .libPaths() to the nodes. Any suggestions? Thanks, Benjamin [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] create a vector from several data frames
If you combine all of the df's into a list, e.g. dfn - paste0(df, 1:20) df - lapply(dfn, get) names(df) - dfn and if target is the day you want in the same date/time format as the day variable in the data frames: sapply(df, function(x) x[x$day==target, tmax]) will return a named vector of the tmax values. - David L Carlson Department of Anthropology Texas AM University College Station, TX 77840-4352 -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Stefano Sofia Sent: Thursday, May 14, 2015 9:23 AM To: r-help@r-project.org Subject: [R] create a vector from several data frames Dear r-users, suppose that I have 20 data frames df1, df2, ..., df20 (one for each different location) with the same column names and column types (the first column contains a date, the others are numeric) like day tmax tmin 2015-05-10 20 10 2015-05-11 21 12 2015-05-12 17 9 2015-05-13 24 13 2015-05-14 25 18 I need to create a vector tmax_all of length 20 with the tmax referred to a particular day (let's say 2015-05-14). I would first build a new data frame tmax_df - Reduce(function(x, y) merge(x, y, by=day), list(df1[ , c(day, tmax)], df2[ , c(day, tmax)], ..., df20[ , c(day, tmax)])) and then select the row of tmax_df where day is the day I want to. Is there an easiest way? Is it possible to create straightforward this vector without passing through the merge of all the data frames? Thank you for your help Stefano AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere informazioni confidenziali, pertanto è destinato solo a persone autorizzate alla ricezione. I messaggi di posta elettronica per i client di Regione Marche possono contenere informazioni confidenziali e con privilegi legali. Se non si è il destinatario specificato, non leggere, copiare, inoltrare o archiviare questo messaggio. Se si è ricevuto questo messaggio per errore, inoltrarlo al mittente ed eliminarlo completamente dal sistema del proprio computer. Ai sensi dell’art. 6 della DGR n. 1394/2008 si segnala che, in caso di necessità ed urgenza, la risposta al presente messaggio di posta elettronica può essere visionata da persone estranee al destinatario. IMPORTANT NOTICE: This e-mail message is intended to be received only by persons entitled to receive the confidential information it may contain. E-mail messages to clients of Regione Marche may contain information that is confidential and legally privileged. Please do not read, copy, forward, or store this message unless you are an intended recipient of it. If you have received this message in error, please forward it to the sender and delete it completely from your computer system. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] error using the huge R package
On May 13, 2015, at 3:45 PM, Juan Fernandez wrote: Dear List I am trying to do an association network using some expression data I have, the data is really huge: 300 samples and ~30,000 genes. I would like to apply a gaussian graphical model to my data using the huge R package. Here is the code I am using dim(data) #[1] 317 32200 huge.out - huge.npn(data) huge.stars - huge.select(huge.out, criterion=“stars”) However in this last step I got the following error: Error in cor(x) : sampling…..in progress:10% Missing values present in input variable ‘x’. Consider using use = ‘pairwise.complete.obs’ Responded on StackOverflow where this duplicate question was posted yesterday -- David. Any help would be very appreciated Juan [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius Alameda, CA, USA __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] mixed-and weights
Hi, I´m beginner with R and I hope that someone can help me. I need to know how make command weights in mixed-effect model wit random intercept. Command weights=xxx is not function in nlme package. But I think that this command is commonly used for linear models. Should I use a different package or special command. Thank you for your advice Jana Ř. = [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Determinant
Hello, I am Vasilis Chasiotis and I am a candidate Ph.D. student in Aristotle University of Thessaloniki in Greece. I have the following problem. I want to check if the square of a number ( for example the square of 1.677722e+29 ) is an integer. The problem is that this number is the calculation of the determinant (so the number should be an integer) of a matrix 22x22, which means it has an approximation ( the real number is 1.6777216e+29 but R gives to me 1.677721599849e+29 ), because R use LU-decomposition to calculate the determinant. That means that the radical of the number 1.677721599849e+29 is not an integer, but it should be. How can we overcome this problem? Thank you in advance. I look forward to hearing from you soon. Vasilis Chasiotis __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] binding two lists of lists of dataframes together
On May 14, 2015, at 7:15 AM, Vin Cheng wrote: Hi David, Understood. I've done a lot of work around this structure, but if there isn't anyway to change it back to the original structure then I'll work around it. I suppose there might be a way to make it back into a data.table, but it won't be a structure that I would recognize as such. The usual data table column is a vector, whereas your object had a complex list structure stored as a single column. It was list1 and list 2 that had the class attribute of c('data.table', 'data.frame'), rather than each list component having those attributes which might have made more sense. If there is some virtue in the origianl structure that I am not appreciating, then just this: list3a - data.table(list3a) # untested Could you possibly show me how to add colnames to list3a? c(id,WgtBand,Wgt,Held,LID,Issuer,Bid,Offer) these would be repeated once for each V1,V2,V3. The code I used to build colnames was just: list1a - lapply(list1, function(x) setNames( data.frame(x), paste0(V, seq(length(x)) ) ) ) So modifying it to put that character vector in the names attribute on list3a itself could just be: list3a - lapply(list3a, function(x) setNames( data.frame(x), c(id,WgtBand,Wgt,Held,LID,Issuer,Bid,Offer) ) ) -- David Thank you again for all the help! It's much appreciated! Vince Subject: Re: [R] binding two lists of lists of dataframes together From: dwinsem...@comcast.net Date: Wed, 13 May 2015 15:51:47 -0700 CC: r-help@r-project.org To: newrnew...@hotmail.com On May 13, 2015, at 2:01 PM, Vin Cheng wrote: Hi David, I tried both solutions you provided(lapply(dlist, function(x) rbind(x,x) ) Map( rbind, smaller, smaller)) and they seem to transpose and reshape the data into a different structure. Whenever I added the str - I only get a NULL. I believe you are misrepresenting my suggestion. I suggested that you coerce each of the items in those lists to data.frames with appropriate column names before applying rbind.data.frame Those list1 and list2 examples appear to me as pathologically deformed. They claim to be data.tables but they have no self referential pointers, suggesting to me that they are not data.tables, and they have no column names suggesting not either data.table, nor data.frame. class(list1) [1] data.table data.frame class(list2) [1] data.table data.frame You basically want a list of the same general structure as list1 where all the elements in list two at the same position and depth have been concatenated? Yes - that sounds exactly right. Fix up the data.structures, first. Then use Map(rbind, ...) as described previously. list1a - lapply(list1, function(x) setNames( data.frame(x), paste0(V, seq(length(x)) ) ) ) list2a - lapply(list2, function(x) setNames( data.frame(x), paste0(V, seq(length(x)) ) )) list3a - Map( rbind.data.frame, list1a, list2a) str(list3a) List of 3 $ V1:'data.frame': 22 obs. of 8 variables: ..$ V1: int [1:22] 15 19 28 9 17 3 11 21 7 8 ... ..$ V2: num [1:22] 1 1 2 3 4 5 6 7 8 9 ... ..$ V3: num [1:22] NaN NaN NA NA NA NA NA NA NA NA ... ..$ V4: num [1:22] 0 0 0 0 0 0 0 0 0 0 ... ..$ V5: Factor w/ 29 levels ID1,ID10,ID11,..: 7 11 21 29 9 23 3 14 27 28 ... ..$ V6: Factor w/ 29 levels Issuer1,Issuer10,..: 7 11 21 29 9 23 3 14 27 28 ... ..$ V7: num [1:22] 99.5 95.5 99.5 100 98.5 ... ..$ V8: num [1:22] 0.4 0.55 0.4 0.4 0.5 0.45 0.4 0.45 0.6 0.4 ... $ V2:'data.frame': 22 obs. of 8 variables: ..$ V1: int [1:22] 10 29 5 19 28 3 10 12 1 21 ... ..$ V2: num [1:22] 1 1 2 3 4 5 6 7 8 9 ... ..$ V3: num [1:22] NaN NaN NA NA NA NA NA NA NA NA ... ..$ V4: num [1:22] 0 0 0 0 0 0 0 0 0 0 ... ..$ V5: Factor w/ 29 levels ID1,ID10,ID11,..: 2 22 25 11 21 23 2 4 1 14 ... ..$ V6: Factor w/ 29 levels Issuer1,Issuer10,..: 2 22 25 11 21 23 2 4 1 14 ... ..$ V7: num [1:22] 98.5 100.2 99 95.5 99.5 ... ..$ V8: num [1:22] 0.6 0.4 0.45 0.55 0.4 0.45 0.6 0.55 0.5 0.45 ... $ V3:'data.frame': 22 obs. of 8 variables: ..$ V1: int [1:22] 21 28 3 7 25 25 15 13 3 20 ... ..$ V2: num [1:22] 1 1 2 3 4 5 6 7 8 9 ... ..$ V3: num [1:22] NaN NaN NA NA NA NA NA NA NA NA ... ..$ V4: num [1:22] 0 0 0 0 0 0 0 0 0 0 ... ..$ V5: Factor w/ 29 levels ID1,ID10,ID11,..: 14 21 23 27 18 18 7 5 23 13 ... ..$ V6: Factor w/ 29 levels Issuer1,Issuer10,..: 14 21 23 27 18 18 7 5 23 13 ... ..$ V7: num [1:22] 98 99.5 99.6 99.8 99.4 ... ..$ V8: num [1:22] 0.45 0.4 0.45 0.6 0.4 0.4 0.4 0.4 0.45 0.3 .. -- David I've created new input(list1,list2) and desired output(list3) examples below. I hope this makes the request a lot clearer. Not sure if this helpful, but I found this bit of script and it keeps
Re: [R] binding two lists of lists of dataframes together
Thanks David! Have a good one! Subject: Re: [R] binding two lists of lists of dataframes together From: dwinsem...@comcast.net Date: Thu, 14 May 2015 07:58:43 -0700 CC: r-help@r-project.org To: newrnew...@hotmail.com On May 14, 2015, at 7:15 AM, Vin Cheng wrote: Hi David, Understood. I've done a lot of work around this structure, but if there isn't anyway to change it back to the original structure then I'll work around it. I suppose there might be a way to make it back into a data.table, but it won't be a structure that I would recognize as such. The usual data table column is a vector, whereas your object had a complex list structure stored as a single column. It was list1 and list 2 that had the class attribute of c('data.table', 'data.frame'), rather than each list component having those attributes which might have made more sense. If there is some virtue in the origianl structure that I am not appreciating, then just this: list3a - data.table(list3a) # untested Could you possibly show me how to add colnames to list3a? c(id,WgtBand,Wgt,Held,LID,Issuer,Bid,Offer) these would be repeated once for each V1,V2,V3. The code I used to build colnames was just: list1a - lapply(list1, function(x) setNames( data.frame(x), paste0(V, seq(length(x)) ) ) ) So modifying it to put that character vector in the names attribute on list3a itself could just be: list3a - lapply(list3a, function(x) setNames( data.frame(x), c(id,WgtBand,Wgt,Held,LID,Issuer,Bid,Offer) ) ) -- David Thank you again for all the help! It's much appreciated! Vince Subject: Re: [R] binding two lists of lists of dataframes together From: dwinsem...@comcast.net Date: Wed, 13 May 2015 15:51:47 -0700 CC: r-help@r-project.org To: newrnew...@hotmail.com On May 13, 2015, at 2:01 PM, Vin Cheng wrote: Hi David, I tried both solutions you provided(lapply(dlist, function(x) rbind(x,x) ) Map( rbind, smaller, smaller)) and they seem to transpose and reshape the data into a different structure. Whenever I added the str - I only get a NULL. I believe you are misrepresenting my suggestion. I suggested that you coerce each of the items in those lists to data.frames with appropriate column names before applying rbind.data.frame Those list1 and list2 examples appear to me as pathologically deformed. They claim to be data.tables but they have no self referential pointers, suggesting to me that they are not data.tables, and they have no column names suggesting not either data.table, nor data.frame. class(list1) [1] data.table data.frame class(list2) [1] data.table data.frame You basically want a list of the same general structure as list1 where all the elements in list two at the same position and depth have been concatenated? Yes - that sounds exactly right. Fix up the data.structures, first. Then use Map(rbind, ...) as described previously. list1a - lapply(list1, function(x) setNames( data.frame(x), paste0(V, seq(length(x)) ) ) ) list2a - lapply(list2, function(x) setNames( data.frame(x), paste0(V, seq(length(x)) ) )) list3a - Map( rbind.data.frame, list1a, list2a) str(list3a) List of 3 $ V1:'data.frame':22 obs. of 8 variables: ..$ V1: int [1:22] 15 19 28 9 17 3 11 21 7 8 ... ..$ V2: num [1:22] 1 1 2 3 4 5 6 7 8 9 ... ..$ V3: num [1:22] NaN NaN NA NA NA NA NA NA NA NA ... ..$ V4: num [1:22] 0 0 0 0 0 0 0 0 0 0 ... ..$ V5: Factor w/ 29 levels ID1,ID10,ID11,..: 7 11 21 29 9 23 3 14 27 28 ... ..$ V6: Factor w/ 29 levels Issuer1,Issuer10,..: 7 11 21 29 9 23 3 14 27 28 ... ..$ V7: num [1:22] 99.5 95.5 99.5 100 98.5 ... ..$ V8: num [1:22] 0.4 0.55 0.4 0.4 0.5 0.45 0.4 0.45 0.6 0.4 ... $ V2:'data.frame':22 obs. of 8 variables: ..$ V1: int [1:22] 10 29 5 19 28 3 10 12 1 21 ... ..$ V2: num [1:22] 1 1 2 3 4 5 6 7 8 9 ... ..$ V3: num [1:22] NaN NaN NA NA NA NA NA NA NA NA ... ..$ V4: num [1:22] 0 0 0 0 0 0 0 0 0 0 ... ..$ V5: Factor w/ 29 levels ID1,ID10,ID11,..: 2 22 25 11 21 23 2 4 1 14 ... ..$ V6: Factor w/ 29 levels Issuer1,Issuer10,..: 2 22 25 11 21 23 2 4 1 14 ... ..$ V7: num [1:22] 98.5 100.2 99 95.5 99.5 ... ..$ V8: num [1:22] 0.6 0.4 0.45 0.55 0.4 0.45 0.6 0.55 0.5 0.45 ... $ V3:'data.frame':22 obs. of 8 variables: ..$ V1: int [1:22] 21 28 3 7 25 25 15 13 3 20 ... ..$ V2: num [1:22] 1 1 2 3 4 5 6 7 8 9 ... ..$ V3: num [1:22] NaN NaN NA NA NA NA NA NA NA NA ... ..$ V4: num [1:22] 0 0 0 0 0 0 0 0 0 0 ... ..$ V5: Factor w/ 29 levels ID1,ID10,ID11,..: 14 21 23 27 18 18 7 5 23 13 ... ..$ V6: Factor w/ 29 levels Issuer1,Issuer10,..: 14 21 23 27
[R] Reading a tiff image
Dear R users, I am new to R and trying to learn raster image processing in R. I have a tiff image with pixel values and I am trying to read this image in R so that I can make some calculations and process the image. Could you please tell me how to read a tiff image in R? Thanks! -- Regards, *Preethi Malur Balaji* | PhD Student University College Cork | Cork, Ireland. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Determinant
Of course the number _is_ an integer. It seems you are asking whether that integer can be exactly _represented_ on a computer? That depends on your processor (eg. 32/64 bit) and the size of the number; alternatively you could calculate with arbitrary precision with the Rmpfr package. For more insights, have a look at Pat Burs' summary of number representation in R (http://www.burns-stat.com/documents/tutorials/impatient-r/more-r-key-objects/more-r-numbers/) and/or read chapter one of his R inferno. Or, maybe you can state more clearly what you are trying to achieve in the end, there might be other options. Cheers, B. On May 14, 2015, at 4:44 AM, chasiot...@math.auth.gr wrote: Hello, I am Vasilis Chasiotis and I am a candidate Ph.D. student in Aristotle University of Thessaloniki in Greece. I have the following problem. I want to check if the square of a number ( for example the square of 1.677722e+29 ) is an integer. The problem is that this number is the calculation of the determinant (so the number should be an integer) of a matrix 22x22, which means it has an approximation ( the real number is 1.6777216e+29 but R gives to me 1.677721599849e+29 ), because R use LU-decomposition to calculate the determinant. That means that the radical of the number 1.677721599849e+29 is not an integer, but it should be. How can we overcome this problem? Thank you in advance. I look forward to hearing from you soon. Vasilis Chasiotis __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Error: Gradient function might be wrong - check it! for system of equations using Optimx
Hello,I am estimating a system of 3 equations using a nonlinear GMM.The first and second equations consists of a linear part and a nonlinear part. The nonlinear parts is specified as a logit and the logit as a whole has a coefficient attached to it. For the first two equations, it is specified as follows:The whole equation: (a1*x1 + a2*x2 +a3*x3 + a4*x4 + a5*x5 + a22*(exp(a6*x6 + a7*x7 + a8*x9 + a9*x10 + a10*x11 + a11*x12 + a14*x16)/(1+exp(a6*x6 + a7*x7 + a8*x9 + a9*x10 + a10*x11 + a11*x12 + a14*x16 The linear portion of the equation: a1*x1 + a2*x2 +a3*x3 + a4*x4 + a5*x5The nonlinear portion of the equation: a22*(exp(a6*x6 + a7*x7 + a8*x9 + a9*x10 + a10*x11 + a11*x12 + a14*x16)/(1+exp(a6*x6 + a7*x7 + a8*x9 + a9*x10 + a10*x11 + a11*x12 + a14*x16)))The third equation is a logit with seven independent variables.The first and the second equation have 12 variables while the third equation have 7 variables. I did calculate my gradient from the moment conditions which led to a 12 by 12 matrix for the first equation, a 12 by 12 matrix for the second equation and a 7 by 7 matrix for the third equation because I have 12, 12, and 7 instruments for the three equations respectively.Since it is estimated as a system of equations, I made it into a block diagonal matrix which is a 31 by 31 matrix. This is the matrix that I used in my optimx routine which gave me the error message Maximizing -- use negfn and neggrError: Gradient function might be wrong - check it! In addition: Warning message:In gn - ga : longer object length is not a multiple of shorter object length When I used optim routine, I got a similar error messageError in optim(parm, fn = obj, gr = gradient, method = BFGS, hessian = TRUE) : gradient in optim evaluated to length 1023 not 35 I used the numDeriv to compare my gradient with the numerical gradient and I have the following error require(numDeriv) mygrad = gradient(parm) numgrad = jacobian(obj, parm) cbind(mygrad,numgrad)Error in cbind(mygrad, numgrad) : number of rows of matrices must match (see arg 2) all.equal(mygrad,numgrad)[1] Attributes: Length mismatch: comparison on first 1 components Attributes: Component “dim”: Mean relative difference: 0.5625 [3] Numeric: lengths (1023, 35) differ A way forward will be appreciated. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Reading access file
Hello everybody. I have a access file to read in R but I can’t to do this. I used Hmisc package, but it doesn’t work. Someone has the commands to read this kind of file? I attached the access file. Thanks. Silvano. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Reading access file
Hi Silvano, your attachment did not go through (only a couple of formats are supported). Please try to give your code next time and what error you get but first read this, it might help: http://www.statmethods.net/input/dbinterface.html best, daniel Feladó: R-help [r-help-boun...@r-project.org] ; meghatalmaz#243;: silvano [silv...@uel.br] Küldve: 2015. május 14. 13:31 To: R Tárgy: [R] Reading access file Hello everybody. I have a access file to read in R but I can’t to do this. I used Hmisc package, but it doesn’t work. Someone has the commands to read this kind of file? I attached the access file. Thanks. Silvano. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Cross correlation between two time series over nested time periods?
Thanks! Here the period of my time series B is a proper subinterval of the period of A. Does ccf(A,B) requires A and B span the same period? If A and B don't span the same period, what does ccf do? When moving B along the period of A by a lag, does ccf(A,B) calculate the cross correlation between B and the part of A overlapping with B? Or does ccf(A,B) calculate the cross correlation between A and the extension of B to the period of A by zero padding? On Thu, 5/14/15, Franklin Bretschneider brets...@xs4all.nl wrote: Subject: Re: [R] Cross correlation between two time series over nested time periods? Date: Thursday, May 14, 2015, 6:14 AM On 2015-05-14 , at 02:11, Tim via R-help r-help@r-project.org wrote: Hello Tim, Re: I have two time series Calculate and plot cross correlation between two time series over nested time periods. Each point in either time series is for a week (not exactly a calendar week, but the first week in a calendar year always starts from Jan 1, and the other weeks in the same year follow that, and the last week of the year may contain more than 7 days but no more than 13 days). The first time series A is stored in a compressed (.gz) text file, which looks like (each week and the corresponding time series value are separated by a comma in a line): week,value 20060101-20060107,0 20060108-20060114,5 ... 20061217-20061223,0 20061224-20061230,0 20070101-20070107,0 20070108-20070114,4 ... 20150903-20150909,0 20150910-20150916,1 The second time series B is similarly stored in a compressed (.gz) text file, but over a subset of period of A, which looks like: week,value 20130122-20130128,509 20130129-20130204,204 ... 20131217-20131223,150 20131224-20131231,148.0 20140101-20140107,365.0 20140108-20140114,45.0 ... 20150305-20150311,0 20150312-20150318,364 I wonder how to calculate the cross correlation between the two time series A and B (up to a specified maximum lag), and plot A and B in a single plot? The auto- and crosscorrelation functions are in the stats package: acf(x, lag.max = NULL, type = c(correlation, covariance, partial), plot = TRUE, na.action = na.fail, demean = TRUE, ...) ccf(x, y, lag.max = NULL, type = c(correlation, covariance), plot = TRUE, na.action = na.fail, ...) See further: ?ccf Succes and Best wishes, Frank --- Franklin Bretschneider Dept of Biology Utrecht University brets...@xs4all.nl __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Deparse substitute assign with list elements
Hello, When I use function `foo` with list elements (example 2), it defines a new object named `b[[1]]`, which is not what I want. How can I change the function code to show the desired behaviour for all data structures passed to the function? Or is there a more appropriate way to sort of pass by references in a function? Thanks Sören src bar - function(x) { return( x + 3 ) } foo - function(x, value) { nm - deparse(substitute(x)) tmp - bar( value ) assign(nm, tmp, parent.frame()) } # 1) a - NA foo(a, 4) a # 7, fine :-) # 2) b - list(NA, NA) foo(b[[1]], 4) # the first list item should be 7 b # wanted 7 but still list with two NAs :-( /src __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Reading access file
mdbConnect-odbcConnectAccess(C:\\temp\\demo.mdb); sqlTables(mdbConnect); demo-sqlFetch(mdbConnect, tblDemo); odbcClose(mdbConnect); rm(demo); On Thu, May 14, 2015 at 6:31 AM, silvano silv...@uel.br wrote: Hello everybody. I have a access file to read in R but I can’t to do this. I used Hmisc package, but it doesn’t work. Someone has the commands to read this kind of file? I attached the access file. Thanks. Silvano. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- == WenSui Liu Credit Risk Manager, 53 Bancorp wensui@53.com 513-295-4370 == [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Determinant
On May 14, 2015, at 1:44 AM, chasiot...@math.auth.gr wrote: Hello, I am Vasilis Chasiotis and I am a candidate Ph.D. student in Aristotle University of Thessaloniki in Greece. I have the following problem. I want to check if the square of a number ( for example the square of 1.677722e+29 ) is an integer. The square of 1.677722e+29 is almost certainly an integer since the power of 10 (+29) exceeds the number of digits. That implies that the number in non-scientific notation has many 0's on the righthand side. I'm guessing that you may be asking whether the square-root is an integer. The problem is that this number is the calculation of the determinant (so the number should be an integer) of a matrix 22x22, which means it has an approximation ( the real number is 1.6777216e+29 but R gives to me 1.677721599849e+29 ), because R use LU-decomposition to calculate the determinant. That means that the radical of the number 1.677721599849e+29 is not an integer, but it should be. Again guessing that by 'radical' you mean the square-root. I am also confused about what test you were applying to that result to determine that it was not an integer. At any rate, I'm guessing that the limitation of R's numerical accuracy may get in the way of determining whether the square-root is an integer. If it were integer then it should equal floor(n) : (1.677721599849e+29)^(1/2) - floor((1.677721599849e+29)^(1/2)) #[1] 0.125 (1.6777216e+29)^(1/2) - floor( (1.6777216e+29)^(1/2) ) #[1] 0 That's because that number was the product of two perfect squares: 16777216^(1/2) - floor( 1.6777216^(1/2) ) [1] 4095 And 10^22 = 10^11*10^11 If you know how big the original was you could round it to the correct precision but that seems too much to hope for. print( round(1.677721599849e+29, digits=10) , digits=10) #[1] 1.6777216e+29 identical( (1.6777216e+29)^(1/2) , floor( (1.6777216e+29)^(1/2) ) ) #[1] TRUE How can we overcome this problem? There are a couple of packages that support exact math on really large numbers. You need to clarify what is being requested. You definitely need to review R-FAQ 7.31 and make sure you understand it and also review ?double and ?integer -- David Winsemius Alameda, CA, USA __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Reading a tiff image
There are many easy ways to answer this kind of question yourself. One possibility: go to www.rseek.org and search for read tiff file. That will quickly suggest the tiff package, which you can install from CRAN, and also the rtiff package, ditto. It will also link to previous discussions of that very topic on this mailing list, and other useful information. Sarah On Thu, May 14, 2015 at 6:50 AM, Preethi Balaji preet.balaj...@gmail.com wrote: Dear R users, I am new to R and trying to learn raster image processing in R. I have a tiff image with pixel values and I am trying to read this image in R so that I can make some calculations and process the image. Could you please tell me how to read a tiff image in R? Thanks! -- Regards, *Preethi Malur Balaji* | PhD Student University College Cork | Cork, Ireland. -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Reading a tiff image
Hello, please set your mailing program to plain text instead of HTML if you post to this list. If you google read tiff in R you end up with the package called 'tiff'. (http://cran.r-project.org/web/packages/tiff/tiff.pdf) In case you do not know how to install and load a package, please consult the intro to R pdf which comes with your installation. Good luck with R, daniel Feladó: R-help [r-help-boun...@r-project.org] ; meghatalmaz#243;: Preethi Balaji [preet.balaj...@gmail.com] Küldve: 2015. május 14. 12:50 To: r-help@r-project.org Tárgy: [R] Reading a tiff image Dear R users, I am new to R and trying to learn raster image processing in R. I have a tiff image with pixel values and I am trying to read this image in R so that I can make some calculations and process the image. Could you please tell me how to read a tiff image in R? Thanks! -- Regards, *Preethi Malur Balaji* | PhD Student University College Cork | Cork, Ireland. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Determinant
On May 14, 2015, at 12:50 PM, David Winsemius wrote: On May 14, 2015, at 1:44 AM, chasiot...@math.auth.gr wrote: Hello, I am Vasilis Chasiotis and I am a candidate Ph.D. student in Aristotle University of Thessaloniki in Greece. I have the following problem. I want to check if the square of a number ( for example the square of 1.677722e+29 ) is an integer. The square of 1.677722e+29 is almost certainly an integer since the power of 10 (+29) exceeds the number of digits. That implies that the number in non-scientific notation has many 0's on the righthand side. I'm guessing that you may be asking whether the square-root is an integer. The problem is that this number is the calculation of the determinant (so the number should be an integer) of a matrix 22x22, which means it has an approximation ( the real number is 1.6777216e+29 but R gives to me 1.677721599849e+29 ), because R use LU-decomposition to calculate the determinant. That means that the radical of the number 1.677721599849e+29 is not an integer, but it should be. Again guessing that by 'radical' you mean the square-root. I am also confused about what test you were applying to that result to determine that it was not an integer. At any rate, I'm guessing that the limitation of R's numerical accuracy may get in the way of determining whether the square-root is an integer. If it were integer then it should equal floor(n) : (1.677721599849e+29)^(1/2) - floor((1.677721599849e+29)^(1/2)) #[1] 0.125 (1.6777216e+29)^(1/2) - floor( (1.6777216e+29)^(1/2) ) #[1] 0 That's because that number was the product of two perfect squares: 16777216^(1/2) - floor( 1.6777216^(1/2) ) [1] 4095 Sorry: Meant to copy this to the response: 16777216^(1/2) - floor( 16777216^(1/2) ) [1] 0 16777216^(1/2) [1] 4096 And 10^22 = 10^11*10^11 If you know how big the original was you could round it to the correct precision but that seems too much to hope for. print( round(1.677721599849e+29, digits=10) , digits=10) #[1] 1.6777216e+29 identical( (1.6777216e+29)^(1/2) , floor( (1.6777216e+29)^(1/2) ) ) #[1] TRUE How can we overcome this problem? There are a couple of packages that support exact math on really large numbers. You need to clarify what is being requested. You definitely need to review R-FAQ 7.31 and make sure you understand it and also review ?double and ?integer -- David Winsemius Alameda, CA, USA __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius Alameda, CA, USA __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Determinant
Note that when using double precision arithmetic you cannot tell if that number is different from other numbers within 10 billion of it -- they all have the same representation. 1.677721599849e+29 == 1.677721599849e+29 + 1e10 [1] TRUE You need to use other, time consuming, methods (e.g., arbitrary precision arithmetic such as in the Rmpfr package, or some analysis) Bill Dunlap TIBCO Software wdunlap tibco.com On Thu, May 14, 2015 at 12:17 PM, Boris Steipe boris.ste...@utoronto.ca wrote: Of course the number _is_ an integer. It seems you are asking whether that integer can be exactly _represented_ on a computer? That depends on your processor (eg. 32/64 bit) and the size of the number; alternatively you could calculate with arbitrary precision with the Rmpfr package. For more insights, have a look at Pat Burs' summary of number representation in R ( http://www.burns-stat.com/documents/tutorials/impatient-r/more-r-key-objects/more-r-numbers/) and/or read chapter one of his R inferno. Or, maybe you can state more clearly what you are trying to achieve in the end, there might be other options. Cheers, B. On May 14, 2015, at 4:44 AM, chasiot...@math.auth.gr wrote: Hello, I am Vasilis Chasiotis and I am a candidate Ph.D. student in Aristotle University of Thessaloniki in Greece. I have the following problem. I want to check if the square of a number ( for example the square of 1.677722e+29 ) is an integer. The problem is that this number is the calculation of the determinant (so the number should be an integer) of a matrix 22x22, which means it has an approximation ( the real number is 1.6777216e+29 but R gives to me 1.677721599849e+29 ), because R use LU-decomposition to calculate the determinant. That means that the radical of the number 1.677721599849e+29 is not an integer, but it should be. How can we overcome this problem? Thank you in advance. I look forward to hearing from you soon. Vasilis Chasiotis __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R-es] comportamiento de data.table al hacer calculos por grupos
Holap. Reproduje tu ejemplo y ciertamente las filas se duplican innecesariamente. No supe cómo corregir este comportamiento. Si no se pudiera arreglar esto, por favor considera la librería sqldf y obtendrás el resultado correcto: sqldf(select sol, dia, con, avg(media) as ave from dd group by sol, dia, con) sol dia con ave 1 con 1 0 -29.37000 2 con 2 0 -31.65000 3 con 3 0 -28.25000 ... donde dd es tu conjunto de datos. Salud. 2015-05-14 20:00 GMT-03:00 eric ericconchamu...@gmail.com: Estimada comunidad tengo un problema del que no encuentro datos que me ayuden mucho en la web. Estoy haciendo calculos por grupos con data,table. Tengo un archivo (zp.res) con tres columnas que clasifican los datos (sol, con, dia) y una columna de datos numericos (media), de la siguiente forma: sol con dia media 1: con 0 1 -22.6 2: con 0 1 -36.6 3: con 0 1 -35.6 y quiero calcular el promedio de media (la col 4) agrupando con las variables sol,con,dia. Lo hago de la siguiente forma: med - zp.res[, mean(media), by=sol,dia,con] cuando reviso med esta todo bien, se han calculado las medias y el objeto tiene solo las filas que corresponden a los promedios con sus respectivas columnas sol,con,dia que los identifican. Pero como notaran por el codigo, la columna con el resultado no tiene un nombre asi es que R la bautiza como V1. Quise ponele un nombre y agregue este al codigo de la siguiente forma: med - zp.res[, ave:=mean(media), by=sol,dia,con] el problema es que ahora el objeto med tiene el mismo numero de filas que zp.res y repite el promedio para cada dato dentro del grupo obtenido con by=sol,dia,con. Esto no me sirve pues tengo que graficar los promedios ... m puede que mi explicacion sea algo confusa, espero que me entiendan. Encontre que luego puedo renombrar la columna, pero no lo quiero hacer, pues pienso que deberia ser estandar poder ponerle el nombre y que se construya bien el objeto con los promedios inmediatamente. Ademas el promedio es solo uno de los calculos que debo hacer y los otros tambien quedan con el nombre V1 en la mismo data.table. Alguna idea de como hacerlo ? Adjunto archivo con datos. Saludos y gracias, eric. -- Forest Engineer Master in Environmental and Natural Resource Economics Ph.D. student in Sciences of Natural Resources at La Frontera University Member in AguaDeTemu2030, citizen movement for Temuco with green city standards for living Nota: Las tildes se han omitido para asegurar compatibilidad con algunos lectores de correo. ___ R-help-es mailing list R-help-es@r-project.org https://stat.ethz.ch/mailman/listinfo/r-help-es -- «No soy aquellas sombras tutelares que honré con versos que no olvida el tiempo.» JL Borges [[alternative HTML version deleted]] ___ R-help-es mailing list R-help-es@r-project.org https://stat.ethz.ch/mailman/listinfo/r-help-es
Re: [R] Deparse substitute assign with list elements
You could use a 'replacement function' named 'bar-', whose last argument is called 'value', and use bar(variable) - newValue where you currently use foo(variable, newValue). bar - function(x) { x + 3 } `bar-` - function(x, value) { bar(value) } a - NA bar(a) - 4 a # [1] 7 b - list(NA, NA) bar(b[[1]]) - 4 b #[[1]] #[1] 7 # #[[2]] #[1] NA Bill Dunlap TIBCO Software wdunlap tibco.com On Thu, May 14, 2015 at 11:28 AM, soeren.vo...@posteo.ch wrote: Hello, When I use function `foo` with list elements (example 2), it defines a new object named `b[[1]]`, which is not what I want. How can I change the function code to show the desired behaviour for all data structures passed to the function? Or is there a more appropriate way to sort of pass by references in a function? Thanks Sören src bar - function(x) { return( x + 3 ) } foo - function(x, value) { nm - deparse(substitute(x)) tmp - bar( value ) assign(nm, tmp, parent.frame()) } # 1) a - NA foo(a, 4) a # 7, fine :-) # 2) b - list(NA, NA) foo(b[[1]], 4) # the first list item should be 7 b # wanted 7 but still list with two NAs :-( /src __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R-es] comportamiento de data.table al hacer calculos por grupos
Estimada comunidad tengo un problema del que no encuentro datos que me ayuden mucho en la web. Estoy haciendo calculos por grupos con data,table. Tengo un archivo (zp.res) con tres columnas que clasifican los datos (sol, con, dia) y una columna de datos numericos (media), de la siguiente forma: sol con dia media 1: con 0 1 -22.6 2: con 0 1 -36.6 3: con 0 1 -35.6 y quiero calcular el promedio de media (la col 4) agrupando con las variables sol,con,dia. Lo hago de la siguiente forma: med - zp.res[, mean(media), by=sol,dia,con] cuando reviso med esta todo bien, se han calculado las medias y el objeto tiene solo las filas que corresponden a los promedios con sus respectivas columnas sol,con,dia que los identifican. Pero como notaran por el codigo, la columna con el resultado no tiene un nombre asi es que R la bautiza como V1. Quise ponele un nombre y agregue este al codigo de la siguiente forma: med - zp.res[, ave:=mean(media), by=sol,dia,con] el problema es que ahora el objeto med tiene el mismo numero de filas que zp.res y repite el promedio para cada dato dentro del grupo obtenido con by=sol,dia,con. Esto no me sirve pues tengo que graficar los promedios ... m puede que mi explicacion sea algo confusa, espero que me entiendan. Encontre que luego puedo renombrar la columna, pero no lo quiero hacer, pues pienso que deberia ser estandar poder ponerle el nombre y que se construya bien el objeto con los promedios inmediatamente. Ademas el promedio es solo uno de los calculos que debo hacer y los otros tambien quedan con el nombre V1 en la mismo data.table. Alguna idea de como hacerlo ? Adjunto archivo con datos. Saludos y gracias, eric. -- Forest Engineer Master in Environmental and Natural Resource Economics Ph.D. student in Sciences of Natural Resources at La Frontera University Member in AguaDeTemu2030, citizen movement for Temuco with green city standards for living Nota: Las tildes se han omitido para asegurar compatibilidad con algunos lectores de correo. ,sol,con,dia,media,ds,num,med,ave 1,con,0,1,-22.6,-22.6,1,-29.37,-29.37 2,con,0,1,-36.6,-36.6,1,-29.37,-29.37 3,con,0,1,-35.6,-35.6,1,-29.37,-29.37 4,con,0,1,-27.1,-27.1,1,-29.37,-29.37 5,con,0,1,-25.5,-25.5,1,-29.37,-29.37 6,con,0,1,-28.9,-28.9,1,-29.37,-29.37 7,con,0,1,-30.8,-30.8,1,-29.37,-29.37 8,con,0,1,-31.4,-31.4,1,-29.37,-29.37 9,con,0,1,-29.3,-29.3,1,-29.37,-29.37 10,con,0,1,-25.9,-25.9,1,-29.37,-29.37 11,dec,1,1,-25.1,-25.1,1,-30.35,-30.35 12,dec,1,1,-23.8,-23.8,1,-30.35,-30.35 13,dec,1,1,-25.2,-25.2,1,-30.35,-30.35 14,dec,1,1,-24.2,-24.2,1,-30.35,-30.35 15,dec,1,1,-24.8,-24.8,1,-30.35,-30.35 16,dec,1,1,-29.3,-29.3,1,-30.35,-30.35 17,dec,1,1,-35.5,-35.5,1,-30.35,-30.35 18,dec,1,1,-38.3,-38.3,1,-30.35,-30.35 19,dec,1,1,-39.3,-39.3,1,-30.35,-30.35 20,dec,1,1,-38,-38,1,-30.35,-30.35 21,dec,3,1,-38.8,-38.8,1,-37.15,-37.15 22,dec,3,1,-36.9,-36.9,1,-37.15,-37.15 23,dec,3,1,-39.2,-39.2,1,-37.15,-37.15 24,dec,3,1,-45.8,-45.8,1,-37.15,-37.15 25,dec,3,1,-31.7,-31.7,1,-37.15,-37.15 26,dec,3,1,-35,-35,1,-37.15,-37.15 27,dec,3,1,-36.4,-36.4,1,-37.15,-37.15 28,dec,3,1,-34.4,-34.4,1,-37.15,-37.15 29,dec,3,1,-36.8,-36.8,1,-37.15,-37.15 30,dec,3,1,-36.5,-36.5,1,-37.15,-37.15 31,dec,5,1,-30.2,-30.2,1,-31.55,-31.55 32,dec,5,1,-35.6,-35.6,1,-31.55,-31.55 33,dec,5,1,-38.9,-38.9,1,-31.55,-31.55 34,dec,5,1,-20.1,-20.1,1,-31.55,-31.55 35,dec,5,1,-32,-32,1,-31.55,-31.55 36,dec,5,1,-27.8,-27.8,1,-31.55,-31.55 37,dec,5,1,-33.2,-33.2,1,-31.55,-31.55 38,dec,5,1,-34.1,-34.1,1,-31.55,-31.55 39,dec,5,1,-35.4,-35.4,1,-31.55,-31.55 40,dec,5,1,-28.2,-28.2,1,-31.55,-31.55 41,dol,1,1,-22.5,-22.5,1,-24.02,-24.02 42,dol,1,1,-20.7,-20.7,1,-24.02,-24.02 43,dol,1,1,-22.6,-22.6,1,-24.02,-24.02 44,dol,1,1,-21.2,-21.2,1,-24.02,-24.02 45,dol,1,1,-21.5,-21.5,1,-24.02,-24.02 46,dol,1,1,-21.5,-21.5,1,-24.02,-24.02 47,dol,1,1,-21.9,-21.9,1,-24.02,-24.02 48,dol,1,1,-26.4,-26.4,1,-24.02,-24.02 49,dol,1,1,-34.8,-34.8,1,-24.02,-24.02 50,dol,1,1,-27.1,-27.1,1,-24.02,-24.02 51,dol,3,1,-23.4,-23.4,1,-32.95,-32.95 52,dol,3,1,-33.6,-33.6,1,-32.95,-32.95 53,dol,3,1,-30.8,-30.8,1,-32.95,-32.95 54,dol,3,1,-26.6,-26.6,1,-32.95,-32.95 55,dol,3,1,-33.3,-33.3,1,-32.95,-32.95 56,dol,3,1,-31.7,-31.7,1,-32.95,-32.95 57,dol,3,1,-38.2,-38.2,1,-32.95,-32.95 58,dol,3,1,-38.3,-38.3,1,-32.95,-32.95 59,dol,3,1,-38.3,-38.3,1,-32.95,-32.95 60,dol,3,1,-35.3,-35.3,1,-32.95,-32.95 61,dol,5,1,-31.8,-31.8,1,-34.95,-34.95 62,dol,5,1,-39,-39,1,-34.95,-34.95 63,dol,5,1,-36.4,-36.4,1,-34.95,-34.95 64,dol,5,1,-34.7,-34.7,1,-34.95,-34.95 65,dol,5,1,-32.9,-32.9,1,-34.95,-34.95 66,dol,5,1,-33.6,-33.6,1,-34.95,-34.95 67,dol,5,1,-38,-38,1,-34.95,-34.95 68,dol,5,1,-32.7,-32.7,1,-34.95,-34.95 69,dol,5,1,-36,-36,1,-34.95,-34.95 70,dol,5,1,-34.4,-34.4,1,-34.95,-34.95 71,lim,1,1,-34.5,-34.5,1,-31.55,-31.55 72,lim,1,1,-30.8,-30.8,1,-31.55,-31.55 73,lim,1,1,-33.3,-33.3,1,-31.55,-31.55 74,lim,1,1,-29.6,-29.6,1,-31.55,-31.55 75,lim,1,1,-21.8,-21.8,1,-31.55,-31.55
Re: [R] Reading access file
Be sure to use the 32bit version of R with the code below. This is a limitation of the ODBC driver for mdb files. If you use the odbcConnectAccess2007() function to connect to accdb files then you can use 64bit R. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. 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. On May 14, 2015 1:58:38 PM PDT, Wensui Liu liuwen...@gmail.com wrote: mdbConnect-odbcConnectAccess(C:\\temp\\demo.mdb); sqlTables(mdbConnect); demo-sqlFetch(mdbConnect, tblDemo); odbcClose(mdbConnect); rm(demo); On Thu, May 14, 2015 at 6:31 AM, silvano silv...@uel.br wrote: Hello everybody. I have a access file to read in R but I can’t to do this. I used Hmisc package, but it doesn’t work. Someone has the commands to read this kind of file? I attached the access file. Thanks. Silvano. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- == WenSui Liu Credit Risk Manager, 53 Bancorp wensui@53.com 513-295-4370 == [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Interpreting GLM Interaction Contrasts in R (using glht)
Hello, I am trying to do a BACI analysis on count data, and I am having trouble interpreting the output from multcomp::glht. I don't understand how the contrast's coefficients are related to effect size (if at all??). I have 5 treatment conditions (one is a control), and I have counts from before the treatments were applied and after. Let's say that my model form is this (Period is the 'before' vs 'after' factor): m.pois - glm(Y_count ~ Treatment + Period + Treatment:Period, data = df.temp, family = poisson) As in all BACI designs, I am interested in the interaction term, i.e., the differences of the differences. For example, I'd like to test whether TreatmentVR30 changed more than the Control did: (TreatmentVR30Later - TreatmentVR30Before) - (ControlLater - ControlBefore). I have done the math, and I created all my planned contrasts, run them through the multcomp::glht, and I am struggling to interpret the output. As an example of my confusion, I ran the same contrast in two directions (A-B and B-A), which should give the same result (one positive, one negative): contr - rbind( VR30 vs Control = c(0, 0, 0, 0, 0, 0, -1, 0, 0, 1), Control vs VR30 = c(0, 0, 0, 0, 0, 0, 1, 0, 0, -1) ) m.pois.contr - summary(glht(m.pois, contr)) which works perfectly, returning one positive and one negative estimate, as expected: Linear Hypotheses: Estimate Std. Error z value Pr(|z|) VR30 vs Control == 0 0.7354 0.5621 1.3080.191 Control vs VR30 == 0 -0.7354 0.5621 -1.3080.191 (Adjusted p values reported -- single-step method) Understanding that the estimates are in log space (due to the link function of the poisson family in the glm), I back transformed using exp(coef(m.pois.contr) to get: VR30 vs Control Control vs VR30 2.0862414 0.4793309 So, which is it? Did Control change more than VR30, or did VR30 change more than Control, and for both questions, by how much? Clearly I am missing something here. I expect that this will be a simple fix, but surprisingly, I cannot find it anywhere online. Thanks in advance to anyone who can help, David Robichaud, Victoria, BC, Canada __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R-es] comportamiento de data.table al hacer calculos por grupos
Hola, Puedes crear las dos nuevas variables (media y desviación) y ordenar así: med - datIn[, .(vmed=mean(media), vstd=sd(media)), by=.(sol,dia,con)][order(sol,dia)] head(med) sol dia con vmed vstd 1: con 1 0 -29.37 4.415641 2: con 2 0 -31.65 3.178487 3: con 3 0 -28.25 1.485672 4: con 4 0 -26.17 1.159550 5: con 5 0 -27.94 2.563505 6: con 6 0 -28.68 3.142823 Saludos, Carlos Ortega www.qualityexcellence.es El 15 de mayo de 2015, 3:00, eric ericconchamu...@gmail.com escribió: Muchas gracias Freddy y Carlos ... estuve intentando con .() y con list(), para calcular la media y el error estandar al mismo tiempo en dos columnas, pero me arrojaba un error que no supe interpretar. Ahora ya funciona como sugiere Carlos. Muchas gracias de nuevo. Saludos, Eric. On 14/05/15 19:28, Carlos Ortega wrote: Hola, La forma de hacerlo con data.table es esta: library(data.table) datIn - fread(zp.res) med - datIn[, .(vmed=mean(media)), by=.(sol,dia,con)] head(med) sol dia con vmed 1: con 1 0 -29.37 2: dec 1 1 -30.35 3: dec 1 3 -37.15 4: dec 1 5 -31.55 5: dol 1 1 -24.02 6: dol 1 3 -32.95 * La solución que has empleado actualiza el valor de una columna. Y aunque te calcula el valor medio por grupo, lo adjunta al data.table original. * En cambio esta otra forma se calcula únicamente el valor medio por grupo. Y bueno si quieres ordenar para que salga el mismo orden que en sqldf, puedes hacer esto otro: setorder(med, sol, dia) head(med) sol dia con vmed 1: con 1 0 -29.37 2: con 2 0 -31.65 3: con 3 0 -28.25 4: con 4 0 -26.17 5: con 5 0 -27.94 6: con 6 0 -28.68 Saludos, Carlos Ortega www.qualiytexcellence.es http://www.qualiytexcellence.es El 15 de mayo de 2015, 1:00, eric ericconchamu...@gmail.com mailto:ericconchamu...@gmail.com escribió: Estimada comunidad tengo un problema del que no encuentro datos que me ayuden mucho en la web. Estoy haciendo calculos por grupos con data,table. Tengo un archivo (zp.res) con tres columnas que clasifican los datos (sol, con, dia) y una columna de datos numericos (media), de la siguiente forma: sol con dia media 1: con 0 1 -22.6 2: con 0 1 -36.6 3: con 0 1 -35.6 y quiero calcular el promedio de media (la col 4) agrupando con las variables sol,con,dia. Lo hago de la siguiente forma: med - zp.res[, mean(media), by=sol,dia,con] cuando reviso med esta todo bien, se han calculado las medias y el objeto tiene solo las filas que corresponden a los promedios con sus respectivas columnas sol,con,dia que los identifican. Pero como notaran por el codigo, la columna con el resultado no tiene un nombre asi es que R la bautiza como V1. Quise ponele un nombre y agregue este al codigo de la siguiente forma: med - zp.res[, ave:=mean(media), by=sol,dia,con] el problema es que ahora el objeto med tiene el mismo numero de filas que zp.res y repite el promedio para cada dato dentro del grupo obtenido con by=sol,dia,con. Esto no me sirve pues tengo que graficar los promedios ... m puede que mi explicacion sea algo confusa, espero que me entiendan. Encontre que luego puedo renombrar la columna, pero no lo quiero hacer, pues pienso que deberia ser estandar poder ponerle el nombre y que se construya bien el objeto con los promedios inmediatamente. Ademas el promedio es solo uno de los calculos que debo hacer y los otros tambien quedan con el nombre V1 en la mismo data.table. Alguna idea de como hacerlo ? Adjunto archivo con datos. Saludos y gracias, eric. -- Forest Engineer Master in Environmental and Natural Resource Economics Ph.D. student in Sciences of Natural Resources at La Frontera University Member in AguaDeTemu2030, citizen movement for Temuco with green city standards for living Nota: Las tildes se han omitido para asegurar compatibilidad con algunos lectores de correo. ___ R-help-es mailing list R-help-es@r-project.org mailto:R-help-es@r-project.org https://stat.ethz.ch/mailman/listinfo/r-help-es -- Saludos, Carlos Ortega www.qualityexcellence.es http://www.qualityexcellence.es -- Forest Engineer Master in Environmental and Natural Resource Economics Ph.D. student in Sciences of Natural Resources at La Frontera University Member in AguaDeTemu2030, citizen movement for Temuco with green city standards for living Nota: Las tildes se han omitido para asegurar compatibilidad con algunos lectores de correo. -- Saludos, Carlos Ortega www.qualityexcellence.es [[alternative HTML version deleted]] ___ R-help-es mailing list R-help-es@r-project.org
Re: [R-es] comportamiento de data.table al hacer calculos por grupos
Hola, La forma de hacerlo con data.table es esta: library(data.table) datIn - fread(zp.res) med - datIn[, .(vmed=mean(media)), by=.(sol,dia,con)] head(med) sol dia con vmed 1: con 1 0 -29.37 2: dec 1 1 -30.35 3: dec 1 3 -37.15 4: dec 1 5 -31.55 5: dol 1 1 -24.02 6: dol 1 3 -32.95 - La solución que has empleado actualiza el valor de una columna. Y aunque te calcula el valor medio por grupo, lo adjunta al data.table original. - En cambio esta otra forma se calcula únicamente el valor medio por grupo. Y bueno si quieres ordenar para que salga el mismo orden que en sqldf, puedes hacer esto otro: setorder(med, sol, dia) head(med) sol dia con vmed 1: con 1 0 -29.37 2: con 2 0 -31.65 3: con 3 0 -28.25 4: con 4 0 -26.17 5: con 5 0 -27.94 6: con 6 0 -28.68 Saludos, Carlos Ortega www.qualiytexcellence.es El 15 de mayo de 2015, 1:00, eric ericconchamu...@gmail.com escribió: Estimada comunidad tengo un problema del que no encuentro datos que me ayuden mucho en la web. Estoy haciendo calculos por grupos con data,table. Tengo un archivo (zp.res) con tres columnas que clasifican los datos (sol, con, dia) y una columna de datos numericos (media), de la siguiente forma: sol con dia media 1: con 0 1 -22.6 2: con 0 1 -36.6 3: con 0 1 -35.6 y quiero calcular el promedio de media (la col 4) agrupando con las variables sol,con,dia. Lo hago de la siguiente forma: med - zp.res[, mean(media), by=sol,dia,con] cuando reviso med esta todo bien, se han calculado las medias y el objeto tiene solo las filas que corresponden a los promedios con sus respectivas columnas sol,con,dia que los identifican. Pero como notaran por el codigo, la columna con el resultado no tiene un nombre asi es que R la bautiza como V1. Quise ponele un nombre y agregue este al codigo de la siguiente forma: med - zp.res[, ave:=mean(media), by=sol,dia,con] el problema es que ahora el objeto med tiene el mismo numero de filas que zp.res y repite el promedio para cada dato dentro del grupo obtenido con by=sol,dia,con. Esto no me sirve pues tengo que graficar los promedios ... m puede que mi explicacion sea algo confusa, espero que me entiendan. Encontre que luego puedo renombrar la columna, pero no lo quiero hacer, pues pienso que deberia ser estandar poder ponerle el nombre y que se construya bien el objeto con los promedios inmediatamente. Ademas el promedio es solo uno de los calculos que debo hacer y los otros tambien quedan con el nombre V1 en la mismo data.table. Alguna idea de como hacerlo ? Adjunto archivo con datos. Saludos y gracias, eric. -- Forest Engineer Master in Environmental and Natural Resource Economics Ph.D. student in Sciences of Natural Resources at La Frontera University Member in AguaDeTemu2030, citizen movement for Temuco with green city standards for living Nota: Las tildes se han omitido para asegurar compatibilidad con algunos lectores de correo. ___ R-help-es mailing list R-help-es@r-project.org https://stat.ethz.ch/mailman/listinfo/r-help-es -- Saludos, Carlos Ortega www.qualityexcellence.es [[alternative HTML version deleted]] ___ R-help-es mailing list R-help-es@r-project.org https://stat.ethz.ch/mailman/listinfo/r-help-es
[R] Using iconv from glibc
The R Installation and Administration manual section A.1 states that glibc should provide a suitable iconv function, but I can't get R's configure script to accept/validate iconv on a platform I need to support using glibc 2.20. Is glibc is actually compatible (or if gnu libiconv is essentially the only path)? If glibc should work, what should I check to troubleshoot my environment? The configure error I get is checking iconv.h usability... yes checking iconv.h presence... yes checking for iconv.h... yes checking for iconv... yes checking whether iconv accepts UTF-8, latin1, ASCII and UCS-*... no configure: error: a suitable iconv is essential My full list of installed glibc / libc packages is glibc-binary-localedata-en-gb - 2.20-r0 glibc-binary-localedata-en-us - 2.20-r0 glibc-gconv - 2.20-r0 glibc-gconv-utf-16 - 2.20-r0 glibc-locale-en-gb - 2.20-r0 libc6 - 2.20-r0 libc6-dev - 2.20-r0 libc6-extra-nss - 2.20-r0 libc6-thread-db - 2.20-r0 Notice to recipient: This email is meant for only the intended recipient of the transmission, and may be a communication privileged by law, subject to export control restrictions or that otherwise contains proprietary information. If you receive this email by mistake, please notify us immediately by replying to this message and then destroy it and do not review, disclose, copy or distribute it. Thank you in advance for your cooperation. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Using iconv from glibc
This belongs on R-devel. Read the Posting Guide, which also warns you to post in plain text (for less confusion and a better reception). --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. 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. On May 14, 2015 4:13:28 PM PDT, Smith, Virgil virgil.sm...@flir.com wrote: The R Installation and Administration manual section A.1 states that glibc should provide a suitable iconv function, but I can't get R's configure script to accept/validate iconv on a platform I need to support using glibc 2.20. Is glibc is actually compatible (or if gnu libiconv is essentially the only path)? If glibc should work, what should I check to troubleshoot my environment? The configure error I get is checking iconv.h usability... yes checking iconv.h presence... yes checking for iconv.h... yes checking for iconv... yes checking whether iconv accepts UTF-8, latin1, ASCII and UCS-*... no configure: error: a suitable iconv is essential My full list of installed glibc / libc packages is glibc-binary-localedata-en-gb - 2.20-r0 glibc-binary-localedata-en-us - 2.20-r0 glibc-gconv - 2.20-r0 glibc-gconv-utf-16 - 2.20-r0 glibc-locale-en-gb - 2.20-r0 libc6 - 2.20-r0 libc6-dev - 2.20-r0 libc6-extra-nss - 2.20-r0 libc6-thread-db - 2.20-r0 Notice to recipient: This email is meant for only the intended recipient of the transmission, and may be a communication privileged by law, subject to export control restrictions or that otherwise contains proprietary information. If you receive this email by mistake, please notify us immediately by replying to this message and then destroy it and do not review, disclose, copy or distribute it. Thank you in advance for your cooperation. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R-es] comportamiento de data.table al hacer calculos por grupos
Muchas gracias Freddy y Carlos ... estuve intentando con .() y con list(), para calcular la media y el error estandar al mismo tiempo en dos columnas, pero me arrojaba un error que no supe interpretar. Ahora ya funciona como sugiere Carlos. Muchas gracias de nuevo. Saludos, Eric. On 14/05/15 19:28, Carlos Ortega wrote: Hola, La forma de hacerlo con data.table es esta: library(data.table) datIn - fread(zp.res) med - datIn[, .(vmed=mean(media)), by=.(sol,dia,con)] head(med) sol dia con vmed 1: con 1 0 -29.37 2: dec 1 1 -30.35 3: dec 1 3 -37.15 4: dec 1 5 -31.55 5: dol 1 1 -24.02 6: dol 1 3 -32.95 * La solución que has empleado actualiza el valor de una columna. Y aunque te calcula el valor medio por grupo, lo adjunta al data.table original. * En cambio esta otra forma se calcula únicamente el valor medio por grupo. Y bueno si quieres ordenar para que salga el mismo orden que en sqldf, puedes hacer esto otro: setorder(med, sol, dia) head(med) sol dia con vmed 1: con 1 0 -29.37 2: con 2 0 -31.65 3: con 3 0 -28.25 4: con 4 0 -26.17 5: con 5 0 -27.94 6: con 6 0 -28.68 Saludos, Carlos Ortega www.qualiytexcellence.es http://www.qualiytexcellence.es El 15 de mayo de 2015, 1:00, eric ericconchamu...@gmail.com mailto:ericconchamu...@gmail.com escribió: Estimada comunidad tengo un problema del que no encuentro datos que me ayuden mucho en la web. Estoy haciendo calculos por grupos con data,table. Tengo un archivo (zp.res) con tres columnas que clasifican los datos (sol, con, dia) y una columna de datos numericos (media), de la siguiente forma: sol con dia media 1: con 0 1 -22.6 2: con 0 1 -36.6 3: con 0 1 -35.6 y quiero calcular el promedio de media (la col 4) agrupando con las variables sol,con,dia. Lo hago de la siguiente forma: med - zp.res[, mean(media), by=sol,dia,con] cuando reviso med esta todo bien, se han calculado las medias y el objeto tiene solo las filas que corresponden a los promedios con sus respectivas columnas sol,con,dia que los identifican. Pero como notaran por el codigo, la columna con el resultado no tiene un nombre asi es que R la bautiza como V1. Quise ponele un nombre y agregue este al codigo de la siguiente forma: med - zp.res[, ave:=mean(media), by=sol,dia,con] el problema es que ahora el objeto med tiene el mismo numero de filas que zp.res y repite el promedio para cada dato dentro del grupo obtenido con by=sol,dia,con. Esto no me sirve pues tengo que graficar los promedios ... m puede que mi explicacion sea algo confusa, espero que me entiendan. Encontre que luego puedo renombrar la columna, pero no lo quiero hacer, pues pienso que deberia ser estandar poder ponerle el nombre y que se construya bien el objeto con los promedios inmediatamente. Ademas el promedio es solo uno de los calculos que debo hacer y los otros tambien quedan con el nombre V1 en la mismo data.table. Alguna idea de como hacerlo ? Adjunto archivo con datos. Saludos y gracias, eric. -- Forest Engineer Master in Environmental and Natural Resource Economics Ph.D. student in Sciences of Natural Resources at La Frontera University Member in AguaDeTemu2030, citizen movement for Temuco with green city standards for living Nota: Las tildes se han omitido para asegurar compatibilidad con algunos lectores de correo. ___ R-help-es mailing list R-help-es@r-project.org mailto:R-help-es@r-project.org https://stat.ethz.ch/mailman/listinfo/r-help-es -- Saludos, Carlos Ortega www.qualityexcellence.es http://www.qualityexcellence.es -- Forest Engineer Master in Environmental and Natural Resource Economics Ph.D. student in Sciences of Natural Resources at La Frontera University Member in AguaDeTemu2030, citizen movement for Temuco with green city standards for living Nota: Las tildes se han omitido para asegurar compatibilidad con algunos lectores de correo. ___ R-help-es mailing list R-help-es@r-project.org https://stat.ethz.ch/mailman/listinfo/r-help-es
Re: [R] Cross correlation between two time series over nested time periods?
On 2015-05-14 , at 02:11, Tim via R-help r-help@r-project.org wrote: Hello Tim, Re: I have two time series Calculate and plot cross correlation between two time series over nested time periods. Each point in either time series is for a week (not exactly a calendar week, but the first week in a calendar year always starts from Jan 1, and the other weeks in the same year follow that, and the last week of the year may contain more than 7 days but no more than 13 days). The first time series A is stored in a compressed (.gz) text file, which looks like (each week and the corresponding time series value are separated by a comma in a line): week,value 20060101-20060107,0 20060108-20060114,5 ... 20061217-20061223,0 20061224-20061230,0 20070101-20070107,0 20070108-20070114,4 ... 20150903-20150909,0 20150910-20150916,1 The second time series B is similarly stored in a compressed (.gz) text file, but over a subset of period of A, which looks like: week,value 20130122-20130128,509 20130129-20130204,204 ... 20131217-20131223,150 20131224-20131231,148.0 20140101-20140107,365.0 20140108-20140114,45.0 ... 20150305-20150311,0 20150312-20150318,364 I wonder how to calculate the cross correlation between the two time series A and B (up to a specified maximum lag), and plot A and B in a single plot? The auto- and crosscorrelation functions are in the stats package: acf(x, lag.max = NULL, type = c(correlation, covariance, partial), plot = TRUE, na.action = na.fail, demean = TRUE, ...) ccf(x, y, lag.max = NULL, type = c(correlation, covariance), plot = TRUE, na.action = na.fail, ...) See further: ?ccf Succes and Best wishes, Frank --- Franklin Bretschneider Dept of Biology Utrecht University brets...@xs4all.nl __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.