[R] Multiple plots

2012-05-02 Thread alcesgabbo
I have a variable : 
*sim.var[,1]
*
Object of class SpatialPixelsDataFrame
Object of class SpatialPixels
Grid topology:
 cellcentre.offset cellsize cells.dim
Xloc   0.3 0.0597
Yloc   0.1 0.05   117
SpatialPoints:
Xloc Yloc
   [1,] 0.30 1.70
   [2,] 0.35 1.70
   [3,] 0.35 1.75
   [4,] 0.40 1.70
   [5,] 0.40 1.75
   [6,] 0.40 1.80
   [7,] 0.40 1.85
   [8,] 0.40 1.90
   [9,] 0.40 2.10
  [10,] 0.40 2.15
  [11,] 0.40 2.20
  [12,] 0.40 2.40
  [13,] 0.40 2.45


and a variable :
*sim.mean[,1]*
Object of class SpatialPixelsDataFrame
Object of class SpatialPixels
Grid topology:
 cellcentre.offset cellsize cells.dim
Xloc   0.3 0.0597
Yloc   0.1 0.05   117
SpatialPoints:
Xloc Yloc
   [1,] 0.30 1.70
   [2,] 0.35 1.70
   [3,] 0.35 1.75
   [4,] 0.40 1.70
   [5,] 0.40 1.75
   [6,] 0.40 1.80
   [7,] 0.40 1.85
   [8,] 0.40 1.90
   [9,] 0.40 2.10
  [10,] 0.40 2.15
  [11,] 0.40 2.20

If I plot these variables with:
*spplot(sim.var[,1],main=var)*
and 
*spplot(sim.mean[,1],main=mean)*

it works.

But how can I plot these two variables together with a single scale?

Thanks


--
View this message in context: 
http://r.789695.n4.nabble.com/Multiple-plots-tp4603205.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] subset in a BIG matrix

2011-02-02 Thread alcesgabbo

I have a matrix with a lot of values inside..

when I execute the folowing command

matrix2=subset(martix, condition.)

it works...

but after the previous command I execute another subset

matrix3=subset(martix2, condition2.)

and appears the following error:

(subscript) logical subscript too long

How can I solve this???
I think the probles is the size of the matrix...
Thanks..
-- 
View this message in context: 
http://r.789695.n4.nabble.com/subset-in-a-BIG-matrix-tp3254115p3254115.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] multi-Operations on a matrix

2011-02-01 Thread alcesgabbo

Hello everybody.

I have this object

  procedure property sensor_data  sensor_date
1S_10 nord626821.0 2002-09-30T00:00:00+0200
2 S_10 nord626821.0 2002-12-05T00:00:00+0100
3S_10 nord626821.1 2008-07-31T00:00:00+0200
4  S_1000 nord626496.8 2002-09-30T00:00:00+0200
5  S_1000 nord626496.8 2002-12-05T00:00:00+0100
6  S_1000 nord626496.9 2009-04-23T00:00:00+0200
7  S_1000 nord626497.0 2009-11-10T00:00:00+0100
8 S_1 nord626485.3 2002-09-30T00:00:00+0200
9S_1 nord626485.3 2002-12-05T00:00:00+0100
10S_1 nord626485.3 2003-02-07T00:00:00+0100

the third colomn (sensor_data) is a distance in meters.
each distance has a date (sensor_date)
for each row I would like to find the difference from the first distance
(with the min date) and the distance.

I know it's difficult to understand.. I give you an example:

for the first procedure S_10 I should find the first distance based on the
date:

distance:626821.0   with the date: 2002-09-30T00:00:00+0200

then I should do the difference between the current distance and the first
distance:

626821.0 - 626821.0 = 0.0
 626821.0 -  626821.0 = 0.0
626821.1 - 626821.0 = 0.1

Then I should do this also for the other procedures.

I would like a resut like this:

 procedure property sensor_data  sensor_date difference
1S_10 nord626821.0 2002-09-30T00:00:00+02000.0
2 S_10 nord626821.0 2002-12-05T00:00:00+0100   0.0
3S_10 nord626821.1 2008-07-31T00:00:00+0200   0.1
4  S_1000 nord626496.8 2002-09-30T00:00:00+0200  0.0
5  S_1000 nord626496.8 2002-12-05T00:00:00+0100   0.0
6  S_1000 nord626496.9 2009-04-23T00:00:00+02000.1
7  S_1000 nord626497.0 2009-11-10T00:00:00+0100   0.2
8 S_1 nord626485.3 2002-09-30T00:00:00+0200 0.0
9S_1 nord626485.3 2002-12-05T00:00:00+0100  0.0
10S_1 nord626485.3 2003-02-07T00:00:00+0100 0.0

How can I do this procedure?


Thanks

