Re: [R] categorizing data

2022-05-29 Thread Janet Choate
I'm sorry if this has come across as a homework assignment!I was trying to
provide a simple example.
There are actually 38323 rows of data, each row is an observation of the
percent that each of those veg types occupies in a spatial unit - where
each line adds to 90 - and values are different every line.
I need a way to categorize the data, so I can reduce the number of unique
observations.

So instead of 38323 unique observations - I can reduce this to
X number of High/Med/Low
X number of Med/Low/High
X number of Low/High/Med
etc... for all combinations

I hope this makes it more clear..
thank you all for your responses,
JC

On Sun, May 29, 2022 at 1:16 PM Avi Gross via R-help 
wrote:

> Tom,
> You may have a very different impression of what was asked! LOL!
> Unless Janet clarifies what seems a bit like a homework assignment, it
> seems to be a fairly simple and straightforward assignment with exactly
> three rows/columns and asking how to replace the variables, in a sense, by
> finding the high and low and perhaps thus identifying the medium, but to do
> this for each row without changing the order of the resulting data.frame.
> I note most techniques people have used focus on columns, not rows, but an
> all-numeric data.frame can be transposed, or converted to a matrix and
> later converted back.
> If this is HW, the question becomes what has been taught so far and is
> supposed to be used in solving it. Can they make their own functions
> perhaps to be called three times, once per row or column, to replace that
> row/column, or can they use some form of loop to iterate over the columns?
> Does it need to sort of be done in place or can they create gradually a
> second data.frame and then move the pointer to it and lots of other similar
> ideas.
> I am not sure, other than as a HW assignment, why this transformation
> would need to be done but of course, there may well be a reason.
> I note that the particular example shown just happens to create almost a
> magic square as the sum of rows and columns and the major diagonal happen
> to be 0, albeit the reverse diagonal is all 50's.
> Again, there are many solutions imaginable but the goal may be more
> specific and I shudder to supply one given that too often questions here
> are not detailed enough and are misunderstood. In this case, I thought I
> understood until I saw what Tom wrote! LOL!
> I will add this. Is it guaranteed that no two items in the same row are
> never equal or is there some requirement for how to handle a tie? And note
> there are base R functions called min() and max() and you can ask for
> things like:
>
> if ( current == min(mydata[1,])) ...
>
>
> -Original Message-
> From: Tom Woolman 
> To: Janet Choate 
> Cc: r-help@r-project.org
> Sent: Sun, May 29, 2022 3:42 pm
> Subject: Re: [R] categorizing data
>
>
> Some ideas:
>
> You could create a cluster model with k=3 for each of the 3 variables,
> to determine what constitutes high/medium/low centroid values for each
> of the 3 types of plant types. Centroid values could then be used as the
> upper/lower boundary ranges for high/med/low.
>
> Or utilize a histogram for each variable, and use quantiles or
> densities, etc. to determine the natural breaks for the high/med/low
> ranges for each of the IVs.
>
>
>
>
> On 2022-05-29 15:28, Janet Choate wrote:
> > Hi R community,
> > I have a data frame with three variables, where each row adds up to 90.
> > I want to assign a category of low, medium, or high to the values in
> > each
> > row - where the lowest value per row will be set to 10, the medium
> > value
> > set to 30, and the high value set to 50 - so each row still adds up to
> > 90.
> >
> > For example:
> > Data: Orig
> > tree  shrub  grass
> > 3211  47
> > 23  41  26
> > 49  23  18
> >
> > Data: New
> > tree  shrub  grass
> > 30  10  50
> > 10  5030
> > 50  3010
> >
> > I am not attaching any code here as I have not been able to write
> > anything
> > effective! appreciate help with this!
> > thank you,
> > JC
> >
> > --
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > 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 -- To UNSUBSCRIBE and mor

[R] turning a list of objects into columns

2019-06-29 Thread Janet Choate
Hi,
I have a data frame that looks something like this (but much longer):
df
scen streamflowtrans evap  psn
1   0.019234 1.658967 0.002883 0.002391
1   0.019027 1.661192 0.002844 0.003142
2   0.018821 1.695623 0.003192 0.002167
2   0.018619 1.503481 0.002536 0.003059
3   0.018425 0.08 1.880355 0.002592
3   0.018369 0.100551 2.225793 0.006642

i want to end up with something like this (for each variable - streamflow,
trans, evap, psn). using the variable trans here as an example:
trans1trans2  trans3
1.658967  1.695623  0.08
1.661192  1.503481  0.100551

so that each variable (streamflow, trans, evap, psn) is in a separate
column based on the scen #.

