Re: [R] transform a list of arrays to tibble

2023-10-17 Thread arnaud gaboury
In fact, I realized this is not recommended to give names to rows. A
better approach is to add a column with all names as row. The
following does the job:

asset.stats <- as_tibble_col(unlist(my.ret.lst), column_name =
'Annualized_return')
asset.stats <- rownames_to_column(asset.stats, var = 'Assets')
asset.stats$Assets <- names(my.ret.lst)

asset.stats <- structure(list(Assets = c("BTCUSDT", "ETHUSDT",
"TRXUSDT"), Annualized_return = c(BTCUSDT = 15.36,
ETHUSDT = 4.06, TRXUSDT = 10.9)), row.names = c(NA, -3L), class = c("tbl_df",
"tbl", "data.frame"))

On Tue, Oct 17, 2023 at 3:33 PM  wrote:
>
> Arnaud,
>
>
> Short answer may be that the tibble data structure will not be supporting row 
> names and you may want to simply save those names in an additional column or 
> externally.
>
> My first thought was to simply save the names you need and then put them back 
> on the tibble. In your code, something like this:
>
> save.names <- names(my.ret.lst)
> result.tib <- as_tibble_col(unlist(my.ret.lst), column_name = 'return')
> rownames(result.tib) <- save.names
>
> Unfortunately, I got an error message:
>
> > save.names
> [1] "BTCUSDT" "ETHUSDT" "TRXUSDT"
> > rownames(result.tib) <- save.names
> Warning message:
> Setting row names on a tibble is deprecated.
> Error in exists(cacheKey, where = .rs.WorkingDataEnv, inherits = FALSE) :
>   invalid first argument
> Error in assign(cacheKey, frame, .rs.CachedDataEnv) :
>   attempt to use zero-length variable name
>
> If a tibble deprecates row names, it may not be the ideal storage for you. A 
> plain data.frame works:
>
> > result.df <- as.data.frame(result.tib)
> > rownames(result.df) <- save.names
> > result.df
> return
> BTCUSDT  15.36
> ETHUSDT   4.06
> TRXUSDT  10.90
>
> Trying to convert it to a tibble, as anticipated, is not working for me:
>
> > as.tibble(result.df)
> # A tibble: 3 × 1
>   return
>
> 1  15.4
> 2   4.06
> 3  10.9
> Warning message:
> `as.tibble()` was deprecated in tibble 2.0.0.
> ℹ Please use `as_tibble()` instead.
> ℹ The signature and semantics have changed, see `?as_tibble`.
> This warning is displayed once every 8 hours.
> Call `lifecycle::last_lifecycle_warnings()` to see where this
> warning was generated.
>
> You can, instead, create a matrix and assign the row and column names you 
> save or create:
>
> result.mat <- matrix(my.ret.lst)
> colnames(result.mat) <- c("return")
> rownames(result.mat) <- save.names
>
> > result.mat
> return
> BTCUSDT 15.36
> ETHUSDT 4.06
> TRXUSDT 10.9
>
> But saving a matrix to reuse has other considerations.
>
> So, if I may make a suggestion, if you really want a tibble that allows you 
> to know what each row is for, consider one of many methods for saving the 
> previous row names as a new column. I used that to take the data.frame 
> version I made above and got:
>
> > temp <- as_tibble(result.df, rownames="rows")
> > temp
> # A tibble: 3 × 2
>   rowsreturn
>   
> 1 BTCUSDT  15.4
> 2 ETHUSDT   4.06
> 3 TRXUSDT  10.9
>
> Note the above uses as_tibble with an underscore, but many other ways to make 
> a column exist.
>
>
> -Original Message-
> From: R-help  On Behalf Of arnaud gaboury
> Sent: Tuesday, October 17, 2023 4:30 AM
> To: r-help 
> Subject: [R] transform a list of arrays to tibble
>
> I work with a list of crypto assets daily closing prices in a xts
> class. Here is a limited example:
>
> asset.xts.lst <- list(BTCUSDT = structure(c(26759.63, 26862, 26852.48, 
> 27154.15,
> 27973.45), dim = c(5L, 1L), index = structure(c(1697068800, 1697155200,
> 1697241600, 1697328000, 1697414400), tzone = "UTC", tclass = "Date"),
> class = c("xts",
> "zoo")), ETHUSDT = structure(c(1539.61, 1552.16, 1554.94, 1557.77,
> 1579.73), dim = c(5L, 1L), index = structure(c(1697068800, 1697155200,
> 1697241600, 1697328000, 1697414400), tzone = "UTC", tclass = "Date"),
> class = c("xts",
> "zoo")), TRXUSDT = structure(c(0.08481, 0.08549, 0.08501, 0.08667,
> 0.08821), dim = c(5L, 1L), index = structure(c(1697068800, 1697155200,
> 1697241600, 1697328000, 1697414400), tzone = "UTC", tclass = "Date"),
> class = c("xts",
> "zoo")))
>
> I will compute some function from PerformanceAnalytics package and
> write all results in a tibble. Let's apply a first function,
> Return.annualized() (at first I computed returns from daily prices). I
> hav

[R] transform a list of arrays to tibble

2023-10-17 Thread arnaud gaboury
I work with a list of crypto assets daily closing prices in a xts
class. Here is a limited example:

asset.xts.lst <- list(BTCUSDT = structure(c(26759.63, 26862, 26852.48, 27154.15,
27973.45), dim = c(5L, 1L), index = structure(c(1697068800, 1697155200,
1697241600, 1697328000, 1697414400), tzone = "UTC", tclass = "Date"),
class = c("xts",
"zoo")), ETHUSDT = structure(c(1539.61, 1552.16, 1554.94, 1557.77,
1579.73), dim = c(5L, 1L), index = structure(c(1697068800, 1697155200,
1697241600, 1697328000, 1697414400), tzone = "UTC", tclass = "Date"),
class = c("xts",
"zoo")), TRXUSDT = structure(c(0.08481, 0.08549, 0.08501, 0.08667,
0.08821), dim = c(5L, 1L), index = structure(c(1697068800, 1697155200,
1697241600, 1697328000, 1697414400), tzone = "UTC", tclass = "Date"),
class = c("xts",
"zoo")))

I will compute some function from PerformanceAnalytics package and
write all results in a tibble. Let's apply a first function,
Return.annualized() (at first I computed returns from daily prices). I
have now a list of arrays named my.ret.lst:

my.ret.lst <- list(BTCUSDT = structure(15.36, dim = c(1L, 1L), dimnames = list(
"Annualized Return", NULL)), ETHUSDT = structure(4.06, dim = c(1L,
1L), dimnames = list("Annualized Return", NULL)), TRXUSDT =
structure(10.9, dim = c(1L,
1L), dimnames = list("Annualized Return", NULL)))

