[R] Designating a new year (Sept-Aug) in R
arun
smartpink111 at yahoo.com
Sat Nov 24 23:51:02 CET 2012
Hi,
Try this:
dat1<-read.table(text="
site,date,precipitation,temp_max,temp_min
Castle Peak,January-70,0,32,18
Castle Peak,January-70,0,39,9
Castle Peak,September-70,0,34,5
Castle Peak,September-70,0,30,7
Castle Peak,October-70,0,40,6
Castle Peak,November-70,0,45,10
Castle Peak,December-70,0,43,8
Castle Peak,October-71,0,42,7
Castle Peak,November-71,0,46,11
Castle Peak,December-71,0,41,9
",sep=",",stringsAsFactors=FALSE,header=TRUE)
Month1<-c("September","October","November","December")
dat1$date[gsub("(.*)\\-.*","\\1",dat1$date)%in%Month1]<-paste0(gsub("(.*\\-).*","\\1",dat1$date[gsub("(.*)\\-.*","\\1",dat1$date)%in%Month1]),as.numeric(gsub(".*\\-(.*)","\\1",dat1$date[gsub("(.*)\\-.*","\\1",dat1$date)%in%Month1]))+1)
dat1
# site date precipitation temp_max temp_min
#1 Castle Peak January-70 0 32 18
#2 Castle Peak January-70 0 39 9
#3 Castle Peak September-71 0 34 5
#4 Castle Peak September-71 0 30 7
#5 Castle Peak October-71 0 40 6
#6 Castle Peak November-71 0 45 10
#7 Castle Peak December-71 0 43 8
#8 Castle Peak October-72 0 42 7
#9 Castle Peak November-72 0 46 11
#10 Castle Peak December-72 0 41 9
A.K.
A.K.
----- Original Message -----
From: nick pardikes <npardikes at hotmail.com>
To: "r-help at R-project.org" <r-help at r-project.org>
Cc:
Sent: Saturday, November 24, 2012 4:01 PM
Subject: [R] Designating a new year (Sept-Aug) in R
If I have data (below) and need some help in figuring out how I can change the values of my date column, so that a year will be from September-August? So the year
1990 = September 89-August 90; 1991
= September 90-August 91, etc...
I was trying to use the if() function, but am unable to figure it out. I basically need to change the years associated with September-December to the following year. Any
help would be greatly appreciated. Otherwise I will have to power through
it and do it all manually in excel. I am sorry that I do not have the original data associated with this posting, nor any R code with it. I really do not have a clue how to even start designating the new year.
head(mydata)
class(mydata)
"data.frame"
site date precipitation temp_max temp_min
1 Castle Peak January-70 0 32 18
2 Castle Peak January-70 0 39 9
3 Castle Peak January-70 0 34 5
4 Castle Peak January-70 0 30 7
5 Castle Peak January-70 0 40 6
6 Castle Peak January-70 0 45 10
Thank you in advance and please let me know what else I can include to help solve this issue. this is my first posting on R-help.
Nick Pardikes
PhD Student
Program in Ecology, Evolution and Conservation Biology
University of Nevada, Reno
303-550-1072
http://wolfweb.unr.edu/homepage/npardikes/MySite/Welcome.html
[[alternative HTML version deleted]]
______________________________________________
R-help at 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.
More information about the R-help
mailing list