i used split which created a list for each scen #:
test = split(df[,,], df$scen)
as well as
test = as.data.frame(split(df[,,], df$scen)

which did separate out each scen instance, but in lists, i.e.:
 $`1`
   [1] 1.658967 1.661192
$`2`
   [1] 1.695623 1.503481
$`3`
   [1] 0.08 0.100551

if i use as.data.frame, i.e.:
test2 = as.data.frame(test)

it seems like it puts it into columns, i.e.:
X1   X2   X3
1 1.658967  1.695623  0.08
2 1.661192  1.503481  0.100551

however, if i look at one of the variables, it still presents as a list,
even though the class is numeric:
head(tmp2$X1)
[1] 1.658967 1.661192

can anyone tell me how to get this into the format i want - where each
variable for each scen # is in it's own column in a data frame?
thank you,
Janet

-- 
Tague Team Lab Manager
1005 Bren Hall
UCSB, Santa Barbara, CA.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] splitting a column of data into multiple columns

2019-06-28 Thread Janet Choate
Hello R community,
I have a data frame that has multiple observations in a single column that
I would like to break into multiple columns.
The data looks something like this:

scen trans evap flow
1   1.10.10.09
1   1.20.20.10
1   1.30.30.20
2   2.10.10.09
2   2.20.20.10
2   2.30.30.20
3   3.10.10.09
3   3.20.20.10
3   3.30.30.20

the column scen runs from 1 through 500, and each scen # contains 1461 rows
- i.e. there are 1461 observations for scen1, 1461 observations for scen2,
etc...
i want to split the trans, evap, and flow columns out by scen #, so that i
end up with something like:

trans1   trans2trans3
1.1 2.11.1
1.2 2.23.2
1.3 2.33.3

and same for the other variables.
thought i could use the separate command to do this, but either not the
right approach or i am not executing it properly.
thank you for any assistance,
Janet
-- 
Tague Team Lab Manager
1005 Bren Hall
UCSB, Santa Barbara, CA.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] pulling recessions out of a hydrograph

2018-02-05 Thread Janet Choate
Dear R community,

I'm hoping someone out there has perhaps done this and can share their code
and/or expertise with me.

I need to pull recession periods out of a hydrograph - can anyone help me
with this?
I want to create a subset from streamflow data that consists of just the
recession curves - the decreasing runoff after the passage of a peak flow.

would really appreciate any help on this!
Janet
-- 
Tague Team Lab Manager
1005 Bren Hall
UCSB, Santa Barbara, CA.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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 Moran.I

2014-08-14 Thread Janet Choate
Dear R community,
i am attempting to use Moran.I for the first time, and am not quite sure on
the inputs needed
i have loaded the ape library.

i have a data frame that includes concentrations of nutrients (no3, nh4,
po4) and the percentage of different land use types (urb, ag, ud, comm, sr,
dp, park) contributing to the locations where the measurements were taken.
it (fwr) looks like this (but longer):

fwr
 no3   nh4po4  urb   ag   ud comm   sr   dp park
1 558.77 10.79 147.95 0.50 0.09 0.37 0.17 0.15 0.18 0.05
2 403.70  9.27  25.11 0.49 0.09 0.37 0.16 0.16 0.17 0.05
3 365.77  9.61 127.22 0.46 0.09 0.40 0.15 0.15 0.16 0.04
4  93.95  1.78  11.34 0.45 0.08 0.42 0.13 0.18 0.14 0.06
5  63.20 21.44  47.17 0.47 0.08 0.40 0.13 0.19 0.15 0.06
6  14.80  4.47  27.06 0.49 0.07 0.38 0.13 0.21 0.15 0.06

i was asked to do multiple regression, and plot the residuals:
no3.mr = lm(no3 ~ urb+ag+ud+comm+sr+dp+park)

then asked to do a Moran's I on the residuals.

i am not sure about the input necessary to do a Moran's I. do i need
coordinate locations? or/and how do i assign the weights?
i think i assign the weights to the land use types -
how would i use the results of the multiple regression (no3.mr) to perform
the Morans.I on the residuals?

thank you for any assistance,
Janet

[[alternative HTML version deleted]]

__
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] function completing properly

2014-07-09 Thread Janet Choate
Hi R community,
i created a function (mkdate) as follows:

mkdate = function(x) {
x$date = as.Date(paste(x$year, x$month, x$day, sep="-"))
x$wy = ifelse(x$month >=10, x$year+1, x$year)
x$yd = as.integer(format(as.Date(x$date), format="%j"))
x$wyd = cal.wyd(x)
x
}

the function results in adding the new columns date, wy, yd, and wyd to the
table i apply it to.
this has always worked in R version 2.14.2.
however, in R version 3.1.0 - instead of my mkdate function adding those
columns to my existing table, it just overwrites my table and leaves me
with just a list of the last variable created by my mkdate function. so i
end up with just a list of numbers representing wyd, and lose all the data
in my original table.

does anyone know what would now be causing this to occur, and what i need
to do to make my function work properly again?

thank you for any assistance,
Janet

[[alternative HTML version deleted]]

__
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] Merge and specify column output order

2014-01-15 Thread Janet Choate
Hi,

i am merging two data frames of different time periods, so that the result
contains data from both for the same time period.
however, I want the result to output columns in a certain order.
the common column between the two data frames is date.

for example:

df1 columns:
mod1 mod2 mod3 mod4 date  #(there are actually 691 mod columns)