Now I can't find how to build a  tibble in a specific format (asset
names as row names and observations as column names) .
I can of course run:
> mytb <- as_tibble(unlist(my.ret.lst)
but I loose row and column names.
> as_tibble_col(unlist(my.ret.lst), column_name = 'return')
will give me the wanted column name but row names (in my case asset
names) are missing.


Thank you for help

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


Re: [R] replace character by numeric value

2023-09-28 Thread arnaud gaboury
On Thu, Sep 28, 2023 at 8:18 AM Ivan Calandra  wrote:
>
> Dear Arnaud,
>
> I don't quite unterstand why you have imbricated ifelse() statements. Do
> you have more that BUY (1) and SELL (-1)? If not, why not simply:
> mynewdf2 <- mydf2 |> dplyr::mutate(side = ifelse(side == 'BUY', 1, -1))

Yes it works indeed.
I found another solution :
df <- df |> mutate(side = as.numeric(ifelse(side == 'BUY', 1,
ifelse(side == 'SELL', -1, side
but yours is much simpler. and I can use dplyr::if_else() or
fifelse(). which looks safer and faster.

>
> That would solve the problem. I'm not quite sure exactly what happens,
> but this is probably related to the intermediary result after the first
> ifelse(), where characters and numeric are mixed. But conversion to
> numeric works properly, so I'm not sure what you meant:
> as.numeric(mynewdf2$side)
>
> More generally, why are you trying to convert to 1 and -1?

I am working on a crypto asset portfolio and want to compute profit &
loss. To achieve it, I need to convert (BUY * quantity) to quantity
and
(SELL * quantity) to -quantity.

Thank you for your answer.

Why not use
> factors? Are you trying to test contrasts maybe? I would be surprised if
> the function for the statistical test you are trying to use does not
> deal with that already on its own.
>
> HTH,
> Ivan
>
>
> On 27/09/2023 13:01, arnaud gaboury wrote:
> > I have two data.frames:
> >
> > mydf1 <- structure(list(symbol = "ETHUSDT", cummulative_quote_qty =
> > 1999.9122, side = "BUY", time = structure(1695656875.805, tzone = "", class
> > = c("POSIXct", "POSIXt"))), row.names = c(NA, -1L), class = c("data.table",
> > "data.frame"))
> >
> > mydf2 <- structure(list(symbol = c("ETHUSDT", "ETHUSDT", "ETHUSDT"),
> > cummulative_quote_qty = c(1999.119408,
> > 0, 2999.890985), side = c("SELL", "BUY", "BUY"), time =
> > structure(c(1695712848.487,
> > 1695744226.993, 1695744509.082), class = c("POSIXct", "POSIXt"
> > ), tzone = "")), row.names = c(NA, -3L), class = c("data.table",
> > "data.frame"))
> >
> > I use this line to replace 'BUY' by numeric 1 and 'SELL' by numeric -1 in
> > mydf1 and mydf2:
> > mynewdf <- mydf |> dplyr::mutate(side = ifelse(side == 'BUY', 1,
> > ifelse(side == 'SELL', -1, side)))
> >
> > This does the job but I am left with an issue: 1 and -1 are characters for
> > mynewdf2 when it is numeric for mynewdf1. The result I am expecting is
> > getting numeric values.
> > I can't solve this issue (using as.numeric(1) doesn't work) and don't
> > understand why I am left with num for mynewdf1 and characters for mynewdf2.
> >
> >> mynewdf1 <- mydf1 |> dplyr::mutate(side = ifelse(side == 'BUY', 1,
> > ifelse(side == 'SELL', -1, side)))
> >> str(mynewdf1)
> > Classes ‘data.table’ and 'data.frame': 1 obs. of  4 variables:
> >   $ symbol   : chr "ETHUSDT"
> >   $ cummulative_quote_qty: num 2000
> >   $ side : num 1  <<<--
> >   $ time : POSIXct, format: "2023-09-25 17:47:55"
> >   - attr(*, ".internal.selfref")=
> >
> >> mynewdf2 <- mydf2 |> dplyr::mutate(side = ifelse(side == 'BUY', 1,
> > ifelse(side == 'SELL', -1, side)))
> >>   str(mynewdf2)
> > Classes ‘data.table’ and 'data.frame': 3 obs. of  4 variables:
> >   $ symbol   : chr  "ETHUSDT" "ETHUSDT" "ETHUSDT"
> >   $ cummulative_quote_qty: num  1999 0 3000
> >   $ side : chr  "-1" "1" "1"   <<<--
> >   $ time : POSIXct, format: "2023-09-26 09:20:48"
> > "2023-09-26 18:03:46" "2023-09-26 18:08:29"
> >   - attr(*, ".internal.selfref")=
> >
> > Thank you for help
> >
> >   [[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 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 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] replace character by numeric value

2023-09-28 Thread arnaud gaboury
I have two data.frames:

mydf1 <- structure(list(symbol = "ETHUSDT", cummulative_quote_qty =
1999.9122, side = "BUY", time = structure(1695656875.805, tzone = "", class
= c("POSIXct", "POSIXt"))), row.names = c(NA, -1L), class = c("data.table",
"data.frame"))

mydf2 <- structure(list(symbol = c("ETHUSDT", "ETHUSDT", "ETHUSDT"),
cummulative_quote_qty = c(1999.119408,
0, 2999.890985), side = c("SELL", "BUY", "BUY"), time =
structure(c(1695712848.487,
1695744226.993, 1695744509.082), class = c("POSIXct", "POSIXt"
), tzone = "")), row.names = c(NA, -3L), class = c("data.table",
"data.frame"))

I use this line to replace 'BUY' by numeric 1 and 'SELL' by numeric -1 in
mydf1 and mydf2:
mynewdf <- mydf |> dplyr::mutate(side = ifelse(side == 'BUY', 1,
ifelse(side == 'SELL', -1, side)))

This does the job but I am left with an issue: 1 and -1 are characters for
mynewdf2 when it is numeric for mynewdf1. The result I am expecting is
getting numeric values.
I can't solve this issue (using as.numeric(1) doesn't work) and don't
understand why I am left with num for mynewdf1 and characters for mynewdf2.

> mynewdf1 <- mydf1 |> dplyr::mutate(side = ifelse(side == 'BUY', 1,
ifelse(side == 'SELL', -1, side)))
> str(mynewdf1)
Classes ‘data.table’ and 'data.frame': 1 obs. of  4 variables:
 $ symbol   : chr "ETHUSDT"
 $ cummulative_quote_qty: num 2000
 $ side : num 1  <<<--
 $ time : POSIXct, format: "2023-09-25 17:47:55"
 - attr(*, ".internal.selfref")=

> mynewdf2 <- mydf2 |> dplyr::mutate(side = ifelse(side == 'BUY', 1,
ifelse(side == 'SELL', -1, side)))
>  str(mynewdf2)
Classes ‘data.table’ and 'data.frame': 3 obs. of  4 variables:
 $ symbol   : chr  "ETHUSDT" "ETHUSDT" "ETHUSDT"
 $ cummulative_quote_qty: num  1999 0 3000
 $ side : chr  "-1" "1" "1"   <<<--
 $ time : POSIXct, format: "2023-09-26 09:20:48"
"2023-09-26 18:03:46" "2023-09-26 18:08:29"
 - attr(*, ".internal.selfref")=

Thank you for help

[[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] apply a function to a list of lists

2023-09-20 Thread arnaud gaboury
I have a list of 9 lists called my.list. Each one of these 9 lists is
itself a list of 6 data.frames. Most of these data.frames have 0 rows and 0
columns.
I want to return all data.frames from the list with row numbers different
from 0.
I first created the following function:

non_empty_df <- function(l) {
lapply(l, function(df) df[sapply(df, function(df) nrow(df) !=0)])
}

If I test this way: non_empty_df(my.list[1]) it does the job. It will
return the data.frame from the first list of my_list with rows.
Now I can't find a way to iterate the above function to all the 9 nested
lists.

Thank you for help

[[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] getting historical data from cryptocurrency exchange

2020-11-25 Thread arnaud gaboury
I need to download basic OHLCV (Open, High, Low, Close, Volume) in a
hourly format from various cryptocurrency exchanges.
There is the crypto package[0] but it has been removed from CRAN. Then
there is the coinmarketcapr[1] package on CRAN, but it is limited to a
paid service, coinmarketcap, which sell data.

Browsing the web, I mainly found Python scripts to fetch the data, which
I would like to avoid. Can anyone point me to any github or website with
material about crypto data fetching with R?

Thank you


[0]https://cran.r-project.org/web/packages/crypto/index.html
[1]https://github.com/amrrs/coinmarketcapr

__
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] change col types of a df/tbl_df

2015-12-10 Thread arnaud gaboury
Here is a sample of my data frame, obtained with read_csv2 from readr package.

myDf <- structure(list(X15 = c("30.09.2015", "05.10.2015", "30.09.2015",

"29.09.2015", "10.10.2015"), X16 = c("02.10.2015", "06.10.2015",
"01.10.2015", "01.10.2015", "13.10.2015"), X17 = c("Grains",
"Grains", "Grains", "Grains", "Grains"), X18 = c("Soyabeans",
"Soyabeans", "Soyabeans", "Soyabeans", "Soyabeans"), X19 = c("20,000",
"20,000", "20,000", "29,930", "26,000")), .Names = c("X15", "X16",
"X17", "X18", "X19"), class = c("tbl_df", "data.frame"), row.names = c(NA,
-5L))

gabx@hortensia [R] str(myDf)
Classes ‘tbl_df’ and 'data.frame': 5 obs. of  5 variables:
 $ X15: chr  "30.09.2015" "05.10.2015" "30.09.2015" "29.09.2015" ...
 $ X16: chr  "02.10.2015" "06.10.2015" "01.10.2015" "01.10.2015" ...
 $ X17: chr  "Grains" "Grains" "Grains" "Grains" ...
 $ X18: chr  "Soyabeans" "Soyabeans" "Soyabeans" "Soyabeans" ...
 $ X19: chr  "20,000" "20,000" "20,000" "29,930" ...

I want to change date to date class and numbers (X19) to numeric, and
keep the class of my object.

This code works:

myDf$X19 <- as.numeric(gsub(",", "", myDf$X19))
myDf$X15 <- as.Date(myDf$X15, format = "%d.%m.%Y"))
myDf$X16 <- as.Date(myDf$X16, format = "%d.%m.%Y"))

Now, as I have more than 5 columns, this can be fastidious and slowing
code (?), even if I can group by type. Columns are only types of char,
num and Date, so it could be OK.

I tried with lapply for the Date columns. It works BUT will place NA
in any columns with numbers as characters.
The reuslt will be this for X19:  num NA NA NA NA NA NA NA NA NA NA ..

How can I target my goal with something else than lapply or writing a
line for each type ?

Thank you for hints.


-- 

google.com/+arnaudgabourygabx

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

Re: [R] change col types of a df/tbl_df

2015-12-10 Thread arnaud gaboury
On Thu, Dec 10, 2015 at 12:54 PM, Duncan Murdoch <murdoch.dun...@gmail.com>
wrote:

> On 10/12/2015 6:12 AM, arnaud gaboury wrote:
>
>> Here is a sample of my data frame, obtained with read_csv2 from readr
>> package.
>>
>> myDf <- structure(list(X15 = c("30.09.2015", "05.10.2015", "30.09.2015",
>>
>> "29.09.2015", "10.10.2015"), X16 = c("02.10.2015", "06.10.2015",
>> "01.10.2015", "01.10.2015", "13.10.2015"), X17 = c("Grains",
>> "Grains", "Grains", "Grains", "Grains"), X18 = c("Soyabeans",
>> "Soyabeans", "Soyabeans", "Soyabeans", "Soyabeans"), X19 = c("20,000",
>> "20,000", "20,000", "29,930", "26,000")), .Names = c("X15", "X16",
>> "X17", "X18", "X19"), class = c("tbl_df", "data.frame"), row.names = c(NA,
>> -5L))
>>
>> gabx@hortensia [R] str(myDf)
>> Classes ‘tbl_df’ and 'data.frame': 5 obs. of  5 variables:
>>   $ X15: chr  "30.09.2015" "05.10.2015" "30.09.2015" "29.09.2015" ...
>>   $ X16: chr  "02.10.2015" "06.10.2015" "01.10.2015" "01.10.2015" ...
>>   $ X17: chr  "Grains" "Grains" "Grains" "Grains" ...
>>   $ X18: chr  "Soyabeans" "Soyabeans" "Soyabeans" "Soyabeans" ...
>>   $ X19: chr  "20,000" "20,000" "20,000" "29,930" ...
>>
>> I want to change date to date class and numbers (X19) to numeric, and
>> keep the class of my object.
>>
>> This code works:
>>
>> myDf$X19 <- as.numeric(gsub(",", "", myDf$X19))
>> myDf$X15 <- as.Date(myDf$X15, format = "%d.%m.%Y"))
>> myDf$X16 <- as.Date(myDf$X16, format = "%d.%m.%Y"))
>>
>> Now, as I have more than 5 columns, this can be fastidious and slowing
>> code (?), even if I can group by type. Columns are only types of char,
>> num and Date, so it could be OK.
>>
>> I tried with lapply for the Date columns. It works BUT will place NA
>> in any columns with numbers as characters.
>> The reuslt will be this for X19:  num NA NA NA NA NA NA NA NA NA NA ..
>>
>> How can I target my goal with something else than lapply or writing a
>> line for each type ?
>>
>
> I don't see how a function could reliably detect the types,

In fact, I only have 25 columns, so it is not difficult to list them in the
3 types: char, num and Date. No need of a function thus.


> but it might be good enough to use a regular expression, possibly just on
> the first line of the result.  Once you've identified columns, e.g.
>
>  numcols <- 19
>  datecols <- c(15:16)
>
> etc, you can use lapply:
>
> myDf[,numcols] <- lapply(myDf[, numcools, drop=FALSE], function(x)
> as.numeric(gsub(",", "", x)))
>
> You can simplify myDf[,numcols] to myDf[numcols] if you want, but I think
> it makes it less clear.


Thank you.

>
>
> Duncan Murdoch
>
>


-- 

google.com/+arnaudgabourygabx
<https://plus.google.com/_/notifications/emlink?emr=05814804238976922326=CKiv-v6PvboCFcfoQgod6msAAA=%2F116159236040461325607%2Fop%2Fu=1383086841306=50>

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

Re: [R] change col types of a df/tbl_df

2015-12-10 Thread arnaud gaboury
On Thu, Dec 10, 2015 at 1:47 PM, Giorgio Garziano <
giorgio.garzi...@ericsson.com> wrote:

> my_convert <- function(col) {
>   v <- grep("[0-9]{2}.[0-9]{2}.[0-9]{4}", col);
>   w <- grep("[0-9]+,[0-9]+", col)
>   col2 <- col
>   if (length(v) == length(col)){
> col2 <- as.Date(col, format="%d.%m.%y")
>   } else if (length(w) == length(col)) {
> col2 <- as.numeric(gsub(",", "", col))
>   }
>   col2
> }
>
> myDf <- as.data.frame(lapply(myDf, my_convert), stringsAsFactors = FALSE)
>
> Sounds good. I will give a try,
Thank you

> --
> GG
>
>
> [[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.
>



-- 

google.com/+arnaudgabourygabx


[[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] R environment variables

2015-10-10 Thread arnaud gaboury
I was doing some cleaning ony my linux machine and, among others, I
try to clean my R environment variables accordingly [0] and [1].
I am not really sure how to declare in a clean manner these startup variables.

Here is my setup:

1- my home folder
-$ ls ~/.config/R
env/  helper/  Renviron  Rprofile.r

2- system R install
/usr/lib/R

3- user library
/developement/language/r/library

4- system configuration files: (NOTE: /usr/lib/R/etc/ are symlnks to
the below files)
$ ls /etc/R/
javaconf  ldpaths  Makeconf  Renviron  repositories



Most important R environment variables for my system:
R_HOME, R_LIBS, R_LIBS_SITE,R_LIBS_USER,R_ENVIRON,R_ENVIRON_USER,R_PROFILE_USER

As far I can understand, in my setup, these above variables would be:
R_LIBS_SITE=/usr/lib/R/library
R_LIBS_USER=/developement/language/r/library
R_ENVIRON=/usr/lib/R/etc/Renviron
R_ENVIRON_USER=~/.config/R/Renviron
R_PROFILE_USER=~/.config/R/Rprofile.r

I have a doubt about two variables:
R_HOME=/usr/lib/R/ right ? Is there any need to export it in my environment?
R_LIBS=${R_LIBS_USER}:${R_LIBS_SITE} right ?

Do I need to export all these mentioned variables in my user
environment? Until now, I jsut export R_ENVIRON_USER,R_PROFILE_USER
via my /etc/profile file.

$ cat ~/.config/r/Renviron

R_HOME=/usr/lib/R
R_HOME_USER=/developement/language/r
R_LIBS_USER=${R_HOME_USER}/library
R_LIBS=${R_LIBS_USER}:${R_HOME}/library
R_HISTFILE=/developement/language/r/R.Rhistory
R_HELPER=/home/gabx/.config/r/helper
R_HISTSIZE=5000


Are the above variables correctly set ?

On a R session, Sys.getenv() returns correctly everything, except
R_LIBS_SITE which is empty. Why? Do I need to export it somewhere ?
R_LIBS/developement/language/r/library:/usr/lib/R/library  Is
this the correct way for R to see R_LIBS? Then, when I upgrade
packages, do I need to upgrade separatly site library and user
library, or just one ligne upgardaing jusr R_LIBS?

Thank you for any advice on my current variable declaration setup.



[0]http://stat.ethz.ch/R-manual/R-devel/library/base/html/EnvVar.html
[1]http://stat.ethz.ch/R-manual/R-devel/library/base/html/Startup.html
-- 

google.com/+arnaudgabourygabx

__
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] Build R with optimized BLAS library

2015-08-22 Thread arnaud gaboury
I want to build R with an optimized BLAS library.
My OS: Fedora 22
Hardware: CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian
CPU(s): 8 Thread(s) per core: 2 Vendor ID: GenuineIntel Model name:
Intel(R) Core(TM) i7-2600K CPU @ 3.40GHz

I am a little confused when it comes to choose a method and would like
to hear your experiences. If I am right, I have 3 possibilities:
- OpenBLAS: opensource and free, but I came across some posts
describing seg faults issues and bugs. These posts are 2 years old and
I wonder if it is still the case.
- ATLAS: can't see any reason to not use it
- Intel MKL: this is part of Intel Parallel Studio and is a paid
software. Now, there is the MKL package distributed by
Revolutionanalytics, but I am not certain how this can be distributed
for free. Is there any kind of difference? In case of use of this
package, do I need to install RRO or can I just build R from GNU
against these libraries?

Thank you for advices.

-- 

google.com/+arnaudgabourygabx

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


Re: [R] Build R with optimized BLAS library

2015-08-22 Thread arnaud gaboury
On Sat, Aug 22, 2015, 5:12 PM Jeff Newmiller jdnew...@dcn.davis.ca.us
wrote:

Questions about compiling generally belong on R-devel.

Ok. Sorrx fpr the noise


---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
---
Sent from my phone. Please excuse my brevity.

On August 22, 2015 7:51:39 AM PDT, arnaud gaboury arnaud.gabo...@gmail.com
wrote:
I want to build R with an optimized BLAS library.
My OS: Fedora 22
Hardware: CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian
CPU(s): 8 Thread(s) per core: 2 Vendor ID: GenuineIntel Model name:
Intel(R) Core(TM) i7-2600K CPU @ 3.40GHz

I am a little confused when it comes to choose a method and would like
to hear your experiences. If I am right, I have 3 possibilities:
- OpenBLAS: opensource and free, but I came across some posts
describing seg faults issues and bugs. These posts are 2 years old and
I wonder if it is still the case.
- ATLAS: can't see any reason to not use it
- Intel MKL: this is part of Intel Parallel Studio and is a paid
software. Now, there is the MKL package distributed by
Revolutionanalytics, but I am not certain how this can be distributed
for free. Is there any kind of difference? In case of use of this
package, do I need to install RRO or can I just build R from GNU
against these libraries?

Thank you for advices.

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


Re: [R] Running R in Server

2015-08-18 Thread arnaud gaboury
On Sun, Aug 16, 2015, 2:29 PM Swagato Chatterjee swagato1...@gmail.com
wrote:

Hello,

I have written a R script which runs a regression of a dataset and saves
the result in a csv file.

Now this dataset has to be edited periodically which is done in a server. I
need to run the R script in a server so that the results can also be shared
in a server and used in a web application.

Have a look at deployR on Revolutioanalytic website. There is a free
open-source solution for windows.

I have coded in R and have used R in windows. I have never used
Ubuntu/Linux. Is there a step by step guide on how to run a R code in
server?

Thanks and Regards,

Swagato

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

[[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] misbehavior with extract_numeric() from tidyr

2015-04-20 Thread arnaud gaboury
R 3.2.0 on Linux


library(tidyr)

playerStats - c(LVL 10, 5,671,448 AP l6,000,000 AP, Unique
Portals Visited 1,038,
XM Collected 15,327,123 XM, Hacks 14,268, Resonators Deployed 11,126,
Links Created 1,744, Control Fields Created 294, Mind Units
Captured 2,995,484 MUs,
Longest Link Ever Created 75 km, Largest Control Field 189,731 MUs,
XM Recharged 3,006,364 XM, Portals Captured 1,204, Unique Portals
Captured 486,
Resonators Destroyed 12,481, Portals Neutralized 1,240, Enemy
Links Destroyed 3,169,
Enemy Control Fields Destroyed 1,394, Distance Walked 230 km,
Max Time Portal Held 240 days, Max Time Link Maintained 15 days,
Max Link Length x Days 276 km-days, Max Time Field Held 4days,
Largest Field MUs x Days 83,226 MU-days)

---
 extract_numeric(playerStats)
 [1] 10 5671448600   1038   15327123
   14268  11126   17442942995484
[10] 75 1897313006364   1204
 486  12481   1240   3169   1394
[19]230240 15 NA
   4 NA


 playerStats[c(22,24)]
[1] Max Link Length x Days 276 km-days  Largest Field MUs x
Days 83,226 MU-days


I do not understand why these two vectors return NA when the function
extract_numeric() works well for others,

Any wrong settings in my env?

Thank you for hints.



-- 

google.com/+arnaudgabourygabx

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


Re: [R] misbehavior with extract_numeric() from tidyr

2015-04-20 Thread arnaud gaboury
On Mon, Apr 20, 2015 at 12:09 PM, Jim Lemon drjimle...@gmail.com wrote:
 Hi arnaud,
 At a guess, it is the two hyphens that are present in those strings. I
 think that the function you are using interprets them as subtraction
 operators and since the string following the hyphen would produce NA,
 the result would be NA.

I was thinking of 'x' as being the culprit (interpreted as multiply)
but you are right indeed

noHyphens - str_replace(playerStats[c(22,24)],'-','')
 extract_numeric(noHyphens)
[1]   276 83226


in fact:
-
 extract_numeric
function (x)
{
as.numeric(gsub([^0-9.-]+, , as.character(x)))
}
environment: namespace:tidyr
-

Is there any particular reason for the hyphen in gsub() ? Why not
remove it thus ?

TY much Jim


 Jim


 On Mon, Apr 20, 2015 at 7:46 PM, arnaud gaboury
 arnaud.gabo...@gmail.com wrote:
 On Mon, Apr 20, 2015 at 9:10 AM, arnaud gaboury
 arnaud.gabo...@gmail.com wrote:
 R 3.2.0 on Linux
 

 library(tidyr)

 playerStats - c(LVL 10, 5,671,448 AP l6,000,000 AP, Unique
 Portals Visited 1,038,
 XM Collected 15,327,123 XM, Hacks 14,268, Resonators Deployed 11,126,
 Links Created 1,744, Control Fields Created 294, Mind Units
 Captured 2,995,484 MUs,
 Longest Link Ever Created 75 km, Largest Control Field 189,731 MUs,
 XM Recharged 3,006,364 XM, Portals Captured 1,204, Unique Portals
 Captured 486,
 Resonators Destroyed 12,481, Portals Neutralized 1,240, Enemy
 Links Destroyed 3,169,
 Enemy Control Fields Destroyed 1,394, Distance Walked 230 km,
 Max Time Portal Held 240 days, Max Time Link Maintained 15 days,
 Max Link Length x Days 276 km-days, Max Time Field Held 4days,
 Largest Field MUs x Days 83,226 MU-days)

 ---
  extract_numeric(playerStats)
  [1] 10 5671448600   1038   15327123
14268  11126   17442942995484
 [10] 75 1897313006364   1204
  486  12481   1240   3169   1394
 [19]230240 15 NA
4 NA

 
  playerStats[c(22,24)]
 [1] Max Link Length x Days 276 km-days  Largest Field MUs x
 Days 83,226 MU-days
 

 I do not understand why these two vectors return NA when the function
 extract_numeric() works well for others,

 Any wrong settings in my env?

 -
  as.numeric(gsub([^0-9], ,playerStats))
  [1] 10 5671448600   1038   15327123
14268  11126   17442942995484
 [10] 75 1897313006364   1204
  486  12481   1240   3169   1394
 [19]230240 15276
4  83226
 

 The above command does the job, but I still can not figure out why
 extract_numeric() returns two NA


 Thank you for hints.



 --

 google.com/+arnaudgabourygabx



 --

 google.com/+arnaudgabourygabx

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



-- 

google.com/+arnaudgabourygabx

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


Re: [R] misbehavior with extract_numeric() from tidyr

2015-04-20 Thread arnaud gaboury
On Mon, Apr 20, 2015 at 9:10 AM, arnaud gaboury
arnaud.gabo...@gmail.com wrote:
 R 3.2.0 on Linux
 

 library(tidyr)

 playerStats - c(LVL 10, 5,671,448 AP l6,000,000 AP, Unique
 Portals Visited 1,038,
 XM Collected 15,327,123 XM, Hacks 14,268, Resonators Deployed 11,126,
 Links Created 1,744, Control Fields Created 294, Mind Units
 Captured 2,995,484 MUs,
 Longest Link Ever Created 75 km, Largest Control Field 189,731 MUs,
 XM Recharged 3,006,364 XM, Portals Captured 1,204, Unique Portals
 Captured 486,
 Resonators Destroyed 12,481, Portals Neutralized 1,240, Enemy
 Links Destroyed 3,169,
 Enemy Control Fields Destroyed 1,394, Distance Walked 230 km,
 Max Time Portal Held 240 days, Max Time Link Maintained 15 days,
 Max Link Length x Days 276 km-days, Max Time Field Held 4days,
 Largest Field MUs x Days 83,226 MU-days)

 ---
  extract_numeric(playerStats)
  [1] 10 5671448600   1038   15327123
14268  11126   17442942995484
 [10] 75 1897313006364   1204
  486  12481   1240   3169   1394
 [19]230240 15 NA
4 NA

 
  playerStats[c(22,24)]
 [1] Max Link Length x Days 276 km-days  Largest Field MUs x
 Days 83,226 MU-days
 

 I do not understand why these two vectors return NA when the function
 extract_numeric() works well for others,

 Any wrong settings in my env?

-
 as.numeric(gsub([^0-9], ,playerStats))
 [1] 10 5671448600   1038   15327123
   14268  11126   17442942995484
[10] 75 1897313006364   1204
 486  12481   1240   3169   1394
[19]230240 15276
   4  83226


The above command does the job, but I still can not figure out why
extract_numeric() returns two NA


 Thank you for hints.



 --

 google.com/+arnaudgabourygabx



-- 

google.com/+arnaudgabourygabx

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


Re: [R] misbehavior with extract_numeric() from tidyr

2015-04-20 Thread arnaud gaboury
On Mon, Apr 20, 2015 at 6:09 PM, William Dunlap wdun...@tibco.com wrote:

 The hyphen without a following digit confuses tidyr::extract_numeric().
 E.g.,
 extract_numeric(23 ft-lbs)
Warning message:
In extract_numeric(23 ft-lbs) : NAs introduced by coercion
[1] NA
 extract_numeric(23 ft*lbs)
[1] 23


See[0] for the reason on the minus in the regex. It is not a bug but a wish.
I am honestly very surprised the maintainer decided to go with such a so
simple solution for negative numbers.

[0]https://github.com/hadley/tidyr/issues/20

Contact the BugReports address for the package
 packageDescription(tidyr)$BugReports
[1] https://github.com/hadley/tidyr/issues;
 or package's maintainer
 maintainer(tidyr)
[1] Hadley Wickham had...@rstudio.com
 to report problems in a user-contributed package.



 Bill Dunlap
 TIBCO Software
 wdunlap tibco.com

 On Mon, Apr 20, 2015 at 12:10 AM, arnaud gaboury arnaud.gabo...@gmail.com
  wrote:

 R 3.2.0 on Linux
 

 library(tidyr)

 playerStats - c(LVL 10, 5,671,448 AP l6,000,000 AP, Unique
 Portals Visited 1,038,
 XM Collected 15,327,123 XM, Hacks 14,268, Resonators Deployed
 11,126,
 Links Created 1,744, Control Fields Created 294, Mind Units
 Captured 2,995,484 MUs,
 Longest Link Ever Created 75 km, Largest Control Field 189,731 MUs,
 XM Recharged 3,006,364 XM, Portals Captured 1,204, Unique Portals
 Captured 486,
 Resonators Destroyed 12,481, Portals Neutralized 1,240, Enemy
 Links Destroyed 3,169,
 Enemy Control Fields Destroyed 1,394, Distance Walked 230 km,
 Max Time Portal Held 240 days, Max Time Link Maintained 15 days,
 Max Link Length x Days 276 km-days, Max Time Field Held 4days,
 Largest Field MUs x Days 83,226 MU-days)


 ---
  extract_numeric(playerStats)
  [1] 10 5671448600   1038   15327123
14268  11126   17442942995484
 [10] 75 1897313006364   1204
  486  12481   1240   3169   1394
 [19]230240 15 NA
4 NA


 
  playerStats[c(22,24)]
 [1] Max Link Length x Days 276 km-days  Largest Field MUs x
 Days 83,226 MU-days

 

 I do not understand why these two vectors return NA when the function
 extract_numeric() works well for others,

 Any wrong settings in my env?

 Thank you for hints.



 --

 google.com/+arnaudgabourygabx

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





-- 

google.com/+arnaudgabourygabx
https://plus.google.com/_/notifications/emlink?emr=05814804238976922326emid=CKiv-v6PvboCFcfoQgod6msAAApath=%2F116159236040461325607%2Fop%2Fudt=1383086841306ub=50

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


Re: [R] Error when loading shared library - stringini()

2015-04-16 Thread arnaud gaboury
On Thu, Apr 16, 2015 at 3:25 PM, arnaud gaboury arnaud.gabo...@gmail.com
wrote:

 On a Linux 64 bits, R.3.1.2, with tidyr() loaded.

 gabx@hortensia [R] separate(rawStats, 'toto')
 Error in dyn.load(file, DLLpath = DLLpath, ...) :
   unable to load shared object
 '/developement/language/r/library/stringi/libs/stringi.so':
   libicui18n.so.54: cannot open shared object file: No such file or
 directory
 

 When trying to upgrade stringini(), it is not available for 3.1.2


 install_github('Rexamine/stringi')

did the trick


 My box run :icu 55.1-1  :lib32-icu 55.1-1

 If I am right, I need to downgrade to 54 to be able to run separate()
 from tidyr package? Or is there any other way?

 Thank you for hint.


 --

 google.com/+arnaudgabourygabx




-- 

google.com/+arnaudgabourygabx
https://plus.google.com/_/notifications/emlink?emr=05814804238976922326emid=CKiv-v6PvboCFcfoQgod6msAAApath=%2F116159236040461325607%2Fop%2Fudt=1383086841306ub=50

[[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] Error when loading shared library - stringini()

2015-04-16 Thread arnaud gaboury
On a Linux 64 bits, R.3.1.2, with tidyr() loaded.

gabx@hortensia [R] separate(rawStats, 'toto')
Error in dyn.load(file, DLLpath = DLLpath, ...) :
  unable to load shared object
'/developement/language/r/library/stringi/libs/stringi.so':
  libicui18n.so.54: cannot open shared object file: No such file or directory


When trying to upgrade stringini(), it is not available for 3.1.2

My box run :icu 55.1-1  :lib32-icu 55.1-1

If I am right, I need to downgrade to 54 to be able to run separate()
from tidyr package? Or is there any other way?

Thank you for hint.


-- 

google.com/+arnaudgabourygabx

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


Re: [R] Running R Remotely on LINUX

2015-04-15 Thread arnaud gaboury
On Tue, Apr 14, 2015 at 10:09 PM, John Sorkin
jsor...@grecc.umaryland.edu wrote:
  I suggest that you investigate installing RStudio server on the Linux
 Box. If you do this, you can logon to RStudio (on the Linux server), and
 it will look exactly like RStudio running on a windows box. You may need
 some help configuring the Linux box to allow access to port 8787, which
 is the default port that RStudio Server uses. You may also have to set
 port forwarding on your cable modem or firewall.
 John

In case you just need a R server, with no IDE (like Rstudio provides
it), please have a look at this project[0]

[0]http://www.obiba.org/?q=node/63


 John David Sorkin M.D., Ph.D.
 Professor of Medicine
 Chief, Biostatistics and Informatics
 University of Maryland School of Medicine Division of Gerontology and
 Geriatric Medicine
 Baltimore VA Medical Center
 10 North Greene Street
 GRECC (BT/18/GR)
 Baltimore, MD 21201-1524
 (Phone) 410-605-7119
 (Fax) 410-605-7913 (Please call phone number above prior to faxing)
 Jeff Newmiller jdnew...@dcn.davis.ca.us 04/14/15 2:54 PM 
 You should investigate using the parallel package. You have to have R
 installed on the Linux machine along with any contributed packages you
 use, but you can delegate tasks to it from within an Rgui or RStudio
 session running on your Windows box. There are even tutorials online
 that step you through setting up a cloud computer to serve this
 purpose.

 It is possible to install R under your own account on a Linux server,
 but there are more hiccups to overcome in doing so. There is a small
 charge for using cloud servers, but if you use it right then the cost
 can be quite cheap.

 Note that while you can set up Windows servers in the cloud, they are
 not as well suited to this remote use as Linux servers are, so it is
 worth the effort to learn enough to do that.
 ---
 Jeff Newmiller The . . Go Live...
 DCN:jdnew...@dcn.davis.ca.us Basics: ##.#. ##.#. Live Go...
  Live: OO#.. Dead: OO#.. Playing
 Research Engineer (Solar/Batteries O.O#. #.O#. with
 /Software/Embedded Controllers) .OO#. .OO#. rocks...1k
 ---

 Sent from my phone. Please excuse my brevity.

 On April 14, 2015 9:57:28 AM PDT, Michael Haenlein
 haenl...@escpeurope.eu wrote:
Dear all,

I am used to running R locally on my Windows-based PC. Since some of my
computations are taking a lot of time I am now trying to move to a
remote R
session on a LINUX server but I am having trouble to getting things
work.

I am able to access the LINUX server using PuTTY and SSH. Once I have
access I can log in with my username and password (which is asked
through
keyboard-interactive authentication). I can then open an R session.

Since I am not used to working with LINUX, I have several questions:

(1) Ideally I am looking for a Windows-based software that would allow
me
to work on R as I am used to with the difference that the computations
are
run remotely on the LINUX server. Does a software like this exist?
Please
note that I do not think that I can install any software on the LINUX
server. But I can install stuff on my Windows-based PC.

(2) I am running an extensive simulation that takes about one week to
run.
Right now it seems that when I log out of R on LINUX and close PuTTY,
the R
session closes as well. Is there a way to let R run in the background
for
the week and just check into the progress 1-2 times a day?

(3) Can I open several instances of R in parallel? On my PC I sometimes
have 2-3 windows open in parallel that work on different calculations
to
save time. Not sure to which extent this is possible on LINUX.

I assume that this questions are very naïve. But since I’m only used to
working with Windows I’m quite stuck at the moment. Any help would be
very
appreciated!

Thanks in advance,

Michael




Michael Haenlein
Professor of Marketing
ESCP Europe

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mand provide commented, minimal, self-contained, 
reproducible code.

 __
 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.
 Confidentiality Statement:
 This email message, including any attachments, is for ...{{dropped:18}}

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

Re: [R] Running R Remotely on LINUX

2015-04-14 Thread arnaud gaboury
On Tue, Apr 14, 2015 at 7:09 PM, Sarah Goslee sarah.gos...@gmail.com wrote:

 Hi Michael,

 On Tue, Apr 14, 2015 at 12:57 PM, Michael Haenlein
 haenl...@escpeurope.eu wrote:
  Dear all,
 
  I am used to running R locally on my Windows-based PC. Since some of my
  computations are taking a lot of time I am now trying to move to a remote R
  session on a LINUX server but I am having trouble to getting things work.

Please have a look at this link[0]. It may help



  I am able to access the LINUX server using PuTTY and SSH. Once I have
  access I can log in with my username and password (which is asked through
  keyboard-interactive authentication). I can then open an R session.
 
  Since I am not used to working with LINUX, I have several questions:
 
  (1) Ideally I am looking for a Windows-based software that would allow me
  to work on R as I am used to with the difference that the computations are
  run remotely on the LINUX server. Does a software like this exist? Please
  note that I do not think that I can install any software on the LINUX
  server. But I can install stuff on my Windows-based PC.

 I'm not even sure what this question means, sorry.

  (2) I am running an extensive simulation that takes about one week to run.
  Right now it seems that when I log out of R on LINUX and close PuTTY, the R
  session closes as well. Is there a way to let R run in the background for
  the week and just check into the progress 1-2 times a day?

 Start screen on the linux system, then start R. Once the R job is
 running, you can disconnect from the screen with Ctrl-A Ctrl-D and the
 R job will continue in the background. Google linux screen for more
 information.

  (3) Can I open several instances of R in parallel? On my PC I sometimes
  have 2-3 windows open in parallel that work on different calculations to
  save time. Not sure to which extent this is possible on LINUX.

 Sure. Using screen you can have multiple sessions going.

 Sarah

 --
 Sarah Goslee
 http://www.functionaldiversity.org

[0]https://www.opencpu.org/

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




-- 

google.com/+arnaudgabourygabx

__
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] replace values in one df by values from key pairs in another df

2015-02-13 Thread arnaud gaboury
I have been searching for a while now, but can't put all pieces of the
puzzle together.

Goal : I want to replace all these kinds of patterns @U032FHV3S by
this @agreenmamba. In a more generic way, it is replacing 'id' by
user 'name'.

I have two df:
The first, 'history', is some message history where I want to do the
replacement. It is a chat history log,
The second one, idName, is a list of id:name. All are unique. This df
rows are exctracted from a bigger one called 'users' this way :
users[users$id %in% ext].


Please find below my two data.frames:
-
history - structure(list(name = c(xaeth, agreenmamba, poisonivy,
agreenmamba, cruzecontrol, poisonivy, poisonivy, vairis,
vairis, poisonivy), text = c(and people told that agent their
geocities experience would never amount to anything (the convo
yesterday) ,
@U032FHV3S http://youtu.be/oGIFublvDes, for me there is no such
question,
@U03AEKWTL|agreenmamba uploaded a file:
https://enlightened.slack.com/files/agreenmamba/F03KGRF3W/screenshot_2015-02-09-14-31-15.png|regarding:
should I stay or should I go?,
Lol., ha ha sorry, some testing with my irc client, anybody
knows how does \Passcode circuitry too hot. Wait for cool down to
enter another passcode.\ works?,
what is the cooldown time or how does it work...;, @U03AEKYL4:
what app are you talking about ?
)), .Names = c(name, text), class = c(data.table, data.frame
), row.names = c(NA, -10L)
--
idName - structure(list(id = c(U03AEKWTL, U032FHV3S, U03AEKYL4),
name = c(agreenmamba, poisonivy, vairis)), .Names = c(id,
name), sorted = name, class = c(data.table, data.frame
), row.names = c(NA, -3L))



1- I can find the pattern to be replaced in history this way :

ext - regmatches(history$text,regexpr('(?=@)[^|]{9}(?=|)',history$text,
perl = T)
 ext
[1] U032FHV3S U03AEKWTL U03AEKYL4

2- I can select the pairs id:name in my 'users' df:

 idName=users[users$id %in% ext]
  idname
1: U03AEKWTL agreenmamba
2: U032FHV3S   poisonivy
3: U03AEKYL4  vairis

3-  i can write a loop to make the changes:

 hist.txt - history$text
 for (i in 1:3){hist.txt - gsub(ext[i],idName[[2]][i], hist.txt, perl = T)}

But this will not work because of two things:
- 'idName' is not ordered the same way as 'ext'
- if a users speak twice it will leave with with some NA

May you have some hints how to process ?
I was thinking of maybe using sapply(myFun) to my 'history' df where
myFun would be the replacement process.
OR something like with assigning in my env each 'id' to its corresponding 'name'


Thank you for help

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


Re: [R] replace values in one df by values from key pairs in another df

2015-02-13 Thread arnaud gaboury
This is the wrong part of my code.


 idName=users[users$id %in% ext]
   idname
 1: U03AEKWTL agreenmamba
 2: U032FHV3S   poisonivy
 3: U03AEKYL4  vairis


Best is to use:

idNames - users[pmatch(ext, users$id, duplicates.ok = T)]. This leave
me with an ordered and duplicate entries :

 idNames - users[pmatch(ext, users$id, duplicates.ok = T)]
  idname
1: U03AEKYL4  vairis
2: U03AEKYL4  vairis
3: U03AEKWTL agreenmamba
4: U032FHV3S   poisonivy

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


Re: [R] gsub : replace regex pattern with values from another data.frame

2015-02-12 Thread arnaud gaboury
On Thu, Feb 12, 2015 at 3:40 PM, arnaud gaboury
arnaud.gabo...@gmail.com wrote:
 I have two df (and dt):

 df1
 structure(list(name = c(poisonivy, poisonivy, poisonivy,
 poisonivy, poisonivy, poisonivy, poisonivy, poisonivy,
 cruzecontrol, agreenmamba, agreenmamba, vairis, vairis,
 vairis, vairis, vairis, vairis, xaeth), text = c(ok,
 need items ?, i didn't submit pass codes for a long now,
 ok, @U03AEKYL4: what app are you talking about ?, some testing
 with my irc client,
 ha ha sorry, for me there is no such question, Lol.,
 @U03AEKWTL|agreenmamba uploaded a file:
 https://enlightened.slack.com/files/agreenmamba/F03KGRF3W/screenshot_2015-02-09-14-31-15.png|regarding:
 should I stay or should I go?,
 @U032FHV3S http://youtu.be/oGIFublvDes, ok, see you around,
 yeah, I had a procrastination rush so I started to decode a little,
 http://ingress.com/intel|ingress.com/intel when you submit passcodes,
 intel, what is the cooldown time or how does it work...;,
 anybody knows how does \Passcode circuitry too hot. Wait for cool
 down to enter another passcode.\ works?,
 and people told that agent their geocities experience would never
 amount to anything (the convo yesterday) 
 ), ts = c(1423594336.000138, 1423594311.000136, 1423594294.000135,
 1423594258.000133, 1423594244.000131, 1423497058.000127,
 1423497041.000126, 1423478555.000123, 1423494427.000125,
 1423492370.000124, 1423478364.000121, 1423594358.000139,
 1423594329.000137, 1423594264.000134, 1423594251.000132,
 1423592204.000130, 1423592174.000129, 1423150354.000112
 )), .Names = c(name, text, ts), class = c(data.table,
 data.frame), row.names = c(NA, -18L))

 df2
 structure(list(id = c(U03KH8Z52, U02AF1DTJ, U02AF0ZT8,
 U03AEKWTL, U02BCJH0G, U033YA1MS, U029QMCRR, U03H139M5,
 U02AET1D0, U02A6U41Z, U02B5T4CX, U02B2QU4R, U03F0LQ5X,
 U03JNFKLY, U02ASMBMQ, U029QLQC7, U03AEMBQU, U02B4D3Q1,
 U02AGDC14, U029A467C, U02A7NFG6, U02AESPPL, U02AQANK7,
 U03ADJDFK, U03EYR0KB, U02AW7Q5Q, U02AE8RKD, U02FT84BS,
 U02B25M3B, U03EZDQT7, U02AECKFF, U03H2691M, U02DWTJ5V,
 U02AFTAHH, U029QQEPM, U03C51Z42, U02CAK2CV, U03AK21DP,
 U03FFN8ED, U02B23V03, U029T2143, U02C1LEEX, U03AF2QH2,
 U03E0GN0S, U03AG20R9, U02AES8S2, U02AG64S7, U02B5A0R7,
 U02AS4SLR, U03C2SG0R, U03AV7CCW, U032XPFDU, U03AUKSSV,
 U02C2A61Y, U02AESHJQ, U02BLSKHU, U02E34WM6, U03AK6P26,
 U02E6ADRZ, U03FCDQ50, U03EW1CC5, U02BL0DBD, U02FHQZ6D,
 U02B47T63, U03H2TTQP, U03AVP71V, U03JLV38V, U02E39HAY,
 U02AE5281, U032FHV3S, U03AL2096, U02ARUG6M, U02AECRSP,
 U02B42XG4, U03AFQZNS, U02AE7H41, U03G9UNTG, U02GEQ0E6,
 U02AGLE5A, U02BQTRC9, U03H0J6GS, U02B3D27F, U02AEKTHV,
 U02C52YN3, U02E33MUW, U03AKUT85, U03B53EHG, U02FBN38P,
 U03AH3E5W, U02B5PLE0, U02AS4RCK, U03ANE1GZ, U02E8LZQB,
 U03EPGJ98, U02E3N220, U03AEKYL4, U02AE7HT1, U02C1RR3G,
 U03JH408J, U03KL0FKN, U02B44R92, U03EURWGX), name = c(10k_affair,
 1upwuzhere, 4xcss, agreenmamba, ait109, arly69, azkop13,
 barcik75, bigolnob, blackrose, blink619, bobaloo23,
 bodger, bomb, bootswithdefer, brandizzle, bregalad,
 camon, celticrain, ch3mical, checksum, cocothunder,
 cruxicon, cruzecontrol, crystalskunk, cscheetah, dabcelin,
 deelicious, delthanar, drkaosdk, droidenl-joe, dukeceph,
 fillerbunny, flickohmsford, flyingg0d, garaxiel, goby9,
 gymbal, hideandseek, hobojr, ijackportals, invalidcharactr,
 itso9, j0shs, jarvis, jc0mm5, jencyberchic, jimbobradyson,
 joespr0cket, jostrander, jueliet, karlashi, khan99,
 kingkonn0r, krispycridder, kritickalmass, lawgiver, maxcorbett,
 memory556, meta000x, minkovsky, mistylady, mstephans,
 mstrinity, nocarryr, ollietronic, philistine11, pickledpickles,
 piercingsbykris, poisonivy, raugmor, remarks999, rheds77,
 rhinz, rigiritter, robbie0017, rohdef, ryoziya, s4n1ty,
 sacredcow133, samwill, sgtlemonpepper, sivan, spline9,
 starwolf, stueliueli, sweetiris, swift2plunder, swissphoenix,
 synyck, test, therug, tinja551, trulyjuan, twinster,
 vairis, vinylz3ro, watervirus, xaeth, yagamiyukari,
 zafo, zexium)), .Names = c(id, name), class = c(data.table,
 data.frame), row.names = c(NA, -102L))

 I need to replace this regex pattern in df1 :
 (?=@)[^|]{9}(?=|) by its corresponding name from df2.

 E.g : if @U03KH8Z52 is found in df1, then I want to replace it by
 the name which correspond to this id in df2., in this case
 10k_affair

 I know of replace an expression with gsub:
 gsub('(?=@)[^|]{9}(?=|)', 'toto', df1, perl = T)
 but I have no idea how to replace it with value from another df.

 Thank you for hints

I am gathering some pieces of the puzzles.

 regmatches(df1$text,regexpr('(?=@)[^|]{9}(?=|)',df1$text, perl = T))
[1] U032FHV3S U03AEKWTL U03AEKYL4
The above commands extract the needed pattern

df2[grep(U032FHV3S,df2$id),][[2]]
[1] poisonivy
The above command returns the name in the same row than the id. I need
more than one name (in my case, I need 3)

Shall I now write a loop and get a list of my needed name ? Pseudo
code would be something like:

for i %in% regmatches(df1$text,regexpr('(?=@)[^|]{9}(?=|)',df1$text,
perl = T

Re: [R] gsub : replace regex pattern with values from another data.frame

2015-02-12 Thread arnaud gaboury
On Thu, Feb 12, 2015 at 7:12 PM, arnaud gaboury
arnaud.gabo...@gmail.com wrote:
 On Thu, Feb 12, 2015 at 3:40 PM, arnaud gaboury
 arnaud.gabo...@gmail.com wrote:
 I have two df (and dt):

 df1
 structure(list(name = c(poisonivy, poisonivy, poisonivy,
 poisonivy, poisonivy, poisonivy, poisonivy, poisonivy,
 cruzecontrol, agreenmamba, agreenmamba, vairis, vairis,
 vairis, vairis, vairis, vairis, xaeth), text = c(ok,
 need items ?, i didn't submit pass codes for a long now,
 ok, @U03AEKYL4: what app are you talking about ?, some testing
 with my irc client,
 ha ha sorry, for me there is no such question, Lol.,
 @U03AEKWTL|agreenmamba uploaded a file:
 https://enlightened.slack.com/files/agreenmamba/F03KGRF3W/screenshot_2015-02-09-14-31-15.png|regarding:
 should I stay or should I go?,
 @U032FHV3S http://youtu.be/oGIFublvDes, ok, see you around,
 yeah, I had a procrastination rush so I started to decode a little,
 http://ingress.com/intel|ingress.com/intel when you submit passcodes,
 intel, what is the cooldown time or how does it work...;,
 anybody knows how does \Passcode circuitry too hot. Wait for cool
 down to enter another passcode.\ works?,
 and people told that agent their geocities experience would never
 amount to anything (the convo yesterday) 
 ), ts = c(1423594336.000138, 1423594311.000136, 1423594294.000135,
 1423594258.000133, 1423594244.000131, 1423497058.000127,
 1423497041.000126, 1423478555.000123, 1423494427.000125,
 1423492370.000124, 1423478364.000121, 1423594358.000139,
 1423594329.000137, 1423594264.000134, 1423594251.000132,
 1423592204.000130, 1423592174.000129, 1423150354.000112
 )), .Names = c(name, text, ts), class = c(data.table,
 data.frame), row.names = c(NA, -18L))

 df2
 structure(list(id = c(U03KH8Z52, U02AF1DTJ, U02AF0ZT8,
 U03AEKWTL, U02BCJH0G, U033YA1MS, U029QMCRR, U03H139M5,
 U02AET1D0, U02A6U41Z, U02B5T4CX, U02B2QU4R, U03F0LQ5X,
 U03JNFKLY, U02ASMBMQ, U029QLQC7, U03AEMBQU, U02B4D3Q1,
 U02AGDC14, U029A467C, U02A7NFG6, U02AESPPL, U02AQANK7,
 U03ADJDFK, U03EYR0KB, U02AW7Q5Q, U02AE8RKD, U02FT84BS,
 U02B25M3B, U03EZDQT7, U02AECKFF, U03H2691M, U02DWTJ5V,
 U02AFTAHH, U029QQEPM, U03C51Z42, U02CAK2CV, U03AK21DP,
 U03FFN8ED, U02B23V03, U029T2143, U02C1LEEX, U03AF2QH2,
 U03E0GN0S, U03AG20R9, U02AES8S2, U02AG64S7, U02B5A0R7,
 U02AS4SLR, U03C2SG0R, U03AV7CCW, U032XPFDU, U03AUKSSV,
 U02C2A61Y, U02AESHJQ, U02BLSKHU, U02E34WM6, U03AK6P26,
 U02E6ADRZ, U03FCDQ50, U03EW1CC5, U02BL0DBD, U02FHQZ6D,
 U02B47T63, U03H2TTQP, U03AVP71V, U03JLV38V, U02E39HAY,
 U02AE5281, U032FHV3S, U03AL2096, U02ARUG6M, U02AECRSP,
 U02B42XG4, U03AFQZNS, U02AE7H41, U03G9UNTG, U02GEQ0E6,
 U02AGLE5A, U02BQTRC9, U03H0J6GS, U02B3D27F, U02AEKTHV,
 U02C52YN3, U02E33MUW, U03AKUT85, U03B53EHG, U02FBN38P,
 U03AH3E5W, U02B5PLE0, U02AS4RCK, U03ANE1GZ, U02E8LZQB,
 U03EPGJ98, U02E3N220, U03AEKYL4, U02AE7HT1, U02C1RR3G,
 U03JH408J, U03KL0FKN, U02B44R92, U03EURWGX), name = c(10k_affair,
 1upwuzhere, 4xcss, agreenmamba, ait109, arly69, azkop13,
 barcik75, bigolnob, blackrose, blink619, bobaloo23,
 bodger, bomb, bootswithdefer, brandizzle, bregalad,
 camon, celticrain, ch3mical, checksum, cocothunder,
 cruxicon, cruzecontrol, crystalskunk, cscheetah, dabcelin,
 deelicious, delthanar, drkaosdk, droidenl-joe, dukeceph,
 fillerbunny, flickohmsford, flyingg0d, garaxiel, goby9,
 gymbal, hideandseek, hobojr, ijackportals, invalidcharactr,
 itso9, j0shs, jarvis, jc0mm5, jencyberchic, jimbobradyson,
 joespr0cket, jostrander, jueliet, karlashi, khan99,
 kingkonn0r, krispycridder, kritickalmass, lawgiver, maxcorbett,
 memory556, meta000x, minkovsky, mistylady, mstephans,
 mstrinity, nocarryr, ollietronic, philistine11, pickledpickles,
 piercingsbykris, poisonivy, raugmor, remarks999, rheds77,
 rhinz, rigiritter, robbie0017, rohdef, ryoziya, s4n1ty,
 sacredcow133, samwill, sgtlemonpepper, sivan, spline9,
 starwolf, stueliueli, sweetiris, swift2plunder, swissphoenix,
 synyck, test, therug, tinja551, trulyjuan, twinster,
 vairis, vinylz3ro, watervirus, xaeth, yagamiyukari,
 zafo, zexium)), .Names = c(id, name), class = c(data.table,
 data.frame), row.names = c(NA, -102L))

 I need to replace this regex pattern in df1 :
 (?=@)[^|]{9}(?=|) by its corresponding name from df2.

 E.g : if @U03KH8Z52 is found in df1, then I want to replace it by
 the name which correspond to this id in df2., in this case
 10k_affair

 I know of replace an expression with gsub:
 gsub('(?=@)[^|]{9}(?=|)', 'toto', df1, perl = T)
 but I have no idea how to replace it with value from another df.

 Thank you for hints

 I am gathering some pieces of the puzzles.

 regmatches(df1$text,regexpr('(?=@)[^|]{9}(?=|)',df1$text, perl = T))
 [1] U032FHV3S U03AEKWTL U03AEKYL4
 The above commands extract the needed pattern

 df2[grep(U032FHV3S,df2$id),][[2]]
 [1] poisonivy
 The above command returns the name in the same row than the id. I need
 more than one name (in my case, I need 3)

 Shall I now write a loop and get a list of my needed name ? Pseudo
 code would be something like

[R] apply two functions to column

2015-02-12 Thread arnaud gaboury
I am little lost between all the possibilities to apply a function to
a data.frame or data.table.

Here is mine:

structure(list(name = c(poisonivy, poisonivy, poisonivy,
poisonivy, poisonivy, poisonivy, poisonivy, poisonivy,
cruzecontrol, agreenmamba, agreenmamba, vairis, vairis,
vairis, vairis, vairis, vairis, xaeth), text = c(ok,
need items ?, i didn't submit pass codes for a long now,
ok, @U03AEKYL4: what app are you talking about ?, some testing
with my irc client,
ha ha sorry, for me there is no such question, Lol.,
@U03AEKWTL|agreenmamba uploaded a file:
https://enlightened.slack.com/files/agreenmamba/F03KGRF3W/screenshot_2015-02-09-14-31-15.png|regarding:
should I stay or should I go?,
@U032FHV3S http://youtu.be/oGIFublvDes, ok, see you around,
yeah, I had a procrastination rush so I started to decode a little,
http://ingress.com/intel|ingress.com/intel when you submit passcodes,
intel, what is the cooldown time or how does it work...;,
anybody knows how does \Passcode circuitry too hot. Wait for cool
down to enter another passcode.\ works?,
and people told that agent their geocities experience would never
amount to anything (the convo yesterday) 
), ts = c(1423594336.000138, 1423594311.000136, 1423594294.000135,
1423594258.000133, 1423594244.000131, 1423497058.000127,
1423497041.000126, 1423478555.000123, 1423494427.000125,
1423492370.000124, 1423478364.000121, 1423594358.000139,
1423594329.000137, 1423594264.000134, 1423594251.000132,
1423592204.000130, 1423592174.000129, 1423150354.000112
)), .Names = c(name, text, ts), class = c(data.table,
data.frame), row.names = c(NA, -18L))

As you can see, it is of class data.frame and data.table.

I need to work on last column ts. These are characters and are times
in epoch format. I want to have time in Posix. I must thus do two
things:
- characters to numeric : myData$ts - as.numeric(myData$ts)
- epoch to Posix : mapply(as.POSIXct, tz = 'GMT', origin =
'1970-01-01', myMerge$ts)

I wonder:
- if I can apply these two functions at the same time
- what will be the fastest way : use dplyr package, or work with
data.table ? My real data will be much more important than the one
posted.

Thank you for advice and hint.

-- 

google.com/+arnaudgabourygabx

__
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] gsub : replace regex pattern with values from another data.frame

2015-02-12 Thread arnaud gaboury
I have two df (and dt):

df1
structure(list(name = c(poisonivy, poisonivy, poisonivy,
poisonivy, poisonivy, poisonivy, poisonivy, poisonivy,
cruzecontrol, agreenmamba, agreenmamba, vairis, vairis,
vairis, vairis, vairis, vairis, xaeth), text = c(ok,
need items ?, i didn't submit pass codes for a long now,
ok, @U03AEKYL4: what app are you talking about ?, some testing
with my irc client,
ha ha sorry, for me there is no such question, Lol.,
@U03AEKWTL|agreenmamba uploaded a file:
https://enlightened.slack.com/files/agreenmamba/F03KGRF3W/screenshot_2015-02-09-14-31-15.png|regarding:
should I stay or should I go?,
@U032FHV3S http://youtu.be/oGIFublvDes, ok, see you around,
yeah, I had a procrastination rush so I started to decode a little,
http://ingress.com/intel|ingress.com/intel when you submit passcodes,
intel, what is the cooldown time or how does it work...;,
anybody knows how does \Passcode circuitry too hot. Wait for cool
down to enter another passcode.\ works?,
and people told that agent their geocities experience would never
amount to anything (the convo yesterday) 
), ts = c(1423594336.000138, 1423594311.000136, 1423594294.000135,
1423594258.000133, 1423594244.000131, 1423497058.000127,
1423497041.000126, 1423478555.000123, 1423494427.000125,
1423492370.000124, 1423478364.000121, 1423594358.000139,
1423594329.000137, 1423594264.000134, 1423594251.000132,
1423592204.000130, 1423592174.000129, 1423150354.000112
)), .Names = c(name, text, ts), class = c(data.table,
data.frame), row.names = c(NA, -18L))

df2
structure(list(id = c(U03KH8Z52, U02AF1DTJ, U02AF0ZT8,
U03AEKWTL, U02BCJH0G, U033YA1MS, U029QMCRR, U03H139M5,
U02AET1D0, U02A6U41Z, U02B5T4CX, U02B2QU4R, U03F0LQ5X,
U03JNFKLY, U02ASMBMQ, U029QLQC7, U03AEMBQU, U02B4D3Q1,
U02AGDC14, U029A467C, U02A7NFG6, U02AESPPL, U02AQANK7,
U03ADJDFK, U03EYR0KB, U02AW7Q5Q, U02AE8RKD, U02FT84BS,
U02B25M3B, U03EZDQT7, U02AECKFF, U03H2691M, U02DWTJ5V,
U02AFTAHH, U029QQEPM, U03C51Z42, U02CAK2CV, U03AK21DP,
U03FFN8ED, U02B23V03, U029T2143, U02C1LEEX, U03AF2QH2,
U03E0GN0S, U03AG20R9, U02AES8S2, U02AG64S7, U02B5A0R7,
U02AS4SLR, U03C2SG0R, U03AV7CCW, U032XPFDU, U03AUKSSV,
U02C2A61Y, U02AESHJQ, U02BLSKHU, U02E34WM6, U03AK6P26,
U02E6ADRZ, U03FCDQ50, U03EW1CC5, U02BL0DBD, U02FHQZ6D,
U02B47T63, U03H2TTQP, U03AVP71V, U03JLV38V, U02E39HAY,
U02AE5281, U032FHV3S, U03AL2096, U02ARUG6M, U02AECRSP,
U02B42XG4, U03AFQZNS, U02AE7H41, U03G9UNTG, U02GEQ0E6,
U02AGLE5A, U02BQTRC9, U03H0J6GS, U02B3D27F, U02AEKTHV,
U02C52YN3, U02E33MUW, U03AKUT85, U03B53EHG, U02FBN38P,
U03AH3E5W, U02B5PLE0, U02AS4RCK, U03ANE1GZ, U02E8LZQB,
U03EPGJ98, U02E3N220, U03AEKYL4, U02AE7HT1, U02C1RR3G,
U03JH408J, U03KL0FKN, U02B44R92, U03EURWGX), name = c(10k_affair,
1upwuzhere, 4xcss, agreenmamba, ait109, arly69, azkop13,
barcik75, bigolnob, blackrose, blink619, bobaloo23,
bodger, bomb, bootswithdefer, brandizzle, bregalad,
camon, celticrain, ch3mical, checksum, cocothunder,
cruxicon, cruzecontrol, crystalskunk, cscheetah, dabcelin,
deelicious, delthanar, drkaosdk, droidenl-joe, dukeceph,
fillerbunny, flickohmsford, flyingg0d, garaxiel, goby9,
gymbal, hideandseek, hobojr, ijackportals, invalidcharactr,
itso9, j0shs, jarvis, jc0mm5, jencyberchic, jimbobradyson,
joespr0cket, jostrander, jueliet, karlashi, khan99,
kingkonn0r, krispycridder, kritickalmass, lawgiver, maxcorbett,
memory556, meta000x, minkovsky, mistylady, mstephans,
mstrinity, nocarryr, ollietronic, philistine11, pickledpickles,
piercingsbykris, poisonivy, raugmor, remarks999, rheds77,
rhinz, rigiritter, robbie0017, rohdef, ryoziya, s4n1ty,
sacredcow133, samwill, sgtlemonpepper, sivan, spline9,
starwolf, stueliueli, sweetiris, swift2plunder, swissphoenix,
synyck, test, therug, tinja551, trulyjuan, twinster,
vairis, vinylz3ro, watervirus, xaeth, yagamiyukari,
zafo, zexium)), .Names = c(id, name), class = c(data.table,
data.frame), row.names = c(NA, -102L))

I need to replace this regex pattern in df1 :
(?=@)[^|]{9}(?=|) by its corresponding name from df2.

E.g : if @U03KH8Z52 is found in df1, then I want to replace it by
the name which correspond to this id in df2., in this case
10k_affair

I know of replace an expression with gsub:
gsub('(?=@)[^|]{9}(?=|)', 'toto', df1, perl = T)
but I have no idea how to replace it with value from another df.

Thank you for hints

__
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] upgrading issues with Rcpp

2015-02-11 Thread arnaud gaboury
gabx@hortensia [R] sessionInfo()
R version 3.1.2 (2014-10-31)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
LC_MONETARY=en_US.UTF-8
 [6] LC_MESSAGES=en_US.UTF-8LC_PAPER=en_US.UTF-8   LC_NAME=C
   LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] utils base

loaded via a namespace (and not attached):
[1] tools_3.1.2


gabx@hortensia [R] search()
[1] .GlobalEnvtools:rstudio package:utils package:base
--

Now when trying to update Rcpp:

gabx@hortensia [R] install.packages(Rcpp)
.
Error in unloadNamespace(pkg_name) :
  namespace ‘Rcpp’ is imported by ‘reshape2’, ‘plyr’, ‘dplyr’ so
cannot be unloaded
..

I can't upgrade my packages because of Rcpp =0.11.3 needed (running
actually 0.11.2)

What is this namespace imported by  'reshape2’, ‘plyr’, ‘dplyr’ ? How
can I get rid of it and upgrade my packages ?

Thank you for hints
-- 

google.com/+arnaudgabourygabx

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

Re: [R] Best Beginner Books?

2014-10-02 Thread arnaud gaboury
On Thu, Oct 2, 2014 at 4:54 AM, Jason Eyerly teamtraders3...@gmail.com wrote:
 A lot of excellent suggestions! Thank you everyone for the input. I’ve 
 purchased via Amazon:

 A Beginner's Guide to R by Zuur
 Data Manipulation with R by Spector
 “Introductory Statistics with R.” by Peter Dalgaard

 Are there any suggestions as to which order I should read them in when they 
 arrive? For best comprehension, I’m thinking “Introductory Statistics with R” 
 would be the best to start with, and perhaps the beginners guide after that, 
 or vice versa?


I would not start with a whole book, but a good short intro (~ 30-40
pages). Feel free to pick up free publications here:
https://github.com/gabx/r-project/tree/master/documentation.

__
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] Building R for better performance

2014-09-11 Thread arnaud gaboury
 I got the benchmark script, which I've attached, from Texas Advanced
 Computing Center.  Here are my results (elapsed times, in secs):


Where can we get the benchmark script?

__
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] Building R for better performance

2014-09-02 Thread arnaud gaboury
 The best that I can see for R would be if someone were to post a how
 to use MKL for compiling R type document.

I build R with MKL and ICC on my Archlinux box[1][2].

If I can help in anything, I will do it.

[1]https://wiki.archlinux.org/index.php/R
[2]https://aur.archlinux.org/packages/r-mkl/

__
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 openBLAS in R under Unix / Linux

2014-08-28 Thread arnaud gaboury
On Thu, Aug 28, 2014 at 11:45 AM, Martin Spindler
spind...@mea.mpisoc.mpg.de wrote:
 Dear all,
 I would like to us openBLAS in R under Linux / Unix.
 Which steps do I have to undertake? Does someone know a detailed
 description? (I found some sources on the web, but none was really
 helpful for me.)
 Thanks and best,
 Martin

I run it on my Archlinux. Please visit R archwiki[1]
Do not hesitate to ask, I will help.

[1]https://wiki.archlinux.org/index.php/R




--

__
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] Help on installing R packages in a Citrix

2014-08-22 Thread arnaud gaboury
On Fri, Aug 22, 2014 at 2:03 PM, S Ellison s.elli...@lgcgroup.com wrote:
 We are currently trying to migrate 3 users of R to a citrix based
 environment, but are coming across major issues trying to install the
 packages to the relevant image.


Please be more precised in your issue.

__
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] Regex - subsetting parts of a file name.