-- 
View this message in context: 
http://r.789695.n4.nabble.com/multi-Operations-on-a-matrix-tp3250807p3250807.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] plot more plots from one matrix

2010-12-03 Thread alcesgabbo

I solved the 1° problem with this command:

matrix2plot2[,sensor_data]-as.numeric(as.character((matrix2plot2[,sensor_data])))

In fact before the previous command I if write: 

str(matrix2plot2[,sensor_data])

I get:
 Factor w/ 10 levels 131.22,148.532,..: 4 6 4 6 9 8 9 8 3 1 ...

And after the command 
matrix2plot2[,sensor_data]-as.numeric(as.character((matrix2plot2[,sensor_data])))

if I write:
str(matrix2plot2[,sensor_data])

I get:
num [1:16] 30.4 31.2 30.4 31.2 50.1 ...
-
but I can't solve the 2° problem
-- 
View this message in context: 
http://r.789695.n4.nabble.com/plot-more-plots-from-one-matrix-tp3069545p3071272.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] subset of a dataframe

2010-12-03 Thread alcesgabbo

HI,
I have a dataframe like this:

nametype
A  t1
B   t2
C  t1
D   t1
E   t3
Ft2

how can I have a sub dataframe based with the column type like this:

(for type = t1)

nametype
A  t1
C  t1
D   t1

(for type = t2)

nametype

B   t2
Ft2


Thanks
-- 
View this message in context: 
http://r.789695.n4.nabble.com/subset-of-a-dataframe-tp3071326p3071326.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] plot more plots from one matrix

2010-12-02 Thread alcesgabbo

Hi,
I have a dataframe like this:

 procedure propertysensor_data  sensor_date   
 | |   | |
 [1,] PAT_Laser_2 Distance   30.42 2010-09-30T15:00:12+0200
 [2,] PAT_Laser_2 Distance   31.22 2010-10-31T15:05:07+0100
 [3,] PAT_Laser_2 Distance   30.42 2011-09-30T15:00:12+0200
 [4,] PAT_Laser_2 Distance   31.22 2011-10-31T15:05:07+0100
 [5,] PAT_Laser_1 Distance   50.1252   2010-09-30T15:00:12+0200
 [6,] PAT_Laser_1 Distance   48.5322010-10-31T15:05:07+0100
 [7,] PAT_Laser_1 Distance   50.1252   2011-09-30T15:00:12+0200
 [8,] PAT_Laser_1 Distance   48.5322011-10-31T15:05:07+0100
 [9,] PAT_Laser_2 Distance_B 3.42  2010-09-30T15:00:12+0200
[10,] PAT_Laser_2 Distance_B 131.222010-10-31T15:05:07+0100
[11,] PAT_Laser_2 Distance_B 303.422011-09-30T15:00:12+0200
[12,] PAT_Laser_2 Distance_B 131.222011-10-31T15:05:07+0100
[13,] PAT_Laser_1 Distance_B 530.1252  2010-09-30T15:00:12+0200
[14,] PAT_Laser_1 Distance_B 428.532   2010-10-31T15:05:07+0100
[15,] PAT_Laser_1 Distance_B 530.1252  2011-09-30T15:00:12+0200
[16,] PAT_Laser_1 Distance_B 148.532   2011-10-31T15:05:07+0100


In order to identify each sensor_data with the columns property and
procedure I create a new column key in this way:

procedure   property sensor_data  sensor_date   
key
1  PAT_Laser_2   Distance   30.42 2010-09-30T15:00:12+0200  
PAT_Laser_2.Distance
2  PAT_Laser_2   Distance   31.22 2010-10-31T15:05:07+0100  
PAT_Laser_2.Distance
3  PAT_Laser_2   Distance   30.42 2011-09-30T15:00:12+0200  
PAT_Laser_2.Distance
4  PAT_Laser_2   Distance   31.22 2011-10-31T15:05:07+0100  
PAT_Laser_2.Distance
5  PAT_Laser_1   Distance 50.1252 2010-09-30T15:00:12+0200  
PAT_Laser_1.Distance
6  PAT_Laser_1   Distance  48.532 2010-10-31T15:05:07+0100  
PAT_Laser_1.Distance
7  PAT_Laser_1   Distance 50.1252 2011-09-30T15:00:12+0200  
PAT_Laser_1.Distance
8  PAT_Laser_1   Distance  48.532 2011-10-31T15:05:07+0100  
PAT_Laser_1.Distance
9  PAT_Laser_2 Distance_B3.42 2010-09-30T15:00:12+0200
PAT_Laser_2.Distance_B
10 PAT_Laser_2 Distance_B  131.22 2010-10-31T15:05:07+0100
PAT_Laser_2.Distance_B
11 PAT_Laser_2 Distance_B  303.42 2011-09-30T15:00:12+0200
PAT_Laser_2.Distance_B
12 PAT_Laser_2 Distance_B  131.22 2011-10-31T15:05:07+0100
PAT_Laser_2.Distance_B
13 PAT_Laser_1 Distance_B530.1252 2010-09-30T15:00:12+0200
PAT_Laser_1.Distance_B
14 PAT_Laser_1 Distance_B 428.532 2010-10-31T15:05:07+0100
PAT_Laser_1.Distance_B
15 PAT_Laser_1 Distance_B530.1252 2011-09-30T15:00:12+0200
PAT_Laser_1.Distance_B
16 PAT_Laser_1 Distance_B 148.532 2011-10-31T15:05:07+0100
PAT_Laser_1.Distance_B

