[R] Getting lm() to work with a matrix

2009-05-19 Thread MikSmith

Hi

I'm fairly new to R and am trying to analyse some large spectral datasets
using stepwise regression (fairly standard in this area). I have a field
sampled dataset, of which a proportion has been held back for validation. I
gather than step() needs to be fed a regression model and lm() can produce a
multiple regression. I had thought something like:

spectra.lm - lm(response[,3]~spectra.spec[,2:20])

might work but lm() doesnt appear to like being fed a range of columns. I
suspect Ive missed something fairly fundamental here.

Any help much appreciated

best wishes

mike
-- 
View this message in context: 
http://www.nabble.com/Getting-lm%28%29-to-work-with-a-matrix-tp23625486p23625486.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] Row number of minimum value?

2009-05-17 Thread MikSmith

Hi

This *must* be an insanely easy thing to work out, but I'm not too familiar
with R syntax. So how do I work out the row number (if I pass a column) of
the minimum value?? I can get the value itself from min(), but where can I
get the row??

Many thanks

mike
-- 
View this message in context: 
http://www.nabble.com/Row-number-of-minimum-value--tp23578215p23578215.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.


Re: [R] Using column length in plot gives error

2009-05-17 Thread MikSmith

Hi Stephanie

Absolutely right! My CSV was imported as a factor. Reading the R FAQ:

http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-do-I-convert-factors-to-numeric_003f

I actually need to do:

as.numeric(as.character(spectra.wavelength))

to get back to my original data.

Many thanks for the pointer

mike



Stephanie Kovalchik wrote:
 
 Is spectra.wavelength a factor? If so, plot will treat it as  
 categorical and not draw a line. Try the following modification.
 
 plot(as.numeric(spectra.wavelength), cormat, type = l, ylim=c(-1,1),  
 xlab=Wavelength (nm), ylab=Correlation)
 
 Quoting MikSmith m...@hsm.org.uk:
 

 Hi

 I'm trying to write a generic script for processing some data which
 finishes
 off with some plots. Given Im never sure how many columns will be in my
 dataframe I wanted to using the following

 plot(spectra.wavelength, cormat, type = l, ylim=c(-1,1),
 xlab=Wavelength
 (nm), ylab=Correlation)

 however even if I specify as type=l it appears plot as points (right
 hand
 plot). If I specify a range such as

 plot(650:700, cormat, type = l, ylim=c(-1,1), xlab=Wavelength (nm),
 ylab=Correlation)

 it looks good (left hand plot). If I try something like:

 plot(spectra.wavelength[1]:spectra.wavelength[length(spectra.wavelength)],
 cormat, type = l, ylim=c(-1,1), xlab=Wavelength (nm),
 ylab=Correlation)

 it fails with variable lengths differ and when I look at
 spectra.wavelength[1] it gives me the value but then states there are 53
 levels.

 What does this mean and how can I get the result I want??!

 many thanks

 mike http://www.nabble.com/file/p23562717/1.pdf 1.pdf
 --
 View this message in context:   
 http://www.nabble.com/Using-column-length-in-plot-gives-error-tp23562717p23562717.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.
 
 

-- 
View this message in context: 
http://www.nabble.com/Using-column-length-in-plot-gives-error-tp23562717p23582038.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.


Re: [R] Row number of minimum value?

2009-05-17 Thread MikSmith

Hi Adrian

Many thanks. That works perfectly! It's easy when you know the answer :)

mike


Adrian Dusa wrote:
 
 Hi Mike,
 
 On Sunday 17 May 2009, MikSmith wrote:
 Hi

 This *must* be an insanely easy thing to work out, but I'm not too
 familiar
 with R syntax. So how do I work out the row number (if I pass a column)
 of
 the minimum value?? I can get the value itself from min(), but where can
 I
 get the row??
 
 Maybe this helps:
 which(mycol == min(mycol))
 
 where mycol is your column.
 Hth,
 Adrian
 
 
 -- 
 Adrian Dusa
 Romanian Social Data Archive
 1, Schitu Magureanu Bd.
 050025 Bucharest sector 5
 Romania
 Tel.:+40 21 3126618 \
  +40 21 3120210 / int.101
 Fax: +40 21 3158391
 
 __
 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.
 
 