2014-07-31 Thread arnaud gaboury
A directory is full of data.frames cache files. All these files have
the same pattern:

df.some_name.RData

my.cache.list - c(df.subject_test.RData, df.subject_train.RData,
df.y_test.RData,
df.y_train.RData)

I want to keep only the part inside the two points. After lots of
headache using grep() when trying something like this:

grep('.(.*?).','df.subject_test.RData',value=T)

 I couldn't find a clean one liner and found this workaround:

my.cache.list - gsub('df.','',my.cache.list)
my.cache.list - gsub('.RData','',my.cache.list)

The two above commands do the trick, but a clean one line with some
regex expression would be a more elegant way.

Does anyone have any suggestion ?

TY for help

__
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] Regex - subsetting parts of a file name.

2014-07-31 Thread arnaud gaboury

 R as.vector(sapply(my.cache.list, function(x)strsplit(x, \\.)[[1]][2]))
 [1] subject_test  subject_train y_testy_train


 R gsub(df\\.(.*)\\.RData, \\1, my.cache.list)
 [1] subject_test  subject_train y_testy_train


 Note that . will match any character, while \\. matches a period.



Thank you for your various suggestions.

__
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] compare two data frames of different dimensions and onlykeep unique rows

2012-02-28 Thread Arnaud Gaboury
TY very much for your setdiffDF(). It does the job perfectly.

Arnaud Gaboury
 
A2CT2 Ltd.


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Petr Savicky
Sent: lundi 27 février 2012 20:41
To: r-help@r-project.org
Subject: Re: [R] compare two data frames of different dimensions and onlykeep 
unique rows

On Mon, Feb 27, 2012 at 07:10:57PM +0100, Arnaud Gaboury wrote:
 No, but I tried your way too.
 
 In fact, the only three unique rows are these ones:
 
  Product Price Nbr.Lots
Cocoa  24405
Cocoa  24501
Cocoa  24406
 
 Here is a dirty working trick I found :
 
  df-merge(exportfile,reported,all.y=T)
  df1-merge(exportfile,reported)
  dff1-do.call(paste,df)
  dff-do.call(paste,df)
  dff1-do.call(paste,df1)
  df[!dff %in% dff1,]
   Product Price Nbr.Lots
 3   Cocoa  24405
 4   Cocoa  24501
  
 
 My two problems are : I do think it is not so a clean code, then I won't know 
 by advance which of my two df will have the greates dimension (I can add some 
 lines to deal with it, but again, seems very heavy).

Hi.

Try the following.

  setdiffDF - function(A, B)
  {
  A[!duplicated(rbind(B, A))[nrow(B) + 1:nrow(A)], ]
  }

  df1 - setdiffDF(reported, exportfile)
  df2 - setdiffDF(exportfile, reported)
  rbind(df1, df2)

I obtained

 Product Price Nbr.Lots
  3Cocoa  24405
  4Cocoa  24501
  31   Cocoa  24406

Is this correct? I see the row

  Cocoa  2440.006

only in exportfile and not in reported.

The trick with paste() is not a bad idea. A variant of it is used also in the 
base function duplicated.matrix(), since it contains

  apply(x, MARGIN, function(x) paste(x, collapse = \r))

If speed is critical, then possibly the paste() trick written for the whole 
columns, for example

  paste(df[[1]], df[[2]], df[[3]], sep=\r)

and then setdiff() can be better.

Hope this helps.

Petr Savicky.

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


[R] compare two data frames with same columns names but of different dimensions

2012-02-27 Thread Arnaud Gaboury
Dear List,

I want to compare and return the rows which are NOT in the two data frames. 
Classic methods don't work as the df have NOT the same dimensions.


Here are one example of my df:

reported -
structure(list(Product = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 
3L, 4L, 5L, 5L), .Label = c(Cocoa, Coffee C, GC, Sugar No 11, 
ZS), class = factor), Price = c(2331, 2356, 2440, 2450, 204.55, 
205.45, 17792, 24.81, 1273.5, 1276.25), Nbr.Lots = c(-61L, -61L, 
5L, 1L, 40L, 40L, -1L, -1L, -1L, 1L)), .Names = c(Product, 
Price, Nbr.Lots), row.names = c(1L, 2L, 3L, 4L, 6L, 7L, 5L, 
10L, 8L, 9L), class = data.frame)

exportfile -
structure(list(Product = c(Cocoa, Cocoa, Cocoa, Coffee C, 
Coffee C, GC, Sugar No 11, ZS, ZS), Price = c(2331, 
2356, 2440, 204.55, 205.45, 17792, 24.81, 1273.5, 1276.25), Nbr.Lots = c(-61, 
-61, 6, 40, 40, -1, -1, -1, 1)), .Names = c(Product, Price, 
Nbr.Lots), row.names = c(NA, 9L), class = data.frame)

As you can see, they have same column names. 
My idea was to merge these two df when passing as argument not to take into 
account duplicate rows, so I will get one df with rows which are not in both 
df.
Is it possible? How to do it?

TY for any help.


Arnaud Gaboury
 
A2CT2 Ltd.

__
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] Ubuntu jaunty - R can't be install

2012-02-27 Thread Arnaud Gaboury
I don't understand where is your problem. Are you looking for jaunty as a 
package on R Crans?? Are you looking to install R package on your Ubuntu box? 
As you know, Jaunty is no more supported by Ubuntu, so packets have been moved 
in Archives.

Arnaud Gaboury
 
A2CT2 Ltd.


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Veyssière Marine
Sent: lundi 27 février 2012 14:50
To: r-help@r-project.org
Subject: [R] Ubuntu jaunty - R can't be install

Dear helpers,
I would like to install R on a computer with Ubuntu Jaunty. 
Unfortunately, Jaunty  does not  appear in any CRAN mirror website I have tried 
(France, Canada, Italy, Germany).
Could you give me any mirror website  allowing installation on Jaunty?or  could 
you give me a procedure to passby this problem?

Thanks for your help,
Best regards,
Marine Veyssière

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


[R] compare two data frames of different dimensions and only keep unique rows

2012-02-27 Thread Arnaud Gaboury
Dear list,

I am still struggling with something that should be easy: I compare two data 
frames with a lot of common rows and want to keep only rows that are NOT in 
both data frames, unique.

Here are an example of these data frame.

reported -
structure(list(Product = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 3L, 4L, 5L, 5L), 
.Label = c(Cocoa, Coffee C, GC, Sugar No 11, ZS), class = factor), 
Price = c(2331, 2356, 2440, 2450, 204.55, 205.45, 17792, 24.81, 1273.5, 
1276.25), Nbr.Lots = c(-61L, -61L, 5L, 1L, 40L, 40L, -1L, -1L, -1L, 1L)), 
.Names = c(Product, Price, Nbr.Lots), row.names = c(1L, 2L, 3L, 4L, 6L, 
7L, 5L, 10L, 8L, 9L), class = data.frame)

exportfile -
structure(list(Product = c(Cocoa, Cocoa, Cocoa, Coffee C, Coffee C, 
GC, Sugar No 11, ZS, ZS), Price = c(2331, 2356, 2440, 204.55, 205.45, 
17792, 24.81, 1273.5, 1276.25), Nbr.Lots = c(-61, -61, 6, 40, 40, -1, -1, -1, 
1)), .Names = c(Product, Price, Nbr.Lots), row.names = c(NA, 9L), class = 
data.frame)

I can rbind() them, thus resulting in one data frame with duplicated row, but I 
have no idea how to delete duplicated rows. I have tried plyaing with unique(), 
duplicated with no success

v-rbind(exportfile,reported)
v -
structure(list(Product = c(Cocoa, Cocoa, Cocoa, Coffee C, 
Coffee C, GC, Sugar No 11, ZS, ZS, Cocoa, Cocoa, 
Cocoa, Cocoa, Coffee C, Coffee C, GC, Sugar No 11, 
ZS, ZS), Price = c(2331, 2356, 2440, 204.55, 205.45, 17792, 
24.81, 1273.5, 1276.25, 2331, 2356, 2440, 2450, 204.55, 205.45, 
17792, 24.81, 1273.5, 1276.25), Nbr.Lots = c(-61, -61, 6, 40, 
40, -1, -1, -1, 1, -61, -61, 5, 1, 40, 40, -1, -1, -1, 1)), .Names = 
c(Product, 
Price, Nbr.Lots), row.names = c(1, 2, 3, 4, 5, 
6, 7, 8, 9, 11, 21, 31, 41, 61, 71, 51, 
10, 81, 91), class = data.frame)


TY for your help

Arnaud Gaboury
 
A2CT2 Ltd.

__
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] compare two data frames of different dimensions and only keep unique rows

2012-02-27 Thread Arnaud Gaboury
No, but I tried your way too.

In fact, the only three unique rows are these ones:

 Product Price Nbr.Lots
   Cocoa  24405
   Cocoa  24501
   Cocoa  24406

Here is a dirty working trick I found :

 df-merge(exportfile,reported,all.y=T)
 df1-merge(exportfile,reported)
 dff1-do.call(paste,df)
 dff-do.call(paste,df)
 dff1-do.call(paste,df1)
 df[!dff %in% dff1,]
  Product Price Nbr.Lots
3   Cocoa  24405
4   Cocoa  24501
 

My two problems are : I do think it is not so a clean code, then I won't know 
by advance which of my two df will have the greates dimension (I can add some 
lines to deal with it, but again, seems very heavy).

I hoped I could find a better solution.


A2CT2 Ltd.


-Original Message-
From: jim holtman [mailto:jholt...@gmail.com] 
Sent: lundi 27 février 2012 18:42
To: Arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] compare two data frames of different dimensions and only keep 
unique rows

is this what you want:

 v - rbind(reported, exportfile)
 v[!duplicated(v), ]
   ProductPrice Nbr.Lots
1Cocoa  2331.00  -61
2Cocoa  2356.00  -61
3Cocoa  2440.005
4Cocoa  2450.001
6 Coffee C   204.55   40
7 Coffee C   205.45   40
5   GC 17792.00   -1
10 Sugar No 1124.81   -1
8   ZS  1273.50   -1
9   ZS  1276.251
13   Cocoa  2440.006



On Mon, Feb 27, 2012 at 12:36 PM, Arnaud Gaboury arnaud.gabo...@a2ct2.com 
wrote:
 Dear list,

 I am still struggling with something that should be easy: I compare two data 
 frames with a lot of common rows and want to keep only rows that are NOT in 
 both data frames, unique.

 Here are an example of these data frame.

 reported -
 structure(list(Product = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 3L, 4L, 
 5L, 5L), .Label = c(Cocoa, Coffee C, GC, Sugar No 11, ZS), 
 class = factor), Price = c(2331, 2356, 2440, 2450, 204.55, 205.45, 
 17792, 24.81, 1273.5, 1276.25), Nbr.Lots = c(-61L, -61L, 5L, 1L, 40L, 
 40L, -1L, -1L, -1L, 1L)), .Names = c(Product, Price, Nbr.Lots), 
 row.names = c(1L, 2L, 3L, 4L, 6L, 7L, 5L, 10L, 8L, 9L), class = 
 data.frame)

 exportfile -
 structure(list(Product = c(Cocoa, Cocoa, Cocoa, Coffee C, 
 Coffee C, GC, Sugar No 11, ZS, ZS), Price = c(2331, 2356, 
 2440, 204.55, 205.45, 17792, 24.81, 1273.5, 1276.25), Nbr.Lots = 
 c(-61, -61, 6, 40, 40, -1, -1, -1, 1)), .Names = c(Product, Price, 
 Nbr.Lots), row.names = c(NA, 9L), class = data.frame)

 I can rbind() them, thus resulting in one data frame with duplicated 
 row, but I have no idea how to delete duplicated rows. I have tried 
 plyaing with unique(), duplicated with no success

 v-rbind(exportfile,reported)
 v -
 structure(list(Product = c(Cocoa, Cocoa, Cocoa, Coffee C, 
 Coffee C, GC, Sugar No 11, ZS, ZS, Cocoa, Cocoa, 
 Cocoa, Cocoa, Coffee C, Coffee C, GC, Sugar No 11, ZS, 
 ZS), Price = c(2331, 2356, 2440, 204.55, 205.45, 17792, 24.81, 
 1273.5, 1276.25, 2331, 2356, 2440, 2450, 204.55, 205.45, 17792, 24.81, 
 1273.5, 1276.25), Nbr.Lots = c(-61, -61, 6, 40, 40, -1, -1, -1, 1, 
 -61, -61, 5, 1, 40, 40, -1, -1, -1, 1)), .Names = c(Product, 
 Price, Nbr.Lots), row.names = c(1, 2, 3, 4, 5, 6, 7, 
 8, 9, 11, 21, 31, 41, 61, 71, 51, 10, 81, 91), 
 class = data.frame)


 TY for your help

 Arnaud Gaboury

 A2CT2 Ltd.

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



--
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

__
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] data frame manipulation with condition

2012-02-24 Thread Arnaud Gaboury
Dear list,

n00b question, but still can't find any easy answer.

Here is a df:

 df-data.frame(cbind(x=c(AA,BB,CC,AA),y=1:4))
 df
   x y
1 AA 1
2 BB 2
3 CC 3
4 AA 4


I want to modify this df this way :
 if df$x==AA then df$y=df$y*10
 if df$x==BB then df$y=df$y*25

and so on with other conditions.

TY for any help.

Trading
 
A2CT2 Ltd.


Arnaud Gaboury
 
A2CT2 Ltd.

__
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] data frame manipulation with condition

2012-02-24 Thread Arnaud Gaboury
TY Uwe,

So I will have to write a line for each condition? Right?

In fact I was trying to do something with apply in one line, but couldn't 
achieve any result. In fact, all my transformation will be multiplying one 
object by a specific number according to the value of df$x.

Arnaud Gaboury
 
A2CT2 Ltd.


-Original Message-
From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de] 
Sent: vendredi 24 février 2012 16:33
To: Arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] data frame manipulation with condition



On 24.02.2012 16:25, Arnaud Gaboury wrote:
 Dear list,

 n00b question, but still can't find any easy answer.

 Here is a df:


Change

 df-data.frame(cbind(x=c(AA,BB,CC,AA),y=1:4))

to

  df - data.frame(x = c(AA,BB,CC,AA), y = 1:4)

to make your object a sensible data.frame.



 df
 x y
 1 AA 1
 2 BB 2
 3 CC 3
 4 AA 4


 I want to modify this df this way :
   if df$x==AA then df$y=df$y*10

df$y[df$x==AA] - df$y[df$x==AA] * 25

...


Uwe Ligges


   if df$x==BB then df$y=df$y*25




 and so on with other conditions.

 TY for any help.

 Trading

 A2CT2 Ltd.


 Arnaud Gaboury

 A2CT2 Ltd.

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


Re: [R] data frame manipulation with condition

2012-02-24 Thread Arnaud Gaboury
 df- data.frame(x = c(AA,BB,CC,AA,DD,DD), y = 1:6)
 mult - c(AA = 10, BB = 25,DD=15)
 df$y - df$y * mult[df$x]
 df
   x  y
1 AA 10
2 BB 50
3 CC 45
4 AA 40
5 DD NA
6 DD NA

My df is in fact much more longer than the chosen example shown here. It seems 
your tip didn't do the job.
I am expecting this as result :

 df
   x  y
1 AA 10   if df$x==AA, df$y-1*10 
2 BB 50    if df$x==BB, df$y-2*25 
3 CC 3 NOTHING
4 AA 40 if df$x==AA, df$y-4*10 
5 DD 75    if df$x==DD, df$y-5*15
6 DD 90    if df$x==DD, df$y-6*15

Arnaud Gaboury
 
A2CT2 Ltd.

