[R] Change column of numbers in data frame to days

Philipp Pagel p.pagel at wzw.tum.de
Sat Oct 23 16:51:28 CEST 2010


> I have a vector of numbers ranging form 20 to 500.  The numbers represent
> days since a starting point. The list is not consecutive, some numbers
> skipped and some numbers duplicated.  I know day 1 was a Monday.  I want to
> use this vector in a lm but I need to factor by day.  I'm wondering how to
> assign "Monday" to 22,29,36,..., Tuesday to 23,30,37,... etc...

Here is one way to do it:

# make some sample data
foo <- c(22,29,23,37)
# convert to factor of weekdays
foo<- factor(foo %% 7, levels=1:7, labels=c('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'))
foo

cu
	Philipp

-- 
Dr. Philipp Pagel
Lehrstuhl für Genomorientierte Bioinformatik
Technische Universität München
Wissenschaftszentrum Weihenstephan
Maximus-von-Imhof-Forum 3
85354 Freising, Germany
http://webclu.bio.wzw.tum.de/~pagel/



More information about the R-help mailing list