-- 
View this message in context: 
http://www.nabble.com/Row-number-of-minimum-value--tp23578215p23582001.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] Using column length in plot gives error

2009-05-15 Thread MikSmith

Hi

I'm trying to write a generic script for processing some data which finishes
off with some plots. Given Im never sure how many columns will be in my
dataframe I wanted to using the following 

plot(spectra.wavelength, cormat, type = l, ylim=c(-1,1), xlab=Wavelength
(nm), ylab=Correlation)

however even if I specify as type=l it appears plot as points (right hand
plot). If I specify a range such as 

plot(650:700, cormat, type = l, ylim=c(-1,1), xlab=Wavelength (nm),
ylab=Correlation)

it looks good (left hand plot). If I try something like:

plot(spectra.wavelength[1]:spectra.wavelength[length(spectra.wavelength)],
cormat, type = l, ylim=c(-1,1), xlab=Wavelength (nm),
ylab=Correlation)

it fails with variable lengths differ and when I look at
spectra.wavelength[1] it gives me the value but then states there are 53
levels.

What does this mean and how can I get the result I want??!

many thanks

mike
-- 
View this message in context: 
http://www.nabble.com/Using-column-length-in-plot-gives-error-tp23562704p23562704.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] Using column length in plot gives error

2009-05-15 Thread MikSmith

Hi

I'm trying to write a generic script for processing some data which finishes
off with some plots. Given Im never sure how many columns will be in my
dataframe I wanted to using the following 

plot(spectra.wavelength, cormat, type = l, ylim=c(-1,1), xlab=Wavelength
(nm), ylab=Correlation)

however even if I specify as type=l it appears plot as points (right hand
plot). If I specify a range such as 

plot(650:700, cormat, type = l, ylim=c(-1,1), xlab=Wavelength (nm),
ylab=Correlation)

it looks good (left hand plot). If I try something like:

plot(spectra.wavelength[1]:spectra.wavelength[length(spectra.wavelength)],
cormat, type = l, ylim=c(-1,1), xlab=Wavelength (nm),
ylab=Correlation)

it fails with variable lengths differ and when I look at
spectra.wavelength[1] it gives me the value but then states there are 53
levels.

What does this mean and how can I get the result I want??!

many thanks

mike http://www.nabble.com/file/p23562717/1.pdf 1.pdf 
-- 
View this message in context: 
http://www.nabble.com/Using-column-length-in-plot-gives-error-tp23562717p23562717.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] rbind help

2009-05-12 Thread MikSmith

Hi

I have a dataset of orientation and elevation in a dataframe which I am
plotting in circular. Orientation is on the range 0-360, however I need to
reduce this to 0-180 as the values over 180 are not necessarily correct. I
can do

striae$orientation[striae$orientation180]-180)

to extract these values, but I then want to combine them back in to the
original dataframe (with the elevation values). I assume rbind is the thing
to use and have tried something like:

test - rbind((striae$orientation[striae$orientation180]-180),
(striae$orientation[striae$orientation=180]))

Not being a regular R user I suspect the syntax is easy when you know it!!
Any help much appreciated.

Best wishes

mike
-- 
View this message in context: 
http://www.nabble.com/rbind-help-tp23499705p23499705.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] Graphic aspect ratio

2009-05-12 Thread MikSmith

Hi

I've been playing with a 3x2 graphics device using the default size as it
appears on screen. This has given me tall thin plots which I can resize by
dragging the window and increasing the window width. However I was wondering
if I can force R to produce square plots or set the actual aspect ratio. asp
seems to affect data units, not on-screen pixel units.

thanks

mike
-- 
View this message in context: 
http://www.nabble.com/Graphic-aspect-ratio-tp23503495p23503495.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] Add data count to plot?

2009-05-11 Thread MikSmith

Hi

I'm a relative newbie to R and had a query concerning plotting. I have
generated a par(mfrow = c(2, 2)) graphic with 10 rose diagrams using
circular. What I wanted to add to each individual plot was n = x for the
number of data observations in each dataset. How might I go about doing
this??

Thanks

Mike
-- 
View this message in context: 
http://www.nabble.com/Add-data-count-to-plot--tp23491681p23491681.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.