-Original Message-
From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de] 
Sent: vendredi 24 février 2012 17:07
To: Arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] data frame manipulation with condition



On 24.02.2012 16:59, Arnaud Gaboury wrote:
 TY Uwe,

 So I will have to write a line for each condition? Right?

 In fact I was trying to do something with apply in one line, but couldn't 
 achieve any result. In fact, all my transformation will be multiplying one 
 object by a specific number according to the value of df$x.

In that case:

mult - c(AA = 10, BB = 25)

Then:


df$y - df$y * mult[df$x]


Uwe Ligges



 Arnaud Gaboury

 A2CT2 Ltd.


 -Original Message-
 From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de]
 Sent: vendredi 24 février 2012 16:33
 To: Arnaud Gaboury
 Cc: r-help@r-project.org
 Subject: Re: [R] data frame manipulation with condition



 On 24.02.2012 16:25, Arnaud Gaboury wrote:
 Dear list,

 n00b question, but still can't find any easy answer.

 Here is a df:


 Change

 df-data.frame(cbind(x=c(AA,BB,CC,AA),y=1:4))

 to

df- data.frame(x = c(AA,BB,CC,AA), y = 1:4)

 to make your object a sensible data.frame.



 df
  x y
 1 AA 1
 2 BB 2
 3 CC 3
 4 AA 4


 I want to modify this df this way :
if df$x==AA then df$y=df$y*10

 df$y[df$x==AA]- df$y[df$x==AA] * 25

 ...


 Uwe Ligges


if df$x==BB then df$y=df$y*25




 and so on with other conditions.

 TY for any help.

 Trading

 A2CT2 Ltd.


 Arnaud Gaboury

 A2CT2 Ltd.

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


Re: [R] data frame manipulation with condition

2012-02-24 Thread Arnaud Gaboury
OK Uwe, I understand, and I will be more explicit.

Here is how could my df be:

reported -
structure(list(Product = structure(c(1L, 2L, 2L, 2L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 4L, 5L, 5L, 5L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, 
9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 
11L, 12L, 12L, 13L, 14L, 14L), .Label = c(CL, Cocoa, Coffee C, 
GC, HG, HO, NG, PL, RB, SI, Sugar No 11, ZC, 
ZL, ZW), class = factor), reported.Price = c(105.35, 2380, 
2407, 2408, 202.35, 202.8, 202.95, 205.85, 206.05, 206.1, 206.2, 
1748, 378.8, 379.25, 379.5, 320.61, 2.538, 2.543, 1669, 1678.5, 
304.49, 321.39, 321.6, 321.65, 322.5, 322.55, 322.8, 323.04, 
3390, 3397.5, 24.16, 24.2, 24.22, 24.23, 24.54, 25.5, 25.55, 
631.75, 638, 53.77, 630.75, 633), reported.Nbr.Lots = c(6L, 3L, 
-1L, -2L, -40L, -1L, -1L, 10L, 5L, 6L, 19L, 17L, 23L, 12L, 35L, 
11L, -54L, -52L, 26L, 26L, 10L, -10L, 1L, 4L, 4L, 1L, 5L, 5L, 
17L, 17L, 114L, 71L, 16L, 27L, -3L, 3L, -3L, -89L, -1L, -1L, 
-51L, -51L)), .Names = c(Product, reported.Price, reported.Nbr.Lots
), row.names = c(7L, 4L, 5L, 6L, 13L, 14L, 15L, 16L, 17L, 18L, 
19L, 8L, 9L, 10L, 11L, 12L, 20L, 21L, 22L, 23L, 35L, 36L, 37L, 
38L, 39L, 40L, 41L, 42L, 31L, 32L, 24L, 25L, 26L, 27L, 28L, 29L, 
30L, 2L, 3L, 1L, 33L, 34L), class = data.frame)


Row will change. I am looking to multiply reported.Price by 100 IF Product=CL, 
multiply by 10 IF product=GC, multiply by 100 IF product=HG, multiply by 1000 
IF Product=NG, multiply by 100 IF product=RB.

I hope I am clear enough, and YES I have tried many workarounds myself before 
posting. Feel free to ignore my post if you think I am lazy and disrespectful 
to the list.


Arnaud Gaboury
 
A2CT2 Ltd.



-Original Message-
From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de] 
Sent: vendredi 24 février 2012 17:41
To: Arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] data frame manipulation with condition



On 24.02.2012 17:36, Arnaud Gaboury wrote:
 df- data.frame(x = c(AA,BB,CC,AA,DD,DD), y = 1:6)
 mult- c(AA = 10, BB = 25,DD=15)
 df$y- df$y * mult[df$x]
 df
 x  y
 1 AA 10
 2 BB 50
 3 CC 45
 4 AA 40
 5 DD NA
 6 DD NA

 My df is in fact much more longer than the chosen example shown here. It 
 seems your tip didn't do the job.
 I am expecting this as result :


This is not the I do the job for you hotline. You are free to think a little 
bit yourself given you have not managed in two attempts to describe your 
problem sufficiently well!

Uwe Ligges



 df
 x  y
 1 AA 10    if df$x==AA, df$y-1*10
 2 BB 50     if df$x==BB, df$y-2*25
 3 CC 3 NOTHING
 4 AA 40  if df$x==AA, df$y-4*10
 5 DD 75     if df$x==DD, df$y-5*15
 6 DD 90     if df$x==DD, df$y-6*15

 Arnaud Gaboury

 A2CT2 Ltd.

 -Original Message-
 From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de]
 Sent: vendredi 24 février 2012 17:07
 To: Arnaud Gaboury
 Cc: r-help@r-project.org
 Subject: Re: [R] data frame manipulation with condition



 On 24.02.2012 16:59, Arnaud Gaboury wrote:
 TY Uwe,

 So I will have to write a line for each condition? Right?

 In fact I was trying to do something with apply in one line, but couldn't 
 achieve any result. In fact, all my transformation will be multiplying one 
 object by a specific number according to the value of df$x.

 In that case:

 mult- c(AA = 10, BB = 25)

 Then:


 df$y- df$y * mult[df$x]


 Uwe Ligges



 Arnaud Gaboury

 A2CT2 Ltd.


 -Original Message-
 From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de]
 Sent: vendredi 24 février 2012 16:33
 To: Arnaud Gaboury
 Cc: r-help@r-project.org
 Subject: Re: [R] data frame manipulation with condition



 On 24.02.2012 16:25, Arnaud Gaboury wrote:
 Dear list,

 n00b question, but still can't find any easy answer.

 Here is a df:


 Change

 df-data.frame(cbind(x=c(AA,BB,CC,AA),y=1:4))

 to

 df- data.frame(x = c(AA,BB,CC,AA), y = 1:4)

 to make your object a sensible data.frame.



 df
   x y
 1 AA 1
 2 BB 2
 3 CC 3
 4 AA 4


 I want to modify this df this way :
 if df$x==AA then df$y=df$y*10

 df$y[df$x==AA]- df$y[df$x==AA] * 25

 ...


 Uwe Ligges


 if df$x==BB then df$y=df$y*25




 and so on with other conditions.

 TY for any help.

 Trading

 A2CT2 Ltd.


 Arnaud Gaboury

 A2CT2 Ltd.

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


Re: [R] data frame manipulation with condition

2012-02-24 Thread Arnaud Gaboury
TY very much Sarah: your tip is doing the job:

reported -
structure(list(Product = structure(c(1L, 2L, 2L, 2L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 4L, 5L, 5L, 5L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, 
9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 
11L, 12L, 12L, 13L, 14L, 14L), .Label = c(CL, Cocoa, Coffee C, 
GC, HG, HO, NG, PL, RB, SI, Sugar No 11, ZC, 
ZL, ZW), class = factor), reported.Price = c(105.35, 2380, 
2407, 2408, 202.35, 202.8, 202.95, 205.85, 206.05, 206.1, 206.2, 
1748, 378.8, 379.25, 379.5, 320.61, 2.538, 2.543, 1669, 1678.5, 
304.49, 321.39, 321.6, 321.65, 322.5, 322.55, 322.8, 323.04, 
3390, 3397.5, 24.16, 24.2, 24.22, 24.23, 24.54, 25.5, 25.55, 
631.75, 638, 53.77, 630.75, 633), reported.Nbr.Lots = c(6L, 3L, 
-1L, -2L, -40L, -1L, -1L, 10L, 5L, 6L, 19L, 17L, 23L, 12L, 35L, 
11L, -54L, -52L, 26L, 26L, 10L, -10L, 1L, 4L, 4L, 1L, 5L, 5L, 
17L, 17L, 114L, 71L, 16L, 27L, -3L, 3L, -3L, -89L, -1L, -1L, 
-51L, -51L)), .Names = c(Product, reported.Price, reported.Nbr.Lots
), row.names = c(7L, 4L, 5L, 6L, 13L, 14L, 15L, 16L, 17L, 18L, 
19L, 8L, 9L, 10L, 11L, 12L, 20L, 21L, 22L, 23L, 35L, 36L, 37L, 
38L, 39L, 40L, 41L, 42L, 31L, 32L, 24L, 25L, 26L, 27L, 28L, 29L, 
30L, 2L, 3L, 1L, 33L, 34L), class = data.frame)

 mult-c(CL=100,GC=10,HG=10,NG=1000,PL=10,RB=100,SI=10,ZL=100,HO=100,KC=1,CC=1,SB=1,ZC=1,ZW=1)
 reported$reported.Price - reported$reported.Price * mult[reported$Product]

reported -
structure(list(Product = structure(c(1L, 2L, 2L, 2L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 4L, 5L, 5L, 5L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, 
9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 
11L, 12L, 12L, 13L, 14L, 14L), .Label = c(CL, Cocoa, Coffee C, 
GC, HG, HO, NG, PL, RB, SI, Sugar No 11, ZC, 
ZL, ZW), class = factor), reported.Price = c(10535, 23800, 
24070, 24080, 2023.5, 2028, 2029.5, 2058.5, 2060.5, 2061, 2062, 
1748000, 3788, 3792.5, 3795, 32061, 25.38, 25.43, 166900, 167850, 
30449, 32139, 32160, 32165, 32250, 32255, 32280, 32304, 3390, 
3397.5, 24.16, 24.2, 24.22, 24.23, 24.54, 25.5, 25.55, 631.75, 
638, 53.77, 630.75, 633), reported.Nbr.Lots = c(6L, 3L, -1L, 
-2L, -40L, -1L, -1L, 10L, 5L, 6L, 19L, 17L, 23L, 12L, 35L, 11L, 
-54L, -52L, 26L, 26L, 10L, -10L, 1L, 4L, 4L, 1L, 5L, 5L, 17L, 
17L, 114L, 71L, 16L, 27L, -3L, 3L, -3L, -89L, -1L, -1L, -51L, 
-51L)), .Names = c(Product, reported.Price, reported.Nbr.Lots
), row.names = c(7L, 4L, 5L, 6L, 13L, 14L, 15L, 16L, 17L, 18L, 
19L, 8L, 9L, 10L, 11L, 12L, 20L, 21L, 22L, 23L, 35L, 36L, 37L, 
38L, 39L, 40L, 41L, 42L, 31L, 32L, 24L, 25L, 26L, 27L, 28L, 29L, 
30L, 2L, 3L, 1L, 33L, 34L), class = data.frame)

Have a good weekend.

Arnaud Gaboury
 
A2CT2 Ltd.
Trade: +41 22 849 88 63
Fax:   +41 22 849 88 66
arnaud.gabo...@a2ct2.com 

This email and any files transmitted with it are confidential and intended 
solely for the use of the individual or entity to whom they are addressed. 
Access to this email by anyone else is unauthorized. If you are not the 
intended recipient, any disclosure, copying, distribution or any action taken 
or omitted to be taken in reliance on it, is prohibited and may be unlawful. If 
you have received this email in error please notify the sender. 


-Original Message-
From: Sarah Goslee [mailto:sarah.gos...@gmail.com] 
Sent: vendredi 24 février 2012 17:54
To: Arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] data frame manipulation with condition

You need, as I already suggested, to use a value of 1 for levels you don't want 
to change.

 mult - c(AA = 10, BB = 25, CC=1, DD=15) mult[df$x]
AA BB CC AA DD DD
10 25  1 10 15 15
 df$y * mult[df$x]
AA BB CC AA DD DD
10 50  3 40 75 90


On Fri, Feb 24, 2012 at 11:36 AM, Arnaud Gaboury arnaud.gabo...@a2ct2.com 
wrote:
 df- data.frame(x = c(AA,BB,CC,AA,DD,DD), y = 1:6) mult 
 - c(AA = 10, BB = 25,DD=15) df$y - df$y * mult[df$x] df
   x  y
 1 AA 10
 2 BB 50
 3 CC 45
 4 AA 40
 5 DD NA
 6 DD NA

 My df is in fact much more longer than the chosen example shown here. It 
 seems your tip didn't do the job.
 I am expecting this as result :

 df
   x  y
 1 AA 10   if df$x==AA, df$y-1*10
 2 BB 50    if df$x==BB, df$y-2*25
 3 CC 3         NOTHING
 4 AA 40     if df$x==AA, df$y-4*10
 5 DD 75    if df$x==DD, df$y-5*15
 6 DD 90    if df$x==DD, df$y-6*15

 Arnaud Gaboury

 A2CT2 Ltd.

 -Original Message-
 From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de]
 Sent: vendredi 24 février 2012 17:07
 To: Arnaud Gaboury
 Cc: r-help@r-project.org
 Subject: Re: [R] data frame manipulation with condition



 On 24.02.2012 16:59, Arnaud Gaboury wrote:
 TY Uwe,

 So I will have to write a line for each condition? Right?

 In fact I was trying to do something with apply in one line, but couldn't 
 achieve any result. In fact, all my transformation will be multiplying one 
 object by a specific number according to the value of df$x.

 In that case:

 mult - c(AA = 10, BB = 25)

 Then:


 df$y - df$y * mult[df$x]


 Uwe Ligges



 Arnaud Gaboury

 A2CT2 Ltd

Re: [R] data frame manipulation with condition

2012-02-24 Thread Arnaud Gaboury
In fact I need to use William tip: Use mult[as.character(df$x)] instead of 
mult[df$x].


Let's try again with a shorter df as example:

The rule: if AA, then multiply y by 2, if BB multiply y by 5, if CC do nothing, 
if DD multiply by 2.


Let's say day 1 I have df1:

df1 -
structure(list(x = structure(c(1L, 2L, 2L, 3L), .Label = c(AA, 
BB, CC), class = factor), y = 1:4), .Names = c(x, y
), row.names = c(NA, -4L), class = data.frame)

 df1
   x y
1 AA 1
2 BB 2
3 BB 3
4 CC 4

mult - c(AA=2,BB=5,CC=1,DD=2)
df1$y - df1$y * mult[as.character(df1$x)]
 df1
   x  y
1 AA  2
2 BB 10
3 BB 15
4 CC  4

WORKING

Now day 2 with df2:

df2 - data.frame(x = c(AA,AA,BB,BB,BB,CC,DD,DD), y = 1:8)
df2$y - df2$y * mult[as.character(df2$x)]
 df2
   x  y
1 AA  2
2 AA  4
3 BB 15
4 BB 20
5 BB 25
6 CC  6
7 DD 14
8 DD 16

WORKING


Ty both of you and have a good weekend.


Arnaud Gaboury
 
A2CT2 Ltd.


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Arnaud Gaboury
Sent: vendredi 24 février 2012 18:17
To: Sarah Goslee
Cc: r-help@r-project.org
Subject: Re: [R] data frame manipulation with condition

TY very much Sarah: your tip is doing the job:

reported -
structure(list(Product = structure(c(1L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 4L, 5L, 5L, 5L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 
10L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 13L, 14L, 14L), .Label = 
c(CL, Cocoa, Coffee C, GC, HG, HO, NG, PL, RB, SI, Sugar 
No 11, ZC, ZL, ZW), class = factor), reported.Price = c(105.35, 2380, 
2407, 2408, 202.35, 202.8, 202.95, 205.85, 206.05, 206.1, 206.2, 1748, 378.8, 
379.25, 379.5, 320.61, 2.538, 2.543, 1669, 1678.5, 304.49, 321.39, 321.6, 
321.65, 322.5, 322.55, 322.8, 323.04, 3390, 3397.5, 24.16, 24.2, 24.22, 24.23, 
24.54, 25.5, 25.55, 631.75, 638, 53.77, 630.75, 633), reported.Nbr.Lots = c(6L, 
3L, -1L, -2L, -40L, -1L, -1L, 10L, 5L, 6L, 19L, 17L, 23L, 12L, 35L, 11L, -54L, 
-52L, 26L, 26L, 10L, -10L, 1L, 4L, 4L, 1L, 5L, 5L, 17L, 17L, 114L, 71L, 16L, 
27L, -3L, 3L, -3L, -89L, -1L, -1L, -51L, -51L)), .Names = c(Product, 
reported.Price, reported.Nbr.Lots
), row.names = c(7L, 4L, 5L, 6L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 8L, 9L, 
10L, 11L, 12L, 20L, 21L, 22L, 23L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 31L, 
32L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 2L, 3L, 1L, 33L, 34L), class = 
data.frame)

 mult-c(CL=100,GC=10,HG=10,NG=1000,PL=10,RB=100,SI=10,ZL=100,HO=100,KC
 =1,CC=1,SB=1,ZC=1,ZW=1) reported$reported.Price - 
 reported$reported.Price * mult[reported$Product]

reported -
structure(list(Product = structure(c(1L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 4L, 5L, 5L, 5L, 6L, 7L, 7L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 
10L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 13L, 14L, 14L), .Label = 
c(CL, Cocoa, Coffee C, GC, HG, HO, NG, PL, RB, SI, Sugar 
No 11, ZC, ZL, ZW), class = factor), reported.Price = c(10535, 23800, 
24070, 24080, 2023.5, 2028, 2029.5, 2058.5, 2060.5, 2061, 2062, 1748000, 3788, 
3792.5, 3795, 32061, 25.38, 25.43, 166900, 167850, 30449, 32139, 32160, 32165, 
32250, 32255, 32280, 32304, 3390, 3397.5, 24.16, 24.2, 24.22, 24.23, 24.54, 
25.5, 25.55, 631.75, 638, 53.77, 630.75, 633), reported.Nbr.Lots = c(6L, 3L, 
-1L, -2L, -40L, -1L, -1L, 10L, 5L, 6L, 19L, 17L, 23L, 12L, 35L, 11L, -54L, 
-52L, 26L, 26L, 10L, -10L, 1L, 4L, 4L, 1L, 5L, 5L, 17L, 17L, 114L, 71L, 16L, 
27L, -3L, 3L, -3L, -89L, -1L, -1L, -51L, -51L)), .Names = c(Product, 
reported.Price, reported.Nbr.Lots
), row.names = c(7L, 4L, 5L, 6L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 8L, 9L, 
10L, 11L, 12L, 20L, 21L, 22L, 23L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 31L, 
32L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 2L, 3L, 1L, 33L, 34L), class = 
data.frame)

Have a good weekend.

Arnaud Gaboury
 
A2CT2 Ltd.
Trade: +41 22 849 88 63
Fax:   +41 22 849 88 66
arnaud.gabo...@a2ct2.com 

This email and any files transmitted with it are confidential and intended 
solely for the use of the individual or entity to whom they are addressed. 
Access to this email by anyone else is unauthorized. If you are not the 
intended recipient, any disclosure, copying, distribution or any action taken 
or omitted to be taken in reliance on it, is prohibited and may be unlawful. If 
you have received this email in error please notify the sender. 


-Original Message-
From: Sarah Goslee [mailto:sarah.gos...@gmail.com]
Sent: vendredi 24 février 2012 17:54
To: Arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] data frame manipulation with condition

You need, as I already suggested, to use a value of 1 for levels you don't want 
to change.

 mult - c(AA = 10, BB = 25, CC=1, DD=15) mult[df$x]
AA BB CC AA DD DD
10 25  1 10 15 15
 df$y * mult[df$x]
AA BB CC AA DD DD
10 50  3 40 75 90


On Fri, Feb 24, 2012 at 11:36 AM, Arnaud Gaboury arnaud.gabo...@a2ct2.com 
wrote:
 df- data.frame(x = c(AA,BB,CC,AA,DD,DD), y = 1:6) mult
 - c(AA = 10, BB = 25,DD=15) df$y - df$y * mult[df$x] df
   x  y
 1 AA 10

Re: [R] install rJava in Ubuntu 11.10

2012-02-24 Thread Arnaud Gaboury
As a Linux user, I know you are not running exactly the same Java as on 
windows. It exists some copyright issues which prevent you to run Sun Java on 
your Linux box. 
As shown, you are running in fact openJDK. If result is the same for you, being 
able to run Java, it is not the same for most apps.
Install folders are different, and I guess R cannot find the right place for 
your Java environment.

Try to google more on this issue (Java on Linux openJDK install folder), or 
anything about building Android on Linux( same problem as Android needs 
java). There is something you could try: add the openJDK path in your 
environment.

Hope this help.


Arnaud Gaboury
 
A2CT2 Ltd.


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of John Kane
Sent: vendredi 24 février 2012 19:32
To: r-help@r-project.org
Subject: [R] install rJava in Ubuntu 11.10

I am trying to install rJava on a WUBI  Ubuntu 11.10 installation of R with no 
luck. I was originally trying to install the iplots package and encountered 
this rJava problem.

Code used:
install.packages(rJava)

(CRAN mirrors --Canada(ON) and Canada(QC2)

I installed iplots with no problem on Windows 7.

I know just about zero about Ubuntu or Linux in general so I have no idea what 
I am doing.

Any suggestions would be gratefully received.

I am getting the error/warning messages below.
=

Cannot compile a simple JNI program. See config.log for details.

Make sure you have Java Development Kit installed and correctly registered in R.
If in doubt, re-run R CMD javareconf as root.

ERROR: configuration failed for package ‘rJava’
* removing ‘/home/john/R/i686-pc-linux-gnu-library/2.13/rJava’

The downloaded packages are in
‘/tmp/RtmphfnJ62/downloaded_packages’
Warning message:
In install.packages(rJava) :
  installation of package 'rJava' had non-zero exit status 
=
EXISTING JAVA INSTALLAION

john@ubuntu:~$ java -version
java version 1.6.0_23
OpenJDK Runtime Environment (IcedTea6 1.11pre) (6b23~pre11-0ubuntu1.11.10.1) 
OpenJDK Client VM (build 20.0-b11, mixed mode, sharing)

===

I have re-run R CMD javareconf as root.

Does the R CMC javareconf need something added?
(i.e. R CMD javaconf xxx)

Do I really need a  Java Development Kit installed?

sessionInfo()
R version 2.13.1 (2011-07-08)
Platform: i686-pc-linux-gnu (32-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C  
 [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=C  LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8   LC_NAME=C 
 [9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C   

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base


Publish your photos in seconds for FREE
TRY IM TOOLPACK at http://www.imtoolpack.com/default.aspx?rc=if4

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


Re: [R] data frame manipulation with conditions

2012-02-24 Thread Arnaud Gaboury
TY Elai for your answer. One solution has been given earlier in this list by 
Sarah Goslee and William Dunlap.

Arnaud Gaboury
 
A2CT2 Ltd.


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of ilai
Sent: vendredi 24 février 2012 20:14
To: A2CT2 Trading
Cc: r-help@r-project.org
Subject: Re: [R] data frame manipulation with conditions

On Fri, Feb 24, 2012 at 8:11 AM, A2CT2 Trading trad...@a2ct2.com wrote:
 Dear list,

 n00b question, but still can't find any easy answer.

 Here is a df:

 df-data.frame(cbind(x=c(AA,BB,CC,AA),y=1:4))

# No, your y is a factor
 str(df)
'data.frame':   4 obs. of  2 variables:
 $ x: Factor w/ 3 levels AA,BB,CC: 1 2 3 1  $ y: Factor w/ 4 levels 
1,2,3,4: 1 2 3 4

# You want to remove the cbind
 df-data.frame(x=c(AA,BB,CC,AA),y=1:4)
 str(df)
'data.frame':   4 obs. of  2 variables:
 $ x: Factor w/ 3 levels AA,BB,CC: 1 2 3 1  $ y: int  1 2 3 4

 I want to modify this df this way :
  if df$x==AA then df$y=df$y*10
  if df$x==BB then df$y=df$y*25

 and so on with other conditions.


 df$y- df$y * c(10,25,.5)[df$x]
[1] 10.0 50.0  1.5 40.0
 # 1*10 2*25 3*.5 4*10

HTH

Elai

 TY for any help.

 Trading

 A2CT2 Ltd.

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

__
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] data frame colnames through ddply

2012-02-23 Thread Arnaud Gaboury
Dear list,

I am trying to pass data frame colnames through ddply without sucess.

Here is my command:

exportfile-ddply(exportfile,c(Product,Price),summarise,Nbr.Lots=sum(Filled.Qty))

exportfile is a df. I want to apply summarise to Product and Price columns and 
sum the Filled.Qty column and renamed it Nbr.Lots. This line works. 

What I would like is changing the col names in the same line, thus avoiding 
another line with 
colnames(exportfile)-c(Contract,Price,Nbr.Lots)

Is there a possibility to change my col names in the same line?

TY



Arnaud Gaboury
 
A2CT2 Ltd.

__
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] ifelse

2012-02-09 Thread Arnaud Gaboury
Hello,

I need to print a screen message after a test.

list-c(10,1,100,10)
ifelse(all(list %in% c(1,10,100)==TRUE),cat(YES\n),cat(NO\n))
YES
Error in ifelse(all(l %in% c(1, 10, 100) == TRUE), cat(YES\n), cat(NO\n)) : 
  replacement has length zero


I have the correct answer, YES, but with an Error.

Why?

TY for any help


Arnaud Gaboury
 
A2CT2 Ltd.

__
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] ifelse

2012-02-09 Thread Arnaud Gaboury
TY much.

Works for me.

Arnaud Gaboury
 
A2CT2 Ltd.


-Original Message-
From: R. Michael Weylandt [mailto:michael.weyla...@gmail.com] 
Sent: jeudi 9 février 2012 17:47
To: Arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] ifelse

cat() returns a null value so it's problematic inside ifelse. Here you probably 
need a regular if statement:

if(all(list %in% c(1, 10, 100))) cat(YES\n) else cat(NO\n) # The == TRUE is 
redundant.

Michael

On Thu, Feb 9, 2012 at 11:37 AM, Arnaud Gaboury arnaud.gabo...@a2ct2.com 
wrote:
 Hello,

 I need to print a screen message after a test.

list-c(10,1,100,10)
ifelse(all(list %in% c(1,10,100)==TRUE),cat(YES\n),cat(NO\n))
 YES
 Error in ifelse(all(l %in% c(1, 10, 100) == TRUE), cat(YES\n), cat(NO\n)) 
 :
  replacement has length zero


 I have the correct answer, YES, but with an Error.

 Why?

 TY for any help


 Arnaud Gaboury

 A2CT2 Ltd.

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


[R] loading packages in a function

2012-02-09 Thread Arnaud Gaboury
Hello,

I sourced successfully my function().

I need to load libraries, so I wrote this inside my function():

function()

{

#load needed library
library(plyr)
library(car)

/...

}

It is OK, but I have this on my invite command when running the function:

 function()
Loading required package: MASS
Loading required package: nnet
YOU DID A GOOD JOB,SEND EMAIL

Last line is the supposed result of my function, so it ok.


How to get rid of the first two lines, only for esthetic purpose?

TY for your time.


Arnaud Gaboury
 
A2CT2 Ltd.

__
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] loading packages in a function

2012-02-09 Thread Arnaud Gaboury
TY for your answer, but here what i did :

#load needed lybrary
suppressPackageStartupMessages(library(plyr))
suppressPackageStartupMessages(library(car))
library(plyr)
library(car)


But I still get :

Loading required package: MASS
Loading required package: nnet


Arnaud Gaboury
 
A2CT2 Ltd.


-Original Message-
From: R. Michael Weylandt [mailto:michael.weyla...@gmail.com] 
Sent: jeudi 9 février 2012 19:26
To: Arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] loading packages in a function

Perhaps the longest function in base R I know of:

suppressPackageStartupMessages

e.g.,

suppressPackageStartupMessages(library(zoo))

Michael

On Thu, Feb 9, 2012 at 12:44 PM, Arnaud Gaboury arnaud.gabo...@a2ct2.com 
wrote:
 Hello,

 I sourced successfully my function().

 I need to load libraries, so I wrote this inside my function():

 function()

 {

 #load needed library
 library(plyr)
 library(car)

 /...

 }

 It is OK, but I have this on my invite command when running the function:

 function()
 Loading required package: MASS
 Loading required package: nnet
 YOU DID A GOOD JOB,SEND EMAIL

 Last line is the supposed result of my function, so it ok.


 How to get rid of the first two lines, only for esthetic purpose?

 TY for your time.


 Arnaud Gaboury

 A2CT2 Ltd.

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


Re: [R] loading packages in a function

2012-02-09 Thread Arnaud Gaboury
Ah, I feel stupid!

OK, it works for me.

TY for your help

Arnaud Gaboury
 
A2CT2 Ltd.


-Original Message-
From: Sarah Goslee [mailto:sarah.gos...@gmail.com] 
Sent: jeudi 9 février 2012 20:02
To: Arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] loading packages in a function

That's because you're loading the packages twice, once suppressing the messages 
and once not.

You only need the first pair of lines.