Now I want to plot the sensor_data column for each sensor_date so I
create a matrix in this way:


m-tapply(matrix2plot2[,sensor_data],matrix2plot2[,c(sensor_date,key)],c)

key
sensor_date  PAT_Laser_1.Distance PAT_Laser_1.Distance_B
PAT_Laser_2.Distance PAT_Laser_2.Distance_B   
  2010-09-30T15:00:12+02009 10  
 
4  3
  2010-10-31T15:05:07+01008  7  
 
6  1
  2011-09-30T15:00:12+02009 10  
 
4  5
  2011-10-31T15:05:07+01008  2  
 
6  1

(1° PROBLEM)
And here there is the first problem: instead of having sensor_data inside
the matrix there is a sequence of numbers 1,2...,10. (I think it is a way to
simplify the matrix but I would like the original values).

Apart this problem when I do:
matplot(m, type=o, xaxt=n, lty=1)

It is ok, It plots the matrix, each line on the plot represents a column.

(2° PROBLEM)
I would like to have 2 plots, one for the values with property= distance
and the other for property=distance_B. Is there a way to do this without
use directly the names distance and distance_B (so it should be possible
to use this method also for other matrix with other property).


Is it clear?? I don't know if I explained the problem in a clear way.  

Thanks!

-- 
View this message in context: 
http://r.789695.n4.nabble.com/plot-more-plots-from-one-matrix-tp3069545p3069545.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] Plot a matrix recursively

2010-12-01 Thread alcesgabbo

Hi,

I have the following matrix (named m):
key
 sensor_date  Laser_1  Laser_2  

Laser_3
  2010-09-30T15:00:12+020063
   
1
  2010-10-31T15:05:07+010054
   
2
  2011-09-30T15:00:12+020063
   
1
  2011-10-31T15:05:07+010054
   
2

I plot the first column with the following function:
plot(m[,1],type=o, xaxt=n,ylim=c(min(m[,1:length(colnames(m))])-1,
max(m[,1:length(colnames(m))])+1))

for the other columns I use there functions:

lines(m[,2],type=\o\)

lines(m[,3],type=\o\)

ok, it works.

But is there a way to do this prodcedures recursively??

for example:

for each columns {
 lines(m[,column],type=\o\)
}

I try with :

lines(m[,2:length(colnames(m))],type=\o\)

but it doesn't work.

Thanks .
Alberto
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Plot-a-matrix-recursively-tp3067283p3067283.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] Concat two rows

2010-11-30 Thread alcesgabbo

I have a table like this:


A   B
aaa   111
bbb   222
ccc   333
ddd   444

and I would like a new row C:

A   B   C
aaa   111  aaa.111
bbb   222  bbb.222
ccc   333  ccc.333
ddd   444  ddd.444


How can I do this
???

Thanks
Alberto

-- 
View this message in context: 
http://r.789695.n4.nabble.com/Concat-two-rows-tp3064998p3064998.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] Concat two rows

2010-11-30 Thread alcesgabbo

thanks
It works!

Alberto
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Concat-two-rows-tp3064998p3065034.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] Plot a matrix

2010-11-30 Thread alcesgabbo

Hi,

I have this MATRIX m:

key
index   sensor1.A sensor1.B sensor2.A sensor2.B sensor3.A
  2010-10-1 7:32:00 8NA 5NA 2
  2010-10-3 4:33:21NA 3NA 2 1
  2010-10-5 7:32:00NA 4NA 6 7

m[,0] represents date
m[,1] represent an array of values
also m[,2],m[,3],m[,4],m[,5] represent arrays of values

how can I plot this matrix? I would like to have: 

at x axes: index (the list of dates)
and 5 lines (one for each columns sensor1.A sensor1.B sensor2.A sensor2.B
sensor3.A)

Thanks
Alberto

-- 
View this message in context: 
http://r.789695.n4.nabble.com/Plot-a-matrix-tp3065094p3065094.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] Odp: Plot a matrix

2010-11-30 Thread alcesgabbo

I explain better

  key
index   sensor1.A sensor1.B sensor2.A sensor2.B sensor3.A
  2010-10-1 7:32:00 8NA 5NA 2
  2010-10-3 4:33:21NA 3NA 2 1
  2010-10-5 7:32:00NA 4NA 6 7

