Skip to content

some help

7 messages · David Winsemius, Rui Barradas, dattel_palme +1 more

#
Hi People!

I have following concern consisting of some steps to do in R: 

I have an ascii file (table) consisting of many columns and rows. 
1. I would like to order all values of the columns one under each other. It
will begin with column 1, then column 2 under column 1, column 3 under
column 2 etc. until at the end there is only 1 column. How do I do it?

2. Second problem is to make a scatterplot of two variables (I think after
further explanation scatter plot itself will not be needed). I have two
columns of two different variables (that I produces before), column 1 with
variable 1 and column 2 with variable 2. I would like to order them by one
variable and 0,01 interval (the varibale values will range between 0 and 1).
minimum value of variable 2. 

3. From the obtained max and min of values of each interval i would like to
make a linear least square regression. 

I hope someone can help me out!
Thanks
Stefan



--
View this message in context: http://r.789695.n4.nabble.com/some-help-tp4648316.html
Sent from the R help mailing list archive at Nabble.com.
#
On Nov 3, 2012, at 9:07 AM, dattel_palme wrote:

            
something along the lines of 

dat <- read.table(filename, sep=<separator>, header=TRUE)
stacked <- do.call(rbind, dat)
Did you now? But from the data produced above you only have one column. Is this another data-object where these column have names?
That is incoherent to this native speaker of English who is sometimes confused by presentations of problems without concrete references. An example would help greatly.
Definitely need an example. Please read the Posting Guide.
#
Hello,

Without data it's not easy to answer to your questions, but

1. Use ?unlist. If the data is in a file, read it with ?read.table and 
the unlist the result. All columns will be stacked.

dat <- read.table(filename, ...)
unlist(dat)

2. At best confusing. But to divide a vector into groups use ?cut or 
?findInterval and then, to find the maximum and minimum of each group, 
?tapply or ?ave.

3. Regress what on what?


Provide a data example using dput for better answers:

dput( head(mydata, 30) )  # paste the output of this in a post


Hope this helps,

Rui Barradas
Em 03-11-2012 16:07, dattel_palme escreveu:
#
HI everybody,

Thanks for your answers,
I can't provide data here, but I can explain more: 

It's satellite images as a text file (ascii). Two different images with two
different variables, land surface temperature (LST -lstascii =filename) and
an vegetation index (NDVI - ndviascii = filename).

The aim was to do a scatter plot of NDVI against LST, whereas the NDVI
should be on the x-axis. - The scatter plot itself is not needed as you will
see.

As I cannot compare each value (pixel value) in one image to the respective
value in the other image, i had the idea to sort all columns one under each
other. In the end I would have one column of one variable. I wanted to put
the two variables LST and NDVI together in one table, so that I have two
columns with two variables, and the value of one variable (NDVI) in each row
can be compared directly to the value of the other variable (LST) in the
same row. Why that? I wanted to sort the columns by the NDVI variable and
make 0,01 NDVI intervals. From each of these intervals I wanted to know the
max and min LST. These values I need for the regression - see the graph in
the file attached.

I this more clear now?

Attached you can see the regression line I need to find. For this I
developed this process (because I cannot compare pixel value by pixel value
in a multi column and row table). 
<http://r.789695.n4.nabble.com/file/n4648382/scatterplot.jpg> 

Best Regards



--
View this message in context: http://r.789695.n4.nabble.com/some-help-tp4648316p4648382.html
Sent from the R help mailing list archive at Nabble.com.
#
HI David,

Thanks for your answers,
I can't provide data here, but I can explain more:

It's satellite images as a text file (ascii). Two different images with two
different variables, land surface temperature (LST -lstascii =filename) and
an vegetation index (NDVI - ndviascii = filename).

The aim was to do a scatter plot of NDVI against LST, whereas the NDVI
should be on the x-axis. - The scatter plot itself is not needed as you will
see.

As I cannot compare each value (pixel value) in one image to the respective
value in the other image, i had the idea to sort all columns one under each
other. In the end I would have one column of one variable. I wanted to put
the two variables LST and NDVI together in one table, so that I have two
columns with two variables, and the value of one variable (NDVI) in each row
can be compared directly to the value of the other variable (LST) in the
same row. Why that? I wanted to sort the columns by the NDVI variable and
make 0,01 NDVI intervals. From each of these intervals I wanted to know the
max and min LST. These values I need for the regression - see the graph in
the file attached.

I this more clear now?

Attached you can see the regression line I need to find. For this I
developed this process (because I cannot compare pixel value by pixel value
in a multi column and row table). 

<http://r.789695.n4.nabble.com/file/n4648410/scatterplot.jpg> 

Best Regards
Stefan



--
View this message in context: http://r.789695.n4.nabble.com/some-help-tp4648316p4648410.html
Sent from the R help mailing list archive at Nabble.com.
21 days later
#
Hey again!

I finally, after some work done before, had time to apply the code. 
The sorting of the table did not work well or maybe something was
misunderstood.

I have a table with 973 rows and 1329 col (ascii/text file). I want to sort
the table that all columns are one under each other so that at the end I
have 973*1329 rows and 1 col. The col should be sorted in a way that col 2
is under col 1, col 3 under col 2, col 4 under col 3 etc. 

I applied this code:
dat <- read.table(filename, sep=<separator>, header=TRUE)
stacked <- do.call(rbind, dat) 
unlist(dat) 

..but putting dim(dat), the number of rows and col was still 973 and 1329.
So seemingly it did not work as i wanted.

Thanks very much for more help.

Stefan







--
View this message in context: http://r.789695.n4.nabble.com/some-help-tp4648316p4650828.html
Sent from the R help mailing list archive at Nabble.com.
3 days later
#
Hi

Maybe you could use  stack(dat) or melt(dat) from reshape package.

Regards
Petr