On Thu, Feb 9, 2012 at 1:55 PM, Arnaud Gaboury arnaud.gabo...@a2ct2.com wrote:
 TY for your answer, but here what i did :

 #load needed lybrary
 suppressPackageStartupMessages(library(plyr))
 suppressPackageStartupMessages(library(car))
 library(plyr)
 library(car)


 But I still get :

 Loading required package: MASS
 Loading required package: nnet


 Arnaud Gaboury

 A2CT2 Ltd.


 -Original Message-
 From: R. Michael Weylandt [mailto:michael.weyla...@gmail.com]
 Sent: jeudi 9 février 2012 19:26
 To: Arnaud Gaboury
 Cc: r-help@r-project.org
 Subject: Re: [R] loading packages in a function

 Perhaps the longest function in base R I know of:

 suppressPackageStartupMessages

 e.g.,

 suppressPackageStartupMessages(library(zoo))

 Michael

 On Thu, Feb 9, 2012 at 12:44 PM, Arnaud Gaboury arnaud.gabo...@a2ct2.com 
 wrote:
 Hello,

 I sourced successfully my function().

 I need to load libraries, so I wrote this inside my function():

 function()

 {

 #load needed library
 library(plyr)
 library(car)

 /...

 }

 It is OK, but I have this on my invite command when running the function:

 function()
 Loading required package: MASS
 Loading required package: nnet
 YOU DID A GOOD JOB,SEND EMAIL

 Last line is the supposed result of my function, so it ok.


 How to get rid of the first two lines, only for esthetic purpose?

 TY for your time.


 Arnaud Gaboury



--
Sarah Goslee
http://www.functionaldiversity.org

__
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] replace elements of a data frame

2012-02-08 Thread Arnaud Gaboury
 names1-recode(df$names,'BO'='BOO';'CL'='CLR';'C'='CC')
 df1-data.frame(names1,price)
 df1
  names1 price
1BOO10
2 CC25
3CLR20

TY for the tip.

Any possibility to write this in one single line?

Arnaud Gaboury
 
A2CT2 Ltd.

-Original Message-
From: Berend Hasselman [mailto:b...@xs4all.nl] 
Sent: mardi 7 février 2012 20:46
To: Arnaud Gaboury
Cc: Jorge I Velez; r-help@r-project.org
Subject: Re: [R] replace elements of a data frame


On 07-02-2012, at 20:24, Arnaud Gaboury wrote:

 I did indeed have a look at recode(), and was able to replace, but an error 
 warning :
 
 recode(names,BO,BOO,df)
 Warning message:
 In recode.default(names, BO, BOO, df) :
  Name(s) of vars duplicates with an object outside the dataFrame.
 
 df
  names price
 1   BOO10
 2 C25
 3CL20
 
 As you can see, BO has been replaced by BOO, but with a warning!

library(car)

 names-c(BO,C,CL)
price-c(10,25,20)
df-data.frame(names,price)
recode(df$names,'BO'='BOO'; 'CL'='CLO'; 'C'='CR')

results in

[1] BOO CR  CLO
Levels: BOO CLO CR

Note the single quotes.

Berend

__
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] decimal number format as quarter

2012-02-08 Thread Arnaud Gaboury
Hello,

I have to deal with numbers with a decimal part as quarter, coming from two 
systems with different way to show decimals. I need to tell R these are in fact 
the same number.

On one side my number are formatted this way : 2.2 , 2.4 and 2.6. On the other 
side, I have 2.25, 2.50 and 2.75.
All numbers are in fact 2.1/4, 2.1/2, 2.3/4.

How can I tell R 2.2 is 2.25, 2.4 is 2.50 and 2.6 is 2.75 ?

TY for any help.

Arnaud Gaboury
 
A2CT2 Ltd.

__
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] decimal number format as quarter

2012-02-08 Thread Arnaud Gaboury
TY Jim,

It do the trick.

I was trying to play without success with the format() options.
No simplest way so?

Arnaud Gaboury
 
A2CT2 Ltd.


-Original Message-
From: jim holtman [mailto:jholt...@gmail.com] 
Sent: mercredi 8 février 2012 15:36
To: Arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] decimal number format as quarter

will this do it for you:

 x - c(2.2, 2.4, 2.6, 3.2, 3.4, 3.6)
 # get integer part
 x.i - as.integer(x)
 # get fractional part
 x.f - (x * 10) %% 10
 # new result
 result - x.i + ifelse(x.f == 2
+ , .25
+ , ifelse(x.f == 4
+ , .5
+ , .75
+ )
+ )
 result
[1] 2.25 2.50 2.75 3.25 3.50 3.75



On Wed, Feb 8, 2012 at 9:12 AM, Arnaud Gaboury arnaud.gabo...@a2ct2.com wrote:
 Hello,

 I have to deal with numbers with a decimal part as quarter, coming from two 
 systems with different way to show decimals. I need to tell R these are in 
 fact the same number.

 On one side my number are formatted this way : 2.2 , 2.4 and 2.6. On the 
 other side, I have 2.25, 2.50 and 2.75.
 All numbers are in fact 2.1/4, 2.1/2, 2.3/4.

 How can I tell R 2.2 is 2.25, 2.4 is 2.50 and 2.6 is 2.75 ?

 TY for any help.

 Arnaud Gaboury

 A2CT2 Ltd.

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



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

__
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] decimal number format as quarter

2012-02-08 Thread Arnaud Gaboury
David,

You are not far indeed, as I trade commodities, and prices are the ones from 
grain market: Corn, wheat and Soybeans.

They are quoted in 1/4, and my trading platform displays them in 2,4,6 and my 
statements are in 25,50,75.

TY

Arnaud Gaboury
 
A2CT2 Ltd.


-Original Message-
From: David Reiner [mailto:david.rei...@xrtrading.com] 
Sent: mercredi 8 février 2012 15:48
To: Arnaud Gaboury; jim holtman
Cc: r-help@r-project.org
Subject: RE: [R] decimal number format as quarter

Looks like something priced in eighths; we deal with similar notation for bonds 
and similar instruments.

 x - c(2.2, 2.4, 2.6, 3.2, 3.4, 3.6)
 as.integer(x)+10*(x-as.integer(x))/8
[1] 2.25 2.50 2.75 3.25 3.50 3.75

Adjust the 10 and 8 if you have other denominators.
-- David

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Arnaud Gaboury
Sent: Wednesday, February 08, 2012 8:45 AM
To: jim holtman
Cc: r-help@r-project.org
Subject: Re: [R] decimal number format as quarter

TY Jim,

It do the trick.

I was trying to play without success with the format() options.
No simplest way so?

Arnaud Gaboury

A2CT2 Ltd.


-Original Message-
From: jim holtman [mailto:jholt...@gmail.com]
Sent: mercredi 8 février 2012 15:36
To: Arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] decimal number format as quarter

will this do it for you:

 x - c(2.2, 2.4, 2.6, 3.2, 3.4, 3.6)
 # get integer part
 x.i - as.integer(x)
 # get fractional part
 x.f - (x * 10) %% 10
 # new result
 result - x.i + ifelse(x.f == 2
+ , .25
+ , ifelse(x.f == 4
+ , .5
+ , .75
+ )
+ )
 result
[1] 2.25 2.50 2.75 3.25 3.50 3.75



On Wed, Feb 8, 2012 at 9:12 AM, Arnaud Gaboury arnaud.gabo...@a2ct2.com wrote:
 Hello,

 I have to deal with numbers with a decimal part as quarter, coming from two 
 systems with different way to show decimals. I need to tell R these are in 
 fact the same number.

 On one side my number are formatted this way : 2.2 , 2.4 and 2.6. On the 
 other side, I have 2.25, 2.50 and 2.75.
 All numbers are in fact 2.1/4, 2.1/2, 2.3/4.

 How can I tell R 2.2 is 2.25, 2.4 is 2.50 and 2.6 is 2.75 ?

 TY for any help.

 Arnaud Gaboury

 A2CT2 Ltd.

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



--
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

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


This e-mail and any materials attached hereto, including, without limitation, 
all content hereof and thereof (collectively, XR Content) are confidential 
and proprietary to XR Trading, LLC (XR) and/or its affiliates, and are 
protected by intellectual property laws.  Without the prior written consent of 
XR, the XR Content may not (i) be disclosed to any third party or (ii) be 
reproduced or otherwise used by anyone other than current employees of XR or 
its affiliates, on behalf of XR or its affiliates.

THE XR CONTENT IS PROVIDED AS IS, WITHOUT REPRESENTATIONS OR WARRANTIES OF ANY 
KIND.  TO THE MAXIMUM EXTENT PERMISSIBLE UNDER APPLICABLE LAW, XR HEREBY 
DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS AND IMPLIED, RELATING TO THE XR 
CONTENT, AND NEITHER XR NOR ANY OF ITS AFFILIATES SHALL IN ANY EVENT BE LIABLE 
FOR ANY DAMAGES OF ANY NATURE WHATSOEVER, INCLUDING, BUT NOT LIMITED TO, 
DIRECT, INDIRECT, CONSEQUENTIAL, SPECIAL AND PUNITIVE DAMAGES, LOSS OF PROFITS 
AND TRADING LOSSES, RESULTING FROM ANY PERSON'S USE OR RELIANCE UPON, OR 
INABILITY TO USE, ANY XR CONTENT, EVEN IF XR IS ADVISED OF THE POSSIBILITY OF 
SUCH DAMAGES OR IF SUCH DAMAGES WERE FORESEEABLE.

__
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] decimal number format as quarter

2012-02-08 Thread Arnaud Gaboury
Thanks so much Peter. You are the man.

Easy way and working for me.

Arnaud Gaboury
 
A2CT2 Ltd.


-Original Message-
From: peter dalgaard [mailto:pda...@gmail.com] 
Sent: mercredi 8 février 2012 16:15
To: David Reiner
Cc: Arnaud Gaboury; jim holtman; r-help@r-project.org
Subject: Re: [R] decimal number format as quarter


On Feb 8, 2012, at 15:48 , David Reiner wrote:

 Looks like something priced in eighths; we deal with similar notation for 
 bonds and similar instruments.
 
 x - c(2.2, 2.4, 2.6, 3.2, 3.4, 3.6)
 as.integer(x)+10*(x-as.integer(x))/8
 [1] 2.25 2.50 2.75 3.25 3.50 3.75
 
 Adjust the 10 and 8 if you have other denominators.

For the case at hand, I expect that you can even get away with

 ceiling(x*4)/4
[1] 2.25 2.50 2.75 3.25 3.50 3.75


--
Peter Dalgaard, Professor
Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 
Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.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] replace elements of a data frame

2012-02-07 Thread Arnaud Gaboury
Hello,

I am getting mad at finding a simple way to replace elements of a df.

Here is a short df :

 names-c(BO,C,CL)
 price-c(10,25,20)
 df-data.frame(names,price)


I want to replace BO by BOB, C by CR, CL by CLO, and the list is 
more long. 
I can do that for each element:

df[df==BO]-BOB

But my df is bigger indeed with other elements.

I was thinking using replace(), but can't get any clean result ( NA or all 
elements replaced with only one), neither with sapply().

TY for any help, and sorry for the n00b question.






Arnaud Gaboury
 
A2CT2 Ltd.

__
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] replace elements of a data frame

2012-02-07 Thread Arnaud Gaboury
I did indeed have a look at recode(), and was able to replace, but an error 
warning :

 recode(names,BO,BOO,df)
Warning message:
In recode.default(names, BO, BOO, df) :
  Name(s) of vars duplicates with an object outside the dataFrame.

 df
  names price
1   BOO10
2 C25
3CL20

As you can see, BO has been replaced by BOO, but with a warning!


Arnaud Gaboury
 
A2CT2 Ltd.
Trade: +41 22 849 88 63
Fax:   +41 22 849 88 66
arnaud.gabo...@a2ct2.com 

This email and any files transmitted with it are confidential and intended 
solely for the use of the individual or entity to whom they are addressed. 
Access to this email by anyone else is unauthorized. If you are not the 
intended recipient, any disclosure, copying, distribution or any action taken 
or omitted to be taken in reliance on it, is prohibited and may be unlawful. If 
you have received this email in error please notify the sender. 

From: Jorge I Velez [mailto:jorgeivanve...@gmail.com] 
Sent: mardi 7 février 2012 19:55
To: Arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] replace elements of a data frame

Hi Arnaud,

Take a look at 

require(car)
?recode

HTH,
Jorge.-

On Tue, Feb 7, 2012 at 1:05 PM, Arnaud Gaboury  wrote:
Hello,

I am getting mad at finding a simple way to replace elements of a df.

Here is a short df :

 names-c(BO,C,CL)
 price-c(10,25,20)
 df-data.frame(names,price)


I want to replace BO by BOB, C by CR, CL by CLO, and the list is 
more long.
I can do that for each element:

df[df==BO]-BOB

But my df is bigger indeed with other elements.

I was thinking using replace(), but can't get any clean result ( NA or all 
elements replaced with only one), neither with sapply().

TY for any help, and sorry for the n00b question.






Arnaud Gaboury
 
A2CT2 Ltd.

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


Re: [R] replace elements of a data frame

2012-02-07 Thread Arnaud Gaboury
I used in fact recode() from epilcac package, not the one you mentioned!

Arnaud Gaboury
 
A2CT2 Ltd.


-Original Message-
From: Arnaud Gaboury 
Sent: mardi 7 février 2012 20:25
To: Jorge I Velez
Cc: r-help@r-project.org; Arnaud Gaboury
Subject: RE: [R] replace elements of a data frame

I did indeed have a look at recode(), and was able to replace, but an error 
warning :

 recode(names,BO,BOO,df)
Warning message:
In recode.default(names, BO, BOO, df) :
  Name(s) of vars duplicates with an object outside the dataFrame.

 df
  names price
1   BOO10
2 C25
3CL20

As you can see, BO has been replaced by BOO, but with a warning!


Arnaud Gaboury
 
A2CT2 Ltd.

From: Jorge I Velez [mailto:jorgeivanve...@gmail.com] 
Sent: mardi 7 février 2012 19:55
To: Arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] replace elements of a data frame

Hi Arnaud,

Take a look at 

require(car)
?recode

HTH,
Jorge.-

On Tue, Feb 7, 2012 at 1:05 PM, Arnaud Gaboury  wrote:
Hello,

I am getting mad at finding a simple way to replace elements of a df.

Here is a short df :

 names-c(BO,C,CL)
 price-c(10,25,20)
 df-data.frame(names,price)


I want to replace BO by BOB, C by CR, CL by CLO, and the list is 
more long.
I can do that for each element:

df[df==BO]-BOB

But my df is bigger indeed with other elements.

I was thinking using replace(), but can't get any clean result ( NA or all 
elements replaced with only one), neither with sapply().

TY for any help, and sorry for the n00b question.






Arnaud Gaboury
 
A2CT2 Ltd.

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


[R] merge two data frames

2010-08-04 Thread arnaud gaboury
Dear list,

here are my two data frames:

av -
structure(list(DESCRIPTION = c(COFFEE C Sep/10, COPPER Sep/10,
CORN Dec/10, CRUDE OIL miNY Sep/10, GOLD Aug/10, HENRY HUB
NATURAL GAS Sep/10,
PALLADIUM Sep/10, SILVER Sep/10, SOYBEANS Nov/10, SPCL HIGH
GRADE ZINC USD,
SUGAR NO.11 Oct/10, WHEAT Sep/10), prix = c(-168.3, -1.62,
-773.75, -78.75, -1168.3, -0.0916, -470.75, 1758.5,
-975.25, 1964, -19.09, -605.75), pos = c(-1, 0, -2, -1, -1, 0,
-1, 1, -1, 1, -1, -1), PL = c(-12.03, -31.68, -43.2, -70.49,
-11.88, -95.04, -3.96, -35.64, -30.24, -12.5, -36.09, -4.32)), .Names
= c(DESCRIPTION,
prix, pos, PL), row.names = c(NA, 12L), class = data.frame)

zz -
structure(list(DESCRIPTION = structure(c(1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 13L, 11L, 12L), .Label = c(COFFEE C Sep/10,
COPPER Sep/10, CORN Dec/10, CRUDE OIL miNY Sep/10, GOLD Aug/10,
HENRY HUB NATURAL GAS Sep/10, PALLADIUM Sep/10, PRM HGH GD ALUMINIUM USD,
SILVER Sep/10, SOYBEANS Nov/10, SPCL HIGH GRADE ZINC USD,
SUGAR NO.11 Oct/10, WHEAT Sep/10), class = factor), pl =
c(-8.22,
2.31, -47.25, -0.234, -12.7,
-0.236, -2, 11.71000, 14.40001, -34.75, -10.75,
55, -0.668), PL = c(3075.001, -575.0003,
2362.5, 115.0002, 1270.000, 2360, 200, -292.7501,
-720.0005, 1737.5, 537.5, -1375, 750.3998), POSITION = c(1,
-1, 2, 2, 1, 2, -1, -1, 1, 2, 0, 0, 0), SETTLEMENT = c(167.4,
324.55, 390.75, 76.99, 1160.4, 4.718, 468.75, 2067.71, 1744.1,
978, 0, 0, 0)), .Names = c(DESCRIPTION, pl, PL, POSITION,
SETTLEMENT), row.names = c(NA, -13L), class = data.frame)

I am looking for one data frame with the column $PL=zz$PL+av$PL.
I have been trying using the merge() function and its different
arguments with no sucess.

Any help is appreciated.
Thank You.

__
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] merge two data frames

2010-08-04 Thread arnaud gaboury
TY Petr, it works. I will then replace NA by 0.

2010/8/4 Petr PIKAL petr.pi...@precheza.cz:
 Hi

 you tried OK

 result - merge(zz, av, by=DESCRIPTION, all=TRUE)

 and as you did not specify what to do when one value is NA  here is one
 possible solution

 rowSums(cbind(result$PL.x, result$PL.y), na.rm=T)

 Regards
 Petr

 r-help-boun...@r-project.org napsal dne 04.08.2010 11:52:00:

 Dear list,

 here are my two data frames:

 av -
 structure(list(DESCRIPTION = c(COFFEE C Sep/10, COPPER Sep/10,
 CORN Dec/10, CRUDE OIL miNY Sep/10, GOLD Aug/10, HENRY HUB
 NATURAL GAS Sep/10,
 PALLADIUM Sep/10, SILVER Sep/10, SOYBEANS Nov/10, SPCL HIGH
 GRADE ZINC USD,
 SUGAR NO.11 Oct/10, WHEAT Sep/10), prix = c(-168.3,
 -1.62,
 -773.75, -78.75, -1168.3, -0.0916, -470.75, 1758.5,
 -975.25, 1964, -19.09, -605.75), pos = c(-1, 0, -2, -1, -1, 0,
 -1, 1, -1, 1, -1, -1), PL = c(-12.03, -31.68, -43.2, -70.49,
 -11.88, -95.04, -3.96, -35.64, -30.24, -12.5, -36.09, -4.32)), .Names
 = c(DESCRIPTION,
 prix, pos, PL), row.names = c(NA, 12L), class = data.frame)

 zz -
 structure(list(DESCRIPTION = structure(c(1L, 2L, 3L, 4L, 5L,
 6L, 7L, 8L, 9L, 10L, 13L, 11L, 12L), .Label = c(COFFEE C Sep/10,
 COPPER Sep/10, CORN Dec/10, CRUDE OIL miNY Sep/10, GOLD Aug/10,
 HENRY HUB NATURAL GAS Sep/10, PALLADIUM Sep/10, PRM HGH GD
 ALUMINIUM USD,
 SILVER Sep/10, SOYBEANS Nov/10, SPCL HIGH GRADE ZINC USD,
 SUGAR NO.11 Oct/10, WHEAT Sep/10), class = factor), pl =
 c(-8.22,
 2.31, -47.25, -0.234, -12.7,
 -0.236, -2, 11.71000, 14.40001, -34.75, -10.75,
 55, -0.668), PL = c(3075.001, -575.0003,
 2362.5, 115.0002, 1270.000, 2360, 200,
 -292.7501,
 -720.0005, 1737.5, 537.5, -1375, 750.3998), POSITION =
 c(1,
 -1, 2, 2, 1, 2, -1, -1, 1, 2, 0, 0, 0), SETTLEMENT = c(167.4,
 324.55, 390.75, 76.99, 1160.4, 4.718, 468.75, 2067.71, 1744.1,
 978, 0, 0, 0)), .Names = c(DESCRIPTION, pl, PL, POSITION,
 SETTLEMENT), row.names = c(NA, -13L), class = data.frame)

 I am looking for one data frame with the column $PL=zz$PL+av$PL.
 I have been trying using the merge() function and its different
 arguments with no sucess.

 Any help is appreciated.
 Thank You.

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





-- 
**
Arnaud Gaboury
Mobile: +41 79 392 79 56
BBM: 255B488F

__
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] which function

2010-06-02 Thread arnaud Gaboury
Dear group,

Here is a list of elements :


l -
c(100415, 100416, 100419, 100420, 100421, 100422, 
100423, 100426, 100427, 100428, 100429, 100430, 100503, 
100504, 100505, 100506, 100507, 100510, 100511, 100512, 
100513, 100514, 100517, 100518, 100519, 100520, 100521, 
100524, 100525, 100526, 100527, 100528, 100531)


 l[3:4]
[1] 100419 100420  #result is fine


 l[(which(100420==l))-1:which(100420==l)]
[1] 100419 100416 100415  #can't understand why I do not have same
result than the above line


Thank You for help

__
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] which function

2010-06-02 Thread arnaud Gaboury
The correct line is :

 l[(which(100420==l)-1):which(100420==l)]
[1] 100419 100420




 -Original Message-
 From: arnaud Gaboury [mailto:arnaud.gabo...@gmail.com]
 Sent: Wednesday, June 02, 2010 9:41 AM
 To: r-help@r-project.org
 Cc: 'arnaud Gaboury'
 Subject: which function
 
 Dear group,
 
 Here is a list of elements :
 
 
 l -
 c(100415, 100416, 100419, 100420, 100421, 100422,
 100423, 100426, 100427, 100428, 100429, 100430, 100503,
 100504, 100505, 100506, 100507, 100510, 100511, 100512,
 100513, 100514, 100517, 100518, 100519, 100520, 100521,
 100524, 100525, 100526, 100527, 100528, 100531)
 
 
  l[3:4]
 [1] 100419 100420  #result is fine
 
 
  l[(which(100420==l))-1:which(100420==l)]
 [1] 100419 100416 100415  #can't understand why I do not have
 same
 result than the above line
 
 
 Thank You for help

__
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] data frame manipulation with zero rows

2010-06-02 Thread arnaud Gaboury
I do really think it is a very good idea.
TY





 -Original Message-
 From: h.wick...@gmail.com [mailto:h.wick...@gmail.com] On Behalf Of
 Hadley Wickham
 Sent: Wednesday, June 02, 2010 3:31 PM
 To: arnaud Gaboury
 Cc: Peter Ehlers; r-help@r-project.org; Prof Brian Ripley
 Subject: Re: [R] data frame manipulation with zero rows
 
 Hi Arnaud,
 
 I've added this case to the set of test cases in plyr and it will be
 fixed in the next version.
 
 Hadley
 
 On Tue, Jun 1, 2010 at 2:33 PM, arnaud Gaboury
 arnaud.gabo...@gmail.com wrote:
  Maybe not the cleanest way, but I create a fake data frame with one
 row so
  ddply() is happy!!
  if (nrow(futures)==0) futures-data.frame(...)
 
 
 
 
 
  -Original Message-
  From: Peter Ehlers [mailto:ehl...@ucalgary.ca]
  Sent: Tuesday, June 01, 2010 12:07 PM
  To: arnaud Gaboury
  Cc: 'Prof Brian Ripley'; r-help@r-project.org
  Subject: Re: [R] data frame manipulation with zero rows
 
  On 2010-06-01 1:53, arnaud Gaboury wrote:
   Brian,
  
   If I do understand correctly, I must use in my function something
  else than
   ddply() if I want to avoid any error each time my df has zero
 rows?
   Am I correct?
  
 
  You could define a function to handle the zero-rows case:
 
  f - function(x){
    if(nrow(x)  1) out - x[, c(1,3,2)]  # or whatever
    else
      out - ddply(x, c(DESCRIPTION,SETTLEMENT), summarise,
                       POSITION=sum(QUANTITY))[,c(1,3,2)]
    out
  }
  f(futures)
 
    -Peter Ehlers
 
  
  
   -Original Message-
   From: Prof Brian Ripley [mailto:rip...@stats.ox.ac.uk]
   Sent: Tuesday, June 01, 2010 9:47 AM
   To: arnaud Gaboury
   Subject: Re: [R] data frame manipulation with zero rows
  
   On Tue, 1 Jun 2010, arnaud Gaboury wrote:
  
   Dear group,
  
   Here is the kind of data.frame I obtain every day with my
 function
  :
  
   futures-
   structure(list(DESCRIPTION = c(CORN Jul/10, CORN Jul/10,
   CORN Jul/10, CORN Jul/10, CORN Jul/10, LIVE CATTLE
 Aug/10,
   LIVE CATTLE Aug/10, SUGAR NO.11 Jul/10, SUGAR NO.11
 Jul/10,
   SUGAR NO.11 Jul/10, SUGAR NO.11 Jul/10, SUGAR NO.11 Jul/10
   ), CREATED.DATE = structure(c(18403, 18406, 18406, 18406, 18406,
   18407, 18408, 18406, 18407, 18407, 18407, 18407), class =
 Date),
       QUANTITY = c(1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1), SETTLEMENT
 =
   c(373.2500,
       373.2500, 373.2500, 373.2500, 373.2500, 90.7750,
       90.7750, 14.9200, 14.9200, 14.9200, 14.9200,
  14.9200
       )), .Names = c(DESCRIPTION, CREATED.DATE, QUANTITY,
   SETTLEMENT), row.names = c(NA, 12L), class = data.frame)
  
   I need then to apply to the df this following code line :
  
   PosFut=ddply(futures, c(DESCRIPTION,SETTLEMENT), summarise,
   POSITION=
   sum(QUANTITY))[,c(1,3,2)]
  
   It works perfectly in most of case, BUT I have a new problem: it
  can
   sometime occurs that my df futures is empty, with zero rows.
  
  
   futures-
   structure(list(DESCRIPTION = character(0), CREATED.DATE =
   structure(numeric(0), class = Date),
       QUANTITY = numeric(0), SETTLEMENT = character(0)), .Names =
   c(DESCRIPTION,
   CREATED.DATE, QUANTITY, SETTLEMENT), row.names =
 integer(0),
   class =
   data.frame)
  
   It is not the usual case, but it can happen. With this df, when
 I
   pass the
   above mentione line, I get an error :
  
   PosFut=ddply(futures, c(DESCRIPTION,SETTLEMENT), summarise,
   POSITION=
   sum(QUANTITY))[,c(1,3,2)]
   Error in tapply(1:nrow(data), splitv, list) :
     arguments must have same length
  
  
   How can I avoid this when my df is empty?
  
   Ask the author of the (missing) function ddply() to correct the
  error
   of using 1:nrow(data) by replacing it by seq_len(nrow(data)).
  
   It's helpful to give example code, but much more helpful if you
 test
   it: yours cannot work without the function ddply() -- this is
 what
   'self-contained' means in the footer here.
  
  
  
   Any help is appreciated
  
   __
   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.
  
  
   --
   Brian D. Ripley,                  rip...@stats.ox.ac.uk
   Professor of Applied Statistics,
  http://www.stats.ox.ac.uk/~ripley/
   University of Oxford,             Tel:  +44 1865 272861 (self)
   1 South Parks Road,                     +44 1865 272866 (PA)
   Oxford OX1 3TG, UK                Fax:  +44 1865 272595
  
 
  __
  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.
 
 
 
 
 --
 Assistant Professor / Dobelman Family Junior Chair
 Department of Statistics / Rice University
 http://had.co.nz

[R] bind select data frames

2010-06-02 Thread arnaud Gaboury
Dear group,

Here is my environment:

 ls()
 [1] DailyPL100419 DailyPL100420 DailyPL100421 ddi
l PLglobal  Pos100416 Pos100419 Pos100420
Pos100421 position 
[13] resultsel   Trad100416Trad100419
Trad100420Trad100421trade

With sel the following element :

sel -
c(100419, 100420, 100421)


DailyPL100419 , DailyPL100420,DailyPL100421 are all data frames with
same columns names. I want to rbind them with this condition :


for (i in sel[-1])  

I have no idea how to write it.

TY for any help

__
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] bind select data frames

2010-06-02 Thread arnaud Gaboury
Yes indeed I just want to rbind the data frames with numbers belonging to 
sel, and if possible, avoid a loop.

To be more precise, if sel[-1]-c(100420, 100421), I look for a line which 
will give me this result :

dd-rbind(DailyPL100420,DailyPL100421)




 -Original Message-
 From: Joshua Wiley [mailto:jwiley.ps...@gmail.com]
 Sent: Wednesday, June 02, 2010 4:48 PM
 To: arnaud Gaboury
 Cc: r-help@r-project.org
 Subject: Re: [R] bind select data frames
 
 Hello,
 
 Does this do what you are looking for?
 
 
 output - NULL
 for(i in paste(DailyPL, sel, sep=)[-1]){
   output - rbind(output, get(i))
   }
 
 
 If you just want to rbind all the data frames, there are ways of doing
 it without a loop too, but since you specifically asked with the
 condition for(i in sep[-1]) I did it using a loop.
 
 Best regards,
 
 Josh
 
 
 On Wed, Jun 2, 2010 at 7:24 AM, arnaud Gaboury
 arnaud.gabo...@gmail.com wrote:
  Dear group,
 
  Here is my environment:
 
  ls()
   [1] DailyPL100419 DailyPL100420 DailyPL100421 dd
  i
  l PLglobal  Pos100416 Pos100419
 Pos100420
  Pos100421 position
  [13] resultsel   Trad100416Trad100419
  Trad100420Trad100421trade
 
  With sel the following element :
 
  sel -
  c(100419, 100420, 100421)
 
 
  DailyPL100419 , DailyPL100420,DailyPL100421 are all data frames
 with
  same columns names. I want to rbind them with this condition :
 
 
  for (i in sel[-1])
 
  I have no idea how to write it.
 
  TY for any help
 
  __
  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.
 
 
 
 
 --
 Joshua Wiley
 Senior in Psychology
 University of California, Riverside
 http://www.joshuawiley.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] bind select data frames