its a matrix.


The first row contains a list (not exactly an array) of date (index it's
just a name, I can substitute that nale with Dates for example)

if I do:
str(m[,0])

 int[1:3, 0 ] 
 - attr(*, dimnames)=List of 2
  ..$ index: chr [1:3] 2010-10-1 7:32:00 2010-10-3 4:33:21 2010-10-5
7:32:00
  ..$ key  : NULL


If I do:

plot(m[,5],type=o)

I can see 3 point with lines:
sensor3.A
2
1
7
 it is OK 
but in the x axes there is 
1.0 1.5 2.0 2.5 3.0 
instead of 
2010-10-1 7:32:00   2010-10-3 4:33:21   2010-10-5 7:32:00

How can I solve this problem??

-- 
View this message in context: 
http://r.789695.n4.nabble.com/Plot-a-matrix-tp3065094p3065163.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] Plot data inside matrix

2010-11-29 Thread alcesgabbo

Hi, I have this problem:

I have this matrix:
 result property procProperty
2010-10-01 07:32:00 40   Asensor1 
2010-10-01 17:32:00 15   Asensor3 
2010-10-02 07:32:00 32   Asensor2 
2010-10-03 04:33:21 20   Bsensor1 
2010-10-03 04:33:21 33   Bsensor2 
2010-10-03 14:33:21 12   Asensor3 
2010-10-05 07:32:00 31   Bsensor1 
2010-10-05 07:32:00 15   Bsensor2 
2010-10-06 17:32:00 4Asensor3 

I would like to plot this matrix in this way:

create in this case 2 plots (one for each property: A and B )
for each plot there will be 3 lines (one for each procProperty:
sensor1,sensor2,sensor3) composed by the result.

How can I do this with few commands??

Thanks Alberto

-- 
View this message in context: 
http://r.789695.n4.nabble.com/Plot-data-inside-matrix-tp3063417p3063417.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] Plot data inside matrix

2010-11-29 Thread alcesgabbo

yes, this is a zoo object.

First off all I have:

procProperty: sensor3 sensor3 sensor3 sensor3 sensor3 sensor3
sensor3 sensor3
property:  A B B A B B A A A
data:  40 20 31 32 15 33 15 12  4

I create a matrix with this objects:

data-cbind(data,property)
data-cbind(data,procProperty)

now data is:

data:
 data property procProperty
 [1,] 40 A  sensor3  
 [2,] 20 B  sensor3  
 [3,] 31 B  sensor3  
 [4,] 32 A  sensor3  
 [5,] 15 B  sensor3  
 [6,] 33 B  sensor3  
 [7,] 15 A  sensor3  
 [8,] 12 A  sensor3  
 [9,] 4  A  sensor3  

index contains the date :  2010-10-1 7:32:00  2010-10-3 4:33:21 
2010-10-5 7:32:00  2010-10-2 7:32:00  2010-10-5 7:32:00
 2010-10-3 4:33:21  2010-10-1 17:32:00 2010-10-3 14:33:21 2010-10-6
17:32:00

I modifed with this function: index-as.POSIXlt(index)

then I do:

sensor-zoo(data,index)

sensor is:
   data property procProperty
2010-10-01 07:32:00 40   Asensor3
2010-10-01 17:32:00 15   Asensor3
2010-10-02 07:32:00 32   Asensor3
2010-10-03 04:33:21 20   Bsensor3
2010-10-03 04:33:21 33   Bsensor3
2010-10-03 14:33:21 12   Asensor3
2010-10-05 07:32:00 31   Bsensor3
2010-10-05 07:32:00 15   Bsensor3
2010-10-06 17:32:00 4Asensor3   

str(sensor) is:
 str(sensor)
‘zoo’ series from 2010-10-01 07:32:00 to 2010-10-06 17:32:00
  Data: chr [1:9, 1:3] 40 15 32 20 33 12 31 15 4 A A
A B B A ...
 - attr(*, dimnames)=List of 2
  ..$ : NULL
  ..$ : chr [1:3] data property procProperty
  Index:  POSIXlt[1:9], format: 2010-10-01 07:32:00 2010-10-01 17:32:00
2010-10-02 07:32:00 2010-10-03 04:33:21 ...

it doesn't matter the type of the plot, the problem is how can i manage all
the data in order to visualize the plot?

How can I tell to the pc that I want one plot for each property (A and
B) and a line for each procProperty??

Maybe I should use the function tapply?? (in order to have an object like
this:)

table for A:
  sensor1  sensor2  sensor3
2010:   40  32 20
2011:   30   30   15


table for B:
  sensor1  sensor2  sensor3
2010:   14  3 12
2011:   10   30   15
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Plot-data-inside-matrix-tp3063417p3063600.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.