df2 columns:
obs wy date

after merge, i want the order of the columns to be all mod data columns
from df1, followed by the obs and wy columns from df2, followed by the date
column.

i almost get want i want with (at least it doesn't put the common column
date as the first column as merge does by default):

new = merge(df1, df2, by=c("date"))[, union(names(df1), names(df2))]

however, that of course gives me all of df1 followed by all of df2, which
doesn't put obs immediately after the mod columns:

what i get:
mod1 mod2 mod3 mod4 date obs wy

what i want:
mod1 mod2 mod3 mod4 obs wy date

any suggestions on how to output the columns in the order i want, without
having to rearrange the order after the fact?

thank you for any help!
Janet

[[alternative HTML version deleted]]

__
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 only a portion of a record

2014-01-13 Thread Janet Choate
Hi R community,
i have a data frame of streamflow for 23 years, i.e.

date year month day   wy  yd wyd  modQ
1 1965-10-01 196510   1 1966 274   1 0.3341630
2 1965-10-02 196510   2 1966 275   2 0.3223247
3 1965-10-03 196510   3 1966 276   3 0.3109057

i only want to plot 1 of the years, along with the date.
i can accomplish this with:

plot(mod.sage$date[mod.sage$wy==1976],mod.sage$modQ[mod.sage$wy==1976],
type="l")

however, this is a bit long and clunky. is there a way to plot just a
portion of the full data record without creating a whole new object with
subset?

thank you for any help!
Janet

[[alternative HTML version deleted]]

__
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] summing 15 minute precip data to daily

2011-02-17 Thread Janet Choate
Hi all,
i'm sure there is an easy way to do this, but i'm stumped, so any help would
be appreciated.

i have a single column of data for precipitation every 15 minutes over a
year.  i want to sum the precip to daily data.
so the first 96 records = the first day, the second 96 records = the second
day, and so on
is there a way to write a for loop that would sum the data to daily, and
write each value to a second object so i end up with a file of daily precip?

thanx,
Janet

[[alternative HTML version deleted]]

__
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] memory error

2010-03-31 Thread Janet Choate
Thanx for clarification on stating my problem, Charlie.

I am attempting to merge to files, i.e.:
hi39 = merge(comb[,c("hillID","geo")], hi.h39, by=c("hillID"))

if this is relevant or helps to explain:
the file 'comb' is 3 columns and 1127 rows
the file 'hi.h39' is 5 columns and 19758564 rows

i started a new clean R session in which i was able to read those 2 files
in, but get the following error when i try to merge them:

R(2175) malloc: *** mmap(size=79036416) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
R(2175) malloc: *** mmap(size=79036416) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
R(2175) malloc: *** mmap(size=158068736) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
R(2175) malloc: *** mmap(size=158068736) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
R(2175) malloc: *** mmap(size=158068736) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
Error: cannot allocate vector of size 150.7 Mb

so the final error is "Cannot allocate vector of size 150.7 Mb", as
suggested when R runs out of memory.

i am running R version 2.9.2, on mac os X 10.5 - leopard.

any suggestion on how to increase R's memory on a mac?
thanx for any much needed help!
Janet

On Wed, Mar 31, 2010 at 5:47 PM, Sharpie  wrote:

>
>
> Janet Choate-2 wrote:
> >
> > Hi R community,
> > i have what appears to be a memory allocation problem:
> >
> > R(51150) malloc: *** mmap(size=158068736) failed (error code=12)
> > *** error: can't allocate region
> > *** set a breakpoint in malloc_error_break to debug
> >
> > can anyone tell me how to increase the memory size for R on mac os X?
> >
> > thank you,
> > Janet
> >
>
> Setting memory limits was something that was done under OS 9- with OS X
> apps
> get as much memory as they request as long as free space is available.
> Also, when R runs out of memory, you usually see errors like:
>
> Cannot allocate vector of size X
>
> Some details may help pin this problem down: what were you doing when you
> got this error?  Is it repeatable?  Is it an error with a base R routine or
> with something provided by a package? If so, what version?
>
> Providing these details will help the people on this list understand what
> your problem is and suggest solutions.
>
> Good luck!
>
> -Charlie
>
> -
> Charlie Sharpsteen
> Undergraduate-- Environmental Resources Engineering
> Humboldt State University
> --
> View this message in context:
> http://n4.nabble.com/memory-error-tp1747357p1747558.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.
>

[[alternative HTML version deleted]]

__
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] memory error

2010-03-31 Thread Janet Choate
Hi R community,
i have what appears to be a memory allocation problem:

R(51150) malloc: *** mmap(size=158068736) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug

can anyone tell me how to increase the memory size for R on mac os X?

thank you,
Janet

[[alternative HTML version deleted]]

__
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] increase size of filled box in a legend

2009-10-21 Thread Janet Choate
Hello R user community,
can anyone tell me how to increase the size of a filled box in a legend?
thanx,
Janet

[[alternative HTML version deleted]]

__
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.