2010-06-02 Thread arnaud Gaboury
I am working with something like this :

  for (i in sel[-1])  {
dd-data.frame(do.call(rbind, 
mget(paste(DailyPL,i,sep=),envir=.GlobalEnv)),row.names=NULL)  
  
   }

But the result is not good. In the case where sel[-1]-c(100420, 100421), 
dd is only equal to DailyPL100421




 -Original Message-
 From: Joshua Wiley [mailto:jwiley.ps...@gmail.com]
 Sent: Wednesday, June 02, 2010 4:48 PM
 To: arnaud Gaboury
 Cc: r-help@r-project.org
 Subject: Re: [R] bind select data frames
 
 Hello,
 
 Does this do what you are looking for?
 
 
 output - NULL
 for(i in paste(DailyPL, sel, sep=)[-1]){
   output - rbind(output, get(i))
   }
 
 
 If you just want to rbind all the data frames, there are ways of doing
 it without a loop too, but since you specifically asked with the
 condition for(i in sep[-1]) I did it using a loop.
 
 Best regards,
 
 Josh
 
 
 On Wed, Jun 2, 2010 at 7:24 AM, arnaud Gaboury
 arnaud.gabo...@gmail.com wrote:
  Dear group,
 
  Here is my environment:
 
  ls()
   [1] DailyPL100419 DailyPL100420 DailyPL100421 dd
  i
  l PLglobal  Pos100416 Pos100419
 Pos100420
  Pos100421 position
  [13] resultsel   Trad100416Trad100419
  Trad100420Trad100421trade
 
  With sel the following element :
 
  sel -
  c(100419, 100420, 100421)
 
 
  DailyPL100419 , DailyPL100420,DailyPL100421 are all data frames
 with
  same columns names. I want to rbind them with this condition :
 
 
  for (i in sel[-1])
 
  I have no idea how to write it.
 
  TY for any help
 
  __
  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.
 
 
 
 
 --
 Joshua Wiley
 Senior in Psychology
 University of California, Riverside
 http://www.joshuawiley.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] bind select data frames

2010-06-02 Thread arnaud Gaboury
Yes Joshua, it does the trick. Once more, I am surprised by the easiness and 
obviousness of R.
Now, I would like to add argument row.names=NULL.

dd - do.call(rbind, mget(paste(DailyPL,sel[-1], sep=),
 envir=.GlobalEnv),row.names=NULL)
 Error in do.call(rbind, mget(paste(DailyPL, sel[-1], sep = ), envir = 
 .GlobalEnv),  : 
  unused argument(s) (row.names = NULL)

Why this error?

TY for your help





 -Original Message-
 From: Joshua Wiley [mailto:jwiley.ps...@gmail.com]
 Sent: Wednesday, June 02, 2010 5:08 PM
 To: arnaud Gaboury
 Cc: r-help@r-project.org
 Subject: Re: [R] bind select data frames
 
 This should do the trick:
 
 dd - do.call(rbind, mget(paste(DailyPL,sel[-1], sep=),
 envir=.GlobalEnv))
 
 
 
 On Wed, Jun 2, 2010 at 8:06 AM, arnaud Gaboury
 arnaud.gabo...@gmail.com wrote:
  I am working with something like this :
 
   for (i in sel[-1])  {
  dd-data.frame(do.call(rbind,
 mget(paste(DailyPL,i,sep=),envir=.GlobalEnv)),row.names=NULL)
 
}
 
  But the result is not good. In the case where sel[-1]-c(100420,
 100421), dd is only equal to DailyPL100421
 
 
 
 
  -Original Message-
  From: Joshua Wiley [mailto:jwiley.ps...@gmail.com]
  Sent: Wednesday, June 02, 2010 4:48 PM
  To: arnaud Gaboury
  Cc: r-help@r-project.org
  Subject: Re: [R] bind select data frames
 
  Hello,
 
  Does this do what you are looking for?
 
  
  output - NULL
  for(i in paste(DailyPL, sel, sep=)[-1]){
output - rbind(output, get(i))
}
  
 
  If you just want to rbind all the data frames, there are ways of
 doing
  it without a loop too, but since you specifically asked with the
  condition for(i in sep[-1]) I did it using a loop.
 
  Best regards,
 
  Josh
 
 
  On Wed, Jun 2, 2010 at 7:24 AM, arnaud Gaboury
  arnaud.gabo...@gmail.com wrote:
   Dear group,
  
   Here is my environment:
  
   ls()
[1] DailyPL100419 DailyPL100420 DailyPL100421 dd
   i
   l PLglobal  Pos100416 Pos100419
  Pos100420
   Pos100421 position
   [13] resultsel   Trad100416Trad100419
   Trad100420Trad100421trade
  
   With sel the following element :
  
   sel -
   c(100419, 100420, 100421)
  
  
   DailyPL100419 , DailyPL100420,DailyPL100421 are all data
 frames
  with
   same columns names. I want to rbind them with this condition :
  
  
   for (i in sel[-1])
  
   I have no idea how to write it.
  
   TY for any help
  
   __
   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.
  
 
 
 
  --
  Joshua Wiley
  Senior in Psychology
  University of California, Riverside
  http://www.joshuawiley.com/
 
 
 
 
 
 --
 Joshua Wiley
 Senior in Psychology
 University of California, Riverside
 http://www.joshuawiley.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] bind select data frames

2010-06-02 Thread arnaud Gaboury
Here we go :

dd-data.frame(do.call(rbind, 
mget(paste(DailyPL,sel[-1],sep=),envir=.GlobalEnv)),row.names=NULL)


TY so much Joshua and Jorge.


 -Original Message-
 From: Joshua Wiley [mailto:jwiley.ps...@gmail.com]
 Sent: Wednesday, June 02, 2010 5:11 PM
 To: arnaud Gaboury
 Cc: r-help@r-project.org
 Subject: Re: [R] bind select data frames
 
 On Wed, Jun 2, 2010 at 8:06 AM, arnaud Gaboury
 arnaud.gabo...@gmail.com wrote:
  I am working with something like this :
 
   for (i in sel[-1])  {
  dd-data.frame(do.call(rbind,
 mget(paste(DailyPL,i,sep=),envir=.GlobalEnv)),row.names=NULL)
 
}
 
  But the result is not good. In the case where sel[-1]-c(100420,
 100421), dd is only equal to DailyPL100421
 
 Yes, because it is in a loop, dd is reassigned for each value of i.
 That is why in the first loop I sent you I included the old data in
 the rbind, otherwise it is just overwritten everytime it loops.
 
 Josh
 
 
 
 
 
  -Original Message-
  From: Joshua Wiley [mailto:jwiley.ps...@gmail.com]
  Sent: Wednesday, June 02, 2010 4:48 PM
  To: arnaud Gaboury
  Cc: r-help@r-project.org
  Subject: Re: [R] bind select data frames
 
  Hello,
 
  Does this do what you are looking for?
 
  
  output - NULL
  for(i in paste(DailyPL, sel, sep=)[-1]){
output - rbind(output, get(i))
}
  
 
  If you just want to rbind all the data frames, there are ways of
 doing
  it without a loop too, but since you specifically asked with the
  condition for(i in sep[-1]) I did it using a loop.
 
  Best regards,
 
  Josh
 
 
  On Wed, Jun 2, 2010 at 7:24 AM, arnaud Gaboury
  arnaud.gabo...@gmail.com wrote:
   Dear group,
  
   Here is my environment:
  
   ls()
[1] DailyPL100419 DailyPL100420 DailyPL100421 dd
   i
   l PLglobal  Pos100416 Pos100419
  Pos100420
   Pos100421 position
   [13] resultsel   Trad100416Trad100419
   Trad100420Trad100421trade
  
   With sel the following element :
  
   sel -
   c(100419, 100420, 100421)
  
  
   DailyPL100419 , DailyPL100420,DailyPL100421 are all data
 frames
  with
   same columns names. I want to rbind them with this condition :
  
  
   for (i in sel[-1])
  
   I have no idea how to write it.
  
   TY for any help
  
   __
   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.
  
 
 
 
  --
  Joshua Wiley
  Senior in Psychology
  University of California, Riverside
  http://www.joshuawiley.com/
 
 
 
 
 
 --
 Joshua Wiley
 Senior in Psychology
 University of California, Riverside
 http://www.joshuawiley.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] bind select data frames

2010-06-02 Thread arnaud Gaboury
Jorge,

Your line works and give the desired result. Now I need to be able to work
with i instead of 100419..., as I need to be able to change these numbers. 
TY for your help




From: Jorge Ivan Velez [mailto:jorgeivanve...@gmail.com] 
Sent: Wednesday, June 02, 2010 5:09 PM
To: arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] bind select data frames

Hi Arnaud,

Try the following (untested):

txt - paste('DailyPL',c(100419, 100420, 100421), sep = )
do.call(rbind, lapply(txt, get))

HTH,
Jorge


On Wed, Jun 2, 2010 at 10:24 AM, arnaud Gaboury  wrote:
Dear group,

Here is my environment:

 ls()
 [1] DailyPL100419 DailyPL100420 DailyPL100421 dd            i
l             PLglobal      Pos100416     Pos100419     Pos100420
Pos100421     position
[13] result        sel           Trad100416    Trad100419
Trad100420    Trad100421    trade

With sel the following element :

sel -
c(100419, 100420, 100421)


DailyPL100419 , DailyPL100420,DailyPL100421 are all data frames with
same columns names. I want to rbind them with this condition :


for (i in sel[-1])

I have no idea how to write it.

TY for any help

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


[R] data frame manipulation with zero rows

2010-06-01 Thread arnaud Gaboury
Dear group,

Here is the kind of data.frame I obtain every day with my function :

futures -
structure(list(DESCRIPTION = c(CORN Jul/10, CORN Jul/10, 
CORN Jul/10, CORN Jul/10, CORN Jul/10, LIVE CATTLE Aug/10, 
LIVE CATTLE Aug/10, SUGAR NO.11 Jul/10, SUGAR NO.11 Jul/10, 
SUGAR NO.11 Jul/10, SUGAR NO.11 Jul/10, SUGAR NO.11 Jul/10
), CREATED.DATE = structure(c(18403, 18406, 18406, 18406, 18406, 
18407, 18408, 18406, 18407, 18407, 18407, 18407), class = Date), 
QUANTITY = c(1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1), SETTLEMENT =
c(373.2500, 
373.2500, 373.2500, 373.2500, 373.2500, 90.7750, 
90.7750, 14.9200, 14.9200, 14.9200, 14.9200, 14.9200
)), .Names = c(DESCRIPTION, CREATED.DATE, QUANTITY, 
SETTLEMENT), row.names = c(NA, 12L), class = data.frame)

I need then to apply to the df this following code line :

PosFut=ddply(futures, c(DESCRIPTION,SETTLEMENT), summarise, POSITION=
sum(QUANTITY))[,c(1,3,2)]

It works perfectly in most of case, BUT I have a new problem: it can
sometime occurs that my df futures is empty, with zero rows.


futures -
structure(list(DESCRIPTION = character(0), CREATED.DATE =
structure(numeric(0), class = Date), 
QUANTITY = numeric(0), SETTLEMENT = character(0)), .Names =
c(DESCRIPTION, 
CREATED.DATE, QUANTITY, SETTLEMENT), row.names = integer(0), class =
data.frame)

It is not the usual case, but it can happen. With this df, when I pass the
above mentione line, I get an error :

PosFut=ddply(futures, c(DESCRIPTION,SETTLEMENT), summarise, POSITION=
sum(QUANTITY))[,c(1,3,2)]
Error in tapply(1:nrow(data), splitv, list) : 
  arguments must have same length


How can I avoid this when my df is empty?

Any help is appreciated

__
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] data frame manipulation with zero rows

2010-06-01 Thread arnaud Gaboury
Brian,

If I do understand correctly, I must use in my function something else than
ddply() if I want to avoid any error each time my df has zero rows?
Am I correct?

TY




 -Original Message-
 From: Prof Brian Ripley [mailto:rip...@stats.ox.ac.uk]
 Sent: Tuesday, June 01, 2010 9:47 AM
 To: arnaud Gaboury
 Subject: Re: [R] data frame manipulation with zero rows
 
 On Tue, 1 Jun 2010, arnaud Gaboury wrote:
 
  Dear group,
 
  Here is the kind of data.frame I obtain every day with my function :
 
  futures -
  structure(list(DESCRIPTION = c(CORN Jul/10, CORN Jul/10,
  CORN Jul/10, CORN Jul/10, CORN Jul/10, LIVE CATTLE Aug/10,
  LIVE CATTLE Aug/10, SUGAR NO.11 Jul/10, SUGAR NO.11 Jul/10,
  SUGAR NO.11 Jul/10, SUGAR NO.11 Jul/10, SUGAR NO.11 Jul/10
  ), CREATED.DATE = structure(c(18403, 18406, 18406, 18406, 18406,
  18407, 18408, 18406, 18407, 18407, 18407, 18407), class = Date),
 QUANTITY = c(1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1), SETTLEMENT =
  c(373.2500,
 373.2500, 373.2500, 373.2500, 373.2500, 90.7750,
 90.7750, 14.9200, 14.9200, 14.9200, 14.9200, 14.9200
 )), .Names = c(DESCRIPTION, CREATED.DATE, QUANTITY,
  SETTLEMENT), row.names = c(NA, 12L), class = data.frame)
 
  I need then to apply to the df this following code line :
 
  PosFut=ddply(futures, c(DESCRIPTION,SETTLEMENT), summarise,
 POSITION=
  sum(QUANTITY))[,c(1,3,2)]
 
  It works perfectly in most of case, BUT I have a new problem: it can
  sometime occurs that my df futures is empty, with zero rows.
 
 
  futures -
  structure(list(DESCRIPTION = character(0), CREATED.DATE =
  structure(numeric(0), class = Date),
 QUANTITY = numeric(0), SETTLEMENT = character(0)), .Names =
  c(DESCRIPTION,
  CREATED.DATE, QUANTITY, SETTLEMENT), row.names = integer(0),
 class =
  data.frame)
 
  It is not the usual case, but it can happen. With this df, when I
 pass the
  above mentione line, I get an error :
 
  PosFut=ddply(futures, c(DESCRIPTION,SETTLEMENT), summarise,
 POSITION=
  sum(QUANTITY))[,c(1,3,2)]
  Error in tapply(1:nrow(data), splitv, list) :
   arguments must have same length
 
 
  How can I avoid this when my df is empty?
 
 Ask the author of the (missing) function ddply() to correct the error
 of using 1:nrow(data) by replacing it by seq_len(nrow(data)).
 
 It's helpful to give example code, but much more helpful if you test
 it: yours cannot work without the function ddply() -- this is what
 'self-contained' means in the footer here.
 
 
 
  Any help is appreciated
 
  __
  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.
 
 
 --
 Brian D. Ripley,  rip...@stats.ox.ac.uk
 Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
 University of Oxford, Tel:  +44 1865 272861 (self)
 1 South Parks Road, +44 1865 272866 (PA)
 Oxford OX1 3TG, UKFax:  +44 1865 272595

__
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] data frame manipulation ddply

2010-06-01 Thread arnaud Gaboury
Dear group,

Here is my data frame:


futures -
structure(list(DESCRIPTION = c(CORN Jul/10, CORN Jul/10, 
CORN Jul/10, CORN Jul/10, CORN Jul/10, LIVE CATTLE Aug/10, 
LIVE CATTLE Aug/10, SUGAR NO.11 Jul/10, SUGAR NO.11 Jul/10, 
SUGAR NO.11 Jul/10, SUGAR NO.11 Jul/10, SUGAR NO.11 Jul/10
), CREATED.DATE = structure(c(18403, 18406, 18406, 18406, 18406, 
18407, 18408, 18406, 18407, 18407, 18407, 18407), class = Date), 
QUANTITY = c(1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1), SETTLEMENT =
c(373.2500, 
373.2500, 373.2500, 373.2500, 373.2500, 90.7750, 
90.7750, 14.9200, 14.9200, 14.9200, 14.9200, 14.9200
)), .Names = c(DESCRIPTION, CREATED.DATE, QUANTITY, 
SETTLEMENT), row.names = c(NA, 12L), class = data.frame)

Here is the line I pass :

PosFut=ddply(futures, c(DESCRIPTION,SETTLEMENT), summarise, POSITION=
sum(QUANTITY))[,c(1,3,2)]

And here the result :

PosFut -
structure(list(DESCRIPTION = structure(1:3, .Label = c(CORN Jul/10, 
LIVE CATTLE Aug/10, SUGAR NO.11 Jul/10), class = factor), 
POSITION = c(5, 4, 5), SETTLEMENT = structure(c(2L, 3L, 1L
), .Label = c(14.9200, 373.2500, 90.7750), class = factor)),
.Names = c(DESCRIPTION, 
POSITION, SETTLEMENT), class = data.frame, row.names = c(NA, 
-3L))

I can no more use ddply, as this above command line is in a function, and
this line should be able to work with a data frame with zero rows, and in
this case ddply doesn't work.
Any suggestion how to obtain the same result without ddply?

TY for any help.

__
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] data frame manipulation ddply

2010-06-01 Thread arnaud Gaboury
Patrick,

When apply to this following df :

futures -
structure(list(DESCRIPTION = character(0), CREATED.DATE =
structure(numeric(0), class = Date), 
QUANTITY = numeric(0), SETTLEMENT = character(0)), .Names =
c(DESCRIPTION, 
CREATED.DATE, QUANTITY, SETTLEMENT), row.names = integer(0), class =
data.frame)


 PosFut - aggregate(futures$QUANTITY, list(DESCRIPTION =
futures$DESCRIPTION,SETTLEMENT=futures$SETTLEMENT),sum)[,c(1,3,2)]
Error in aggregate.data.frame(as.data.frame(x), ...) : 
  no rows to aggregate



 -Original Message-
 From: Patrick Hausmann [mailto:patrick.hausm...@uni-bremen.de]
 Sent: Tuesday, June 01, 2010 11:38 AM
 To: arnaud Gaboury
 Subject: Re: [R] data frame manipulation ddply
 
 Hi Arnaud,
 
 maybe aggregate can help:
 
 PosFut - aggregate(futures$QUANTITY, list(DESCRIPTION =
 futures$DESCRIPTION,
   SETTLEMENT  = futures$SETTLEMENT),
 sum)[, c(1,3,2)]
 
 HTH,
 Patrick
 
 Am 01.06.2010 11:02, schrieb arnaud Gaboury:
  Dear group,
 
  Here is my data frame:
 
 
  futures-
  structure(list(DESCRIPTION = c(CORN Jul/10, CORN Jul/10,
  CORN Jul/10, CORN Jul/10, CORN Jul/10, LIVE CATTLE Aug/10,
  LIVE CATTLE Aug/10, SUGAR NO.11 Jul/10, SUGAR NO.11 Jul/10,
  SUGAR NO.11 Jul/10, SUGAR NO.11 Jul/10, SUGAR NO.11 Jul/10
  ), CREATED.DATE = structure(c(18403, 18406, 18406, 18406, 18406,
  18407, 18408, 18406, 18407, 18407, 18407, 18407), class = Date),
   QUANTITY = c(1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1), SETTLEMENT =
  c(373.2500,
   373.2500, 373.2500, 373.2500, 373.2500, 90.7750,
   90.7750, 14.9200, 14.9200, 14.9200, 14.9200, 14.9200
   )), .Names = c(DESCRIPTION, CREATED.DATE, QUANTITY,
  SETTLEMENT), row.names = c(NA, 12L), class = data.frame)
 
  Here is the line I pass :
 
  PosFut=ddply(futures, c(DESCRIPTION,SETTLEMENT), summarise,
 POSITION=
  sum(QUANTITY))[,c(1,3,2)]
 
  And here the result :
 
  PosFut-
  structure(list(DESCRIPTION = structure(1:3, .Label = c(CORN Jul/10,
  LIVE CATTLE Aug/10, SUGAR NO.11 Jul/10), class = factor),
   POSITION = c(5, 4, 5), SETTLEMENT = structure(c(2L, 3L, 1L
   ), .Label = c(14.9200, 373.2500, 90.7750), class =
 factor)),
  .Names = c(DESCRIPTION,
  POSITION, SETTLEMENT), class = data.frame, row.names = c(NA,
  -3L))
 
  I can no more use ddply, as this above command line is in a function,
 and
  this line should be able to work with a data frame with zero rows,
 and in
  this case ddply doesn't work.
  Any suggestion how to obtain the same result without ddply?
 
  TY for any help.
 
  __
  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.


Re: [R] data frame manipulation with zero rows

2010-06-01 Thread arnaud Gaboury
It is indeed ddply() from package plyr.





 -Original Message-
 From: Prof Brian Ripley [mailto:rip...@stats.ox.ac.uk]
 Sent: Tuesday, June 01, 2010 12:24 PM
 To: Peter Ehlers
 Cc: arnaud Gaboury; r-help@r-project.org
 Subject: Re: [R] data frame manipulation with zero rows
 
 On Tue, 1 Jun 2010, Peter Ehlers wrote:
 
  On 2010-06-01 1:53, arnaud Gaboury wrote:
  Brian,
 
  If I do understand correctly, I must use in my function something
 else than
  ddply() if I want to avoid any error each time my df has zero rows?
  Am I correct?
 
 
  You could define a function to handle the zero-rows case:
 
  f - function(x){
  if(nrow(x)  1) out - x[, c(1,3,2)]  # or whatever
  else
out - ddply(x, c(DESCRIPTION,SETTLEMENT), summarise,
 POSITION=sum(QUANTITY))[,c(1,3,2)]
  out
  }
  f(futures)
 
 Or simply fix ddply.  We don't know what that is or what it should do
 for the case of zero rows: it may or may not be the one in package
 plyr.
 
 
  -Peter Ehlers
 
 
 
  -Original Message-
  From: Prof Brian Ripley [mailto:rip...@stats.ox.ac.uk]
  Sent: Tuesday, June 01, 2010 9:47 AM
  To: arnaud Gaboury
  Subject: Re: [R] data frame manipulation with zero rows
 
  On Tue, 1 Jun 2010, arnaud Gaboury wrote:
 
  Dear group,
 
  Here is the kind of data.frame I obtain every day with my function
 :
 
  futures-
  structure(list(DESCRIPTION = c(CORN Jul/10, CORN Jul/10,
  CORN Jul/10, CORN Jul/10, CORN Jul/10, LIVE CATTLE Aug/10,
  LIVE CATTLE Aug/10, SUGAR NO.11 Jul/10, SUGAR NO.11 Jul/10,
  SUGAR NO.11 Jul/10, SUGAR NO.11 Jul/10, SUGAR NO.11 Jul/10
  ), CREATED.DATE = structure(c(18403, 18406, 18406, 18406, 18406,
  18407, 18408, 18406, 18407, 18407, 18407, 18407), class = Date),
  QUANTITY = c(1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1), SETTLEMENT =
  c(373.2500,
  373.2500, 373.2500, 373.2500, 373.2500, 90.7750,
  90.7750, 14.9200, 14.9200, 14.9200, 14.9200,
 14.9200
  )), .Names = c(DESCRIPTION, CREATED.DATE, QUANTITY,
  SETTLEMENT), row.names = c(NA, 12L), class = data.frame)
 
  I need then to apply to the df this following code line :
 
  PosFut=ddply(futures, c(DESCRIPTION,SETTLEMENT), summarise,
  POSITION=
  sum(QUANTITY))[,c(1,3,2)]
 
  It works perfectly in most of case, BUT I have a new problem: it
 can
  sometime occurs that my df futures is empty, with zero rows.
 
 
  futures-
  structure(list(DESCRIPTION = character(0), CREATED.DATE =
  structure(numeric(0), class = Date),
  QUANTITY = numeric(0), SETTLEMENT = character(0)), .Names =
  c(DESCRIPTION,
  CREATED.DATE, QUANTITY, SETTLEMENT), row.names = integer(0),
  class =
  data.frame)
 
  It is not the usual case, but it can happen. With this df, when I
  pass the
  above mentione line, I get an error :
 
  PosFut=ddply(futures, c(DESCRIPTION,SETTLEMENT), summarise,
  POSITION=
  sum(QUANTITY))[,c(1,3,2)]
  Error in tapply(1:nrow(data), splitv, list) :
arguments must have same length
 
 
  How can I avoid this when my df is empty?
 
  Ask the author of the (missing) function ddply() to correct the
 error
  of using 1:nrow(data) by replacing it by seq_len(nrow(data)).
 
  It's helpful to give example code, but much more helpful if you
 test
  it: yours cannot work without the function ddply() -- this is what
  'self-contained' means in the footer here.
 
 --
 Brian D. Ripley,  rip...@stats.ox.ac.uk
 Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
 University of Oxford, Tel:  +44 1865 272861 (self)
 1 South Parks Road, +44 1865 272866 (PA)
 Oxford OX1 3TG, UKFax:  +44 1865 272595

__
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] as.date

2010-06-01 Thread arnaud Gaboury
Dear group,

Here is my df (obtained with a read.csv2()):


df -
structure(list(DESCRIPTION = c(COTTON NO.2 Jul/10, COTTON NO.2 Jul/10, 
PALLADIUM Jun/10, PALLADIUM Jun/10, SUGAR NO.11 Jul/10, 
SUGAR NO.11 Jul/10), CREATED.DATE = c(13/05/2010, 13/05/2010, 
14/05/2010, 14/05/2010, 10/05/2010, 10/05/2010), QUANITY = c(1, 
1, -1, -1, 1, 1), CLOSING.PRICE = c(81.2000, 81.2000, 503.6000, 
503.6000, 13.8900, 13.8900)), .Names = c(DESCRIPTION, 
CREATED.DATE, QUANITY, CLOSING.PRICE), row.names = c(NA, 
6L), class = data.frame)

 str(df)
'data.frame':   6 obs. of  4 variables:
 $ DESCRIPTION  : chr  COTTON NO.2 Jul/10 COTTON NO.2 Jul/10 PALLADIUM
Jun/10 PALLADIUM Jun/10 ...
 $ CREATED.DATE : chr  13/05/2010 13/05/2010 14/05/2010 14/05/2010
...
 $ QUANITY  : num  1 1 -1 -1 1 1
 $ CLOSING.PRICE: chr  81.2000 81.2000 503.6000 503.6000 ...

I want to change the class of df$CREATED.DATE from Chr to Date:


pose$CREATED.DATE=as.Date(pose$CREATED.DATE,%d/%m/%y)

Here is what I get :

df -
structure(list(DESCRIPTION = c(COTTON NO.2 Jul/10, COTTON NO.2 Jul/10, 
PALLADIUM Jun/10, PALLADIUM Jun/10, SUGAR NO.11 Jul/10, 
SUGAR NO.11 Jul/10), CREATED.DATE = structure(c(18395, 18395, 
18396, 18396, 18392, 18392), class = Date), QUANITY = c(1, 
1, -1, -1, 1, 1), CLOSING.PRICE = c(81.2000, 81.2000, 503.6000, 
503.6000, 13.8900, 13.8900)), .Names = c(DESCRIPTION, 
CREATED.DATE, QUANITY, CLOSING.PRICE), row.names = c(NA, 
6L), class = data.frame)

Where does the problem comes from?? Maybe from my sytem date ??

TY for any help

__
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] as.date

2010-06-01 Thread arnaud Gaboury
TY for the tip. The lower case is in fact the culprit.





 -Original Message-
 From: Erik Iverson [mailto:er...@ccbr.umn.edu]
 Sent: Tuesday, June 01, 2010 6:05 PM
 To: arnaud Gaboury
 Cc: r-help@r-project.org
 Subject: Re: [R] as.date
 
 
  Where does the problem comes from?? Maybe from my sytem date ??
 
 Simply from not reading the options carefully enough, from ?strptime,
 
   '%y' Year without century (00-99). If you use this on input,
 which
century you get is system-specific.  So don't!  Most often
values 00 to 68 are prefixed by 20 and 69 to 99 by 19 - that
is the behaviour specified by the 2001 POSIX standard, but
 it
does also say 'it is expected that in a future version of
IEEE Std 1003.1-2001 the default century inferred from a
2-digit year will change'.
 
   '%Y' Year with century.
 
 
 You want %Y, not %y.

__
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] data frame manipulation with zero rows

