[R] Date object and origin BC
hi everybody, is this intended behaviour? x - as.Date('0-01-01') as.Date(as.character(x)) [1] 0-01-01 a - x - 365 as.Date(a) [1] -1-01-01 as.Date(as.character(a)) Error in charToDate(x) : character string is not in a standard unambiguous format Is this a bug? I found this, while trying to convert dates stored as months since -2-01-01 00:00:00. For the past I extracted this first_date string and converted my data using dates - as.Date(x, origin=as.Date(first_date)) But this fails with -2-01-01 Any ideas how to solve this? thanks and best regards, Stefan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Error in sink(output.txt) : sink stack is full
hi, It is a good idea not to reply to existing messages, if you want to open a new subject. On Sun, Feb 28, 2010 at 06:33:00PM +, Amy Hessen wrote: Hi, After some runs to my program, I receive this error message: ?Error in sink(output.txt) : sink stack is full? Could you please tell me how I can avoid this message? You should close some sink connections using sink(). see ?sink regards, stefan __ 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] ggplot 'annotate problem' again.
Hi, I suggest to use geom_text to add multiple labels. Put all the information needed by for your labels in a dataframe: lab = data.frame(x=namposts+2.5, y = temprange[2], label= mlabs) and add them to the plot: p + geom_text(data=lab,aes(x,y,label=label), size=2.5,colour='black', hjust = 0, vjust = 0) regards, Stefan On Sun, Feb 28, 2010 at 01:25:15PM -0800, John Kane wrote: I had a problem annotating a graph last year ( see http://n4.nabble.com/Putting-names-on-a-ggplot-td907158.html#a907158 for the discussion) Stefan (smu) provided a solution using annotate(). However I apparently did not update the graph file and,now, when I go back to the thread and try to use Stefan's solution it does not seem to work although I am sure that it did then. The problem arises at: p + annotate(text, x=namposts+2.5, y = temprange[2], label= mlabs, size=2.5, colour='black', hjust = 0, vjust = 0) Error: When _setting_ aesthetics, they may only take one value. Problems: label I want the names of the months along the top of the graph (one month per division).It appears that I am being told that the label can only have one value. mlabs contains the 12 months of the year If this is true is there another way to annotate the graph? Unfortunately ?annotate only shows a one value entry. Any suggestions would be welcome. Code # Data is below code. #== library(ggplot2) year[,5] - 1:length(year[,1]) names(year) - c('month','days','year','temps', duration) month.days - as.vector(table(year[,1])) months - rep(month.name[1:12], month.days) month.counts - cumsum(as.vector( table(year[,1]))) namposts - c(1, month.counts[1:11]) mlabs - month.name[1:12] temprange - range(year$temps, na.rm=TRUE) p - ggplot(year, aes(duration, temps, colour=months)) + geom_line() + opts(legend.position = none, title=Yearly temperatures, axis.text.x = theme_blank(), axis.ticks = theme_blank()) p p - p + geom_vline(xintercept=month.counts) + ylab(Temperature (C)) + xlab(Daily Temperatures) p p + annotate(text, x=namposts+2.5, y = temprange[2], label= mlabs, size=2.5, colour='black', hjust = 0, vjust = 0) Data #= year - structure(list(month = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 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, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L), days = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 1L, 2L, 3L, 4L
Re: [R] simple data manipulation question
for example: d = data.frame(gender=c(m,f,unkown), x=rnorm(300)) tapply(d$x,d$gender,mean) f munkown 0.0787628409 0.0940534765 -0.0005323276 regards, stefan On Wed, Dec 09, 2009 at 04:50:37PM -0800, dolar wrote: Hi there I have a dataframe of a whole lot of variables lets say, one of my variables is gender how do I simply get an average of all other variables by gender? -- View this message in context: http://n4.nabble.com/simple-data-manipulation-question-tp956600p956600.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Replace Values in Matrix
matritz[is.na(matritz)] - 0 On Fri, Nov 27, 2009 at 04:15:45PM -0200, Romildo Martins wrote: Hello, how to replace the NA by number zero? matrizt [,1] [,2] [,3][,4] [1,] 1.000NA NA NA [2,] 0.6717685 0.1453253 NA NA [3,] 0.3971276 0.1493241 0.14532526 NA [4,] 0.1493241 0.1453253 0.06795269 0.06217967 Thanks! Romildo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Feature request for as.Date() function
hi, it fails, when the NA is surrounded by double quotes, which is the default way of quoting of the write.table command. x - read.csv(textConnection('date,value + + 2009-01-01,10 + + 2009-02-01,1 + + NA, 3'), colClasses=c(Date, 'integer')) Fehler in fromchar(x) : character string is not in a standard unambiguous format regards, stefan On Wed, Nov 25, 2009 at 02:56:56PM -0500, jim holtman wrote: Seems to work fine in my testing: x - read.csv(textConnection(date,value + 2009-01-01,10 + 2009-02-01,1 + 'NA', 3), colClasses=c(Date, 'integer')) str(x) 'data.frame': 3 obs. of 2 variables: $ date :Class 'Date' num [1:3] 14245 14276 NA $ value: int 10 1 3 x - read.csv(textConnection(date,value + 2009-01-01,10 + 2009-02-01,1 + NA, 3), colClasses=c(Date, 'integer')) str(x) 'data.frame': 3 obs. of 2 variables: $ date :Class 'Date' num [1:3] 14245 14276 NA $ value: int 10 1 3 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. On Wed, Nov 25, 2009 at 12:38 PM, nabble.30.miller_2...@spamgourmet.com wrote: Hello - I have a csv file with a few date columns. Some of the records have an NA character string instead of the date. When I attempt to use read.csv() and typecast the columns using colClasses, I receive the following error: Error in charToDate(x) : character string is not in a standard unambiguous format Similarly, the following command produces the same error: as.Date(NA) However, as.Date(NA) performs as documented. Can we enhance the as.Date() function to convert NA strings into NA value prior to type conversion? Thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Classification
Hello, x - c(3,5,7,3,9,7) as.numeric(as.factor(x)) [1] 1 2 3 1 4 3 regards, stefan On Fri, Nov 20, 2009 at 12:02:59AM -0800, Chris Li wrote: Hi all, I have got a dataset like the following: 3 5 7 3 9 7 i.e. random numbers with some repeats. I want R to classify them for me. E.g. every row that has a value of 3 will be asigned a value of 1, and every row that has a value will be asigned a value of 2 etc. I want R to return the following, using the example above: 1 2 3 1 4 3 Thanks in advance. Chris -- View this message in context: http://old.nabble.com/Classification-tp26429330p26429330.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sum over indexed value
P=data.frame(x=c(1,1,2,3,2,1),y=rnorm(6)) tapply(P$y,P$x,sum) regards, stefan On Mon, Nov 16, 2009 at 09:49:17AM -0800, Gunadi wrote: I am sure this is easy but I am not finding a function to do this. I have two columns in a matrix. The first column contains multiple entries of numbers from 1 to 100 (i.e. 10 ones, 8 twos etc.). The second column contains unique numbers. I want to sum the numbers in column two based on the indexed values in column one (e.g. sum of all values in column two associated with the value 1 in column one). I would like two columns in return - the indexed value in column one (i.e. this time no duplicates) and the sum in column two. How do I do this? -- View this message in context: http://old.nabble.com/Sum-over-indexed-value-tp26376359p26376359.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Writing a data frame in an excel file
hello, sep=\n will seperate each column by \n which is not what you want. I think a csv would be the best solution. write.table(yourdataframe,sep=,) or use write.csv directly. regards, stefan On Mon, Nov 16, 2009 at 11:49:28AM -0800, anna_l wrote: Hello, I am having trouble by using the write.table function to write a data frame of 4 columns and 7530 rows. I don´t know if I should just use a sep=\n and change the .xls file into a .csv file. Thanks in advance - Anna Lippel new in R so be careful I should be asking a lt of questions!:teeth: -- View this message in context: http://old.nabble.com/Writing-a-data-frame-in-an-excel-file-tp26378240p26378240.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] partial cumsum
Hello, I am searching for a function to calculate partial cumsums. For example it should calculate the cumulative sums until a NA appears, and restart the cumsum calculation after the NA. this: x - c(1, 2, 3, NA, 5, 6, 7, 8, 9, 10) should become this: 1 3 6 NA 5 11 18 26 35 45 any ideas? thank you and best regards, stefan __ 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] partial cumsum
On Wed, Nov 11, 2009 at 08:53:50AM -0800, William Dunlap wrote: Perhaps ave(x, rev(cumsum(rev(is.na(x, FUN=cumsum) [1] 1 3 6 NA 5 11 18 26 35 45 it takes some time to understand how it works, but it's perfect. thank you, stefan __ 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] sum two columns with same value
On Sat, Oct 17, 2009 at 09:36:50AM +0200, Alfredo Alessandrini wrote: Hi, I've two dataframe: snag_totale AREA snag_ha 12 1.628128 23 10.274249 34 2.778503 45 73.764307 57 12.015985 log_totale AREAlog_ha 11 22.29846 22 17.16889 33 48.80377 44 144.18996 55 70.30962 66 61.81850 77 13.24876 How can I obtain a new data.frame, by the sum of value snag_ha + log_ha in the same AREA? one way would be: tmp - merge(snag_totale, log_totale, by=AREA) tmp$sum - tmp$snag_ha + tmp$log_ha regards, stefan __ 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] Putting names on a ggplot
hi, On Sat, Oct 17, 2009 at 02:04:43PM -0700, John Kane wrote: Putting names on a ggplot p - p + geom_text(aes(x = namposts + 2.5, y = temprange[2], label = mlabs), data = year, size = 2.5, colour='black', hjust = 0, vjust = 0) you shouldn't use aes in this case since nampost, temprange, ... are not part of the dataframe year. It should also work with geom_text i guess, but I prefere annotate for thinks like that: p + annotate(text,x=namposts+2.5, y = temprange[2], label = mlabs,size=2.5, colour='black', hjust = 0, vjust = 0) regards, stefan __ 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] Color of graph
abline(m1, col=red) regards, Stefan On Thu, Oct 01, 2009 at 09:57:11AM -0400, Ashta wrote: I am trying to plot a line graph for 3 or more regression lines abline(m1) abline(m2) abline(m3) Can I change the color of each line? if so how? Thanks in advance Ashta [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ggplot2 graphing multiple lines of data
hey, On Mon, Sep 14, 2009 at 07:51:42AM -0700, John Kane wrote: p - ggplot(bmm, aes(x=age, y=bm, colour=pp, group=pp)) p - p + geom_line() remove the quotes and it will work: ggplot(bmm, aes(x=age, y=bm, colour=pp, group=pp))+geom_line() regards, Stefan __ 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] local sequence function
hey, I can not find a function for the following problem, hopefully you can help me. I have a vactor like this one v = c(NA,NA,TRUE,TRUE,NA,TRUE,NA,TRUE,TRUE,TRUE) and I would like to the TRUE values by the their local sequence number. This means, the result should look thike this: c(NA,NA,1,2,NA,1,NA,1,2,3) Of course I could solve the problems using a loop, but this would be much to slow, because the real vector is much larger. Can you point me in the right direction? thank you! regards, Stefan __ 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] source compile and problem with Hmisc
On Thu, Jul 23, 2009 at 12:16:36PM +0200, Stefan wrote: I want to compile R version 2.9.1 on debian stable but the make command stops with this message: ... begin installing recommended package VR Error in library(Hmisc, verbose = FALSE) : there is no package called 'Hmisc' Execution halted ... library(Hmisc, verbose=FALSE) in ~/.Rprofile was the problem. __ 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] Question on qplot
hey, On Sat, Jul 18, 2009 at 01:52:34AM -0700, RON70 wrote: Hi, suppose I have following codes : library(zoo); library(ggplot2) dat - matrix(rnorm(500*2), 500); dat - zooreg(dat, start = as.Date(01/01/01, %m/%d/%y), frequency=1); plot(dat) head(dat); month.no - format(index(dat), %m); dat1 - cbind(coredata(dat), as.numeric(month.no)) x - dat1[,1]; y - dat1[,2]; z - dat1[,3] Now I draw a qplot like : qplot(x, z) It is ok However if I reverse that like qplot(z, x) I am getting strange plot. I expected it should look just like transpose of above plot. Using your code I get the transposed plot. regards, stefan __ 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.