Re: [R] remove axes on barp from plotrix
On 01/19/2014 07:48 AM, Chrisee wrote: Hello guys, I'm using the barp function from the plotrix package, which works really really great. Unfortunately, I need a finer spacing of the labels on the y - axis. Is there any way to control this? Looking at the documentation of barp, it seems to be done rather automatically. An option would be to not plot axes at all from barp, and add them later by using axes(), which I was not able to get to work.. I tried axes=FALSE, and yaxt=n, and par settings: yaxp = c(a,b,n), all of which did not work. Hi Chrisee, Look at the arguments height.at and height.lab. These allow the user to place tick marks and labels anywhere on the Y axis (height.at) and define the labels (height.lab) much like the axis function. Check the first example on the help page to see how it is done. Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] remove axes on barp from plotrix
Thanks, Jim! Well, I just don't know how I didn't see / get that. :-) Thank you very much. -- View this message in context: http://r.789695.n4.nabble.com/remove-axes-on-barp-from-plotrix-tp4683808p4683824.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Discussion board
Hi 1-I cannot find a way to add a topic in the discussion board. 2-I have written and tested the script gemonitor.R in RGUI and it works fine; however when I run the source(http://spark-public.s3.amazonaws.com/compdata/scripts/getmonitor-test.R;) getmonitor.testscript() I get the following error message Error in data$sulfate : $ operator is invalid for atomic vectors In addition: Warning message: In getmonitor.testscript() : NAs introduced by coercion I cannot understand why. My gmonitor.R script is as follows. # getmonitor.R getmonitor- function(id, directory,summerize=FALSE) { xid-toString(id) xid-paste(000,xid,sep=) xid-substr(xid, nchar(xid)-2,nchar(xid)) f-sub( ,,paste(xid,.csv,sep=)) f-sub( ,,paste(directory, /,f,sep=)) ff-read.csv(f) print(ff) if (summerize == TRUE){ print(summary(ff)) } } 3-What should I submit, the output file or the code? Thanks Farhad [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Non-ACSII characters in R on Windows
On 13-09-17 9:01 AM, Duncan Murdoch wrote: On 13-09-17 8:15 AM, Milan Bouchet-Valat wrote: Le lundi 16 septembre 2013 à 20:04 +0400, Maxim Linchits a écrit : Here is that old post: http://r.789695.n4.nabble.com/read-csv-and-FileEncoding-in-Windows-version-of-R-2-13-0-td3567177.html A taste: Again, the issue is that opening this UTF-8 encoded file under R 2.13.0 yields an error, but opening it under R 2.12.2 works without any issues. (...) I have tried with R 2.12.2 both 32 and 64 bit on Windows Server 2008 with the French (CP1252) locale, and I still experience an error with the test case I provided in previous messages. So it does not sound like it is the same issue. I can reproduce the error with a file sent to me by Maxim. From a quick look, I suspect that changes will be needed to read.table to handle this, and they'll be large enough that they won't make it into 3.0.2, but hopefully will go into R-patched after the release. This took a lot longer than expected, but some changes are now in R-devel (as of r64831). Files that can't be displayed in the local encoding are not necessarily displayed well, but they should be stored properly. Please let me know of any problems. I think the display issues can be improved, not sure about solved. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] subset every 5th row
Hi Veepsirtt, May be this helps: dat1 - structure(list(V2 = c(11109.75, 11135.15, 11105.85, 11099.75, 11055.55, 11063.45, 11045.65, 11065, 11061.2, 11070.25, 11069.3, 11076, 11081.85, 11086.4, 11086.7, 11065.6, 11071.25, 11073.15, 11077.8, 11067.7, 11061.1, 11065.9, 11069.1, 11063.3, 11070.45, 11074.4, 11069.4, 11063.65, 11067.05, 11070.1, 11074, 11069.6, 11072.65, 11073.7, 11061.35, 11064.2, 11066.85, 11078.15, 11079.65, 11079.5, 11075.9, 11066.95, 11072.55, 11068.85, 11073.5, 11067.6, 11055.3, 11053.3, 11052.65, 11047.6, 11045.25, 11028.9, 11036.15, 11034.3, 11044.05, 11030.65, 11036.6, 11039.75, 11035.35, 11019.05 )), .Names = V2, class = data.frame, row.names = c(NA, 60L )) dat1[seq(5,nrow(dat1),by=5),,drop=FALSE] #or dat1[((seq(nrow(dat1))-1)%%5+1)==5,,drop=FALSE] A.K. On Sunday, January 19, 2014 9:40 AM, veepsi...@gmail.com veepsi...@gmail.com wrote: Hi A.K sir 1,11109.75 2,11135.15 3,11105.85 4,11099.75 5,11055.55 6,11063.45 7,11045.65 8,11065 9,11061.2 10,11070.25 11,11069.3 12,11076 13,11081.85 14,11086.4 15,11086.7 16,11065.6 17,11071.25 18,11073.15 19,11077.8 20,11067.7 21,11061.1 22,11065.9 23,11069.1 24,11063.3 25,11070.45 26,11074.4 27,11069.4 28,11063.65 29,11067.05 30,11070.1 31,11074 32,11069.6 33,11072.65 34,11073.7 35,11061.35 36,11064.2 37,11066.85 38,11078.15 39,11079.65 40,11079.5 41,11075.9 42,11066.95 43,11072.55 44,11068.85 45,11073.5 46,11067.6 47,11055.3 48,11053.3 49,11052.65 50,11047.6 51,11045.25 52,11028.9 53,11036.15 54,11034.3 55,11044.05 56,11030.65 57,11036.6 58,11039.75 59,11035.35 60,11019.05 thanks veepsirtt _ Sent from http://r.789695.n4.nabble.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to replace NA values
Dear R community  I have a large data set contain some empty cells. Because of that, may be I am wrong, NA values are produced. Now I want replace both empty and NA values with zero.  Elder1 - data.frame(  ID=c(ID1,ID2,ID3,ID6,ID8),  age=c(38,35,,NA,NA)) Output I am expecting  ID  age ID1 38 ID2 35 ID3 0 ID6 0 ID8 0  In advance I thank your help. -- View this message in context: http://r.789695.n4.nabble.com/how-to-replace-NA-values-tp4683831.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to replace NA values
Dear Kinsly, try http://bit.ly/1mhXOfH Although values are usually missing for some good reason. Changing them to 0 might be very dangerous, R is going to think that ID3, 6 and 8 are all newborn babies! best daniel Feladó: r-help-boun...@r-project.org [r-help-boun...@r-project.org] ; meghatalmaz#243;: kingsly [ecoking...@yahoo.co.in] Küldve: 2014. január 19. 20:39 To: r-help@r-project.org Tárgy: [R] how to replace NA values Dear R community I have a large data set contain some empty cells. Because of that, may be I am wrong, NA values are produced. Now I want replace both empty and NA values with zero. Elder1 - data.frame( ID=c(ID1,ID2,ID3,ID6,ID8), age=c(38,35,,NA,NA)) Output I am expecting ID age ID1 38 ID2 35 ID3 0 ID6 0 ID8 0 In advance I thank your help. -- View this message in context: http://r.789695.n4.nabble.com/how-to-replace-NA-values-tp4683831.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Discussion board
On Jan 18, 2014, at 7:33 PM, F. Keshavarz wrote: Hi 1-I cannot find a way to add a topic in the discussion board. Rhelp is NOT a discussion board. It is a mailing list to which you have emailed a question. You should use an informative subject line. 2-I have written and tested the script gemonitor.R in RGUI and it works fine; however when I run the source(http://spark-public.s3.amazonaws.com/compdata/scripts/getmonitor-test.R;) getmonitor.testscript() I get the following error message Error in data$sulfate : $ operator is invalid for atomic vectors In addition: Warning message: In getmonitor.testscript() : NAs introduced by coercion I cannot understand why. You obviously have run something more than just that R script. I get: getmonitor.testscript() Error in checkSanity() : directory 'specdata' not found; please change your working directory My gmonitor.R script is as follows. # getmonitor.R getmonitor- function(id, directory,summerize=FALSE) { xid-toString(id) xid-paste(000,xid,sep=) xid-substr(xid, nchar(xid)-2,nchar(xid)) f-sub( ,,paste(xid,.csv,sep=)) f-sub( ,,paste(directory, /,f,sep=)) ff-read.csv(f) print(ff) if (summerize == TRUE){ print(summary(ff)) } } 3-What should I submit, the output file or the code? You should provide a) enough background in English to let us know what you are trying to do, and b) enough code to determine what packages need to be installed and loaded, and c) enough data to allow these packages to do a) and b) [[alternative HTML version deleted]] And please do post in plain text as the Posting Guide requests. As I said above, Rhelp is an old-style mailing list, not one of those new-fangled web discussion boards. and as noted at the bottom of all postings ...\/\/\/\/\/\/\/\/\//\ PLEASE do read the posting guide http://www.R-project.org/posting-guide.html ^ and further ...\/\/\/\/\/\/\ and provide commented, minimal, self-contained, reproducible code. ^ -- David Winsemius Alameda, CA, USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] changing font size in Forest plot code.
Hi All, I have pulled the following function (fplot) from the internet, and unfortunately I do not see an author to whom I can give credit. It used grid graphics and relies mostly on package rmeta by Thomas Lumley. I am trying to make the font smaller in my labeltext, but dont see any references to font size in the code. Digitize changes the number size on the x-axis, but dont see a corresponding way of making the labeling size smaller. Using R 3.0.2 Any suggestions appreciated. Gerard Smits fplot=function (labeltext, mean, lower, upper, align = NULL, is.summary = FALSE, clip = c(-Inf, Inf), xlab = , zero = 1, graphwidth = unit(3,inches), col = meta.colors(), xlog = FALSE, xticks = NULL, xlow=0, xhigh, digitsize, boxsize, ...) { require(grid) || stop(`grid' package not found) require(rmeta) || stop(`rmeta' package not found) drawNormalCI - function(LL, OR, UL, size) { size = 0.75 * size clipupper - convertX(unit(UL, native), npc, valueOnly = TRUE) 1 cliplower - convertX(unit(LL, native), npc, valueOnly = TRUE) 0 box - convertX(unit(OR, native), npc, valueOnly = TRUE) clipbox - box 0 || box 1 if (clipupper || cliplower) { ends - both lims - unit(c(0, 1), c(npc, npc)) if (!clipupper) { ends - first lims - unit(c(0, UL), c(npc, native)) } if (!cliplower) { ends - last lims - unit(c(LL, 1), c(native, npc)) } grid.lines(x = lims, y = 0.5, arrow = arrow(ends = ends, length = unit(0.05, inches)), gp = gpar(col = col$lines)) if (!clipbox) grid.rect(x = unit(OR, native), width = unit(size, snpc), height = unit(size, snpc), gp = gpar(fill = col$box, col = col$box)) } else { grid.lines(x = unit(c(LL, UL), native), y = 0.5, gp = gpar(col = col$lines)) grid.rect(x = unit(OR, native), width = unit(size, snpc), height = unit(size, snpc), gp = gpar(fill = col$box, col = col$box)) if ((convertX(unit(OR, native) + unit(0.5 * size, lines), native, valueOnly = TRUE) UL) (convertX(unit(OR, native) - unit(0.5 * size, lines), native, valueOnly = TRUE) LL)) grid.lines(x = unit(c(LL, UL), native), y = 0.5, gp = gpar(col = col$lines)) } } drawSummaryCI - function(LL, OR, UL, size) { grid.polygon(x = unit(c(LL, OR, UL, OR), native), y = unit(0.5 + c(0, 0.5 * size, 0, -0.5 * size), npc), gp = gpar(fill = col$summary, col = col$summary)) } plot.new() widthcolumn - !apply(is.na(labeltext), 1, any) nc - NCOL(labeltext) labels - vector(list, nc) if (is.null(align)) align - c(l, rep(r, nc - 1)) else align - rep(align, length = nc) nr - NROW(labeltext) is.summary - rep(is.summary, length = nr) for (j in 1:nc) { labels[[j]] - vector(list, nr) for (i in 1:nr) { if (is.na(labeltext[i, j])) next x - switch(align[j], l = 0, r = 1, c = 0.5) just - switch(align[j], l = left, r = right, c = center) labels[[j]][[i]] - textGrob(labeltext[i, j], x = x, just = just, gp = gpar(fontface = if (is.summary[i]) bold else plain, col = rep(col$text, length = nr)[i])) } } colgap - unit(3, mm) colwidths - unit.c(max(unit(rep(1, sum(widthcolumn)), grobwidth, labels[[1]][widthcolumn])), colgap) if (nc 1) { for (i in 2:nc) colwidths - unit.c(colwidths, max(unit(rep(1, sum(widthcolumn)), grobwidth, labels[[i]][widthcolumn])), colgap) } colwidths - unit.c(colwidths, graphwidth) pushViewport(viewport(layout = grid.layout(nr + 1, nc * 2 + 1, widths = colwidths, heights = unit(c(rep(1, nr), 0.5), lines cwidth - (upper - lower) #xrange - c(max(min(lower, na.rm = TRUE), clip[1]), min(max(upper, na.rm = TRUE), clip[2])) xrange - c(xlow,xhigh) info - 1/cwidth info - info/max(info[!is.summary], na.rm = TRUE) info[is.summary] - 1 if (!is.null(boxsize)) info - rep(boxsize, length = length(info)) for (j in 1:nc) { for (i in 1:nr) { if (!is.null(labels[[j]][[i]])) { pushViewport(viewport(layout.pos.row = i, layout.pos.col = 2 * j - 1)) grid.draw(labels[[j]][[i]]) popViewport() } } } pushViewport(viewport(layout.pos.col = 2 * nc + 1, xscale = xrange)) grid.lines(x = unit(zero, native), y = 0:1, gp = gpar(col = col$zero)) if (xlog) { if (is.null(xticks))
Re: [R] changing font size in Forest plot code.
On Jan 19, 2014, at 1:13 PM, Gerard Smits wrote: Hi All, I have pulled the following function (fplot) from the internet, and unfortunately I do not see an author to whom I can give credit. It used grid graphics and relies mostly on package rmeta by Thomas Lumley. I am trying to make the font smaller in my labeltext, but don‚t see any references to font size in the code. Digitize changes the number size on the x-axis, but don‚t see a corresponding way of making the labeling size smaller. Wouldn't it just be needed to specify grid parameters (as exemplified several other places in that code) in the code where 'labels' are created? ... labels[[j]][[i]] - textGrob(labeltext[i, j], x = x, just = just, gp = gpar(fontsize=8, fontface = if (is.summary[i]) bold else plain, col = rep(col$text, length = nr)[i])) ... Seems to succeed (once the errant and quite strange double comma character '„' is removed and replaced with a proper double quote.) If you are doing this on a word processor, then you should convert to a programming text editor. -- David. Using R 3.0.2 Any suggestions appreciated. Gerard Smits fplot=function (labeltext, mean, lower, upper, align = NULL, is.summary = FALSE, clip = c(-Inf, Inf), xlab = , zero = 1, graphwidth = unit(3,inches), col = meta.colors(), xlog = FALSE, xticks = NULL, xlow=0, xhigh, digitsize, boxsize, ...) { require(grid) || stop(`grid' package not found) require(rmeta) || stop(`rmeta' package not found) drawNormalCI - function(LL, OR, UL, size) { size = 0.75 * size clipupper - convertX(unit(UL, native), npc, valueOnly = TRUE) 1 cliplower - convertX(unit(LL, native), npc, valueOnly = TRUE) 0 box - convertX(unit(OR, native), npc, valueOnly = TRUE) clipbox - box 0 || box 1 if (clipupper || cliplower) { ends - both lims - unit(c(0, 1), c(npc, npc)) if (!clipupper) { ends - first lims - unit(c(0, UL), c(npc, native)) } if (!cliplower) { ends - last lims - unit(c(LL, 1), c(native, npc)) } grid.lines(x = lims, y = 0.5, arrow = arrow(ends = ends, length = unit(0.05, inches)), gp = gpar(col = col$lines)) if (!clipbox) grid.rect(x = unit(OR, native), width = unit(size, snpc), height = unit(size, snpc), gp = gpar(fill = col$box, col = col$box)) } else { grid.lines(x = unit(c(LL, UL), native), y = 0.5, gp = gpar(col = col$lines)) grid.rect(x = unit(OR, native), width = unit(size, snpc), height = unit(size, snpc), gp = gpar(fill = col$box, col = col$box)) if ((convertX(unit(OR, native) + unit(0.5 * size, lines), native, valueOnly = TRUE) UL) (convertX(unit(OR, native) - unit(0.5 * size, lines), native, valueOnly = TRUE) LL)) grid.lines(x = unit(c(LL, UL), native), y = 0.5, gp = gpar(col = col$lines)) } } drawSummaryCI - function(LL, OR, UL, size) { grid.polygon(x = unit(c(LL, OR, UL, OR), native), y = unit(0.5 + c(0, 0.5 * size, 0, -0.5 * size), npc), gp = gpar(fill = col$summary, col = col$summary)) } plot.new() widthcolumn - !apply(is.na(labeltext), 1, any) nc - NCOL(labeltext) labels - vector(list, nc) if (is.null(align)) align - c(l, rep(r, nc - 1)) else align - rep(align, length = nc) nr - NROW(labeltext) is.summary - rep(is.summary, length = nr) for (j in 1:nc) { labels[[j]] - vector(list, nr) for (i in 1:nr) { if (is.na(labeltext[i, j])) next x - switch(align[j], l = 0, r = 1, c = 0.5) just - switch(align[j], l = left, r = right, c = center) labels[[j]][[i]] - textGrob(labeltext[i, j], x = x, just = just, gp = gpar(fontface = if (is.summary[i]) bold else plain, col = rep(col$text, length = nr)[i])) } } colgap - unit(3, mm) colwidths - unit.c(max(unit(rep(1, sum(widthcolumn)), grobwidth, labels[[1]][widthcolumn])), colgap) if (nc 1) { for (i in 2:nc) colwidths - unit.c(colwidths, max(unit(rep(1, sum(widthcolumn)), grobwidth, labels[[i]][widthcolumn])), colgap) } colwidths - unit.c(colwidths, graphwidth) pushViewport(viewport(layout = grid.layout(nr + 1, nc * 2 + 1, widths = colwidths, heights = unit(c(rep(1, nr), 0.5), lines cwidth - (upper - lower) #xrange - c(max(min(lower, na.rm = TRUE), clip[1]), min(max(upper, na.rm = TRUE), clip[2])) xrange -
Re: [R] changing font size in Forest plot code.
Hi David, That worked perfectly. I had tried something like that, but obviously messed up the change. Thanks for your help. Much appreciated. Gerard On Jan 19, 2014, at 2:16 PM, David Winsemius dwinsem...@comcast.net wrote: On Jan 19, 2014, at 1:13 PM, Gerard Smits wrote: Hi All, I have pulled the following function (fplot) from the internet, and unfortunately I do not see an author to whom I can give credit. It used grid graphics and relies mostly on package rmeta by Thomas Lumley. I am trying to make the font smaller in my labeltext, but don‚t see any references to font size in the code. Digitize changes the number size on the x-axis, but don‚t see a corresponding way of making the labeling size smaller. Wouldn't it just be needed to specify grid parameters (as exemplified several other places in that code) in the code where 'labels' are created? ... labels[[j]][[i]] - textGrob(labeltext[i, j], x = x, just = just, gp = gpar(fontsize=8, fontface = if (is.summary[i]) bold else plain, col = rep(col$text, length = nr)[i])) ... Seems to succeed (once the errant and quite strange double comma character '„' is removed and replaced with a proper double quote.) If you are doing this on a word processor, then you should convert to a programming text editor. -- David. Using R 3.0.2 Any suggestions appreciated. Gerard Smits fplot=function (labeltext, mean, lower, upper, align = NULL, is.summary = FALSE, clip = c(-Inf, Inf), xlab = , zero = 1, graphwidth = unit(3,inches), col = meta.colors(), xlog = FALSE, xticks = NULL, xlow=0, xhigh, digitsize, boxsize, ...) { require(grid) || stop(`grid' package not found) require(rmeta) || stop(`rmeta' package not found) drawNormalCI - function(LL, OR, UL, size) { size = 0.75 * size clipupper - convertX(unit(UL, native), npc, valueOnly = TRUE) 1 cliplower - convertX(unit(LL, native), npc, valueOnly = TRUE) 0 box - convertX(unit(OR, native), npc, valueOnly = TRUE) clipbox - box 0 || box 1 if (clipupper || cliplower) { ends - both lims - unit(c(0, 1), c(npc, npc)) if (!clipupper) { ends - first lims - unit(c(0, UL), c(npc, native)) } if (!cliplower) { ends - last lims - unit(c(LL, 1), c(native, npc)) } grid.lines(x = lims, y = 0.5, arrow = arrow(ends = ends, length = unit(0.05, inches)), gp = gpar(col = col$lines)) if (!clipbox) grid.rect(x = unit(OR, native), width = unit(size, snpc), height = unit(size, snpc), gp = gpar(fill = col$box, col = col$box)) } else { grid.lines(x = unit(c(LL, UL), native), y = 0.5, gp = gpar(col = col$lines)) grid.rect(x = unit(OR, native), width = unit(size, snpc), height = unit(size, snpc), gp = gpar(fill = col$box, col = col$box)) if ((convertX(unit(OR, native) + unit(0.5 * size, lines), native, valueOnly = TRUE) UL) (convertX(unit(OR, native) - unit(0.5 * size, lines), native, valueOnly = TRUE) LL)) grid.lines(x = unit(c(LL, UL), native), y = 0.5, gp = gpar(col = col$lines)) } } drawSummaryCI - function(LL, OR, UL, size) { grid.polygon(x = unit(c(LL, OR, UL, OR), native), y = unit(0.5 + c(0, 0.5 * size, 0, -0.5 * size), npc), gp = gpar(fill = col$summary, col = col$summary)) } plot.new() widthcolumn - !apply(is.na(labeltext), 1, any) nc - NCOL(labeltext) labels - vector(list, nc) if (is.null(align)) align - c(l, rep(r, nc - 1)) else align - rep(align, length = nc) nr - NROW(labeltext) is.summary - rep(is.summary, length = nr) for (j in 1:nc) { labels[[j]] - vector(list, nr) for (i in 1:nr) { if (is.na(labeltext[i, j])) next x - switch(align[j], l = 0, r = 1, c = 0.5) just - switch(align[j], l = left, r = right, c = center) labels[[j]][[i]] - textGrob(labeltext[i, j], x = x, just = just, gp = gpar(fontface = if (is.summary[i]) bold else plain, col = rep(col$text, length = nr)[i])) } } colgap - unit(3, mm) colwidths - unit.c(max(unit(rep(1, sum(widthcolumn)), grobwidth, labels[[1]][widthcolumn])), colgap) if (nc 1) { for (i in 2:nc) colwidths - unit.c(colwidths, max(unit(rep(1, sum(widthcolumn)), grobwidth, labels[[i]][widthcolumn])), colgap) } colwidths - unit.c(colwidths, graphwidth) pushViewport(viewport(layout = grid.layout(nr + 1, nc * 2 + 1, widths = colwidths, heights = unit(c(rep(1,
[R] collapsing records
I am trying to read a csv file with a date-time field. There are many rows with the same date but different times. I first want to clear the times so that rows from the same day have the same date-time field (called Date). There is another field called Text and I want to collapse all the records with the same date so that there is only one record for this date and with a text field that contains all the strings from all the corresponding text fields. At the same time I want to create a new field that has the count of how many records were collapsed for each date. There is a third field called Tw.ID and I was trying to use tapply on this field to do this. Later I will create a DocumentTermMatrix with the tm package on this dataframe. In the code below I have not figured out how to collapse the data so that there is only one record for each date and I don't really have a good way to add in a count field. Can anyone make any suggestions? Thanks. install.packages(c(tm)) library(tm) y.df=read.csv(YHOO3000.csv, header=TRUE) y.df$Date= as.POSIXlt( y.df$Date) ysub14.df=y.df ysub14.df$Date=y.df$Date -14*3600 #I pushed the record times back a little here. ysub14.df$Date=as.Date(ysub14.df$Date, %Y-%m-%d) # might want to use groups - unstack(data.frame(ysub14.df$Text,ysub14.df$Date)) # to put all the tweets for one day into a group. This makes a list # I think, with the name of the list being the Date and # the tweets for that date being stored in a vector. countgroup2=tapply(ysub14.df$Tw.ID,ysub14.df$Date,length) [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Generating weights based on certain condition in the dataset
Please delete this thread https://stat.ethz.ch/pipermail/r-help/2011-December/298414.html I already solved this problem and I forgot my login information so I am unable to login and delete this thread. Sincerely Sudhi [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] collapsing records
On 01/20/2014 11:44 AM, Bill wrote: I am trying to read a csv file with a date-time field. There are many rows with the same date but different times. I first want to clear the times so that rows from the same day have the same date-time field (called Date). There is another field called Text and I want to collapse all the records with the same date so that there is only one record for this date and with a text field that contains all the strings from all the corresponding text fields. At the same time I want to create a new field that has the count of how many records were collapsed for each date. There is a third field called Tw.ID and I was trying to use tapply on this field to do this. Later I will create a DocumentTermMatrix with the tm package on this dataframe. In the code below I have not figured out how to collapse the data so that there is only one record for each date and I don't really have a good way to add in a count field. Can anyone make any suggestions? Thanks. install.packages(c(tm)) library(tm) y.df=read.csv(YHOO3000.csv, header=TRUE) y.df$Date= as.POSIXlt( y.df$Date) ysub14.df=y.df ysub14.df$Date=y.df$Date -14*3600 #I pushed the record times back a little here. ysub14.df$Date=as.Date(ysub14.df$Date, %Y-%m-%d) # might want to use groups- unstack(data.frame(ysub14.df$Text,ysub14.df$Date)) # to put all the tweets for one day into a group. This makes a list # I think, with the name of the list being the Date and # the tweets for that date being stored in a vector. countgroup2=tapply(ysub14.df$Tw.ID,ysub14.df$Date,length) Hi Bill, Here is one way: # get some date-time strings dates-paste(2014-01-,10:15, ,sample(0:23,20), :,sample(0:60,20),:,sample(0:60,20),sep=) # function to return stupid text sillytext-function(n) { return(paste(sample(letters[1:26],n),sep=,collapse=)) } # get the stupid text ttext-sapply(rep(10,20),sillytext) # make the data frame y.df-data.frame(dates,ttext) # convert the date-time strings to dates y.df$dates- as.Date(format(as.Date(dates,%Y-%m-%d %H:%M:%S), Y-%m-%d),Y-%m-%d) library(prettyR) # stretch out all the text strings for each day y2.df-stretch_df(y.df,dates,ttext) # get the dimension of the resulting data frame ydim-dim(y2.df) # function to count the NAs nna-function(x) return(sum(is.na(x))) # add a column with a count of _not_ NAs y2.df$nrec- (ydim[2]-1)-apply(as.matrix(y2.df[,2:ydim[2]]),1,nna) Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.