2010-06-01 Thread arnaud Gaboury
Maybe not the cleanest way, but I create a fake data frame with one row so
ddply() is happy!!
 if (nrow(futures)==0) futures-data.frame(...)





 -Original Message-
 From: Peter Ehlers [mailto:ehl...@ucalgary.ca]
 Sent: Tuesday, June 01, 2010 12:07 PM
 To: arnaud Gaboury
 Cc: 'Prof Brian Ripley'; r-help@r-project.org
 Subject: Re: [R] data frame manipulation with zero rows
 
 On 2010-06-01 1:53, arnaud Gaboury wrote:
  Brian,
 
  If I do understand correctly, I must use in my function something
 else than
  ddply() if I want to avoid any error each time my df has zero rows?
  Am I correct?
 
 
 You could define a function to handle the zero-rows case:
 
 f - function(x){
   if(nrow(x)  1) out - x[, c(1,3,2)]  # or whatever
   else
 out - ddply(x, c(DESCRIPTION,SETTLEMENT), summarise,
  POSITION=sum(QUANTITY))[,c(1,3,2)]
   out
 }
 f(futures)
 
   -Peter Ehlers
 
 
 
  -Original Message-
  From: Prof Brian Ripley [mailto:rip...@stats.ox.ac.uk]
  Sent: Tuesday, June 01, 2010 9:47 AM
  To: arnaud Gaboury
  Subject: Re: [R] data frame manipulation with zero rows
 
  On Tue, 1 Jun 2010, arnaud Gaboury wrote:
 
  Dear group,
 
  Here is the kind of data.frame I obtain every day with my function
 :
 
  futures-
  structure(list(DESCRIPTION = c(CORN Jul/10, CORN Jul/10,
  CORN Jul/10, CORN Jul/10, CORN Jul/10, LIVE CATTLE Aug/10,
  LIVE CATTLE Aug/10, SUGAR NO.11 Jul/10, SUGAR NO.11 Jul/10,
  SUGAR NO.11 Jul/10, SUGAR NO.11 Jul/10, SUGAR NO.11 Jul/10
  ), CREATED.DATE = structure(c(18403, 18406, 18406, 18406, 18406,
  18407, 18408, 18406, 18407, 18407, 18407, 18407), class = Date),
  QUANTITY = c(1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1), SETTLEMENT =
  c(373.2500,
  373.2500, 373.2500, 373.2500, 373.2500, 90.7750,
  90.7750, 14.9200, 14.9200, 14.9200, 14.9200,
 14.9200
  )), .Names = c(DESCRIPTION, CREATED.DATE, QUANTITY,
  SETTLEMENT), row.names = c(NA, 12L), class = data.frame)
 
  I need then to apply to the df this following code line :
 
  PosFut=ddply(futures, c(DESCRIPTION,SETTLEMENT), summarise,
  POSITION=
  sum(QUANTITY))[,c(1,3,2)]
 
  It works perfectly in most of case, BUT I have a new problem: it
 can
  sometime occurs that my df futures is empty, with zero rows.
 
 
  futures-
  structure(list(DESCRIPTION = character(0), CREATED.DATE =
  structure(numeric(0), class = Date),
  QUANTITY = numeric(0), SETTLEMENT = character(0)), .Names =
  c(DESCRIPTION,
  CREATED.DATE, QUANTITY, SETTLEMENT), row.names = integer(0),
  class =
  data.frame)
 
  It is not the usual case, but it can happen. With this df, when I
  pass the
  above mentione line, I get an error :
 
  PosFut=ddply(futures, c(DESCRIPTION,SETTLEMENT), summarise,
  POSITION=
  sum(QUANTITY))[,c(1,3,2)]
  Error in tapply(1:nrow(data), splitv, list) :
arguments must have same length
 
 
  How can I avoid this when my df is empty?
 
  Ask the author of the (missing) function ddply() to correct the
 error
  of using 1:nrow(data) by replacing it by seq_len(nrow(data)).
 
  It's helpful to give example code, but much more helpful if you test
  it: yours cannot work without the function ddply() -- this is what
  'self-contained' means in the footer here.
 
 
 
  Any help is appreciated
 
  __
  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.
 
 
  --
  Brian D. Ripley,  rip...@stats.ox.ac.uk
  Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
  University of Oxford, Tel:  +44 1865 272861 (self)
  1 South Parks Road, +44 1865 272866 (PA)
  Oxford OX1 3TG, UKFax:  +44 1865 272595
 

__
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] data frame manipulation change elements meeting criteria

2010-05-27 Thread arnaud Gaboury
Thank you for the answer.
Is there any way to combine if() and switch() in one line? In my case,
something like :

if(trade$Trade.Status==DEL)switch(.)

I would like to avoid the loop .



From: Joris Meys [mailto:jorism...@gmail.com] 
Sent: Wednesday, May 26, 2010 9:15 PM
To: arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] data frame manipulation change elements meeting criteria

see ?switch

X- rep(c(Buy,Sell,something else),each=5)
Y- rep(c(DEL,INS,DEL),5)


new.vect - X
for (i in which(Y==DEL)){
    new.vect[i]-switch(
  EXPR = X[i],
  Sell=Buy,
  Buy=Sell,
  X[i])
}
cbind(new.vect,X,Y)
On Wed, May 26, 2010 at 7:43 PM, arnaud Gaboury arnaud.gabo...@gmail.com
wrote:
Dear group,

Here is my df :

trade -
structure(list(Trade.Status = c(DEL, INS, INS), Instrument.Long.Name =
c(SUGAR NO.11,
CORN, CORN), Delivery.Prompt.Date = c(Jul/10, Jul/10,
Jul/10), Buy.Sell..Cleared. = c(Sell, Buy, Buy), Volume = c(1L,
2L, 1L), Price = c(15.2500, 368., 368.5000), Net.Charges..sum. =
c(4.01,
-8.64, -4.32)), .Names = c(Trade.Status, Instrument.Long.Name,
Delivery.Prompt.Date, Buy.Sell..Cleared., Volume, Price,
Net.Charges..sum.), row.names = c(NA, 3L), class = data.frame)

Here is what I want :

If trade$Trade.Status==DEL: then if trade$buy.Sell..Cleared==Sell , change
it to Buy, if trade$buy.Sell..Cleared==Buy, change it to Sell.
If trade$Trade.Status==INS, do nothing
I tried to work around with ifelse, but don't know how to deal with so many
conditions.

Any help is appreciated.

TY

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



-- 
Joris Meys
Statistical Consultant

Ghent University
Faculty of Bioscience Engineering 
Department of Applied mathematics, biometrics and process control

Coupure Links 653
B-9000 Gent

tel : +32 9 264 59 87
joris.m...@ugent.be 
---
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php

__
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] switch function

2010-05-27 Thread arnaud Gaboury
Dear group,

Here is my df :

trades -
structure(list(Trade.Status = c(DEL, INS, INS), Instrument.Long.Name =
c(SUGAR NO.11,
CORN, CORN), Delivery.Prompt.Date = c(Jul/10, Jul/10,
Jul/10), Buy.Sell..Cleared. = c(Sell, Buy, Buy), Volume = c(1L,
2L, 1L), Price = c(15.2500, 368., 368.5000), Net.Charges..sum. =
c(4.01,
-8.64, -4.32)), .Names = c(Trade.Status, Instrument.Long.Name,
Delivery.Prompt.Date, Buy.Sell..Cleared., Volume, Price,
Net.Charges..sum.), row.names = c(NA, 3L), class = data.frame)

I want to replace Buy by Sell and Sell by Buy in column
Buy.Sell..Cleared. when element in column Trade.Status is equal to
DEL.

I think I can write something like this :


tradesnew-sapply(trades$Buy.Sell..Cleared[which(trades$Buy.Sell..Cleared==
DEL),],switch,...)  but I don't really know how to pass further
arguments to the switch function.

Any help is appreciated.

__
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] data frame change elements meeting criteria

2010-05-27 Thread arnaud Gaboury
If i pass this line :

tradesnew-sapply(trades[which(trades$Trade.Status==DEL),],switch,Sell=B
uy,Buy=Sell)

Here is what I get :

 tradesnew
$Trade.Status
NULL

$Instrument.Long.Name
NULL

$Delivery.Prompt.Date
NULL

$Buy.Sell..Cleared.
[1] Buy

$Volume
[1] Buy

$Price
NULL

$Net.Charges..sum.
NULL

That's certainly not what I want.



From: Joris Meys [mailto:jorism...@gmail.com] 
Sent: Thursday, May 27, 2010 8:43 AM
To: arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] data frame manipulation change elements meeting criteria

The loop is due to the switch statement, not the condition. Without
condition it would become:

for (i in 1:length(Y)){
    new.vect[i]-switch(
  EXPR = X[i],
  Sell=Buy,
  Buy=Sell,
  X[i])
}
You can make an sapply construct too off course :

new.vect - sapply(X[which(Y==DEL)],switch,Sell=Buy,Buy=Sell) 

This will speed up things a little bit, but the effect is marginal.
Cheers
Joris
On Thu, May 27, 2010 at 8:33 AM, arnaud Gaboury arnaud.gabo...@gmail.com
wrote:
Thank you for the answer.
Is there any way to combine if() and switch() in one line? In my case,
something like :

if(trade$Trade.Status==DEL)switch(.)

I would like to avoid the loop .



From: Joris Meys [mailto:jorism...@gmail.com]
Sent: Wednesday, May 26, 2010 9:15 PM
To: arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] data frame manipulation change elements meeting criteria

see ?switch

X- rep(c(Buy,Sell,something else),each=5)
Y- rep(c(DEL,INS,DEL),5)


new.vect - X
for (i in which(Y==DEL)){
    new.vect[i]-switch(
  EXPR = X[i],
  Sell=Buy,
  Buy=Sell,
  X[i])
}
cbind(new.vect,X,Y)
On Wed, May 26, 2010 at 7:43 PM, arnaud Gaboury arnaud.gabo...@gmail.com
wrote:
Dear group,

Here is my df :

trade -
structure(list(Trade.Status = c(DEL, INS, INS), Instrument.Long.Name =
c(SUGAR NO.11,
CORN, CORN), Delivery.Prompt.Date = c(Jul/10, Jul/10,
Jul/10), Buy.Sell..Cleared. = c(Sell, Buy, Buy), Volume = c(1L,
2L, 1L), Price = c(15.2500, 368., 368.5000), Net.Charges..sum. =
c(4.01,
-8.64, -4.32)), .Names = c(Trade.Status, Instrument.Long.Name,
Delivery.Prompt.Date, Buy.Sell..Cleared., Volume, Price,
Net.Charges..sum.), row.names = c(NA, 3L), class = data.frame)

Here is what I want :

If trade$Trade.Status==DEL: then if trade$buy.Sell..Cleared==Sell , change
it to Buy, if trade$buy.Sell..Cleared==Buy, change it to Sell.
If trade$Trade.Status==INS, do nothing
I tried to work around with ifelse, but don't know how to deal with so many
conditions.

Any help is appreciated.

TY

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



--
Joris Meys
Statistical Consultant

Ghent University
Faculty of Bioscience Engineering
Department of Applied mathematics, biometrics and process control

Coupure Links 653
B-9000 Gent

tel : +32 9 264 59 87
joris.m...@ugent.be
---
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php



-- 
Joris Meys
Statistical Consultant

Ghent University
Faculty of Bioscience Engineering 
Department of Applied mathematics, biometrics and process control

Coupure Links 653
B-9000 Gent

tel : +32 9 264 59 87
joris.m...@ugent.be 
---
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php

__
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] data frame manipulation change elements meeting criteria

2010-05-27 Thread arnaud Gaboury
Joris,

If i pass this line :

tradesnew-sapply(trades[which(trades$Trade.Status==DEL),],switch,Sel
l=Buy,Buy=Sell)

Here is what I get :

 tradesnew
$Trade.Status
NULL

$Instrument.Long.Name
NULL

$Delivery.Prompt.Date
NULL

$Buy.Sell..Cleared.
[1] Buy

$Volume
[1] Buy

$Price
NULL

$Net.Charges..sum.
NULL

That's certainly not what I want.




From: Joris Meys [mailto:jorism...@gmail.com] 
Sent: Thursday, May 27, 2010 8:43 AM
To: arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] data frame manipulation change elements meeting criteria

The loop is due to the switch statement, not the condition. Without
condition it would become:

for (i in 1:length(Y)){
    new.vect[i]-switch(
  EXPR = X[i],
  Sell=Buy,
  Buy=Sell,
  X[i])
}
You can make an sapply construct too off course :

new.vect - sapply(X[which(Y==DEL)],switch,Sell=Buy,Buy=Sell) 

This will speed up things a little bit, but the effect is marginal.
Cheers
Joris
On Thu, May 27, 2010 at 8:33 AM, arnaud Gaboury arnaud.gabo...@gmail.com
wrote:
Thank you for the answer.
Is there any way to combine if() and switch() in one line? In my case,
something like :

if(trade$Trade.Status==DEL)switch(.)

I would like to avoid the loop .



From: Joris Meys [mailto:jorism...@gmail.com]
Sent: Wednesday, May 26, 2010 9:15 PM
To: arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] data frame manipulation change elements meeting criteria

see ?switch

X- rep(c(Buy,Sell,something else),each=5)
Y- rep(c(DEL,INS,DEL),5)


new.vect - X
for (i in which(Y==DEL)){
    new.vect[i]-switch(
  EXPR = X[i],
  Sell=Buy,
  Buy=Sell,
  X[i])
}
cbind(new.vect,X,Y)
On Wed, May 26, 2010 at 7:43 PM, arnaud Gaboury arnaud.gabo...@gmail.com
wrote:
Dear group,

Here is my df :

trade -
structure(list(Trade.Status = c(DEL, INS, INS), Instrument.Long.Name =
c(SUGAR NO.11,
CORN, CORN), Delivery.Prompt.Date = c(Jul/10, Jul/10,
Jul/10), Buy.Sell..Cleared. = c(Sell, Buy, Buy), Volume = c(1L,
2L, 1L), Price = c(15.2500, 368., 368.5000), Net.Charges..sum. =
c(4.01,
-8.64, -4.32)), .Names = c(Trade.Status, Instrument.Long.Name,
Delivery.Prompt.Date, Buy.Sell..Cleared., Volume, Price,
Net.Charges..sum.), row.names = c(NA, 3L), class = data.frame)

Here is what I want :

If trade$Trade.Status==DEL: then if trade$buy.Sell..Cleared==Sell , change
it to Buy, if trade$buy.Sell..Cleared==Buy, change it to Sell.
If trade$Trade.Status==INS, do nothing
I tried to work around with ifelse, but don't know how to deal with so many
conditions.

Any help is appreciated.

TY

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



--
Joris Meys
Statistical Consultant

Ghent University
Faculty of Bioscience Engineering
Department of Applied mathematics, biometrics and process control

Coupure Links 653
B-9000 Gent

tel : +32 9 264 59 87
joris.m...@ugent.be
---
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php



-- 
Joris Meys
Statistical Consultant

Ghent University
Faculty of Bioscience Engineering 
Department of Applied mathematics, biometrics and process control

Coupure Links 653
B-9000 Gent

tel : +32 9 264 59 87
joris.m...@ugent.be 
---
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php

__
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] data frame manipulation change elements meeting criteria

2010-05-27 Thread arnaud Gaboury
Maybe should I be more precise. Here is what I have :

trades -
structure(list(Trade.Status = c(DEL, INS, INS), Instrument.Long.Name =
c(SUGAR NO.11,
CORN, CORN), Delivery.Prompt.Date = c(Jul/10, Jul/10,
Jul/10), Buy.Sell..Cleared. = c(Sell, Buy, Buy), Volume = c(1L,
2L, 1L), Price = c(15.2500, 368., 368.5000), Net.Charges..sum. =
c(4.01,
-8.64, -4.32)), .Names = c(Trade.Status, Instrument.Long.Name,
Delivery.Prompt.Date, Buy.Sell..Cleared., Volume, Price,
Net.Charges..sum.), row.names = c(NA, 3L), class = data.frame)

Here is what I want :

tradesnew -
structure(list(Trade.Status = c(DEL, INS, INS), Instrument.Long.Name =
c(SUGAR NO.11,
CORN, CORN), Delivery.Prompt.Date = c(Jul/10, Jul/10,
Jul/10), Buy.Sell..Cleared. = c(Buy, Buy, Buy), Volume = c(1L,
2L, 1L), Price = c(15.2500, 368., 368.5000), Net.Charges..sum. =
c(4.01,
-8.64, -4.32)), .Names = c(Trade.Status, Instrument.Long.Name,
Delivery.Prompt.Date, Buy.Sell..Cleared., Volume, Price,
Net.Charges..sum.), row.names = c(NA, 3L), class = data.frame)



From: Joris Meys [mailto:jorism...@gmail.com] 
Sent: Thursday, May 27, 2010 10:38 AM
To: arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] data frame manipulation change elements meeting criteria

Off course. You put in a matrix to sapply, but sapply is for vectors. You
want to apply the switch command on every entry of the vector
trades$Buy.Sell..Cleared for which trades$Trade.Status equals DEL. Why do
you try to put in a matrix with all variables for the observations where
status is DEL?

You should have done :

tradesnew-sapply(trades$Buy.Sell..Cleared[which(trades$Trade.Status==DEL)
],
 switch,Sell=Buy,Buy=Sell)

Check the help files, and keep track of what goes in and out a function.

Cheers
Joris
On Thu, May 27, 2010 at 9:41 AM, arnaud Gaboury arnaud.gabo...@gmail.com
wrote:
Joris,

If i pass this line :

tradesnew-sapply(trades[which(trades$Trade.Status==DEL),],switch,Sel
l=Buy,Buy=Sell)

Here is what I get :

 tradesnew
$Trade.Status
NULL

$Instrument.Long.Name
NULL

$Delivery.Prompt.Date
NULL

$Buy.Sell..Cleared.
[1] Buy

$Volume
[1] Buy

$Price
NULL

$Net.Charges..sum.
NULL

That's certainly not what I want.




From: Joris Meys [mailto:jorism...@gmail.com]
Sent: Thursday, May 27, 2010 8:43 AM
To: arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] data frame manipulation change elements meeting criteria

The loop is due to the switch statement, not the condition. Without
condition it would become:

for (i in 1:length(Y)){
    new.vect[i]-switch(
  EXPR = X[i],
  Sell=Buy,
  Buy=Sell,
  X[i])
}
You can make an sapply construct too off course :

new.vect - sapply(X[which(Y==DEL)],switch,Sell=Buy,Buy=Sell)

This will speed up things a little bit, but the effect is marginal.
Cheers
Joris
On Thu, May 27, 2010 at 8:33 AM, arnaud Gaboury arnaud.gabo...@gmail.com
wrote:
Thank you for the answer.
Is there any way to combine if() and switch() in one line? In my case,
something like :

if(trade$Trade.Status==DEL)switch(.)

I would like to avoid the loop .



From: Joris Meys [mailto:jorism...@gmail.com]
Sent: Wednesday, May 26, 2010 9:15 PM
To: arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] data frame manipulation change elements meeting criteria

see ?switch

X- rep(c(Buy,Sell,something else),each=5)
Y- rep(c(DEL,INS,DEL),5)


new.vect - X
for (i in which(Y==DEL)){
    new.vect[i]-switch(
  EXPR = X[i],
  Sell=Buy,
  Buy=Sell,
  X[i])
}
cbind(new.vect,X,Y)
On Wed, May 26, 2010 at 7:43 PM, arnaud Gaboury arnaud.gabo...@gmail.com
wrote:
Dear group,

Here is my df :

trade -
structure(list(Trade.Status = c(DEL, INS, INS), Instrument.Long.Name =
c(SUGAR NO.11,
CORN, CORN), Delivery.Prompt.Date = c(Jul/10, Jul/10,
Jul/10), Buy.Sell..Cleared. = c(Sell, Buy, Buy), Volume = c(1L,
2L, 1L), Price = c(15.2500, 368., 368.5000), Net.Charges..sum. =
c(4.01,
-8.64, -4.32)), .Names = c(Trade.Status, Instrument.Long.Name,
Delivery.Prompt.Date, Buy.Sell..Cleared., Volume, Price,
Net.Charges..sum.), row.names = c(NA, 3L), class = data.frame)

Here is what I want :

If trade$Trade.Status==DEL: then if trade$buy.Sell..Cleared==Sell , change
it to Buy, if trade$buy.Sell..Cleared==Buy, change it to Sell.
If trade$Trade.Status==INS, do nothing
I tried to work around with ifelse, but don't know how to deal with so many
conditions.

Any help is appreciated.

TY

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



--
Joris Meys
Statistical Consultant

Ghent University
Faculty of Bioscience Engineering
Department of Applied mathematics, biometrics and process control

Coupure Links 653
B-9000 Gent

tel : +32 9 264 59 87
joris.m...@ugent.be
---
Disclaimer : http://helpdesk.ugent.be

Re: [R] data frame manipulation change elements meeting criteria

2010-05-27 Thread arnaud Gaboury
Sorry Joris, but I am totally lost on this issue!!


tradenews-sapply(trades$Buy.Sell..Cleared[which(trades$Trade.Status==DEL
)],switch,Sell=Buy,Buy=Sell)

 tradenews
 Sell 
Buy

Not really what I want !!

From: Joris Meys [mailto:jorism...@gmail.com] 
Sent: Thursday, May 27, 2010 10:38 AM
To: arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] data frame manipulation change elements meeting criteria

Off course. You put in a matrix to sapply, but sapply is for vectors. You
want to apply the switch command on every entry of the vector
trades$Buy.Sell..Cleared for which trades$Trade.Status equals DEL. Why do
you try to put in a matrix with all variables for the observations where
status is DEL?

You should have done :

tradesnew-sapply(trades$Buy.Sell..Cleared[which(trades$Trade.Status==DEL)
],
 switch,Sell=Buy,Buy=Sell)

Check the help files, and keep track of what goes in and out a function.

Cheers
Joris
On Thu, May 27, 2010 at 9:41 AM, arnaud Gaboury arnaud.gabo...@gmail.com
wrote:
Joris,

If i pass this line :

tradesnew-sapply(trades[which(trades$Trade.Status==DEL),],switch,Sel
l=Buy,Buy=Sell)

Here is what I get :

 tradesnew
$Trade.Status
NULL

$Instrument.Long.Name
NULL

$Delivery.Prompt.Date
NULL

$Buy.Sell..Cleared.
[1] Buy

$Volume
[1] Buy

$Price
NULL

$Net.Charges..sum.
NULL

That's certainly not what I want.




From: Joris Meys [mailto:jorism...@gmail.com]
Sent: Thursday, May 27, 2010 8:43 AM
To: arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] data frame manipulation change elements meeting criteria

The loop is due to the switch statement, not the condition. Without
condition it would become:

for (i in 1:length(Y)){
    new.vect[i]-switch(
  EXPR = X[i],
  Sell=Buy,
  Buy=Sell,
  X[i])
}
You can make an sapply construct too off course :

new.vect - sapply(X[which(Y==DEL)],switch,Sell=Buy,Buy=Sell)

This will speed up things a little bit, but the effect is marginal.
Cheers
Joris
On Thu, May 27, 2010 at 8:33 AM, arnaud Gaboury arnaud.gabo...@gmail.com
wrote:
Thank you for the answer.
Is there any way to combine if() and switch() in one line? In my case,
something like :

if(trade$Trade.Status==DEL)switch(.)

I would like to avoid the loop .



From: Joris Meys [mailto:jorism...@gmail.com]
Sent: Wednesday, May 26, 2010 9:15 PM
To: arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] data frame manipulation change elements meeting criteria

see ?switch

X- rep(c(Buy,Sell,something else),each=5)
Y- rep(c(DEL,INS,DEL),5)


new.vect - X
for (i in which(Y==DEL)){
    new.vect[i]-switch(
  EXPR = X[i],
  Sell=Buy,
  Buy=Sell,
  X[i])
}
cbind(new.vect,X,Y)
On Wed, May 26, 2010 at 7:43 PM, arnaud Gaboury arnaud.gabo...@gmail.com
wrote:
Dear group,

Here is my df :

trade -
structure(list(Trade.Status = c(DEL, INS, INS), Instrument.Long.Name =
c(SUGAR NO.11,
CORN, CORN), Delivery.Prompt.Date = c(Jul/10, Jul/10,
Jul/10), Buy.Sell..Cleared. = c(Sell, Buy, Buy), Volume = c(1L,
2L, 1L), Price = c(15.2500, 368., 368.5000), Net.Charges..sum. =
c(4.01,
-8.64, -4.32)), .Names = c(Trade.Status, Instrument.Long.Name,
Delivery.Prompt.Date, Buy.Sell..Cleared., Volume, Price,
Net.Charges..sum.), row.names = c(NA, 3L), class = data.frame)

Here is what I want :

If trade$Trade.Status==DEL: then if trade$buy.Sell..Cleared==Sell , change
it to Buy, if trade$buy.Sell..Cleared==Buy, change it to Sell.
If trade$Trade.Status==INS, do nothing
I tried to work around with ifelse, but don't know how to deal with so many
conditions.

Any help is appreciated.

TY

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



--
Joris Meys
Statistical Consultant

Ghent University
Faculty of Bioscience Engineering
Department of Applied mathematics, biometrics and process control

Coupure Links 653
B-9000 Gent

tel : +32 9 264 59 87
joris.m...@ugent.be
---
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php



--
Joris Meys
Statistical Consultant

Ghent University
Faculty of Bioscience Engineering
Department of Applied mathematics, biometrics and process control

Coupure Links 653
B-9000 Gent

tel : +32 9 264 59 87
joris.m...@ugent.be
---
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php



-- 
Joris Meys
Statistical Consultant

Ghent University
Faculty of Bioscience Engineering 
Department of Applied mathematics, biometrics and process control

Coupure Links 653
B-9000 Gent

tel : +32 9 264 59 87
joris.m...@ugent.be 
---
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting

Re: [R] switch function

2010-05-27 Thread arnaud Gaboury

Maybe should I be more precise. Here is what I have :

trades -
structure(list(Trade.Status = c(DEL, INS, INS), Instrument.Long.Name =
c(SUGAR NO.11, CORN, CORN), Delivery.Prompt.Date = c(Jul/10,
Jul/10, Jul/10), Buy.Sell..Cleared. = c(Sell, Buy, Buy), Volume =
c(1L, 2L, 1L), Price = c(15.2500, 368., 368.5000),
Net.Charges..sum. = c(4.01, -8.64, -4.32)), .Names = c(Trade.Status,
Instrument.Long.Name, Delivery.Prompt.Date, Buy.Sell..Cleared.,
Volume, Price, Net.Charges..sum.), row.names = c(NA, 3L), class =
data.frame)

Here is what I want :

tradesnew -
structure(list(Trade.Status = c(DEL, INS, INS), Instrument.Long.Name =
c(SUGAR NO.11, CORN, CORN), Delivery.Prompt.Date = c(Jul/10,
Jul/10, Jul/10), Buy.Sell..Cleared. = c(Buy, Buy, Buy), Volume =
c(1L, 2L, 1L), Price = c(15.2500, 368., 368.5000),
Net.Charges..sum. = c(4.01, -8.64, -4.32)), .Names = c(Trade.Status,
Instrument.Long.Name, Delivery.Prompt.Date, Buy.Sell..Cleared.,
Volume, Price, Net.Charges..sum.), row.names = c(NA, 3L), class =
data.frame)



From: Joris Meys [mailto:jorism...@gmail.com] 
Sent: Thursday, May 27, 2010 10:38 AM
To: arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] data frame manipulation change elements meeting criteria

Off course. You put in a matrix to sapply, but sapply is for vectors. You
want to apply the switch command on every entry of the vector
trades$Buy.Sell..Cleared for which trades$Trade.Status equals DEL. Why do
you try to put in a matrix with all variables for the observations where
status is DEL?

You should have done :

tradesnew-sapply(trades$Buy.Sell..Cleared[which(trades$Trade.Status==DEL)
],
 switch,Sell=Buy,Buy=Sell)

Check the help files, and keep track of what goes in and out a function.

Cheers
Joris
On Thu, May 27, 2010 at 9:41 AM, arnaud Gaboury arnaud.gabo...@gmail.com
wrote:
Joris,

If i pass this line :

tradesnew-sapply(trades[which(trades$Trade.Status==DEL),],switch,Sel
l=Buy,Buy=Sell)

Here is what I get :

 tradesnew
$Trade.Status
NULL

$Instrument.Long.Name
NULL

$Delivery.Prompt.Date
NULL

$Buy.Sell..Cleared.
[1] Buy

$Volume
[1] Buy

$Price
NULL

$Net.Charges..sum.
NULL

That's certainly not what I want.




From: Joris Meys [mailto:jorism...@gmail.com]
Sent: Thursday, May 27, 2010 8:43 AM
To: arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] data frame manipulation change elements meeting criteria

The loop is due to the switch statement, not the condition. Without
condition it would become:

for (i in 1:length(Y)){
    new.vect[i]-switch(
  EXPR = X[i],
  Sell=Buy,
  Buy=Sell,
  X[i])
}
You can make an sapply construct too off course :

new.vect - sapply(X[which(Y==DEL)],switch,Sell=Buy,Buy=Sell)

This will speed up things a little bit, but the effect is marginal.
Cheers
Joris
On Thu, May 27, 2010 at 8:33 AM, arnaud Gaboury arnaud.gabo...@gmail.com
wrote:
Thank you for the answer.
Is there any way to combine if() and switch() in one line? In my case,
something like :

if(trade$Trade.Status==DEL)switch(.)

I would like to avoid the loop .



From: Joris Meys [mailto:jorism...@gmail.com]
Sent: Wednesday, May 26, 2010 9:15 PM
To: arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] data frame manipulation change elements meeting criteria

see ?switch

X- rep(c(Buy,Sell,something else),each=5)
Y- rep(c(DEL,INS,DEL),5)


new.vect - X
for (i in which(Y==DEL)){
    new.vect[i]-switch(
  EXPR = X[i],
  Sell=Buy,
  Buy=Sell,
  X[i])
}
cbind(new.vect,X,Y)
On Wed, May 26, 2010 at 7:43 PM, arnaud Gaboury arnaud.gabo...@gmail.com
wrote:
Dear group,

Here is my df :

trade -
structure(list(Trade.Status = c(DEL, INS, INS), Instrument.Long.Name =
c(SUGAR NO.11,
CORN, CORN), Delivery.Prompt.Date = c(Jul/10, Jul/10,
Jul/10), Buy.Sell..Cleared. = c(Sell, Buy, Buy), Volume = c(1L,
2L, 1L), Price = c(15.2500, 368., 368.5000), Net.Charges..sum. =
c(4.01,
-8.64, -4.32)), .Names = c(Trade.Status, Instrument.Long.Name,
Delivery.Prompt.Date, Buy.Sell..Cleared., Volume, Price,
Net.Charges..sum.), row.names = c(NA, 3L), class = data.frame)

Here is what I want :

If trade$Trade.Status==DEL: then if trade$buy.Sell..Cleared==Sell , change
it to Buy, if trade$buy.Sell..Cleared==Buy, change it to Sell.
If trade$Trade.Status==INS, do nothing
I tried to work around with ifelse, but don't know how to deal with so many
conditions.

Any help is appreciated.

TY

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



--
Joris Meys
Statistical Consultant

Ghent University
Faculty of Bioscience Engineering
Department of Applied mathematics, biometrics and process control

Coupure Links 653
B-9000 Gent

tel : +32 9 264 59 87
joris.m...@ugent.be
---
Disclaimer : http://helpdesk.ugent.be

Re: [R] switch function

2010-05-27 Thread arnaud Gaboury
Thanks to Joris, this line does what I want :

trades$Buy.Sell..Cleared.[which(trades$Trade.Status==DEL)] - 
  sapply(trades$Buy.Sell..Cleared.[which(trades$Trade.Status==DEL)],
  switch,Sell=Buy,Buy=Sell)





 -Original Message-
 From: jim holtman [mailto:jholt...@gmail.com]
 Sent: Thursday, May 27, 2010 2:34 PM
 To: arnaud Gaboury
 Cc: r-help@r-project.org
 Subject: Re: [R] switch function
 
 try this:
 
  toBuy - trades$Trade.Status == DEL  trades$Buy.Sell..Cleared. ==
 Sell
  toSell - trades$Trade.Status == DEL  trades$Buy.Sell..Cleared. ==
 Buy
  x - trades  # make a copy to change
  x$Buy.Sell..Cleared.[toBuy] - Buy
  x$Buy.Sell..Cleared.[toSell] - Sell
  x
   Trade.Status Instrument.Long.Name Delivery.Prompt.Date
 Buy.Sell..Cleared. VolumePrice Net.Charges..sum.
 1  DEL  SUGAR NO.11   Jul/10
  Buy  1  15.2500  4.01
 2  INS CORN   Jul/10
  Buy  2 368. -8.64
 3  INS CORN   Jul/10
  Buy  1 368.5000 -4.32
  trades
   Trade.Status Instrument.Long.Name Delivery.Prompt.Date
 Buy.Sell..Cleared. VolumePrice Net.Charges..sum.
 1  DEL  SUGAR NO.11   Jul/10
 Sell  1  15.2500  4.01
 2  INS CORN   Jul/10
  Buy  2 368. -8.64
 3  INS CORN   Jul/10
  Buy  1 368.5000 -4.32
 
 
 
 
 On Thu, May 27, 2010 at 4:03 AM, arnaud Gaboury
 arnaud.gabo...@gmail.com wrote:
  Dear group,
 
  Here is my df :
 
  trades -
  structure(list(Trade.Status = c(DEL, INS, INS),
 Instrument.Long.Name =
  c(SUGAR NO.11,
  CORN, CORN), Delivery.Prompt.Date = c(Jul/10, Jul/10,
  Jul/10), Buy.Sell..Cleared. = c(Sell, Buy, Buy), Volume =
 c(1L,
  2L, 1L), Price = c(15.2500, 368., 368.5000),
 Net.Charges..sum. =
  c(4.01,
  -8.64, -4.32)), .Names = c(Trade.Status, Instrument.Long.Name,
  Delivery.Prompt.Date, Buy.Sell..Cleared., Volume, Price,
  Net.Charges..sum.), row.names = c(NA, 3L), class = data.frame)
 
  I want to replace Buy by Sell and Sell by Buy in column
  Buy.Sell..Cleared. when element in column Trade.Status is equal
 to
  DEL.
 
  I think I can write something like this :
 
 
 tradesnew-
 sapply(trades$Buy.Sell..Cleared[which(trades$Buy.Sell..Cleared==
  DEL),],switch,...)  but I don't really know how to pass further
  arguments to the switch function.
 
  Any help is appreciated.
 
  __
  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.
 
 
 
 
 --
 Jim Holtman
 Cincinnati, OH
 +1 513 646 9390
 
 What is the problem that you are trying to solve?

__
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] writing function : can't find an object

2010-05-26 Thread arnaud Gaboury
Dear group,

Here is my function:


#return the daily PL for day y

PLDaily-function(x,y)


{

#find elements in my directory with LSCPos in the name, keep the numeric
part in the name and
#create a list
  l-gsub(\\D,,dir()[grep(LSCPos,dir())])

#select in the list the desired elements
  assign(sel,l[which(l==x):which(l==y)],envir=.GlobalEnv)
  #here is another solution  select-l[l %in% seq(x, y)]
  
#first we need to create the Pos and Trad elements

  for (i in sel)  {

  assign(paste(Pos,i,sep=),position(i),envir=.GlobalEnv)
  assign(paste(Trad,i,sep=),trade(i),envir=.GlobalEnv)

   }
#access elements in my environment
  posA-get(paste(c(Pos,x),collapse=))
  posB-get(paste(c(Pos,y),collapse=))
  av-get(paste(c(Trad,y),collapse=))
  
#apply some change on element columns then create only one data frame with
the three elements
  allcon-ddply(rbind(av[,1:3],
transform(posA,prix=POSITION*SETTLEMENT,SETTLEMENT=NULL), 
  transform(posB, prix = -POSITION * SETTLEMENT, SETTLEMENT = NULL,
POSITION = POSITION * -1)),
  DESCRIPTION,summarise,pl=sum(prix),quantity=sum(POSITION))  
 
#remove the date in $DESCRPTION and add a new column $SHORTDESCRIPTION
  allcon$SHORTDESCRIPTION-sub('
[a-z]{3}/[0-9]{2}','',allcon$DESCRIPTION,ignore.case=TRUE)  
 
#read the contractvalue file
  value-read.csv2(contractvalue.csv,sep=,,h=T,strip.white=T)
 
#merge value with allcon, change some columns, then merge with PosB,
replace NA by zero and assign the final result to element PL
  zz-merge(transform(merge(value,allcon,all.y=T),SHORTDESCRIPTION=NULL,
  VALUE=NULL,PL=-VALUE*pl,quantity=NULL),PosB,all.x=T,sort=F) 
  zz[is.na(zz)]-0
  #PL-zz[c(1,3,4)]
  assign(paste(DailyPL,y,sep=),zz[,c(1,3,4)],envir=.GlobalEnv)
 
}

Here is what I get :

 PLDaily(100524,100525)
Error in as.data.frame(y) : object 'PosB' not found

 ls()
[1] PLDailyPos100524  Pos100525  position   sel
Trad100524 Trad100525 trade

Why R can't find PosB ?

TY for your help.

__
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] (no subject)

2010-05-26 Thread arnaud Gaboury
Dear group,

Here is my data frame:

 dput(u)
structure(list(DESCRIPTION = structure(c(2L, 5L, 6L, 7L, 9L, 
11L, 12L, 15L, 14L, 16L, 1L, 10L, 3L, 4L, 13L, 8L, 17L), .Label = c(COFFEE
C Jul/10, 
COPPER May/10, CORN Jul/10, CORN May/10, COTTON NO.2 Jul/10, 
CRUDE OIL miNY May/10, GOLD Jun/10, HENRY HUB NATURAL GAS May/10, 
ROBUSTA COFFEE (10) Jul/10, SILVER May/10, SOYBEANS Jul/10, 
SPCL HIGH GRADE ZINC USD, STANDARD LEAD USD, SUGAR NO.11 Jul/10, 
SUGAR NO.11 May/10, WHEAT Jul/10, WHEAT May/10), class = factor), 
PL = c(3500, -1874.999, -2612.503, -2169.998, 
-680, 425, 1025, 1008.000, -3057.599, 3212.5, 
-1781.251, -2265.0, 75, -387.5, 2950, 490.0013, 
0), POSITION = c(-2, 3, 2, 2, 18, 3, -1, -1, 5, 5, 0, 0, 
0, 0, 0, 0, 0)), .Names = c(DESCRIPTION, PL, POSITION
), class = data.frame, row.names = c(NA, -17L))

I want to give a warning message if one of the element of the POSITION
column is different from zero.

I tried using mapply with some line like this :

 mapply(if,u$POSITION,==0,print(WARNING:POSITIONS ARE WRONG,quote=F))  
But it seems it is not the correct way to pass the various arguments.

Any help is appreciated




***
Arnaud Gaboury
Mobile: +41 79 392 79 56
BBM: 255B488F

__
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] condition apply to elements of a data frame column

2010-05-26 Thread arnaud Gaboury
Oops, forgot to give a subject


 -Original Message-
 From: arnaud Gaboury [mailto:arnaud.gabo...@gmail.com]
 Sent: Wednesday, May 26, 2010 2:31 PM
 To: r-help@r-project.org
 Cc: 'arnaud Gaboury'
 Subject:
 
 Dear group,
 
 Here is my data frame:
 
  dput(u)
 structure(list(DESCRIPTION = structure(c(2L, 5L, 6L, 7L, 9L,
 11L, 12L, 15L, 14L, 16L, 1L, 10L, 3L, 4L, 13L, 8L, 17L), .Label =
 c(COFFEE
 C Jul/10,
 COPPER May/10, CORN Jul/10, CORN May/10, COTTON NO.2 Jul/10,
 CRUDE OIL miNY May/10, GOLD Jun/10, HENRY HUB NATURAL GAS May/10,
 ROBUSTA COFFEE (10) Jul/10, SILVER May/10, SOYBEANS Jul/10,
 SPCL HIGH GRADE ZINC USD, STANDARD LEAD USD, SUGAR NO.11 Jul/10,
 SUGAR NO.11 May/10, WHEAT Jul/10, WHEAT May/10), class =
 factor),
 PL = c(3500, -1874.999, -2612.503, -
 2169.998,
 -680, 425, 1025, 1008.000, -3057.599, 3212.5,
 -1781.251, -2265.0, 75, -387.5, 2950, 490.0013,
 0), POSITION = c(-2, 3, 2, 2, 18, 3, -1, -1, 5, 5, 0, 0,
 0, 0, 0, 0, 0)), .Names = c(DESCRIPTION, PL, POSITION
 ), class = data.frame, row.names = c(NA, -17L))
 
 I want to give a warning message if one of the element of the POSITION
 column is different from zero.
 
 I tried using mapply with some line like this :
 
  mapply(if,u$POSITION,==0,print(WARNING:POSITIONS ARE
 WRONG,quote=F))
 But it seems it is not the correct way to pass the various arguments.
 
 Any help is appreciated
 
 
 
 
 ***
 Arnaud Gaboury
 Mobile: +41 79 392 79 56
 BBM: 255B488F
 ***


__
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] condition apply to elements of a data frame column

2010-05-26 Thread arnaud Gaboury
Joris,

I want to add a line in a  function with a print warning if one element of
the column is 0.
I could use if(sum(u$POSITION)0) as a condition, but I can imagine having
one element equal to -2, and another one to 2. So in this case, sum=0, but
the condition is false in fact (minimum of one element different from zero).






From: Joris Meys [mailto:jorism...@gmail.com] 
Sent: Wednesday, May 26, 2010 2:48 PM
To: arnaud Gaboury
Cc: r-help@r-project.org
Subject: Re: [R] (no subject)

What exactly are you trying to do? If you want to know which position is
wrong, try :

if (sum(u$POSITION==0)0) cat(WARNING:POSITION IS WRONG FOR
,which(u$POSITION==0),\n)

or even : 
wrong - which(u$POSITION==0)
if(length(wrong)0) cat(WARNING: POSITION IS WRONG
FOR,u$DESCRIPTION[wrong],\n)

Gives you the exact location of wrong positions. If you do that, make sure
u$DESCRIPTION is a character vector and not a factor.

Cheers
Joris
On Wed, May 26, 2010 at 2:31 PM, arnaud Gaboury arnaud.gabo...@gmail.com
wrote:
Dear group,

Here is my data frame:

 dput(u)
structure(list(DESCRIPTION = structure(c(2L, 5L, 6L, 7L, 9L,
11L, 12L, 15L, 14L, 16L, 1L, 10L, 3L, 4L, 13L, 8L, 17L), .Label = c(COFFEE
C Jul/10,
COPPER May/10, CORN Jul/10, CORN May/10, COTTON NO.2 Jul/10,
CRUDE OIL miNY May/10, GOLD Jun/10, HENRY HUB NATURAL GAS May/10,
ROBUSTA COFFEE (10) Jul/10, SILVER May/10, SOYBEANS Jul/10,
SPCL HIGH GRADE ZINC USD, STANDARD LEAD USD, SUGAR NO.11 Jul/10,
SUGAR NO.11 May/10, WHEAT Jul/10, WHEAT May/10), class = factor),
   PL = c(3500, -1874.999, -2612.503, -2169.998,
   -680, 425, 1025, 1008.000, -3057.599, 3212.5,
   -1781.251, -2265.0, 75, -387.5, 2950, 490.0013,
   0), POSITION = c(-2, 3, 2, 2, 18, 3, -1, -1, 5, 5, 0, 0,
   0, 0, 0, 0, 0)), .Names = c(DESCRIPTION, PL, POSITION
), class = data.frame, row.names = c(NA, -17L))

I want to give a warning message if one of the element of the POSITION
column is different from zero.

I tried using mapply with some line like this :

 mapply(if,u$POSITION,==0,print(WARNING:POSITIONS ARE WRONG,quote=F))
But it seems it is not the correct way to pass the various arguments.

Any help is appreciated




***
Arnaud Gaboury
Mobile: +41 79 392 79 56
BBM: 255B488F

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



-- 
Joris Meys
Statistical Consultant

Ghent University
Faculty of Bioscience Engineering 
Department of Applied mathematics, biometrics and process control

Coupure Links 653
B-9000 Gent

tel : +32 9 264 59 87
joris.m...@ugent.be 
---
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php

__
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] data frame manipulation change elements meeting criteria

2010-05-26 Thread arnaud Gaboury
Dear group,

Here is my df :

trade -
structure(list(Trade.Status = c(DEL, INS, INS), Instrument.Long.Name =
c(SUGAR NO.11, 
CORN, CORN), Delivery.Prompt.Date = c(Jul/10, Jul/10, 
Jul/10), Buy.Sell..Cleared. = c(Sell, Buy, Buy), Volume = c(1L, 
2L, 1L), Price = c(15.2500, 368., 368.5000), Net.Charges..sum. =
c(4.01, 
-8.64, -4.32)), .Names = c(Trade.Status, Instrument.Long.Name, 
Delivery.Prompt.Date, Buy.Sell..Cleared., Volume, Price, 
Net.Charges..sum.), row.names = c(NA, 3L), class = data.frame)

Here is what I want :

If trade$Trade.Status==DEL: then if trade$buy.Sell..Cleared==Sell , change
it to Buy, if trade$buy.Sell..Cleared==Buy, change it to Sell.
If trade$Trade.Status==INS, do nothing
I tried to work around with ifelse, but don't know how to deal with so many
conditions.

Any help is appreciated.

TY

__
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] writing function:loop and rbind

2010-05-24 Thread arnaud Gaboury
Dear group,

I have a function, let's call it myfun, wich give me a list of result:
R1,R2,R3...
There is a loop in this function to get my results. Here is the structure of
my function:

Myfun-function()

{
For (i in X ){

---instructions-

Ri

{
{

All Results (R1,R2...) are Data.frame. As a final result (call it Final),
I need to rbind all these dataframe. One solution could be to create another
loop, but I think I can avoid it. How can I add a line like this :
Final-rbind(R1,R2...) using the i parameter? Another solution could may be
to create a list of all my results, then apply rbind to the list?

Any idea would be appreciated.

TY in advance

__
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] writing function:loop and rbind

2010-05-24 Thread arnaud Gaboury
One solution is to create a list, then do.call.
Here is my environment:

 ls()
 [1] DailyPL100416 DailyPL100419 DailyPL100420 l ll
PLglobal  Pos100415 Pos100416 Pos100419 Pos100420
position  r
[13] resultsel   selectTrad100415
Trad100416Trad100419Trad100420trade tt
w  

   l-list(grep(DailyPL,ls(),value=T))   #create a list of elements with
DailyPL in the name

 l
[[1]]
[1] DailyPL100416 DailyPL100419 DailyPL100420

 DF-do.call(rbind,l)
 DF
 [,1][,2][,3]   
[1,] DailyPL100416 DailyPL100419 DailyPL100420

That's not what I want! I expect DF to be a data.frame binded by row.

I suspect there is an issue with get() or assign(), or something like that.

Any help is appreciated.






 -Original Message-
 From: arnaud Gaboury [mailto:arnaud.gabo...@gmail.com]
 Sent: Monday, May 24, 2010 2:55 PM
 To: r-help@r-project.org
 Cc: 'arnaud Gaboury'
 Subject: writing function:loop and rbind
 
 Dear group,
 
 I have a function, let's call it myfun, wich give me a list of result:
 R1,R2,R3...
 There is a loop in this function to get my results. Here is the
 structure of
 my function:
 
 Myfun-function()
 
 {
 For (i in X ){
 
 ---instructions-
 
 Ri
 
 {
 {
 
 All Results (R1,R2...) are Data.frame. As a final result (call it
 Final),
 I need to rbind all these dataframe. One solution could be to create
 another
 loop, but I think I can avoid it. How can I add a line like this :
 Final-rbind(R1,R2...) using the i parameter? Another solution could
 may be
 to create a list of all my results, then apply rbind to the list?
 
 Any idea would be appreciated.
 
 TY in advance

__
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] writing function:loop and rbind

2010-05-24 Thread arnaud Gaboury
Maybe is there a neater solution, but the function mget() does the trick. So 
until further advice, I will work with your solution.

Thank you




 -Original Message-
 From: Joshua Wiley [mailto:jwiley.ps...@gmail.com]
 Sent: Monday, May 24, 2010 5:07 PM
 To: arnaud Gaboury
 Cc: r-help@r-project.org
 Subject: Re: [R] writing function:loop and rbind
 
 On Mon, May 24, 2010 at 7:00 AM, arnaud Gaboury
 arnaud.gabo...@gmail.com wrote:
  One solution is to create a list, then do.call.
  Here is my environment:
 
  ls()
   [1] DailyPL100416 DailyPL100419 DailyPL100420 l
 ll
  PLglobal  Pos100415 Pos100416 Pos100419
 Pos100420
  position  r
  [13] resultsel   selectTrad100415
  Trad100416Trad100419Trad100420trade tt
  w
 
l-list(grep(DailyPL,ls(),value=T))   #create a list of elements
 with
  DailyPL in the name
 A list of their names, not the elements themselves.
 
  l
  [[1]]
  [1] DailyPL100416 DailyPL100419 DailyPL100420
 
  DF-do.call(rbind,l)
  DF
  [,1][,2][,3]
  [1,] DailyPL100416 DailyPL100419 DailyPL100420
 
  That's not what I want! I expect DF to be a data.frame binded by
 row.
 It is binded by row, but it is from the list you fed it, which is just
 a list with a single element of character strings.
 
  I suspect there is an issue with get() or assign(), or something like
 that.
 
  Any help is appreciated.
 
 I am sure there is a neater solution, but something like this should
 work where envir=whether the objects actually are.
 
 do.call(rbind, mget(grep(DailyPL,ls(),value=TRUE),envir=.GlobalEnv))
 
 Best regards,
 
 Josh
 
 
  -Original Message-
  From: arnaud Gaboury [mailto:arnaud.gabo...@gmail.com]
  Sent: Monday, May 24, 2010 2:55 PM
  To: r-help@r-project.org
  Cc: 'arnaud Gaboury'
  Subject: writing function:loop and rbind
 
  Dear group,
 
  I have a function, let's call it myfun, wich give me a list of
 result:
  R1,R2,R3...
  There is a loop in this function to get my results. Here is the
  structure of
  my function:
 
  Myfun-function()
 
  {
  For (i in X ){
 
  ---instructions-
 
  Ri
 
  {
  {
 
  All Results (R1,R2...) are Data.frame. As a final result (call it
  Final),
  I need to rbind all these dataframe. One solution could be to create
  another
  loop, but I think I can avoid it. How can I add a line like this :
  Final-rbind(R1,R2...) using the i parameter? Another solution could
  may be
  to create a list of all my results, then apply rbind to the list?
 
  Any idea would be appreciated.
 
  TY in advance
 
  __
  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.
 
 
 
 
 --
 Joshua Wiley
 Senior in Psychology
 University of California, Riverside
 http://www.joshuawiley.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] writing function:loop and rbind

2010-05-24 Thread arnaud Gaboury
Do you think there is a way to add somewhere the argument row.names=NULL ? Or 
should I have to write another line to remove the row.names?





 -Original Message-
 From: Joshua Wiley [mailto:jwiley.ps...@gmail.com]
 Sent: Monday, May 24, 2010 5:07 PM
 To: arnaud Gaboury
 Cc: r-help@r-project.org
 Subject: Re: [R] writing function:loop and rbind
 
 On Mon, May 24, 2010 at 7:00 AM, arnaud Gaboury
 arnaud.gabo...@gmail.com wrote:
  One solution is to create a list, then do.call.
  Here is my environment:
 
  ls()
   [1] DailyPL100416 DailyPL100419 DailyPL100420 l
 ll
  PLglobal  Pos100415 Pos100416 Pos100419
 Pos100420
  position  r
  [13] resultsel   selectTrad100415
  Trad100416Trad100419Trad100420trade tt
  w
 
l-list(grep(DailyPL,ls(),value=T))   #create a list of elements
 with
  DailyPL in the name
 A list of their names, not the elements themselves.
 
  l
  [[1]]
  [1] DailyPL100416 DailyPL100419 DailyPL100420
 
  DF-do.call(rbind,l)
  DF
  [,1][,2][,3]
  [1,] DailyPL100416 DailyPL100419 DailyPL100420
 
  That's not what I want! I expect DF to be a data.frame binded by
 row.
 It is binded by row, but it is from the list you fed it, which is just
 a list with a single element of character strings.
 
  I suspect there is an issue with get() or assign(), or something like
 that.
 
  Any help is appreciated.
 
 I am sure there is a neater solution, but something like this should
 work where envir=whether the objects actually are.
 
 do.call(rbind, mget(grep(DailyPL,ls(),value=TRUE),envir=.GlobalEnv))
 
 Best regards,
 
 Josh
 
 
  -Original Message-
  From: arnaud Gaboury [mailto:arnaud.gabo...@gmail.com]
  Sent: Monday, May 24, 2010 2:55 PM
  To: r-help@r-project.org
  Cc: 'arnaud Gaboury'
  Subject: writing function:loop and rbind
 
  Dear group,
 
  I have a function, let's call it myfun, wich give me a list of
 result:
  R1,R2,R3...
  There is a loop in this function to get my results. Here is the
  structure of
  my function:
 
  Myfun-function()
 
  {
  For (i in X ){
 
  ---instructions-
 
  Ri
 
  {
  {
 
  All Results (R1,R2...) are Data.frame. As a final result (call it
  Final),
  I need to rbind all these dataframe. One solution could be to create
  another
  loop, but I think I can avoid it. How can I add a line like this :
  Final-rbind(R1,R2...) using the i parameter? Another solution could
  may be
  to create a list of all my results, then apply rbind to the list?
 
  Any idea would be appreciated.
 
  TY in advance
 
  __
  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.
 
 
 
 
 --
 Joshua Wiley
 Senior in Psychology
 University of California, Riverside
 http://www.joshuawiley.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] writing function

2010-05-24 Thread arnaud Gaboury
Dear group,

Here is my environment after I run a function, myfun()

myfun()
 ls()
 [1] allconavprix16  DailyPL100416 DailyPL100419
DailyPL100420 l llmyl   PL
PLdaily   PLglobal  PLmonthly
[13] Pos100415 Pos100416 Pos100419 Pos100420
pose15pose16position  r result
sel   selectTrad100415   
[25] Trad100416Trad100419Trad100420trade tt
value w zz  

Elements DailyPL100416 DailyPL100419 DailyPL100420 are data frames
created by a function, myfun().
If then I pass this line manually at the prompt:

dd-data.frame(do.call(rbind,
mget(grep(DailyPL,ls(),value=TRUE),envir=.GlobalEnv)),row.names=NULL)  

Here is what I get, wich is the expected result :

dd -
structure(list(DESCRIPTION = structure(c(2L, 5L, 6L, 7L, 9L, 
11L, 12L, 15L, 14L, 16L, 1L, 10L, 3L, 4L, 13L, 8L, 17L, 2L, 3L, 
5L, 7L, 9L, 11L, 12L, 13L, 14L, 16L, 18L, 8L, 6L, 10L, 15L, 5L, 
19L, 9L, 10L, 11L, 12L, 13L, 14L, 16L, 2L, 3L, 20L, 18L, 7L, 
21L), .Label = c(COFFEE C Jul/10, COPPER May/10, CORN Jul/10, 
CORN May/10, COTTON NO.2 Jul/10, CRUDE OIL miNY May/10, 
GOLD Jun/10, HENRY HUB NATURAL GAS May/10, ROBUSTA COFFEE (10) Jul/10,

SILVER May/10, SOYBEANS Jul/10, SPCL HIGH GRADE ZINC USD, 
STANDARD LEAD USD, SUGAR NO.11 Jul/10, SUGAR NO.11 May/10, 
WHEAT Jul/10, WHEAT May/10, CRUDE OIL miNY Jun/10, HENRY HUB NATURAL
GAS Jun/10, 
PALLADIUM Jun/10, PLATINUM Jul/10), class = factor), PL = c(3500, 
-1874.999, -2612.503, -2169.998, -680, 
425, 1025, 1008.000, -3057.599, 3212.5, -1781.251, 
-2265.0, 75, -387.5, 2950, 490.0013, 0, 2612.498, 
-4162.5, 279.998, 589.9964, -3670, -1212.5, 887.5, 
-625, 3976.000, -7250, -1112.500, -289., 
-1414.999, 275, -526.4003, 6914.999, 
-19.99978, -2330, 54.99955, 1725, -3012.5, -5175, 
-1769.601, 3787.5, -537.5009, 175, -5330.001, 
362.499, 590.0009, -2995.000)), .Names =
c(DESCRIPTION, 
PL), row.names = c(NA, -47L), class = data.frame)

If I add this same line at the end of my function , here is what I get:

 myfun()
data frame with 0 columns and 0 rows  #dd doesn't return


What is wrong?

Thank you for help.

__
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] writing function

2010-05-24 Thread arnaud Gaboury
Thank you so much. You are totally right.




 -Original Message-
 From: Joshua Wiley [mailto:jwiley.ps...@gmail.com]
 Sent: Monday, May 24, 2010 6:33 PM
 To: arnaud Gaboury
 Cc: r-help@r-project.org
 Subject: Re: [R] writing function
 
 My guess is that either ls(), called inside grep() or mget() is
 looking in an environment you do not want it to.  When you create a
 function, it has it's own environment.  If you want the dataframes to
 be created inside the function call (which is what I think you were
 doing before), you should set ls() and mget() to use your function
 environment.  If the dataframes are supposed to be in the global
 environment, I would try adding:
 
 mget(grep(DailyPL,ls(envir=.GlobalEnv),value=TRUE),envir=.GlobalEnv))
 
 HTH,
 
 Josh
 
 On Mon, May 24, 2010 at 9:17 AM, arnaud Gaboury
 arnaud.gabo...@gmail.com wrote:
  Dear group,
 
  Here is my environment after I run a function, myfun()
 
 myfun()
  ls()
   [1] allconavprix16  DailyPL100416 DailyPL100419
  DailyPL100420 l llmyl   PL
  PLdaily   PLglobal  PLmonthly
  [13] Pos100415 Pos100416 Pos100419 Pos100420
  pose15pose16position  r
 result
  sel   selectTrad100415
  [25] Trad100416Trad100419Trad100420trade
 tt
  value w zz
 
  Elements DailyPL100416 DailyPL100419 DailyPL100420 are data
 frames
  created by a function, myfun().
  If then I pass this line manually at the prompt:
 
 dd-data.frame(do.call(rbind,
 
 mget(grep(DailyPL,ls(),value=TRUE),envir=.GlobalEnv)),row.names=NULL)
 
  Here is what I get, wich is the expected result :
 
  dd -
  structure(list(DESCRIPTION = structure(c(2L, 5L, 6L, 7L, 9L,
  11L, 12L, 15L, 14L, 16L, 1L, 10L, 3L, 4L, 13L, 8L, 17L, 2L, 3L,
  5L, 7L, 9L, 11L, 12L, 13L, 14L, 16L, 18L, 8L, 6L, 10L, 15L, 5L,
  19L, 9L, 10L, 11L, 12L, 13L, 14L, 16L, 2L, 3L, 20L, 18L, 7L,
  21L), .Label = c(COFFEE C Jul/10, COPPER May/10, CORN Jul/10,
  CORN May/10, COTTON NO.2 Jul/10, CRUDE OIL miNY May/10,
  GOLD Jun/10, HENRY HUB NATURAL GAS May/10, ROBUSTA COFFEE (10)
 Jul/10,
 
  SILVER May/10, SOYBEANS Jul/10, SPCL HIGH GRADE ZINC USD,
  STANDARD LEAD USD, SUGAR NO.11 Jul/10, SUGAR NO.11 May/10,
  WHEAT Jul/10, WHEAT May/10, CRUDE OIL miNY Jun/10, HENRY HUB
 NATURAL
  GAS Jun/10,
  PALLADIUM Jun/10, PLATINUM Jul/10), class = factor), PL =
 c(3500,
  -1874.999, -2612.503, -2169.998, -680,
  425, 1025, 1008.000, -3057.599, 3212.5, -
 1781.251,
  -2265.0, 75, -387.5, 2950, 490.0013, 0, 2612.498,
  -4162.5, 279.998, 589.9964, -3670, -1212.5, 887.5,
  -625, 3976.000, -7250, -1112.500, -289.,
  -1414.999, 275, -526.4003, 6914.999,
  -19.99978, -2330, 54.99955, 1725, -3012.5, -5175,
  -1769.601, 3787.5, -537.5009, 175, -5330.001,
  362.499, 590.0009, -2995.000)), .Names =
  c(DESCRIPTION,
  PL), row.names = c(NA, -47L), class = data.frame)
 
  If I add this same line at the end of my function , here is what I
 get:
 
  myfun()
  data frame with 0 columns and 0 rows  #dd doesn't return
 
 
  What is wrong?
 
  Thank you for help.
 
  __
  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.
 
 
 
 
 --
 Joshua Wiley
 Senior in Psychology
 University of California, Riverside
 http://www.joshuawiley.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.


  1   2   >