[R] Date issues
Strangely this is not working ... what am I doing wrong here? > tDate <- FnO_Data$Date[1] > tDate [1] 20090101 > as.Date(c(tDate),format="%Y%m%d") [1] NA __ 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] Date issues
Thanks. -Original Message- From: David Winsemius [mailto:dwinsem...@comcast.net] Sent: 18 September 2010 21:07 To: Santosh Srinivas Cc: r-help@r-project.org Subject: Re: [R] Date issues On Sep 18, 2010, at 11:25 AM, Santosh Srinivas wrote: > Strangely this is not working ... what am I doing wrong here? > >> tDate <- FnO_Data$Date[1] >> tDate > [1] 20090101 >> as.Date(c(tDate),format="%Y%m%d") > [1] NA ?sasDate as.Date does not take numeric arguments. Try: > as.Date(as.character(tDate), format="%Y%M%d") [1] "2009-09-01" -- David Winsemius, MD West Hartford, CT __ 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] Date issues
I tried this and it works too (For most part) strangely for certain dates (20090831) it is giving NA ... > FnO_Data$Date[m:l] [1] 20090828 20090828 20090828 20090828 20090828 20090828 20090828 20090828 20090828 20090828 20090828 20090828 [13] 20090828 20090828 20090828 20090828 20090828 20090828 20090828 20090828 20090828 20090828 20090828 20090828 [25] 20090828 20090828 20090828 20090828 20090828 20090828 20090828 20090828 20090828 20090828 20090831 20090831 [37] 20090831 20090831 20090831 20090831 20090831 20090831 20090831 20090831 20090831 20090831 20090831 20090831 [49] 20090831 20090831 20090831 > as.Date(as.character(FnO_Data$Date[m:l]), format="%Y%M%d") [1] "2009-09-28" "2009-09-28" "2009-09-28" "2009-09-28" "2009-09-28" "2009-09-28" "2009-09-28" "2009-09-28" [9] "2009-09-28" "2009-09-28" "2009-09-28" "2009-09-28" "2009-09-28" "2009-09-28" "2009-09-28" "2009-09-28" [17] "2009-09-28" "2009-09-28" "2009-09-28" "2009-09-28" "2009-09-28" "2009-09-28" "2009-09-28" "2009-09-28" [25] "2009-09-28" "2009-09-28" "2009-09-28" "2009-09-28" "2009-09-28" "2009-09-28" "2009-09-28" "2009-09-28" [33] "2009-09-28" "2009-09-28" NA NA NA NA NA NA [41] NA NA NA NA NA NA NA NA [49] NA NA NA > sessionInfo() R version 2.11.1 (2010-05-31) i386-pc-mingw32 locale: [1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252 [3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C [5] LC_TIME=English_United Kingdom.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] zoo_1.6-4 loaded via a namespace (and not attached): [1] grid_2.11.1lattice_0.18-8 tools_2.11.1 -Original Message- From: Gabor Grothendieck [mailto:ggrothendi...@gmail.com] Sent: 18 September 2010 21:27 To: Santosh Srinivas Cc: r-help@r-project.org Subject: Re: [R] Date issues On Sat, Sep 18, 2010 at 11:25 AM, Santosh Srinivas wrote: > Strangely this is not working ... what am I doing wrong here? > >> tDate <- FnO_Data$Date[1] >> tDate > [1] 20090101 >> as.Date(c(tDate),format="%Y%m%d") > [1] NA > Do you have zoo loaded? If you do then a minimal reproducible example (see last line of every message to r-help) is: > library(zoo) > as.Date(20090101, format = "%Y%m%d") [1] NA Note that numeric arguments here are treated as the number of days since the Epoch and not as mmdd. As others have pointed out this works: > as.Date(as.character(20090101), format = "%Y%m%d") [1] "2009-01-01" -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at 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] DateDiff
Dear List, I have a column of dates say: test$date1 <- seq(19900511, to = 19900521) I want the next column to have the number of days between each subsequent date i.e days between r(i+1) and r(i) Any easy way to do this? (I've done it in a roundabout way but just wondering if there is any way more than done a loop) Thanks. __ 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] StrSplit
Newbie question ... I am looking something equivalent to read.delim but which accepts a text line as parameter instead of a file input. Below is my problem, I'm unable to get the exact output which is a simple data frame of the data where the delimiter exists ... coming quite close though I have a data frame with 10 lines called MF_Data > MF_Data [1:10] [1] "Scheme Code;Scheme Name;Net Asset Value;Repurchase Price;Sale Price;Date" [2] "" [3] "Open Ended Schemes ( Liquid )" [4] "" [5] "" [6] "AIG Global Investment Group Mutual Fund" [7] "106506;AIG India Liquid Fund-Institutional Plan-Daily Dividend Option;1001.;1001.;1001.;02-Oct-2010" [8] "106511;AIG India Liquid Fund-Institutional Plan-Growth Option;1210.4612;1210.4612;1210.4612;02-Oct-2010" [9] "106507;AIG India Liquid Fund-Institutional Plan-Weekly Dividend Option;1001.8765;1001.8765;1001.8765;02-Oct-2010" [10] "106503;AIG India Liquid Fund-Retail Plan-DailyDividend Option;1001.;1001.;1001.;02-Oct-2010" Now for the lines below .. they are delimted by ; ... I am using tempTxt <- MF_Data[7] MF_Data_F <- unlist(strsplit(tempTxt,";", fixed = TRUE)) tempTxt <- MF_Data[8] MF_Data_F1 <- unlist(strsplit(tempTxt,";", fixed = TRUE)) MF_Data_F <- rbind(MF_Data_F,MF_Data_F1) But MF_Data_F is not a simple 2X6 data frame which is what I want __ 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] StrSplit
Thanks Jim. Exactly what I needed! -Original Message- From: jim holtman [mailto:jholt...@gmail.com] Sent: 09 October 2010 22:01 To: Santosh Srinivas Cc: r-help@r-project.org Subject: Re: [R] StrSplit Is this what you are after: > x <- c("Scheme Code;Scheme Name;Net Asset Value;Repurchase Price;Sale Price;Date" + , "" + ,"Open Ended Schemes ( Liquid )" + , "" + , "" + , "AIG Global Investment Group Mutual Fund" + , "106506;AIG India Liquid Fund-Institutional Plan-Daily Dividend Option;1001.;1001.;1001.;02-Oct-2010" + , "106511;AIG India Liquid Fund-Institutional Plan-Growth Option;1210.4612;1210.4612;1210.4612;02-Oct-2010" + , "106507;AIG India Liquid Fund-Institutional Plan-Weekly Dividend Option;1001.8765;1001.8765;1001.8765;02-Oct-2010" + , "106503;AIG India Liquid Fund-Retail Plan-DailyDividend Option;1001.;1001.;1001.;02-Oct-2010") > > myData <- read.table(textConnection(x[7:10]), sep=';') > closeAllConnections() > str(myData) 'data.frame': 4 obs. of 6 variables: $ V1: int 106506 106511 106507 106503 $ V2: Factor w/ 4 levels "AIG India Liquid Fund-Institutional Plan-Daily Dividend Option",..: 1 2 3 4 $ V3: num 1001 1210 1002 1001 $ V4: num 1001 1210 1002 1001 $ V5: num 1001 1210 1002 1001 $ V6: Factor w/ 1 level "02-Oct-2010": 1 1 1 1 > myData V1 V2 V3 V4 V5 V6 1 106506 AIG India Liquid Fund-Institutional Plan-Daily Dividend Option 1001.000 1001.000 1001.000 02-Oct-2010 2 106511 AIG India Liquid Fund-Institutional Plan-Growth Option 1210.461 1210.461 1210.461 02-Oct-2010 3 106507 AIG India Liquid Fund-Institutional Plan-Weekly Dividend Option 1001.876 1001.876 1001.876 02-Oct-2010 4 106503 AIG India Liquid Fund-Retail Plan-DailyDividend Option 1001.000 1001.000 1001.000 02-Oct-2010 > > On Sat, Oct 9, 2010 at 12:18 PM, Santosh Srinivas wrote: > Newbie question ... > > I am looking something equivalent to read.delim but which accepts a text line as parameter instead of a file input. > > Below is my problem, I'm unable to get the exact output which is a simple data frame of the data where the delimiter exists ... coming quite close though > > I have a data frame with 10 lines called MF_Data >> MF_Data [1:10] > [1] "Scheme Code;Scheme Name;Net Asset Value;Repurchase Price;Sale Price;Date" > [2] "" > [3] "Open Ended Schemes ( Liquid )" > [4] "" > [5] "" > [6] "AIG Global Investment Group Mutual Fund" > [7] "106506;AIG India Liquid Fund-Institutional Plan-Daily Dividend Option;1001.;1001.;1001.;02-Oct-2010" > [8] "106511;AIG India Liquid Fund-Institutional Plan-Growth Option;1210.4612;1210.4612;1210.4612;02-Oct-2010" > [9] "106507;AIG India Liquid Fund-Institutional Plan-Weekly Dividend Option;1001.8765;1001.8765;1001.8765;02-Oct-2010" > [10] "106503;AIG India Liquid Fund-Retail Plan-DailyDividend Option;1001.;1001.;1001.;02-Oct-2010" > > > Now for the lines below .. they are delimted by ; ... I am using > > tempTxt <- MF_Data[7] > MF_Data_F <- unlist(strsplit(tempTxt,";", fixed = TRUE)) > tempTxt <- MF_Data[8] > MF_Data_F1 <- unlist(strsplit(tempTxt,";", fixed = TRUE)) > MF_Data_F <- rbind(MF_Data_F,MF_Data_F1) > > But MF_Data_F is not a simple 2X6 data frame which is what I want > > __ > 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] read.table issue
Dear R-Group, I am getting this error message "incomplete final line found by readTableHeader" in the code below. It seems to me that the error message is because of quote in the text data. Is there any easy way to handle this? Or should I do a substitute. > tempTxt <- "100589;Canara Robeco Expo-Income Plan;18.92;18.92;19.35;02-Apr-2007 + " > read.table(textConnection(tempTxt), sep=';') V1 V2V3V4V5 V6 1 100589 Canara Robeco Expo-Income Plan 18.92 18.92 19.35 02-Apr-2007 > tempTxt <- "103272;Canara Robeco Fortune '94;30.07;30.07;30.75;02-Apr-2007 + " > read.table(textConnection(tempTxt), sep=';') Error in read.table(textConnection(tempTxt), sep = ";") : incomplete final line found by readTableHeader on 'tempTxt' Thanks, Santosh __ 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] trycatch examples
Dear R-group, I am looking for some good examples on trycatch. Any pointers? The help manual seems quite limited. Thanks. __ 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] Number of occurences of a character in a string
New to R ... which is a function to most effectively search the number of occurrences of a character in a string? b <- c("jkhrikujhj345hi5hiklfjsdkljfksdio324j';;'lfd;g'lkfit34'5;435l;43'5k") I want the number of semi-colons ";" in b? Thanks. __ 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] textConnection on List
I'm trying to optimize some code that I have I have a list of delimited text in a list (see below). I want to do a read.table via a text connection so that I can get the delimited values into a table ... Something like ... tmp_MF_Data_F <- read.table(textConnection(tmpTxtList), sep=';', quote = '') ... but this fails ... Any idea how to go about it? Thanks for the help. head(tmpTxtList) [[1]] [1] "\"106270;BIRLA SUN LIFE CAPITAL PROTECTION ORIENTED FUND-3 YRS- DIVIDEND;10.3287;10.3287;0.;01-Apr-2008\"" [[2]] [1] "\"106269;BIRLA SUN LIFE CAPITAL PROTECTION ORIENTED FUND-3 YRS- GROWTH;10.3287;10.3287;0.;01-Apr-2008\"" [[3]] [1] "\"102767;Birla Sun Life Dynamic Bond Fund-Retail Plan-Growth;12.6832;12.6832;12.6832;01-Apr-2008\"" [[4]] [1] "\"102766;Birla Sun Life Dynamic Bond Fund-Retail Plan-Quarterly Dividend;10.5396;10.5396;10.5396;01-Apr-2008\"" [[5]] [1] "\"102855;Birla Sun Life Fixed Maturity Plan - Annual Series 3-Dividend;9.9830;9.7833;9.9830;01-Apr-2008\"" [[6]] [1] "\"102856;Birla Sun Life Fixed Maturity Plan - Annual Series 3-Growth;12.3964;12.1485;12.3964;01-Apr-2008\"" __ 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] textConnection on List
I think "unlist" did the trick ... I used tmpData <- unlist (tmpTxtList) tmp_MF_Data_F <- read.table(textConnection(tempTxt), sep=';', quote = '') write.table(tmp_MF_Data_F,file="MF_Data_F.txt", append=T, sep ="|", col.names=F, row.names=F, quote=F) -Original Message- From: Santosh Srinivas [mailto:santosh.srini...@gmail.com] Sent: 11 October 2010 11:05 To: 'r-help' Subject: textConnection on List I'm trying to optimize some code that I have I have a list of delimited text in a list (see below). I want to do a read.table via a text connection so that I can get the delimited values into a table ... Something like ... tmp_MF_Data_F <- read.table(textConnection(tmpTxtList), sep=';', quote = '') ... but this fails ... Any idea how to go about it? Thanks for the help. head(tmpTxtList) [[1]] [1] "\"106270;BIRLA SUN LIFE CAPITAL PROTECTION ORIENTED FUND-3 YRS- DIVIDEND;10.3287;10.3287;0.;01-Apr-2008\"" [[2]] [1] "\"106269;BIRLA SUN LIFE CAPITAL PROTECTION ORIENTED FUND-3 YRS- GROWTH;10.3287;10.3287;0.;01-Apr-2008\"" [[3]] [1] "\"102767;Birla Sun Life Dynamic Bond Fund-Retail Plan-Growth;12.6832;12.6832;12.6832;01-Apr-2008\"" [[4]] [1] "\"102766;Birla Sun Life Dynamic Bond Fund-Retail Plan-Quarterly Dividend;10.5396;10.5396;10.5396;01-Apr-2008\"" [[5]] [1] "\"102855;Birla Sun Life Fixed Maturity Plan - Annual Series 3-Dividend;9.9830;9.7833;9.9830;01-Apr-2008\"" [[6]] [1] "\"102856;Birla Sun Life Fixed Maturity Plan - Annual Series 3-Growth;12.3964;12.1485;12.3964;01-Apr-2008\"" __ 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] Dataset Transformation
I need to transpose the following input dataset into an output dataset like below Input Date TICKER Price 11/10/2010 A 0.991642 11/10/2010 B 0.475023 11/10/2010 C 0.218642 11/10/2010 D 0.365135 12/10/2010 A 0.687873 12/10/2010 B 0.47006 12/10/2010 C 0.533542 12/10/2010 D 0.812439 13/10/2010 A 0.210848 13/10/2010 B 0.699799 13/10/2010 C 0.546003 13/10/2010 D 0.152316 Output needed Date A B C D 11/10/2010 0.991642 0.475023 0.218642 0.365135 12/10/2010 0.687873 0.47006 0.533542 0.812439 13/10/2010 0.210848 0.699799 0.546003 0.152316 I tried using the aggregate function but not quite getting the method. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Dataset Transformation
Repost .. since the previous msg had problems I need to transpose the following input dataset into an output dataset like below Input DateTICKER Price 11/10/2010 A 0.991642 11/10/2010 B 0.475023 11/10/2010 C 0.218642 11/10/2010 D 0.365135 12/10/2010 A 0.687873 12/10/2010 B 0.47006 12/10/2010 C 0.533542 12/10/2010 D 0.812439 13/10/2010 A 0.210848 13/10/2010 B 0.699799 13/10/2010 C 0.546003 13/10/2010 D 0.152316 Output needed DateA B C D 11/10/2010 0.9916420.4750230.2186420.365135 12/10/2010 0.6878730.47006 0.5335420.812439 13/10/2010 0.2108480.6997990.5460030.152316 I tried using the aggregate function but not quite getting the method. __ 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] Read from a website
Something similar to this was discussed recently, but I'm unable to find the thread. I want to read from a site where I need to enter the date into a form before I am presented with the CSV link. E.g. like reading ticker data from yahoo (but assuming you HAVE to enter the dates and click on request). How do I simulate this from R? Thanks for the help. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Basic data question
I have a question about the output given below after running few lines of code. Surely a 101 query! MF_Data <- read.csv("MF_Data_F.txt", header = F, sep="|") temp <- head(MF_Data) #Get the sample Data temp1 <- subset(temp, select= c(V1,V4,V6)) #where V1, V4, V6 are the col names .. to Get the relevant data names(temp1) <- c('Ticker', 'Price','Date') #Adjusted column names Now as expected, I get: > temp1 Ticker PriceDate 1 106270 10.3287 01-Apr-2008 2 106269 10.3287 01-Apr-2008 3 102767 12.6832 01-Apr-2008 4 102766 10.5396 01-Apr-2008 5 102855 9.7833 01-Apr-2008 6 102856 12.1485 01-Apr-2008 BUT, for the below: temp1$Price [1] 10.3287 10.3287 12.6832 10.5396 9.7833 12.1485 439500 Levels: -101.2358 -102.622 -2171.1276 -6796.4926 -969.5193 ... Repurchase Price What is this line? "439500 Levels: -101.2358 -102.622 -2171.1276 -6796.4926 -969.5193 ... Repurchase Price"?? Many thanks for the help. Santosh __ 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] Drop matching lines from readLines
Dear R-group, I have some noise in my text file (coding issues!) ... I imported a 200 MB text file using readlines Used grep to find the lines with the error? What is the easiest way to drop those lines? I plan to write back the "cleaned" data set to my base file. Thanks. __ 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] Drop matching lines from readLines
I guess "invert" does the trick. For recording ... example .. file <- grep("Repurchase Price",file, fixed = TRUE, invert = TRUE) -Original Message- From: Santosh Srinivas [mailto:santosh.srini...@gmail.com] Sent: 14 October 2010 11:28 To: 'r-help' Subject: Drop matching lines from readLines Dear R-group, I have some noise in my text file (coding issues!) ... I imported a 200 MB text file using readlines Used grep to find the lines with the error? What is the easiest way to drop those lines? I plan to write back the "cleaned" data set to my base file. Thanks. __ 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] Replacing N.A values in a data frame
Hello, I have a data frame as below ... in cases where I have N.A. I want to use an average of the past date and next date .. any help? 13/10/2010 A 23 13/10/2010 B 12 13/10/2010 C 124 14/10/2010 A 43 14/10/2010 B 54 14/10/2010 C 65 15/10/2010 A 43 15/10/2010 B N.A. 15/10/2010 C 65 -- Thanks R-Helpers. __ 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] Replacing N.A values in a data frame
Wow! Thats Amazing! Many thanks! When I do the below ... why do the column names get thrown off? Ticker is a factor / character ... I tried both > temp <- head(MF_Data_Sub) > temp Date Ticker Price 1 2008-04-01 106270 10.3287 2 2008-04-01 106269 10.3287 3 2008-04-01 102767 12.6832 4 2008-04-01 102766 10.5396 5 2008-04-01 102855 9.7833 6 2008-04-01 102856 12.1485 > tZoo <- read.zoo(temp,split=2) > tZoo X102766 X102767 X102855 X102856 X106269 X106270 2008-04-01 10.5396 12.6832 9.7833 12.1485 10.3287 10.3287 Also, is there an easy way to do a return profile on the data below after it is transformed? Thanks very much! S -Original Message- From: Gabor Grothendieck [mailto:ggrothendi...@gmail.com] Sent: 14 October 2010 18:22 To: Santosh Srinivas Cc: r-help Subject: Re: [R] Replacing N.A values in a data frame On Thu, Oct 14, 2010 at 4:17 AM, Santosh Srinivas wrote: > Hello, I have a data frame as below ... in cases where I have N.A. I want > to use an average of the past date and next date .. any help? > > 13/10/2010 A 23 > 13/10/2010 B 12 > 13/10/2010 C 124 > 14/10/2010 A 43 > 14/10/2010 B 54 > 14/10/2010 C 65 > 15/10/2010 A 43 > 15/10/2010 B N.A. > 15/10/2010 C 65 Assuming A, B and C refer to separate time series you can use na.approx in zoo. Lines <- "13/10/2010 A 23 13/10/2010 B 12 13/10/2010 C 124 14/10/2010 A 43 14/10/2010 B 54 14/10/2010 C 65 15/10/2010 A 43 15/10/2010 B N.A. 15/10/2010 C 65" library(zoo) # z <- read.zoo("myfile.dat", format = "%d/%m/%Y", split = 2, na.strings = "N.A.") z <- read.zoo(textConnection(Lines), format = "%d/%m/%Y", split = 2, na.strings = "N.A.") na.approx(z) # or na.approx(z, rule = 2) which gives this multivariate time series in zoo: > na.approx(z) A B C 2010-10-13 23 12 124 2010-10-14 43 54 65 2010-10-15 43 NA 65 > # or > na.approx(z, rule = 2) A B C 2010-10-13 23 12 124 2010-10-14 43 54 65 2010-10-15 43 54 65 -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at 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.
Re: [R] Drop matching lines from readLines
Yes, thanks ... that works. -Original Message- From: Bert Gunter [mailto:gunter.ber...@gene.com] Sent: 14 October 2010 21:26 To: Mike Marchywka Cc: santosh.srini...@gmail.com; r-help@r-project.org Subject: Re: [R] Drop matching lines from readLines If I understand correctly, the poster knows what regex error pattern to look for, in which case (mod memory capacity -- but 200 mb should not be a problem, I think) is not merely cleanData <- dirtyData[!grepl("errorPatternregex",dirtyData)] sufficient? Cheers, Bert On Thu, Oct 14, 2010 at 4:05 AM, Mike Marchywka wrote: > > > > > > > >> From: santosh.srini...@gmail.com >> To: r-help@r-project.org >> Date: Thu, 14 Oct 2010 11:27:57 +0530 >> Subject: [R] Drop matching lines from readLines >> >> Dear R-group, >> >> I have some noise in my text file (coding issues!) ... I imported a 200 MB >> text file using readlines >> Used grep to find the lines with the error? >> >> What is the easiest way to drop those lines? I plan to write back the >> "cleaned" data set to my base file. > > Generally for text processing, I've been using utilities external to R > although there may be R alternatives that work better for you. You > mention grep, I've suggested sed as a general way to fix formatting things, > there is also something called "uniq" on linux or cygwin. > I have gotten into the habit of using these for a variety of data > manipulation tasks, only feed clean data into R. > > $ echo -e a bc\\na bc > a bc > a bc > > $ echo -e a bc\\na bc | uniq > a bc > > $ uniq --help > Usage: uniq [OPTION]... [INPUT [OUTPUT]] > Filter adjacent matching lines from INPUT (or standard input), > writing to OUTPUT (or standard output). > > With no options, matching lines are merged to the first occurrence. > > Mandatory arguments to long options are mandatory for short options too. > -c, --count prefix lines by the number of occurrences > -d, --repeated only print duplicate lines > -D, --all-repeated[=delimit-method] print all duplicate lines > delimit-method={none(default),prepend,separate} > Delimiting is done with blank lines > -f, --skip-fields=N avoid comparing the first N fields > -i, --ignore-case ignore differences in case when comparing > -s, --skip-chars=N avoid comparing the first N characters > -u, --unique only print unique lines > -z, --zero-terminated end lines with 0 byte, not newline > -w, --check-chars=N compare no more than N characters in lines > --help display this help and exit > --version output version information and exit > > A field is a run of blanks (usually spaces and/or TABs), then non-blank > characters. Fields are skipped before chars. > > Note: 'uniq' does not detect repeated lines unless they are adjacent. > You may want to sort the input first, or use `sort -u' without `uniq'. > Also, comparisons honor the rules specified by `LC_COLLATE'. > > > > > > > > > > >> >> Thanks. > > > __ > 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. > -- Bert Gunter Genentech Nonclinical Biostatistics __ 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] Joining together multiple csv files
I guess you could simply read the files into a loop and write into the aggregated files using write.table with append = true in the same loop -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of aenea...@priest.com Sent: 15 October 2010 08:47 To: r-help@r-project.org Subject: [R] Joining together multiple csv files Hi, This feels like a kinda dumb basic question, but I haven't been able to figure it out. I have a bunch of csv files I'd like to put into one csv using R. I have tried cat, append, join, aggregate, and a bunch of other things, but none of them really work for combining the data. If it's one of those listed, then my syntax is goofy. The csv files have different row numbers but the same columns. I just want to add each one to the end of the other. I've removed the heading from all but one of them (but I could easily get the headings all back if that helps). Thanks for the help! Tyler [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-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] Downloading file with lapply
I'm still getting familiar with lapply I have this date sequence x <- seq(as.Date("01-Jan-2010",format="%d-%b-%Y"), Sys.Date(), by=1) #to generate series of dates I want to apply the function for all values of x . so I use lapply (Still a newbie!) I wrote this test function pFun <- function (x) { print(paste("This is: ",x,sep="")) } When I run it: > lapply(x,pFun(x)) It gives the result correctly.. but end with an error Error in match.fun(FUN) : 'pFun(x)' is not a function, character or symbol Question 1: What is the issue here?? Now, to the real problem. I wrote a function to cmDownFun(sDate)which is working correctly If I do cmDownFun (x[6]) .. it works correctly .. (i.e. my function was ok this time around!) Hoewever if I do, lapply (x,cmDownFun(x)) It fails at 01-Jan-2010 this is because of: HTTP status was '404 Not Found' This is OK, because the file does not exist ... but I want to continue for the remaining values of x lapply(x,try(cmDownFun(x),silent = TRUE)) .. does not work I also put the try inside the function itself but does not work either. -- Thanks R-Helpers. Yes, this is a silly question and it will not be repeated! :-) __ 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] Downloading file with lapply
Thx. -Original Message- From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de] Sent: 15 October 2010 13:11 To: Santosh Srinivas Cc: r-help@r-project.org Subject: Re: [R] Downloading file with lapply On 15.10.2010 09:19, Santosh Srinivas wrote: > I'm still getting familiar with lapply > > I have this date sequence > x<- seq(as.Date("01-Jan-2010",format="%d-%b-%Y"), Sys.Date(), by=1) #to > generate series of dates > > I want to apply the function for all values of x . so I use lapply (Still a > newbie!) > I wrote this test function > pFun<- function (x) { >print(paste("This is: ",x,sep="")) >} > > > When I run it: >> lapply(x,pFun(x)) > > It gives the result correctly.. but end with an error > > Error in match.fun(FUN) : >'pFun(x)' is not a function, character or symbol > > Question 1: What is the issue here?? You have to pass the function, not to call it already: lapply(x, pFun) > > Now, to the real problem. I wrote a function to cmDownFun(sDate)which is > working correctly > If I do cmDownFun (x[6]) .. it works correctly .. (i.e. my function was ok > this time around!) > > Hoewever if I do, lapply (x,cmDownFun(x)) > It fails at 01-Jan-2010 this is because of: HTTP status was '404 Not > Found' > > This is OK, because the file does not exist ... but I want to continue for > the remaining values of x > lapply(x,try(cmDownFun(x),silent = TRUE)) .. does not work > I also put the try inside the function itself but does not work either. Then either use try() in cmDownFun directly or use an anonymous function rather than a call, again: lapply(x, function(x) try(cmDownFun(x),silent = TRUE)) Uwe Ligges > > > > -- > Thanks R-Helpers. Yes, this is a silly question and it will not be repeated! > :-) > > __ > 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] R & MySQL (Databases)
Dear R-helpers, Considering that a substantial part of analysis is related data manipulation, I'm just wondering if I should do the basic data part in a database server (currently I have the data in .txt file). For this purpose, I am planning to use MySQL. Is MySQL a good way to go about? Are there any anticipated problems that I need to be aware of? Considering, that many users here use large datasets. Do you typical store the data in databases and query relevant portions for your analysis? Does it speed up the entire process? Is it neater to do things in a database? (for e.g. errors could corrected at data import stage itself by conditions in defining the data itself in the database as opposed to discovering things when you do the analysis in R and realize something is wrong in the output?) This is vis-à-vis using the built in SQLLite, indexing, etc capabilities in R itself? Does performance work better with a database backend (especially for simple but large datasets)? The financial applications that I am thinking of are not exactly realtime but quick response and fast performance would definitely help. Aside info, I want to take things to a cloud environment at some point of time just because it will be easier and cheaper to deliver. Kind of an open question, but any inputs will 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] Class mode text isopen can read can write - too many open connections
I am downloading data files using RCurl and everything works except till some limit is hit and says too many connections open It is a simple download using URL and I am writing the status in a tryCatch block to a log file. showConnections() description class mode text isopen can read can write > showConnections(all=T) description class mode text isopen can read can write 0 "stdin" "terminal" "r" "text" "opened" "yes""no" 1 "stdout""terminal" "w" "text" "opened" "no" "yes" 2 "stderr""terminal" "w" "text" "opened" "no" "yes" I tried closeAllConnections() but of no use. When I try to delete a downloaded file . It says cannot be done because "folder is open in R GUI front end" Any idea how to resolve this? > sessionInfo() R version 2.11.1 (2010-05-31) i386-pc-mingw32 locale: [1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C LC_TIME=English_United Kingdom.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] RCurl_1.4-4.1 bitops_1.0-4.1 zoo_1.6-4 loaded via a namespace (and not attached): [1] grid_2.11.1 lattice_0.19-11 tools_2.11.1 > __ 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] Basic structure operations doubt
I'm doing these manipulations on the data frame and wondering why does R have to remember historical data on my operation and not just keep the needed info. Probably a basic fundamentals of the way R handles data .. Pls point me to the manual if possible .. I have this Index data: > head(NIFTY_INDX) Constituents.list.of.S.P.CNX.Nifty X X.1 X.2 X.3 1 2 Company Name IndustrySymbol SeriesISIN Code 3 4 ACC Ltd. CEMENT AND CEMENT PRODUCTS ACC EQ INE012A01025 5Ambuja Cements Ltd. CEMENT AND CEMENT PRODUCTS AMBUJACEM EQ INE079A01024 6 Axis Bank Ltd. BANKS AXISBANK EQ INE238A01026 I Import the section that is relevant to me: > Indx_Constituents <- NIFTY_INDX[4:NROW(NIFTY_INDX),] > head(Indx_Constituents) Constituents.list.of.S.P.CNX.Nifty X X.1 X.2 X.3 4 ACC Ltd. CEMENT AND CEMENT PRODUCTS ACC EQ INE012A01025 5Ambuja Cements Ltd. CEMENT AND CEMENT PRODUCTS AMBUJACEM EQ INE079A01024 6 Axis Bank Ltd. BANKS AXISBANK EQ INE238A01026 7Bajaj Auto Ltd. AUTOMOBILES - 2 AND 3 WHEELERS BAJAJ-AUTO EQ INE917I01010 8 Bharat Heavy Electricals Ltd. ELECTRICAL EQUIPMENT BHEL EQ INE257A01018 9 Bharat Petroleum Corporation Ltd. REFINERIES BPCL EQ INE029A01011 > colNames <- NIFTY_INDX[2,] > colNames Constituents.list.of.S.P.CNX.NiftyXX.1X.2 X.3 2 Company Name Industry Symbol Series ISIN Code I want to assign the info from colNames[1,] to Indx_Constituents I am unable to do this directly ... I can probably pull out the values and do it but there should be an easier way Now when I do this: > colNames[1,1] [1] Company Name 52 Levels: ACC Ltd. Ambuja Cements Ltd. Axis Bank Ltd. Bajaj Auto Ltd. Bharat Heavy Electricals Ltd. Bharat Petroleum Corporation Ltd. Bharti Airtel Ltd. Cairn India Ltd. Cipla Ltd. Company Name ... Wipro Ltd. Why does R have to remember the 52 levels?? Why can't it just have the relevant data stored What are the alternatives so that I can simply have my needed data in my data frames? Thanks for your explanation. -- Thanks R-Helpers. Yes, this is a silly question and it will not be repeated! :-) __ 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] Class mode text isopen can read can write - too many open connections
I'm basically doing using code: NOTE THIS IS A RECURSIVE DOWNLOAD ... SO CHANGE TO A DIRECTORY THAT YOU WANT TO JUNK ... After the download ... try deleting the data without closing R and it says the file is currently held "open" by R ... Not sure how I can close that connection .. Please let me know any "release" operations that I ened to add in the code too. library(zoo) library("RCurl") x <- seq(as.Date("01-Jan-2010",format="%d-%b-%Y"), Sys.Date(), by=1) #to generate series of dates #sDate <- x[6] cmDownFun <- function (sDate) { sMonth <- casefold( as.character(sDate,format="%b"),upper=T) #Get the month sYear <- casefold( as.character(sDate,format="%Y"),upper=T) #Get the month sDate1 <- casefold( as.character(sDate, format="%d%b%Y"), upper =T) #Get the date sURL <- paste("http://www.nseindia.com/content/historical/EQUITIES/",sYear,"/",sMonth,"/cm",sDate1,"bhav.csv.zip";, sep="") tryCatch( { download.file(sURL,paste("CM",sDate1,".zip",sep="")) #download the file print (paste("Successfully downloaded:", paste("CM",sDate1,".zip",sep=""))) write(paste("Successfully downloaded:", paste("CM",sDate1,".zip",sep="")),file = "Success-Log.txt",append=TRUE,sep="\n") closeAllConnections() }, warning = function (ex){ print(paste("Failed to download:", paste("CM",sDate1,".zip",sep="")),file = "Failure-Log.txt",append=TRUE,sep="\n") write(paste("Failed to download:", paste("CM",sDate1,".zip",sep="")),file = "Failure-Log.txt",append=TRUE,sep="\n") closeAllConnections() }) } #lapply(x, function(x) try(cmDownFun(x),silent = TRUE)) lapply(x, cmDownFun) -Original Message- From: Joshua Wiley [mailto:jwiley.ps...@gmail.com] Sent: 17 October 2010 21:39 To: Santosh Srinivas Cc: r-help@r-project.org Subject: Re: [R] Class mode text isopen can read can write - too many open connections Hi, Is it a public URL (i.e., that we can try downloading from too)? Do you get the same error now matter where/what you download or just from that one place? Finally, if you are using Windows > XP, are you running R as an administrator (or very sure that the log file or whatever else you are creating is not being written to some place that Windows will try to restrict such as in Programs)? Cheers, Josh On Sun, Oct 17, 2010 at 8:57 AM, Santosh Srinivas wrote: > I am downloading data files using RCurl and everything works except till > some limit is hit and says too many connections open > It is a simple download using URL and I am writing the status in a tryCatch > block to a log file. > > > showConnections() > � � description class mode text isopen can read can write >> showConnections(all=T) > �description class � � �mode text � isopen � can read can write > 0 "stdin" � � "terminal" "r" �"text" "opened" "yes" � �"no" > 1 "stdout" � �"terminal" "w" �"text" "opened" "no" � � "yes" > 2 "stderr" � �"terminal" "w" �"text" "opened" "no" � � "yes" > > I tried closeAllConnections() but of no use. > > When I try to delete a downloaded file . It says cannot be done because > "folder is open in R GUI front end" > > Any idea how to resolve this? > >> sessionInfo() > R version 2.11.1 (2010-05-31) > i386-pc-mingw32 > > locale: > [1] LC_COLLATE=English_United Kingdom.1252 �LC_CTYPE=English_United > Kingdom.1252 � �LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C > LC_TIME=English_United Kingdom.1252 > > attached base packages: > [1] stats � � graphics �grDevices utils � � datasets �methods � base > > other attached packages: > [1] RCurl_1.4-4.1 �bitops_1.0-4.1 zoo_1.6-4 > > loaded via a namespace (and not attached): > [1] grid_2.11.1 � � lattice_0.19-11 tools_2.11.1 >> > > __ > 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 Ph.D. Student, Health Psychology University of California, Los Angeles 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] Basic structure operations doubt
Thanks Josh. At your convenience, Any pointers on why this was designed like this? i.e. shouldn’t droplevels() be the default behavior? I'm missing something in understanding on how these operations (manipulations) were designed to work. -Original Message- From: Joshua Wiley [mailto:jwiley.ps...@gmail.com] Sent: 18 October 2010 07:47 To: Santosh Srinivas Cc: r-help@r-project.org Subject: Re: [R] Basic structure operations doubt Hi, The easiest way to get rid of the empty levels is with droplevels(). See ?droplevels for details. It actually has a method for data frames even. So you could just do something like: Indx_Constituents <- droplevels(Indx_Constituents) or whatever your data frame was called and it will drop any unused levels for you. Cheers, Josh On Sun, Oct 17, 2010 at 7:06 PM, Santosh Srinivas wrote: > I'm doing these manipulations on the data frame and wondering why does R > have to remember historical data on my operation and not just keep the > needed info. > Probably a basic fundamentals of the way R handles data .. Pls point me to > the manual if possible .. > > I have this Index data: >> head(NIFTY_INDX) > �Constituents.list.of.S.P.CNX.Nifty � � � � � � � � � � � � �X � � � X.1 > X.2 � � � � �X.3 > 1 > > 2 � � � � � � � � � � � Company Name � � � � � � � � � Industry � �Symbol > Series � �ISIN Code > 3 > > 4 � � � � � � � � � � � � � ACC Ltd. CEMENT AND CEMENT PRODUCTS � � � ACC > EQ INE012A01025 > 5 � � � � � � � �Ambuja Cements Ltd. CEMENT AND CEMENT PRODUCTS AMBUJACEM > EQ INE079A01024 > 6 � � � � � � � � � � Axis Bank Ltd. � � � � � � � � � � �BANKS �AXISBANK > EQ INE238A01026 > > > I Import the section that is relevant to me: > >> Indx_Constituents <- NIFTY_INDX[4:NROW(NIFTY_INDX),] >> head(Indx_Constituents) > �Constituents.list.of.S.P.CNX.Nifty � � � � � � � � � � � � � � �X > X.1 X.2 � � � � �X.3 > 4 � � � � � � � � � � � � � ACC Ltd. � � CEMENT AND CEMENT PRODUCTS > ACC �EQ INE012A01025 > 5 � � � � � � � �Ambuja Cements Ltd. � � CEMENT AND CEMENT PRODUCTS > AMBUJACEM �EQ INE079A01024 > 6 � � � � � � � � � � Axis Bank Ltd. � � � � � � � � � � � � �BANKS > AXISBANK �EQ INE238A01026 > 7 � � � � � � � � � �Bajaj Auto Ltd. AUTOMOBILES - 2 AND 3 WHEELERS > BAJAJ-AUTO �EQ INE917I01010 > 8 � � �Bharat Heavy Electricals Ltd. � � � � � ELECTRICAL EQUIPMENT > BHEL �EQ INE257A01018 > 9 �Bharat Petroleum Corporation Ltd. � � � � � � � � � � REFINERIES > BPCL �EQ INE029A01011 > > >> colNames <- NIFTY_INDX[2,] >> colNames > �Constituents.list.of.S.P.CNX.Nifty � � � �X � �X.1 � �X.2 � � � X.3 > 2 � � � � � � � � � � � Company Name Industry Symbol Series ISIN Code > > > I want to assign the info from colNames[1,] to Indx_Constituents I am > unable to do this directly ... I can probably pull out the values and do it > but there should be an easier way > > > Now when I do this: >> colNames[1,1] > [1] Company Name > 52 Levels: �ACC Ltd. Ambuja Cements Ltd. Axis Bank Ltd. Bajaj Auto Ltd. > Bharat Heavy Electricals Ltd. Bharat Petroleum Corporation Ltd. Bharti > Airtel Ltd. Cairn India Ltd. Cipla Ltd. Company Name ... Wipro Ltd. > > Why does R have to remember the 52 levels?? Why can't it just have the > relevant data stored > What are the alternatives so that I can simply have my needed data in my > data frames? > > Thanks for your explanation. > > > > -- > Thanks R-Helpers. Yes, this is a silly question and it will not be repeated! > :-) > > __ > 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 Ph.D. Student, Health Psychology University of California, Los Angeles 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] read.zoo issues
I am getting problems using read.zoo I have the following data frame > head(anlyNiftyDat[,1:10]) TIMESTAMPACC AMBUJACEM AXISBANK BAJAJ-AUTO BHARTIARTL BHEL BPCL CAIRN CIPLA 1 2010-01-04 00:00:00 913.60106.10 992.101732.05 325.20 2426.10 650.75 285.50 337.55 2 2010-01-05 00:00:00 901.75105.30 1012.801740.05 330.35 2435.40 640.95 295.85 331.50 3 2010-01-06 00:00:00 907.60105.95 995.801713.15 326.85 2426.25 631.30 299.45 344.90 4 2010-01-07 00:00:00 913.35105.80 1002.851683.10 329.40 2409.50 619.05 307.85 342.05 5 2010-01-08 00:00:00 912.15105.90 1015.951655.25 325.05 2424.10 629.55 306.15 341.10 6 2010-01-11 00:00:00 915.15106.10 1049.401669.55 328.95 2396.95 627.90 300.15 342.30 > class(anlyNiftyDat) [1] "cast_df""data.frame" > > anlyNiftyDatZoo <- read.zoo(anlyNiftyDat,split=2,check.names=F) > head(anlyNiftyDatZoo[,1:10]) X805.45.1 X805.45.2 X805.45.3 X805.45.4 X805.45.5 X805.45.6 X805.45.7 X805.45.8 X805.45.9 X805.45.10 2010-01-04NANANANANANA NANANA NA 2010-01-05NANANANANANA NANANA NA 2010-01-06NANANANANANA NANANA NA 2010-01-07NANANANANANA NANANA NA 2010-01-08NANANANANANA NANANA NA 2010-01-11NANANANANANA NANANA NA Both the column names and values are thrown off. __ 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] Directive for first and last array arguments
X[1,1] .. first x[NROW(x),NCOL(x)] for last element and so on Is this what you need? -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Alaios Sent: 18 October 2010 15:59 To: Rhelp Subject: [R] Directive for first and last array arguments Hello everyone, could you help me learn if there are any directives that can be used to address the first and last element of a matrix array? I would like to thank you in advance for your help Best Regards Alex [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-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] read.zoo issues
Okay ... now I gotcha ... Thanks -Original Message- From: Gabor Grothendieck [mailto:ggrothendi...@gmail.com] Sent: 18 October 2010 17:19 To: Santosh Srinivas Cc: r-help@r-project.org Subject: Re: [R] read.zoo issues On Mon, Oct 18, 2010 at 4:24 AM, Santosh Srinivas wrote: > I am getting problems using read.zoo > > I have the following data frame > >> head(anlyNiftyDat[,1:10]) > TIMESTAMP ACC AMBUJACEM AXISBANK BAJAJ-AUTO BHARTIARTL > BHEL BPCL CAIRN CIPLA > 1 2010-01-04 00:00:00 913.60 106.10 992.10 1732.05 325.20 > 2426.10 650.75 285.50 337.55 > 2 2010-01-05 00:00:00 901.75 105.30 1012.80 1740.05 330.35 > 2435.40 640.95 295.85 331.50 > 3 2010-01-06 00:00:00 907.60 105.95 995.80 1713.15 326.85 > 2426.25 631.30 299.45 344.90 > 4 2010-01-07 00:00:00 913.35 105.80 1002.85 1683.10 329.40 > 2409.50 619.05 307.85 342.05 > 5 2010-01-08 00:00:00 912.15 105.90 1015.95 1655.25 325.05 > 2424.10 629.55 306.15 341.10 > 6 2010-01-11 00:00:00 915.15 106.10 1049.40 1669.55 328.95 > 2396.95 627.90 300.15 342.30 > >> class(anlyNiftyDat) > [1] "cast_df" "data.frame" >> > >> anlyNiftyDatZoo <- read.zoo(anlyNiftyDat,split=2,check.names=F) >> head(anlyNiftyDatZoo[,1:10]) > X805.45.1 X805.45.2 X805.45.3 X805.45.4 X805.45.5 X805.45.6 > X805.45.7 X805.45.8 X805.45.9 X805.45.10 > 2010-01-04 NA NA NA NA NA NA > NA NA NA NA > 2010-01-05 NA NA NA NA NA NA > NA NA NA NA > 2010-01-06 NA NA NA NA NA NA > NA NA NA NA > 2010-01-07 NA NA NA NA NA NA > NA NA NA NA > 2010-01-08 NA NA NA NA NA NA > NA NA NA NA > 2010-01-11 NA NA NA NA NA NA > NA NA NA NA > > Both the column names and values are thrown off. There is no reason to think that read.zoo should be able to understand cast_df objects from the reshape package. Use the reshape2 package instead which produces ordinary data frames rather than cast_df objects. -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at 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] Download.file problem
Strange problem with download.file . for non existent URL an empty file is created but I am not able to delete the without shutting down R Example: > download.file("http://test.com/test.txt","test.txt";) trying URL 'http://test.com/test.txt' Error in download.file("http://test.com/test.txt";, "test.txt") : cannot open URL 'http://test.com/test.txt' In addition: Warning message: In download.file("http://test.com/test.txt";, "test.txt") : cannot open: HTTP status was '404 Not Found' If you go to working directory through windows explorer, you can see the empty file test.txt but try deleteting the file and it says that the file is locked. I tried closeAllConnections() but of no use. Any suggestions? Thanks, S __ 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 -> RE: Download.file problem
Dear R-helpers ... any thoughts on the below issue ... will help me complete a small project! Strange problem with download.file . for non existent URL an empty file is created but I am not able to delete the without shutting down R Example: > download.file("http://test.com/test.txt","test.txt";) trying URL 'http://test.com/test.txt' Error in download.file("http://test.com/test.txt";, "test.txt") : cannot open URL 'http://test.com/test.txt' In addition: Warning message: In download.file("http://test.com/test.txt";, "test.txt") : cannot open: HTTP status was '404 Not Found' If you go to working directory through windows explorer, you can see the empty file test.txt but try deleteting the file and it says that the file is locked. I tried closeAllConnections() but of no use. Any suggestions? Thanks, S __ 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] If Statement with more than one condition
I'm unable to find the OR operator like other language .. any suggestions? I want to do If (condition1 OR condition 2){ do something } Thanks for answering this elementary question. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] dbWriteTable
I'm having a strange problem with dbWriteTable ... I have the dbWriteTable inside a batchloop. dbWriteTable(con,"mutual_funds",tmp_MF_Data_F,append=T,row.names=F) # append rows to the data table The data gets updated for the first 3 loops (out of say 100) but then there is no error and data doesn't update. The command is getting executed without a problem but the data does not get updated in the database. Any suggestions? I used debug I Revo and the dataframe that I am using to update MySQL seems to be fine. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Extract table from a webpage
Dear R-group, I've been able to use the XML package for getting relevant tables from webpages for my analysis. I'm stuck with this slightly more interactive problem involving clicking a link Fro this link . http://www.etintelligence.com/etig/et500/et500Ranking.jsp I want to get the data table into R. I was able to do it using XML .. but now I want to get the whole list of 500 companies . for this . I need to find a way to click on the "View All" link and then get the data into R (hopefully). Any suggestions how to go about it? Thanks, S __ 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] Best IDE for R
Dear R-Group, I am looking for suggestions for the "best" IDE for R. Best is obviously subjective but I need just the basic features that should function well (and I looked through the threads already). - Proper integration with R 2.11.1 - Good key shortcuts ... similar to the R Gui - Manageability of Projects, etc. - Neat formatting features I tried Revolution R but it seems huge in size for something my basic needs and keep throwing up configuration problems. I tried Komodo. It works fine but having problems with "proper" integration into R and unable to do debugging. Any help? Thanks, S __ 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] R and Matlab
Dear Group, I am looking for ways to use R and Matlab. Doing the data transformations in R and using the data in Matlab to analyze with some pre-defined scripts. Any good ways to transfer the data into matlab in its most recent version? I tried using R.matlab but the writeMat output is not readable by Matlab. I just need to output a data.frame and read it as is into matlab where I can do any needed transformations on the variables. Thanks, S __ 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] transforming a dataset for association analysis
A more usable problem input would definitely help ... use dput to send a reproducible sample to the group Think the below should solve your problem > read.csv("Book1.csv") Subject Item Score 1 Subject 1 Item 1 1 2 Subject 1 Item 2 0 3 Subject 1 Item 3 1 4 Subject 2 Item 1 1 5 Subject 2 Item 2 1 6 Subject 2 Item 3 0 > library("reshape2") > tDat.m <- melt(tDat) > tDatCast <- acast(tDat.m,Subject~Item) > tDatCast Item 1 Item 2 Item 3 Subject 1 1 0 1 Subject 2 1 1 0 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ajay Ohri Sent: 30 October 2010 16:27 To: Rhelp Subject: [R] transforming a dataset for association analysis Hi I would like to transform a data frame like SubjectItem Score Subject 1 Item 1 1 Subject 1 Item 2 0 Subject 1 Item 3 1 Subject 2 Item 1 1 Subject 2 Item 2 1 Subject 2 Item 3 0 *to * Subject Item1 Item2 Item3 .Item N Subject1 1 0 1 Subject2 1 10 SubjectP.. Apologize for the simple nature of my query but I am stuck. How can I do this transformation? Regards Ajay Websites- http://decisionstats.com http://dudeofdata.com Linkedin- www.linkedin.com/in/ajayohri On Sat, Oct 30, 2010 at 2:39 PM, Alaios wrote: > Hello everyone. > I have written quite a big function that at the end correctly returns the > values > I want. I found a rare exception that I want to cover also. The easier for > me > would be to write something like that > > > function(){ > > if (rare exception happened) > return that value > > # The comes the code for normal execution > # ... > # ... > return value # Normal values to return > > } > > > > Would that be feasible with R or two returns statements are not accepted? > > Regards > Alex > > > >[[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-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] Downloading Package Sources
Dear Group, any idea how I can download the source code for all packages in Windows 7? __ 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] write.csv changes the format of the date
Dear Group, Why does write.csv modify the date format when it write to a file. I have the following variable Param_Dat: dput(Param_Dat) structure(list(Last_Successful_Run = structure(1L, .Label = "30/10/2010", class = "factor")), .Names = "Last_Successful_Run", class = "data.frame", row.names = c(NA, -1L)) When I do: write.csv(Param_Dat,"Param.csv",quote=F,row.names=F) The format of the info in the file is: Last_Successful_Run 31OCT2010 I want to retain the dd/mm/ format ... Please advise. -- Thanks R-Helpers. Yes, this is a silly question and it will not be repeated! :-) __ 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] File Downloading Problem
Dear Group, My code stopped working ... used to work till last week! sURL <- "http://www.nseindia.com/content/historical/EQUITIES/2010/NOV/cm01NOV2010bha v.csv.zip" > download.file(sURL,"test.zip") trying URL 'http://www.nseindia.com/content/historical/EQUITIES/2010/NOV/cm01NOV2010bha v.csv.zip' Error in download.file(sURL, "test.zip") : cannot open URL 'http://www.nseindia.com/content/historical/EQUITIES/2010/NOV/cm01NOV2010bha v.csv.zip' In addition: Warning message: In download.file(sURL, "test.zip") : cannot open: HTTP status was '403 Forbidden' I put the same URL in a browser and it works just fine. Any idea why? Thanks, S __ 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] write.csv changes the format of the date
Hi David, Its strange ... when I run this separately it works ... but I when I do in my function it changes the format. I just opened it using Notepad. -Original Message- From: David Winsemius [mailto:dwinsem...@comcast.net] Sent: 01 November 2010 19:15 To: Santosh Srinivas Cc: 'Rhelp' Subject: Re: [R] write.csv changes the format of the date On Nov 1, 2010, at 9:14 AM, Santosh Srinivas wrote: > Dear Group, > > Why does write.csv modify the date format when it write to a file. > > I have the following variable Param_Dat: > > dput(Param_Dat) > structure(list(Last_Successful_Run = structure(1L, .Label = > "30/10/2010", > class = "factor")), .Names = "Last_Successful_Run", class = > "data.frame", > row.names = c(NA, > -1L)) > > > When I do: > write.csv(Param_Dat,"Param.csv",quote=F,row.names=F) > > The format of the info in the file is: > Last_Successful_Run > 31OCT2010 Unable to reproduce. When I execute that code I get this file: Last_Successful_Run 30/10/2010 I'm guessing you are viewing that file with something other than a plain text editor. > > I want to retain the dd/mm/ format ... > > Please advise. -- David Winsemius, MD West Hartford, CT > sessionInfo() R version 2.11.1 Patched (2010-06-14 r52281) x86_64-apple-darwin9.8.0 locale: [1] en_US/en_US/en_US/C/en_US/en_US attached base packages: [1] splines stats graphics grDevices utils datasets methods [8] base other attached packages: [1] Hmisc_3.8-1 survival_2.35-8 dismo_0.5-6 rJava_0.8-7 [5] raster_1.5-16 sp_0.9-72 sos_1.2-9 brew_0.1-1 [9] lattice_0.18-8 loaded via a namespace (and not attached): [1] cluster_1.12.3 grid_2.11.1tools_2.11.1 __ 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] File Downloading Problem
Nope Duncan ... no changes .. the same old way without a proxy ... actually the download.file is being returned "403 forbidden" which is strange. These are just two lines that I am trying to run. sURL<- "http://www.nseindia.com/content/historical/EQUITIES/2010/NOV/cm01NOV2010bha v.csv.zip" download.file(sURL,"test.zip") Put the same URL in a browser and it works fine. -Original Message- From: Duncan Murdoch [mailto:murdoch.dun...@gmail.com] Sent: 01 November 2010 19:04 To: Santosh Srinivas Cc: 'Rhelp' Subject: Re: [R] File Downloading Problem On 01/11/2010 9:22 AM, Santosh Srinivas wrote: > Dear Group, > > My code stopped working ... used to work till last week! > > sURL<- > "http://www.nseindia.com/content/historical/EQUITIES/2010/NOV/cm01NOV2010bha > v.csv.zip" > > > download.file(sURL,"test.zip") > trying URL > 'http://www.nseindia.com/content/historical/EQUITIES/2010/NOV/cm01NOV2010bha > v.csv.zip' > Error in download.file(sURL, "test.zip") : >cannot open URL > 'http://www.nseindia.com/content/historical/EQUITIES/2010/NOV/cm01NOV2010bha > v.csv.zip' > In addition: Warning message: > In download.file(sURL, "test.zip") : >cannot open: HTTP status was '403 Forbidden' > > I put the same URL in a browser and it works just fine. Are you using a proxy? If you've recently updated R, you may have told it not to use the proxy. You can test this by running setInternet2(TRUE) (which will use a proxy if one is defined in Internet Explorer) and repeating the download.file() call. You can make Internet2 the default by putting --internet2 on the command line when you start R. Duncan Murdoch __ 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] File Downloading Problem
It's strange and the internet connection is fine because I am able to get data from yahoo. This was working till just yesterday ... strange if the website is creating issues with public access of basic data! -Original Message- From: David Winsemius [mailto:dwinsem...@comcast.net] Sent: 01 November 2010 20:48 To: Duncan Murdoch Cc: Santosh Srinivas; 'Rhelp' Subject: Re: [R] File Downloading Problem On Nov 1, 2010, at 10:41 AM, Duncan Murdoch wrote: > On 01/11/2010 10:37 AM, Santosh Srinivas wrote: >> Nope Duncan ... no changes .. the same old way without a proxy ... >> actually >> the download.file is being returned "403 forbidden" which is strange. >> >> These are just two lines that I am trying to run. >> >> sURL<- >> "http://www.nseindia.com/content/historical/EQUITIES/2010/NOV/cm01NOV2010bha >> v.csv.zip" >> download.file(sURL,"test.zip") >> >> Put the same URL in a browser and it works fine. > > It doesn't work for me, so presumably there is some kind of security > setting at the site (a cookie?), which allows your browser, but > doesn't allow you to use R, or me to use anything. Firefox in a Mac platform will download and unzip the file with no security complaints and no cookie appears to be set when downloading, but that code will not access the file, nor will my efforts to wrap the URL in url() or unz() so it seems more likely that Santosh and I do not understand the file opening processes that R supports. > con= unz(description="http://www.nseindia.com/content/historical/EQUITIES/2010/NO V/cm01NOV2010bhav.csv.zip ", file="~/cm01NOV2010bhav.csv") > test.df <- read.csv(file=con) Error in open.connection(file, "rt") : cannot open the connection In addition: Warning message: In open.connection(file, "rt") : cannot open zip file 'http://www.nseindia.com/content/historical/EQUITIES/2010/NOV/cm01NOV2010bha v.csv.zip' -- David. > > Duncan Murdoch > >> -Original Message- >> From: Duncan Murdoch [mailto:murdoch.dun...@gmail.com] >> Sent: 01 November 2010 19:04 >> To: Santosh Srinivas >> Cc: 'Rhelp' >> Subject: Re: [R] File Downloading Problem >> >> On 01/11/2010 9:22 AM, Santosh Srinivas wrote: >> > Dear Group, >> > >> > My code stopped working ... used to work till last week! >> > >> > sURL<- >> > >> "http://www.nseindia.com/content/historical/EQUITIES/2010/NOV/cm01NOV2010bha >> > v.csv.zip" >> > >> > > download.file(sURL,"test.zip") >> > trying URL >> > >> 'http://www.nseindia.com/content/historical/EQUITIES/2010/NOV/cm01NOV2010bha >> > v.csv.zip' >> > Error in download.file(sURL, "test.zip") : >> > cannot open URL >> > >> 'http://www.nseindia.com/content/historical/EQUITIES/2010/NOV/cm01NOV2010bha >> > v.csv.zip' >> > In addition: Warning message: >> > In download.file(sURL, "test.zip") : >> > cannot open: HTTP status was '403 Forbidden' >> > >> > I put the same URL in a browser and it works just fine. >> >> >> Are you using a proxy? If you've recently updated R, you may have >> told >> it not to use the proxy. You can test this by running >> >> setInternet2(TRUE) >> >> (which will use a proxy if one is defined in Internet Explorer) and >> repeating the download.file() call. You can make Internet2 the >> default >> by putting --internet2 on the command line when you start R. >> >> Duncan Murdoch >> > > __ > 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. David Winsemius, MD West Hartford, CT __ 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] File Downloading Problem
Thanks Duncan and Alex. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Duncan Temple Lang Sent: 01 November 2010 22:34 To: r-help@r-project.org Subject: Re: [R] File Downloading Problem I got this working almost immediately with RCurl although with that one has to specify any value for the useragent option, or the same error occurs. The issue is that R does not add an Accept entry to the HTTP request header. It should add something like Accept: *.* Using RCurl, u = "http://www.nseindia.com/content/historical/EQUITIES/2010/NOV/cm01NOV2010bha v.csv.zip" o = getURLContent(u, verbose = TRUE, useragent = getOption("HTTPUserAgent")) succeeds (but not if there is no useragent). We could fix R's download.file() to send Accept: *.*, or allow general headers to be specified either as an option for all requests, or as a parameter of download.file() (or both). Or we could have the makeUserAgent() function in utils be more customizable through options, or allow the R user specify the function herself. But while this would be good, the HTTP facilities in R are not intended to be as general something like libcurl (and hence RCurl). Unless there is a compelling reason to enhance R's internal facilities, I suggest people use something like libcurl. This approach also has the advantage of having the data directly in memory and avoiding writing it to disk and then reading it back in, e.g. library(Rcompression) z = zipArchive(o) names(z) read.csv(textConnection(z[[1]])) D. On 11/1/10 8:27 AM, Santosh Srinivas wrote: > It's strange and the internet connection is fine because I am able to get > data from yahoo. > This was working till just yesterday ... strange if the website is creating > issues with public access of basic data! > > -Original Message- > From: David Winsemius [mailto:dwinsem...@comcast.net] > Sent: 01 November 2010 20:48 > To: Duncan Murdoch > Cc: Santosh Srinivas; 'Rhelp' > Subject: Re: [R] File Downloading Problem > > > On Nov 1, 2010, at 10:41 AM, Duncan Murdoch wrote: > >> On 01/11/2010 10:37 AM, Santosh Srinivas wrote: >>> Nope Duncan ... no changes .. the same old way without a proxy ... >>> actually >>> the download.file is being returned "403 forbidden" which is strange. >>> >>> These are just two lines that I am trying to run. >>> >>> sURL<- >>> > "http://www.nseindia.com/content/historical/EQUITIES/2010/NOV/cm01NOV2010bha >>> v.csv.zip" >>> download.file(sURL,"test.zip") >>> >>> Put the same URL in a browser and it works fine. >> >> It doesn't work for me, so presumably there is some kind of security >> setting at the site (a cookie?), which allows your browser, but >> doesn't allow you to use R, or me to use anything. > > Firefox in a Mac platform will download and unzip the file with no > security complaints and no cookie appears to be set when downloading, > but that code will not access the file, nor will my efforts to wrap > the URL in url() or unz() so it seems more likely that Santosh and I > do not understand the file opening processes that R supports. > > > con= > unz(description="http://www.nseindia.com/content/historical/EQUITIES/2010/NO > V/cm01NOV2010bhav.csv.zip > ", file="~/cm01NOV2010bhav.csv") > > test.df <- read.csv(file=con) > Error in open.connection(file, "rt") : cannot open the connection > In addition: Warning message: > In open.connection(file, "rt") : >cannot open zip file > 'http://www.nseindia.com/content/historical/EQUITIES/2010/NOV/cm01NOV2010bha > v.csv.zip' > > > __ 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] File Downloading Problem
Just for info how did you guys figure out that useragent was the problem? -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Duncan Temple Lang Sent: 01 November 2010 22:34 To: r-help@r-project.org Subject: Re: [R] File Downloading Problem I got this working almost immediately with RCurl although with that one has to specify any value for the useragent option, or the same error occurs. The issue is that R does not add an Accept entry to the HTTP request header. It should add something like Accept: *.* Using RCurl, u = "http://www.nseindia.com/content/historical/EQUITIES/2010/NOV/cm01NOV2010bha v.csv.zip" o = getURLContent(u, verbose = TRUE, useragent = getOption("HTTPUserAgent")) succeeds (but not if there is no useragent). We could fix R's download.file() to send Accept: *.*, or allow general headers to be specified either as an option for all requests, or as a parameter of download.file() (or both). Or we could have the makeUserAgent() function in utils be more customizable through options, or allow the R user specify the function herself. But while this would be good, the HTTP facilities in R are not intended to be as general something like libcurl (and hence RCurl). Unless there is a compelling reason to enhance R's internal facilities, I suggest people use something like libcurl. This approach also has the advantage of having the data directly in memory and avoiding writing it to disk and then reading it back in, e.g. library(Rcompression) z = zipArchive(o) names(z) read.csv(textConnection(z[[1]])) D. On 11/1/10 8:27 AM, Santosh Srinivas wrote: > It's strange and the internet connection is fine because I am able to get > data from yahoo. > This was working till just yesterday ... strange if the website is creating > issues with public access of basic data! > > -Original Message- > From: David Winsemius [mailto:dwinsem...@comcast.net] > Sent: 01 November 2010 20:48 > To: Duncan Murdoch > Cc: Santosh Srinivas; 'Rhelp' > Subject: Re: [R] File Downloading Problem > > > On Nov 1, 2010, at 10:41 AM, Duncan Murdoch wrote: > >> On 01/11/2010 10:37 AM, Santosh Srinivas wrote: >>> Nope Duncan ... no changes .. the same old way without a proxy ... >>> actually >>> the download.file is being returned "403 forbidden" which is strange. >>> >>> These are just two lines that I am trying to run. >>> >>> sURL<- >>> > "http://www.nseindia.com/content/historical/EQUITIES/2010/NOV/cm01NOV2010bha >>> v.csv.zip" >>> download.file(sURL,"test.zip") >>> >>> Put the same URL in a browser and it works fine. >> >> It doesn't work for me, so presumably there is some kind of security >> setting at the site (a cookie?), which allows your browser, but >> doesn't allow you to use R, or me to use anything. > > Firefox in a Mac platform will download and unzip the file with no > security complaints and no cookie appears to be set when downloading, > but that code will not access the file, nor will my efforts to wrap > the URL in url() or unz() so it seems more likely that Santosh and I > do not understand the file opening processes that R supports. > > > con= > unz(description="http://www.nseindia.com/content/historical/EQUITIES/2010/NO > V/cm01NOV2010bhav.csv.zip > ", file="~/cm01NOV2010bhav.csv") > > test.df <- read.csv(file=con) > Error in open.connection(file, "rt") : cannot open the connection > In addition: Warning message: > In open.connection(file, "rt") : >cannot open zip file > 'http://www.nseindia.com/content/historical/EQUITIES/2010/NOV/cm01NOV2010bha > v.csv.zip' > > > __ 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] Using R for Production - Discussion
Hello Group, This is an open-ended question. Quite fascinated by the things I can do and the control I have on my activities since I started using R. I basically have been using this for analytical related work off my desktop. My experience has been quite good and most issues where I need to investigate and solve are typical items more related to data errors, format corruption, etc... not necessarily "R" Related. Complementing this with Python gives enough firepower to do lots of production (analytical related activities) on the cloud (from my research I see that every innovative technology provider seems to support Python ... google, amazon, etc). Question on using R for Production activities: Q1) Does anyone have experience of using R-scripts etc ... for production related activities. E.g. serving off a computational/ analytical / simulation environment from a webportal with the analytical processing done in R. I've seen that most useful things for normal (not rocket science) business (80-20 rule) can be done just as well in R in comparison with tools like SAS, Matlab, etc. Q2) I haven't tried the processing routines for much larger data-sets assuming "size" is not a constraint nowadays. I know that I should try out ... but any forewarnings would help. Is it likely that something that works for my "desktop" dataset is quite as likely to work when scaled up to a "cloud dataset"? Assuming that I do the clearing out of unused objects, not running into infinite loops, etc? i.e. is there any problem with the "fundamental architecture of R itself"? (like press articles often say) Q3) There are big fans of the SAS, Matlab, Mathworks environments out there does anyone have a comparison of how R fares. >From my experience R is quite neat and low level ... so overheads should be quite low. Most slowness comes due to lack of knowledge (see my code ... like using the wrong structures, functions, loops, etc.) rather than something wrong with the way R itself is. Perhaps there is no "commercial" focus to enhance performance related issues but my guess is that it is just matter of time till the community evolves the language to score higher on that too. And perhaps develops documentation to assist the challenge users with "performance tips" (the ten commandments types) Q4) You must have heard about the latest comment from James Goodnight of SAS ... "We haven't noticed that a lot. Most of our companies need industrial strength software that has been tested, put through every possible scenario or failure to make sure everything works correctly." My "gut" is that random passionate geeks (playing part-time) do better testing than a military of professionals ... (but I've no empirical evidence here) I am not taking a side here (although I appreciate those who do!) .. but looking for an objective reasoning. Thanks, S __ 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] how to compare two datasets in R>?
Take a look at ?merge for doing such join operations. (I believe that should help) If you had provided a sample of your datasets using dput, I would have checked that for you. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of song song Sent: 02 November 2010 11:44 To: r-help@r-project.org Subject: [R] how to compare two datasets in R>? hi, everybody, my question is: suppose I have two data sets, set A is large and have variables like ID, Gender, Income. Set B is small and suppose only has ID. Now I want to get a subset from data set A which contains ID from Set B. How to do this in R>? Is there any commands to do this? Thank you [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-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] Setting the names of a data.frame
I have tData as below. I need to set the names with the headers from the first row in sHeaders Sorry .. forgot how to set the names from row in another data frame .. pls advise. names(tData) = sHeaders[1,] does not work correctly Also, why doesn't drop.levels(sHeaders) not work? dput(tData) structure(list(V1 = structure(c(3L, 1L, 1L, 2L), .Label = c("P H Ravi Kumar", "Rahul Kumar Singh", "Ramu GSV"), class = "factor"), V2 = structure(c(1L, 3L, 3L, 2L), .Label = c("05/10/2010", "09/09/2010", "30/09/2010" ), class = "factor"), V3 = structure(c(2L, 1L, 1L, 2L), .Label = c("B", "S"), class = "factor"), V4 = structure(c(2L, 3L, 3L, 1L), .Label = c("2120", "4000", "11000"), class = "factor"), V5 = structure(c(1L, 2L, 2L, 1L), .Label = c("", "0.01"), class = "factor"), V6 = structure(c(2L, 3L, 3L, 1L), .Label = c("765", "1000", "11000"), class = "factor"), V7 = structure(c(1L, 2L, 2L, 1L), .Label = c("", "0.01"), class = "factor")), .Names = c("V1", "V2", "V3", "V4", "V5", "V6", "V7"), row.names = 5:8, class = "data.frame") dput(sHeaders) structure(list(V1 = structure(1L, .Label = c("Name of Acquirer / Seller", "Qty", "Ramu GSV"), class = "factor"), V2 = structure(3L, .Label = c("05/10/2010", "%", "Transaction Date"), class = "factor"), V3 = structure(1L, .Label = c("Buy /Sale", "Qty", "S"), class = "factor"), V4 = structure(3L, .Label = c("4000", "%", "No.of Shares Transacted"), class = "factor"), V5 = structure(2L, .Label = c("", "Holding after Transaction"), class = "factor"), V6 = structure(NA_integer_, .Label = "1000", class = "factor"), V7 = structure(NA_integer_, .Label = "", class = "factor")), .Names = c("V1", "V2", "V3", "V4", "V5", "V6", "V7"), row.names = 3L, class = "data.frame") Thanks very much. __ 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] Setting the names of a data.frame
Thanks. Actually the sHeaders was a line in tData itself ... I just did sHeaders = tData [1,] How can I can build it without factors like your first suggestions? -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ivan Calandra Sent: 02 November 2010 20:22 To: r-help@r-project.org Subject: Re: [R] Setting the names of a data.frame Hi, The problem is that all your columns of sHeaders are factors. It might be better to set stringsAsFactors to FALSE when you build it. Or you can do it with a for loop like this: for (i in 1:length(sHeaders)){ names(tData)[i] <- as.character(sHeaders[1,i]) } Or with lapply: names(tData) <- unlist(lapply(sHeaders[1, ], FUN=as.character)) HTH, Ivan Le 11/2/2010 14:58, Santosh Srinivas a écrit : > I have tData as below. I need to set the names with the headers from the > first row in sHeaders > Sorry .. forgot how to set the names from row in another data frame .. pls > advise. > > names(tData) = sHeaders[1,] does not work correctly > > Also, why doesn't drop.levels(sHeaders) not work? > > dput(tData) > structure(list(V1 = structure(c(3L, 1L, 1L, 2L), .Label = c("P H Ravi > Kumar", > "Rahul Kumar Singh", "Ramu GSV"), class = "factor"), V2 = structure(c(1L, > 3L, 3L, 2L), .Label = c("05/10/2010", "09/09/2010", "30/09/2010" > ), class = "factor"), V3 = structure(c(2L, 1L, 1L, 2L), .Label = c("B", > "S"), class = "factor"), V4 = structure(c(2L, 3L, 3L, 1L), .Label = > c("2120", > "4000", "11000"), class = "factor"), V5 = structure(c(1L, 2L, > 2L, 1L), .Label = c("", "0.01"), class = "factor"), V6 = structure(c(2L, > 3L, 3L, 1L), .Label = c("765", "1000", "11000"), class = "factor"), > V7 = structure(c(1L, 2L, 2L, 1L), .Label = c("", "0.01"), class = > "factor")), .Names = c("V1", > "V2", "V3", "V4", "V5", "V6", "V7"), row.names = 5:8, class = "data.frame") > > > dput(sHeaders) > structure(list(V1 = structure(1L, .Label = c("Name of Acquirer / Seller", > "Qty", "Ramu GSV"), class = "factor"), V2 = structure(3L, .Label = > c("05/10/2010", > "%", "Transaction Date"), class = "factor"), V3 = structure(1L, .Label = > c("Buy /Sale", > "Qty", "S"), class = "factor"), V4 = structure(3L, .Label = c("4000", > "%", "No.of Shares Transacted"), class = "factor"), V5 = structure(2L, > .Label = c("", > "Holding after Transaction"), class = "factor"), V6 = structure(NA_integer_, > .Label = "1000", class = "factor"), > V7 = structure(NA_integer_, .Label = "", class = "factor")), .Names = > c("V1", > "V2", "V3", "V4", "V5", "V6", "V7"), row.names = 3L, class = "data.frame") > > > Thanks very much. > > __ > 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. > -- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. Säugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calan...@uni-hamburg.de ** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.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-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] Setting the names of a data.frame
It is just read from a file that has introductory text in the beginning and a the header starts slight below so couldnt use header as such. I just modified that dataset to ignore the earlier lines ... sHeaders = tData[4,] & tData = tData [5:end] The original data was actually a readHTMLtable from a webpage. Your solutions works well enough for my purpose ... thanks. -Original Message- From: Ivan Calandra [mailto:ivan.calan...@uni-hamburg.de] Sent: 02 November 2010 22:15 To: Santosh Srinivas Cc: r-help@r-project.org Subject: Re: [R] Setting the names of a data.frame Wait wait, If sHeaders is actually the first line of tData, the question is how do you create/read this dataset in R? Isn't read from a text/csv file? In that case, set the "header" argument to TRUE. If not, there are probably better ways to do it, better than what you did (i.e. extract the first line and reuse it). In any case, that would be easier then (though still not the best way): names(tData) <- unlist(lapply(tData[1, ], FUN=as.character)) Ivan Le 11/2/2010 16:09, Santosh Srinivas a écrit : > Thanks. > > Actually the sHeaders was a line in tData itself ... > I just did sHeaders = tData [1,] > > How can I can build it without factors like your first suggestions? > > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf Of Ivan Calandra > Sent: 02 November 2010 20:22 > To: r-help@r-project.org > Subject: Re: [R] Setting the names of a data.frame > > Hi, > > The problem is that all your columns of sHeaders are factors. It might > be better to set stringsAsFactors to FALSE when you build it. > > Or you can do it with a for loop like this: > for (i in 1:length(sHeaders)){ >names(tData)[i]<- as.character(sHeaders[1,i]) > } > > Or with lapply: > names(tData)<- unlist(lapply(sHeaders[1, ], FUN=as.character)) > > HTH, > Ivan > > Le 11/2/2010 14:58, Santosh Srinivas a écrit : >> I have tData as below. I need to set the names with the headers from the >> first row in sHeaders >> Sorry .. forgot how to set the names from row in another data frame .. pls >> advise. >> >> names(tData) = sHeaders[1,] does not work correctly >> >> Also, why doesn't drop.levels(sHeaders) not work? >> >> dput(tData) >> structure(list(V1 = structure(c(3L, 1L, 1L, 2L), .Label = c("P H Ravi >> Kumar", >> "Rahul Kumar Singh", "Ramu GSV"), class = "factor"), V2 = structure(c(1L, >> 3L, 3L, 2L), .Label = c("05/10/2010", "09/09/2010", "30/09/2010" >> ), class = "factor"), V3 = structure(c(2L, 1L, 1L, 2L), .Label = c("B", >> "S"), class = "factor"), V4 = structure(c(2L, 3L, 3L, 1L), .Label = >> c("2120", >> "4000", "11000"), class = "factor"), V5 = structure(c(1L, 2L, >> 2L, 1L), .Label = c("", "0.01"), class = "factor"), V6 = structure(c(2L, >> 3L, 3L, 1L), .Label = c("765", "1000", "11000"), class = "factor"), >> V7 = structure(c(1L, 2L, 2L, 1L), .Label = c("", "0.01"), class = >> "factor")), .Names = c("V1", >> "V2", "V3", "V4", "V5", "V6", "V7"), row.names = 5:8, class = > "data.frame") >> >> dput(sHeaders) >> structure(list(V1 = structure(1L, .Label = c("Name of Acquirer / Seller", >> "Qty", "Ramu GSV"), class = "factor"), V2 = structure(3L, .Label = >> c("05/10/2010", >> "%", "Transaction Date"), class = "factor"), V3 = structure(1L, .Label = >> c("Buy /Sale", >> "Qty", "S"), class = "factor"), V4 = structure(3L, .Label = c("4000", >> "%", "No.of Shares Transacted"), class = "factor"), V5 = structure(2L, >> .Label = c("", >> "Holding after Transaction"), class = "factor"), V6 = > structure(NA_integer_, >> .Label = "1000", class = "factor"), >> V7 = structure(NA_integer_, .Label = "", class = "factor")), .Names = >> c("V1", >> "V2", "V3", "V4", "V5", "V6", "V7"), row.names = 3L, class = "data.frame") >> >> >> Thanks very much. >> >> __ >> 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. >> -- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. Säugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calan...@uni-hamburg.de ** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.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] Drawing circles on a chart
Dear Group, I have the following data matrix which is a timeseries. > dput(tData) structure(list(A = c(0.2, 0.13, 0.05, 0.1, 0.02, 0.18, 0.09, 0.06, 0.13), B = c(0.15, 0.06, 0.09, 0.02, 0.03, 0.12, 0.01, 0.15, 0.06), C = c(-0.1, 0, -0.07, -0.06, -0.05, -0.05, -0.06, -0.08, -0.07), D = c(-0.15, -0.05, -0.1, -0.03, -0.13, -0.04, -0.1, -0.04, -0.15), E = c(-0.17, -0.16, -0.08, -0.07, -0.09, -0.14, -0.1, -0.05, 0)), .Names = c("A", "B", "C", "D", "E"), class = "data.frame", row.names = c(NA, -9L)) I am trying to display this data in a graphic. The values vary from -0.2 to +0.2 There should be a table with 5 Rows and 9 Columns. Rows labeled A to E and Columns labeled 1 to 9. Inside each cell there should be a circle (sphere preferable) with radius of mod(data value). The color should be either red or green depending on -ve or +ve and the intensity should be based on the value of the datapoint. Any help on how to go about this? Thanks, S __ 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] Drawing circles on a chart
Thanks Gabor. I used melt to transform the data and plot using balloonplot. tData <- structure(list(A = c(0.2, 0.13, 0.05, 0.1, 0.02, 0.18, 0.09, 0.06, 0.13), B = c(0.15, 0.06, 0.09, 0.02, 0.03, 0.12, 0.01, 0.15, 0.06), C = c(-0.1, 0, -0.07, -0.06, -0.05, -0.05, -0.06, -0.08, -0.07), D = c(-0.15, -0.05, -0.1, -0.03, -0.13, -0.04, -0.1, -0.04, -0.15), E = c(-0.17, -0.16, -0.08, -0.07, -0.09, -0.14, -0.1, -0.05, 0)), .Names = c("A", "B", "C", "D", "E"), class = "data.frame", row.names = c(NA, -9L)) tData$Period <- rownames(tData) tData.m <- melt(tData) # need to find a way to adjust the color for -ve values balloonplot(tData.m$Period,tData.m$variable,abs(tData.m$value)) -Original Message- From: Gabor Grothendieck [mailto:ggrothendi...@gmail.com] Sent: 03 November 2010 07:51 To: Santosh Srinivas Cc: r-help@r-project.org Subject: Re: [R] Drawing circles on a chart On Tue, Nov 2, 2010 at 10:07 PM, Santosh Srinivas wrote: > Dear Group, > I have the following data matrix which is a timeseries. > >> dput(tData) > structure(list(A = c(0.2, 0.13, 0.05, 0.1, 0.02, 0.18, 0.09, > 0.06, 0.13), B = c(0.15, 0.06, 0.09, 0.02, 0.03, 0.12, 0.01, > 0.15, 0.06), C = c(-0.1, 0, -0.07, -0.06, -0.05, -0.05, -0.06, > -0.08, -0.07), D = c(-0.15, -0.05, -0.1, -0.03, -0.13, -0.04, > -0.1, -0.04, -0.15), E = c(-0.17, -0.16, -0.08, -0.07, -0.09, > -0.14, -0.1, -0.05, 0)), .Names = c("A", "B", "C", "D", "E"), class = > "data.frame", row.names = c(NA, > -9L)) > > > I am trying to display this data in a graphic. The values vary from -0.2 to > +0.2 > There should be a table with 5 Rows and 9 Columns. Rows labeled A to E and > Columns labeled 1 to 9. > Inside each cell there should be a circle (sphere preferable) with radius of > mod(data value). The color should be either red or green depending on -ve or > +ve and the intensity should be based on the value of the datapoint. > See balloonplot in the gplots package. -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at 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] Data transformation
Dear Group, Need to do the following transformation: I have the dataset structure(list(Date = structure(1L, .Label = "2010-06-16", class = "factor"), ACC.returns1Day = -0.018524832, ACC.returns5Day = 0.000863931, ACC.returns7Day = -0.019795222, BCC.returns1Day = -0.009861859, BCC.returns5Day = 0.000850706, BCC.returns7Day = -0.014695715), .Names = c("Date", "ACC.returns1Day", "ACC.returns5Day", "ACC.returns7Day", "BCC.returns1Day", "BCC.returns5Day", "BCC.returns7Day"), class = "data.frame", row.names = c(NA, -1L)) I can split the names using: retNames <- strsplit(names(returns),"\\.returns") Assuming that the frame has only one row, how do I transform this into 1Day5Day7Day ACC -0.0185 0.0009 -0.0198 BCC -0.0099 0.0009 -0.0147 If I have more than one unique date ... is there some nice structure that I could put this into where I have the date as the parent and the sub data structure that gives the data as above for any unique date? I can always do this with for-loops ... but I think there are easier ways to achieve this. Thanks, S __ 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] Drawing circles on a chart
Thanks Barry ... actually the intention was to have areas of the circle depicting the value (radius imputed) -Original Message- From: b.rowling...@googlemail.com [mailto:b.rowling...@googlemail.com] On Behalf Of Barry Rowlingson Sent: 03 November 2010 15:02 To: Santosh Srinivas Cc: r-help@r-project.org Subject: Re: [R] Drawing circles on a chart On Wed, Nov 3, 2010 at 2:07 AM, Santosh Srinivas wrote: > Dear Group, > Inside each cell there should be a circle (sphere preferable) with radius of > mod(data value). The color should be either red or green depending on -ve or > +ve and the intensity should be based on the value of the datapoint. > > Any help on how to go about this? If you really want a sphere then you should look at the rgl package, which enables the drawing of 3d graphic objects with illumination. However it does it in its own graphics window and you'll not be able to use any of the standard R graphics functions. Otherwise you'll have to find some way of putting a 3d sphere on a 2d R graphics window, or faking it with a shaded circle and some highlights. Yuck. Also, drawing circles (strictly, a disc) with radius proportional to data value is usually a bad idea since we interpret areas. A circle with twice the radius has four times the area, and so looks four times as big. But the data is only twice as big... Barry __ 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] postForm() in RCurl and library RHTMLForms
I dont have the implementation in the way you want it . Sorry but someone here will definitely know The group showed me to do it this way though . library(zoo) library("RCurl") sNiftyURL = "http://nseindia.com/content/indices/histdata/S&P%20CNX%20NIFTY01-01-2000-02 -11-2010.csv" Nifty_Dat = getURLContent(sNiftyURL, verbose = TRUE, useragent = getOption("HTTPUserAgent")) tblNifty <- read.csv(textConnection(Nifty_Dat)) tblNifty <- subset(tblNifty,select=c(Date,Close)) tblNifty$Date <- as.Date(tblNifty$Date, format ="%d-%b-%Y") tblNifty <-read.zoo((tblNifty)) closeAllConnections() HTH. S From: sayan dasgupta [mailto:kitt...@gmail.com] Sent: 04 November 2010 15:09 To: r-help@r-project.org Cc: dun...@wald.ucdavis.edu; santosh.srini...@gmail.com Subject: postForm() in RCurl and library RHTMLForms Hi RUsers, Suppose I want to see the data on the website url <- "http://www.nseindia.com/content/indices/ind_histvalues.htm"; for the index "S&P CNX NIFTY" for dates "FromDate"="01-11-2010","ToDate"="02-11-2010" then read the html table from the page using readHTMLtable() I am using this code webpage <- postForm(url,.params=list( "FromDate"="01-11-2010", "ToDate"="02-11-2010", "IndexType"="S&P CNX NIFTY", "Indicesdata"="Get Details"), .opts=list(useragent = getOption("HTTPUserAgent"))) But it doesn't give me desired result Also I was trying to use the function getHTMLFormDescription from the package RHTMLForms but there we can't use the argument .opts=list(useragent = getOption("HTTPUserAgent")) which is needed for this particular website Thanks and Regards Sayan Dasgupta __ 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] Extracting data only for particular index values from a zoo structure
Hello All, I have a zoo structure as follows: > dput(tMRet) structure(c(0.00138742474397713, -0.0309023681475112, 0.0390276302410908, 0.0832282874685357, -0.00315002033871414, -0.0158548785709138, -0.0410876001496389, -0.0503189291168807, 0.00229628598547049, 0.112348434473647, 0.0760004696254608, 0.100820586425124, 0.0803767768546975, 0.0967805566974766, 0.054288018745434, 0.106415042990242, 0.0848339767191362, -0.0293833917022324, -0.0355384394730908, 0.0398272106900921), .Dim = c(20L, 1L), .Dimnames = list(c("Sep 2002", "Oct 2002", "Nov 2002", "Dec 2002", "Jan 2003", "Feb 2003", "Mar 2003", "Apr 2003", "May 2003", "Jun 2003", "Jul 2003", "Aug 2003", "Sep 2003", "Oct 2003", "Nov 2003", "Dec 2003", "Jan 2004", "Feb 2004", "Mar 2004", "Apr 2004"), "Close"), index = structure(c(2002.667, 2002.75, 2002.833, 2002.917, 2003, 2003.083, 2003.167, 2003.25, 2003.333, 2003.417, 2003.5, 2003.583, 2003.667, 2003.75, 2003.833, 2003.917, 2004, 2004.083, 2004.167, 2004.25 ), class = "yearmon"), class = "zoo") I want to extract only the values for say "November" but may span multiple years. How can I use conditions on the zoo index? For info, I did an aggregate over daily data to reach here. Have a great weekend! Thanks. S __ 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] Extracting data only for particular index values from a zoo structure
Thanks Gabor for pointing in the right direction. Looked up cycle and the doc is tough to understand " cycle gives the positions in the cycle of each observation." ... how is cycle defined. I just extended your idea to make it readable for an avg. user in the following way mRet[format(index(mRet),"%m")==11] -Original Message- From: Gabor Grothendieck [mailto:ggrothendi...@gmail.com] Sent: 05 November 2010 20:59 To: Santosh Srinivas Cc: r-help@r-project.org Subject: Re: [R] Extracting data only for particular index values from a zoo structure On Fri, Nov 5, 2010 at 11:21 AM, Santosh Srinivas wrote: > Hello All, > > I have a zoo structure as follows: >> dput(tMRet) > structure(c(0.00138742474397713, -0.0309023681475112, 0.0390276302410908, > 0.0832282874685357, -0.00315002033871414, -0.0158548785709138, > -0.0410876001496389, -0.0503189291168807, 0.00229628598547049, > 0.112348434473647, 0.0760004696254608, 0.100820586425124, > 0.0803767768546975, > 0.0967805566974766, 0.054288018745434, 0.106415042990242, > 0.0848339767191362, > -0.0293833917022324, -0.0355384394730908, 0.0398272106900921), .Dim = c(20L, > > 1L), .Dimnames = list(c("Sep 2002", "Oct 2002", "Nov 2002", "Dec 2002", > "Jan 2003", "Feb 2003", "Mar 2003", "Apr 2003", "May 2003", "Jun 2003", > "Jul 2003", "Aug 2003", "Sep 2003", "Oct 2003", "Nov 2003", "Dec 2003", > "Jan 2004", "Feb 2004", "Mar 2004", "Apr 2004"), "Close"), index = > structure(c(2002.667, > 2002.75, 2002.833, 2002.917, 2003, 2003.083, > 2003.167, 2003.25, 2003.333, 2003.417, > 2003.5, 2003.583, 2003.667, 2003.75, 2003.833, > 2003.917, 2004, 2004.083, 2004.167, 2004.25 > ), class = "yearmon"), class = "zoo") > > I want to extract only the values for say "November" but may span multiple > years. > How can I use conditions on the zoo index? > Try this: > tMRet[cycle(tMRet) == 11,, drop = FALSE] Close Nov 2002 0.03902763 Nov 2003 0.05428802 If you just want a 1 dimensional object omit the drop=FALSE part. -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at 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] Row-wise recurive function call
Dear Group, I have a following dataset: > a A B C D 1 22 3 31 40 2 26 31 36 32 3 3 7 49 16 4 24 40 27 26 5 20 45 47 0 6 34 43 11 18 7 48 48 24 2 8 3 16 39 48 9 20 49 7 21 10 17 36 47 10 > dput(a) structure(list(A = c(22L, 26L, 3L, 24L, 20L, 34L, 48L, 3L, 20L, 17L), B = c(3L, 31L, 7L, 40L, 45L, 43L, 48L, 16L, 49L, 36L), C = c(31L, 36L, 49L, 27L, 47L, 11L, 24L, 39L, 7L, 47L), D = c(40L, 32L, 16L, 26L, 0L, 18L, 2L, 48L, 21L, 10L)), .Names = c("A", "B", "C", "D"), class = "data.frame", row.names = c(NA, -10L)) I have a function that works off EVERY individual ROW to throw a result. Like playFn <- function (x){ + result = ((x$A+6*x$B)/(3*x$C)+20)*x$D + return(result) + } I want to apply the function for every row can I use an "apply" function ... tried but not been able to ... e.g. print(rapply(a,playFn)) Please advise. Thanks, S __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Row-wise recurive function call
Thanks this works. Only, I need to reference in the formula using indexes. -Original Message- From: Dimitris Rizopoulos [mailto:d.rizopou...@erasmusmc.nl] Sent: 09 November 2010 13:22 To: Santosh Srinivas Cc: r-help@r-project.org Subject: Re: [R] Row-wise recurive function call try this: apply(data.matrix(a), 1, playFn) I hope it helps. Best, Dimitris On 11/9/2010 8:32 AM, Santosh Srinivas wrote: > Dear Group, > > I have a following dataset: >> a > A B C D > 1 22 3 31 40 > 2 26 31 36 32 > 3 3 7 49 16 > 4 24 40 27 26 > 5 20 45 47 0 > 6 34 43 11 18 > 7 48 48 24 2 > 8 3 16 39 48 > 9 20 49 7 21 > 10 17 36 47 10 > >> dput(a) > structure(list(A = c(22L, 26L, 3L, 24L, 20L, 34L, 48L, 3L, 20L, > 17L), B = c(3L, 31L, 7L, 40L, 45L, 43L, 48L, 16L, 49L, 36L), > C = c(31L, 36L, 49L, 27L, 47L, 11L, 24L, 39L, 7L, 47L), D = c(40L, > 32L, 16L, 26L, 0L, 18L, 2L, 48L, 21L, 10L)), .Names = c("A", > "B", "C", "D"), class = "data.frame", row.names = c(NA, -10L)) > > > I have a function that works off EVERY individual ROW to throw a result. > Like > > playFn<- function (x){ > + result = ((x$A+6*x$B)/(3*x$C)+20)*x$D > + return(result) > + } > > > I want to apply the function for every row can I use an "apply" > function ... tried but not been able to ... > e.g. print(rapply(a,playFn)) > > Please advise. > > Thanks, > S > > __ > 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. > -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/biostatistiek/ __ 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] Creating a list to store output objects from a recursive loop
Dear Group, I am having a function that I am running in a loop that generated two results for each loop The result1 is a zoo object The result2 is a data frame Now I want to put both of them in a list or some structure ... that I can access or output to a file after the loop is done. For e.g. for (i in 1:20){ niceFunction(x[i],i) } niceFunction (x,i) { result1 = someOperations() #zoo object result2 = someOperations() #data.frame OutputObj[i,1]=result1 OutputObj[i,2]=result2 } How can I go about this? Thanks, S __ 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] Creating a list to store output objects from a recursive loop
Figured this out this ways I think outPut <- list(list(result1),list(result2)) -Original Message- From: Santosh Srinivas [mailto:santosh.srini...@gmail.com] Sent: 09 November 2010 14:21 To: 'r-help@r-project.org' Subject: Creating a list to store output objects from a recursive loop Dear Group, I am having a function that I am running in a loop that generated two results for each loop The result1 is a zoo object The result2 is a data frame Now I want to put both of them in a list or some structure ... that I can access or output to a file after the loop is done. For e.g. for (i in 1:20){ niceFunction(x[i],i) } niceFunction (x,i) { result1 = someOperations() #zoo object result2 = someOperations() #data.frame OutputObj[i,1]=result1 OutputObj[i,2]=result2 } How can I go about this? Thanks, S __ 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] arrays of arrays
Not sure if this is the best way ... but something similar to my question from yesterday that I could solve as follows. > tD <- read.csv("Book1.csv") > tD X0 X0.1 X1 X1.1 X X.1 1 13 5 NA NA NA 2 44 NA NA NA NA 3 7 -1 89 10 6 > x1 <- tD[1,1:3] > > x2 <- tD[2,1:2] > > x3 <- tD[3,1:6] > tData<-list(vector('numeric')) > tData<-list(vector('numeric')) > x1 = unlist(x1) > x2 = unlist(x2) > x3 = unlist(x3) > tData[[1]]=x1 > tData[[2]]=x2 > tData[[3]]=x3 > tData [[1]] X0 X0.1 X1 135 [[2]] X0 X0.1 44 [[3]] X0 X0.1 X1 X1.1X X.1 7 -189 106 > HTH, S -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of sachinthaka.abeyward...@allianz.com.au Sent: 10 November 2010 08:26 To: r-help@r-project.org Subject: [R] arrays of arrays Hi All, I want to have an array/ matrix that looks this x<- 0 0 1 1 1 3 5 4 4 7 -1 8 9 10 6 I hope this makes sense. So basically if I want x[1,3] it will access 0 and similarly x[4,2], -1. Thanks in advance, Sachin p.s. sorry about the corporate notice. --- Please consider the environment before printing this email --- Allianz - Best General Insurance Company of the Year 2010* Allianz - General Insurance Company of the Year 2009+ * Australian Banking and Finance Insurance Awards + Australia and New Zealand Insurance Industry Awards This email and any attachments has been sent by Allianz Australia Insurance Limited (ABN 15 000 122 850) and is intended solely for the addressee. It is confidential, may contain personal information and may be subject to legal professional privilege. Unauthorised use is strictly prohibited and may be unlawful. If you have received this by mistake, confidentiality and any legal privilege are not waived or lost and we ask that you contact the sender and delete and destroy this and any other copies. In relation to any legal use you may make of the contents of this email, you must ensure that you comply with the Privacy Act (Cth) 1988 and you should note that the contents may be subject to copyright and therefore may not be reproduced, communicated or adapted without the express consent of the owner of the copyright. Allianz will not be liable in connection with any data corruption, interruption, delay, computer virus or unauthorised access or amendment to the contents of this email. If this email is a commercial electronic message and you would prefer not to receive further commercial electronic messages from Allianz, please forward a copy of this email to unsubscr...@allianz.com.au with the word unsubscribe in the subject header. __ 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] concatenating a string to a column
Try on these lines library(MASS) data(Boston) Boston$crim<-paste(Boston$crim,"Test",sep="-") -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of sachinthaka.abeyward...@allianz.com.au Sent: 10 November 2010 10:39 To: R-help Forum Subject: [R] concatenating a string to a column Hi All, Suppose I want to concatenate a zero to all the values to a column called period in data frame A. I want to do the following but the following command actually deletes the entire column altogether. A$period<-cat(A$period,"0",sep=""); Any help would be appreciated. Thanks, Sachin p.s. sorry about the corporate notice. --- Please consider the environment before printing this email --- Allianz - Best General Insurance Company of the Year 2010* Allianz - General Insurance Company of the Year 2009+ * Australian Banking and Finance Insurance Awards + Australia and New Zealand Insurance Industry Awards This email and any attachments has been sent by Allianz Australia Insurance Limited (ABN 15 000 122 850) and is intended solely for the addressee. It is confidential, may contain personal information and may be subject to legal professional privilege. Unauthorised use is strictly prohibited and may be unlawful. If you have received this by mistake, confidentiality and any legal privilege are not waived or lost and we ask that you contact the sender and delete and destroy this and any other copies. In relation to any legal use you may make of the contents of this email, you must ensure that you comply with the Privacy Act (Cth) 1988 and you should note that the contents may be subject to copyright and therefore may not be reproduced, communicated or adapted without the express consent of the owner of the copyright. Allianz will not be liable in connection with any data corruption, interruption, delay, computer virus or unauthorised access or amendment to the contents of this email. If this email is a commercial electronic message and you would prefer not to receive further commercial electronic messages from Allianz, please forward a copy of this email to unsubscr...@allianz.com.au with the word unsubscribe in the subject header. __ 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] Parsing txt file
You could use the following to achieve your objective. To start with ?readLines ?strsplit ?for ?ifelse As you try, you may receive more specific answers for the issues you come up with. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of karthicklakshman Sent: 10 November 2010 15:06 To: r-help@r-project.org Subject: [R] Parsing txt file Hello, I have a tab limited text document with multiple lines as mentioned below, #FILE FORMAT #Book booknameauthor publisher pages #CD namecontent -- BookbioRxxx abc publishers 230 CD biorexampleschapter5 -- Bookbioc++ mmm tata publishers 400 CD samples workexamples CD dataexperiments -- Bookmanagement toolsaaa some publishers 200 -- here the texts "book" and "CD" are present in each block. now, I am interested in creating a data frame with two columns, column names="bookname" and "content". Using "grep" it is possible to pick specific rows (grep("^book, finename")) but my expertise in programming is limited to create the mentioned data.frame. Note: the rowname "book" is present in all blocks but "CD" is variable (ie., some block has two and some with no CD row, as shown above) please help me in creating something like this, bookname content [1] bioR chapter5 [2] bioc++workexamples, experiments [3] management tools NA Thanks in advance, karthick -- View this message in context: http://r.789695.n4.nabble.com/Parsing-txt-file-tp3035749p3035749.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] format as percentage
Basic question ... checked the help page but the only answer was to use paste! Is there any way to format as %? > degree = c(0.20,0.5) > degree [1] 0.2 0.5 > print(degree) [1] 0.2 0.5 -- Thanks R-Helpers. Yes, this is a silly question and it will not be repeated! :-) __ 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] Parallel code runs slower!
My parallel code is running slower than my non-parallel code! Can someone pls advise what am I doing wrong here? t and tTA are simple matrices of equal dimensions. #NON PARALLEL CODE nCols=ncol(t) nRows=nrow(t) tTA = matrix(nrow=nRows,ncol=nCols) require(TTR) system.time( for (i in 1:nCols) { x = t[,i] xROC = ROC(x) tTA[,i]=xROC } ) user system elapsed 123.240.07 123.47 # PARALLEL CODE nCols=ncol(t) nRows=nrow(t) tTA = matrix(nrow=nRows,ncol=nCols) require(doSMP) workers <- startWorkers(4) # My computer has 4 cores registerDoSMP(workers) system.time( foreach (i=1:nCols) %dopar%{ x = t[,i] xROC = ROC(x) tTA[,i]=xROC } ) # stop workers stopWorkers(workers) It is taking ages! Thanks, S __ 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] Time Delay / Wait
Hi Group, Is there something like a delay function based on System time or equivalent? I basically am generating a few graphs and I would like to see each graph for say 2mins before moving on to the next one? I can always have an empty for-loop I guess but is there a better way? Thanks, S __ 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] Deploying code as exe
Dear Group, Is there some way for me to package a few lines of R-code as exe and have it running in the background? (unable to find info in the archives) Even better if I can package it as an installation and send to my team who do not have any background in programming / R? If they can install and run the exe ... it would suffice. Thanks, S __ 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] filling a vector with a tapply function applied to another vector
You could just create a new data frame with the result and cbind? On Fri, Nov 12, 2010 at 2:11 PM, albechan wrote: > > I have a data frame with three columns. The first one is filled with factors, > the second one with numeric values and the third one is an empty vector. > I need fill the third column with the results of the function > tapply(secondcolumn,firstcolumn,mean) so that I have for each row of the > third column the mean of the second column conditional to the factor element > in the first column. > Thank you very much for your help. > Alb > -- > View this message in context: > http://r.789695.n4.nabble.com/filling-a-vector-with-a-tapply-function-applied-to-another-vector-tp3039271p3039271.html > Sent from the R help mailing list archive at Nabble.com. > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] RMySQL on Windows 2008 64 Bit -Help!
Dear Group, I'm having lots of problems getting RMySQL on a 64 bit machine. I followed all instructions available but couldn't get it working yet! Please help. See the output below. I did a install of RMySQL binary from the revolution cran source. It seems to have unpacked fine but gives this error when I call RMySQL Error: package 'RMySQL' is not installed for 'arch=x64' I set this environment variable on the windows path > Sys.getenv('MYSQL_HOME') MYSQL_HOME "C:/Program Files/MySQL/MySQL Server 5.0" > install.packages('RMySQL',type='source') trying URL 'http://cran.revolutionanalytics.com/src/contrib/RMySQL_0.7-5.tar.gz' Content type 'application/x-gzip' length 160769 bytes (157 Kb) opened URL downloaded 157 Kb * installing *source* package 'RMySQL' ... checking for $MYSQL_HOME... C:/Program Files/MySQL/MySQL Server 5.0 test: Files/MySQL/MySQL: unknown operand ERROR: configuration failed for package 'RMySQL' * removing 'C:/Revolution/Revo-4.0/RevoEnt64/R-2.11.1/library/RMySQL' * restoring previous 'C:/Revolution/Revo-4.0/RevoEnt64/R-2.11.1/library/RMySQL' The downloaded packages are in 'C:\Users\Administrator\AppData\Local\Temp\2\RtmpvGgrzb\downloaded_packages' Warning message: In install.packages("RMySQL", type = "source") : installation of package 'RMySQL' had non-zero exit status > sessionInfo() R version 2.11.1 (2010-05-31) x86_64-pc-mingw32 locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252LC_MONETARY=English_United States.1252 LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] Revobase_4.0.0 RevoScaleR_1.0-0 lattice_0.18-8 loaded via a namespace (and not attached): [1] grid_2.11.1 tools_2.11.1 __ 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] RMySQL on Windows 2008 64 Bit -Help!
I could do that but will have to change all my code. It would be great if I could get RMySQL on the 64 bit machine. -Original Message- From: Ajay Ohri [mailto:ohri2...@gmail.com] Sent: 13 November 2010 14:13 To: Santosh Srinivas Cc: r-help@r-project.org Subject: Re: [R] RMySQL on Windows 2008 64 Bit -Help! did you try the RODBC package as well. Regards Ajay Websites- http://decisionstats.com http://dudeofdata.com Linkedin- www.linkedin.com/in/ajayohri On Sat, Nov 13, 2010 at 9:22 AM, Santosh Srinivas wrote: > Dear Group, > > I'm having lots of problems getting RMySQL on a 64 bit machine. I followed > all instructions available but couldn't get it working yet! Please help. > See the output below. > > I did a install of RMySQL binary from the revolution cran source. It seems > to have unpacked fine but gives this error when I call RMySQL > Error: package 'RMySQL' is not installed for 'arch=x64' > > > I set this environment variable on the windows path >> Sys.getenv('MYSQL_HOME') > MYSQL_HOME > "C:/Program Files/MySQL/MySQL Server 5.0" > >> install.packages('RMySQL',type='source') > trying URL > 'http://cran.revolutionanalytics.com/src/contrib/RMySQL_0.7-5.tar.gz' > Content type 'application/x-gzip' length 160769 bytes (157 Kb) > opened URL > downloaded 157 Kb > > * installing *source* package 'RMySQL' ... > checking for $MYSQL_HOME... C:/Program Files/MySQL/MySQL Server 5.0 > test: Files/MySQL/MySQL: unknown operand > ERROR: configuration failed for package 'RMySQL' > * removing 'C:/Revolution/Revo-4.0/RevoEnt64/R-2.11.1/library/RMySQL' > * restoring previous > 'C:/Revolution/Revo-4.0/RevoEnt64/R-2.11.1/library/RMySQL' > > The downloaded packages are in > > 'C:\Users\Administrator\AppData\Local\Temp\2\RtmpvGgrzb\downloaded_packages' > Warning message: > In install.packages("RMySQL", type = "source") : > installation of package 'RMySQL' had non-zero exit status >> sessionInfo() > R version 2.11.1 (2010-05-31) > x86_64-pc-mingw32 > > locale: > [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United > States.1252 LC_MONETARY=English_United States.1252 LC_NUMERIC=C > > [5] LC_TIME=English_United States.1252 > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > other attached packages: > [1] Revobase_4.0.0 RevoScaleR_1.0-0 lattice_0.18-8 > > loaded via a namespace (and not attached): > [1] grid_2.11.1 tools_2.11.1 > > __ > 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] Access DDE Data
Hello Group, Is it possible to access DDE data from R? Thanks in advance for any pointers. S __ 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] Accessing variables inside a namespace
Hello Group, I am trying to see if there is way to access data that is inside another namespace. For e.g. the addATR function in the quantmod package calculates the ATR using the TTR package and then plots it to the graph. Now since it has already calculated the info that I need, can I access that data which if I look at the function code is stored in a variable called "atr" library(TTR) library(quantmod) data(ttrc) x <- subset(ttrc,select=c("Date","Open","High","Low","Close")) x.z <- read.zoo(x) x.xts <- as.xts(x.z) chartSeries(x.xts) addATR() Just so that I don't need to recalculate the same stuff again. I believe the data hasn't "expired" already. Thanks for your help. S __ 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] Option to Print with numbers formatted
Hello group, I have a data frame called test.df with a bunch of columns. When I do a print(test.df), I want the numbers to appear a pre-defined setting. I believe this can be achieved by sprintf but this needs to be done individually for the data. However, is there an option that I can set so that all numerical values default to comma separated, 2 decimal places when they appear? Thanks, S __ 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] a philosophy R question
Not many really care about what it is called but here is what the page says R is `GNU S', a freely available language and environment for statistical computing and graphics which provides a wide variety of statistical and graphical techniques: linear and nonlinear modelling, statistical tests, time series analysis, classification, clustering, etc. http://cran.r-project.org/index.html -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Erin Hodgess Sent: 21 November 2010 07:26 To: R help Subject: [R] a philosophy R question Dear R People: Do we say that R is a programming language or a programming environment, please? Which is correct, please? Thanks in advance, Sincerely, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@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-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] Check for is.object
Hello, I am trying to recursively append some data from multiple files into a common object For this, I am using in a loop NewObject <- rbind(NewObject,tempObject) For the first loop, obviously there is no NewObject ... so I wanted to do NewObject <- tempObject[0,] Now when it loops again I want to put the statement do "NewObject <- tempObject[0,]" inside a if statement ... so that it does I can skip it once NewObject has been initialized. But, is.object doesn't seem to work. What is the alternative check that I can do? And is there a better way to achieve what I want? Thanks, S __ 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] Executing multiple .R files
Hello R-Helpers, I have a directory with some ".R" files that I execute every day. I want to write a script that executes each one of time sequentially. Is there a statement for this? 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.
[R] Finding the rows with the duplicated index
Hello Group, I have a huge time series dataset with sample below. I am basically trying to read it into a zoo object with columns 1:6 to index. Zoo issues a warning that some of the rows have duplicated index. dput(z) structure(list(TrdTimestamp = structure(list(sec = c(19, 19, 18, 10, 12, 43, 41, 59, 40, 29), min = c(58L, 57L, 39L, 37L, 4L, 5L, 26L, 45L, 24L, 16L), hour = c(11L, 12L, 10L, 12L, 14L, 14L, 15L, 14L, 11L, 11L), mday = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), mon = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), year = c(109L, 109L, 109L, 109L, 109L, 109L, 109L, 109L, 109L, 109L), wday = c(4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), yday = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), isdst = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L)), .Names = c("sec", "min", "hour", "mday", "mon", "year", "wday", "yday", "isdst"), class = c("POSIXt", "POSIXlt")), Ticker = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "NIFTY", class = "factor"), InstTyp = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("FUTIDX", "OPTIDX" ), class = "factor"), ExpDt = c(20090129L, 20090129L, 20090129L, 20090129L, 20090129L, 20090129L, 20090129L, 20090129L, 20090129L, 20090129L), OptTyp = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("CE", "FF", "PE"), class = "factor"), Strike = c(2700L, 2700L, 2700L, 2700L, 2700L, 2700L, 2700L, 2700L, 2700L, 2700L), TrdPrice = c(347.4, 340, 334.95, 335.5, 349.95, 353, 380, 378.1, 340.25, 339), TrdQty = c(50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L)), .Names = c("TrdTimestamp", "Ticker", "InstTyp", "ExpDt", "OptTyp", "Strike", "TrdPrice", "TrdQty"), row.names = c(NA, 10L), class = "data.frame") Z should ideally have a unique index based on columns 1:6 ... but looks like some are duplicated. I want to get the count against each unique set .. i.e. z[,1:6] and the number of rows with that combination? I can put the unique index sets into a different object and do a rowcount using apply but was wondering if there is an easier way already? 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] Finding the rows with the duplicated index
Thanks. Sorry about the naming (just cobbled the example). The rows are duplicate in the actual data. I am looking for a way to find the number of duplicate rows for each unique rowindex combination which is based on columns 1:6. -Original Message- From: Gabor Grothendieck [mailto:ggrothendi...@gmail.com] Sent: 23 November 2010 21:54 To: Santosh Srinivas Cc: r-help@r-project.org Subject: Re: [R] Finding the rows with the duplicated index On Tue, Nov 23, 2010 at 11:04 AM, Santosh Srinivas wrote: > Hello Group, > > I have a huge time series dataset with sample below. I am basically trying > to read it into a zoo object with columns 1:6 to index. Zoo issues a warning > that some of the rows have duplicated index. > > dput(z) > structure(list(TrdTimestamp = structure(list(sec = c(19, 19, > 18, 10, 12, 43, 41, 59, 40, 29), min = c(58L, 57L, 39L, 37L, > 4L, 5L, 26L, 45L, 24L, 16L), hour = c(11L, 12L, 10L, 12L, 14L, > 14L, 15L, 14L, 11L, 11L), mday = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L), mon = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), > year = c(109L, 109L, 109L, 109L, 109L, 109L, 109L, 109L, > 109L, 109L), wday = c(4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, > 4L), yday = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), isdst = c(0L, > 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L)), .Names = c("sec", "min", > "hour", "mday", "mon", "year", "wday", "yday", "isdst"), class = c("POSIXt", > > "POSIXlt")), Ticker = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L), .Label = "NIFTY", class = "factor"), InstTyp = structure(c(2L, > 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("FUTIDX", "OPTIDX" > ), class = "factor"), ExpDt = c(20090129L, 20090129L, 20090129L, > 20090129L, 20090129L, 20090129L, 20090129L, 20090129L, 20090129L, > 20090129L), OptTyp = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L), .Label = c("CE", "FF", "PE"), class = "factor"), > Strike = c(2700L, 2700L, 2700L, 2700L, 2700L, 2700L, 2700L, > 2700L, 2700L, 2700L), TrdPrice = c(347.4, 340, 334.95, 335.5, > 349.95, 353, 380, 378.1, 340.25, 339), TrdQty = c(50L, 50L, > 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L)), .Names = c("TrdTimestamp", > "Ticker", "InstTyp", "ExpDt", "OptTyp", "Strike", "TrdPrice", > "TrdQty"), row.names = c(NA, 10L), class = "data.frame") > > > > Z should ideally have a unique index based on columns 1:6 ... but looks like > some are duplicated. > I want to get the count against each unique set .. i.e. z[,1:6] and the > number of rows with that combination? > > I can put the unique index sets into a different object and do a rowcount > using apply but was wondering if there is an easier way already? > Data frames should not hold POSIXlt objects and its very confusing naming the data frame z since that makes one think its a zoo object. Without your code its hard to know what the problem is but perhaps you were reading the series in with Date index in which case all the rows would have the same date. Specify tz = "" to use POSIXct. Also note that you cannot have a mixture of character and numeric variables in a zoo object. A 2d zoo object is a matrix with an index. Assuming that DF is a data frame in long format with multiple stocks identified by the second column we can split it according to the stock like this and there are no duplicates, at least in the data above. library(zoo) DF <- z rm(z) DF2 <- transform(DF, TrdTimestamp = as.POSIXct(TrdTimestamp)) z <- read.zoo(DF2[c(1:2, 4, 6:8)], split = 2, tz = "") -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at 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] Finding the nearest data in intraday data from two zoo objects
Hello Group, I have the following options and future data in zoo objects > head(optData.z) ExpDt OptTyp Strike TrdPrice TotTrdQty 2009-01-01 09:55:03 20090129 1 2900 180.50 2009-01-01 09:55:31 20090129 1 2900 188.50 2009-01-01 09:55:37 20090129 1 2900 185. 500 2009-01-01 09:55:39 20090129 1 2900 185. 500 2009-01-01 09:55:47 20090129 1 2900 185.1125 600 2009-01-01 09:55:48 20090129 1 2900 185.250050 > head(futData.z) ExpDt OptTyp Strike TrdPrice TotTrdQty 2009-01-01 09:55:09 20090129 2 0 2979.000 900 2009-01-01 09:55:11 20090129 2 0 2976.633 600 2009-01-01 09:55:12 20090129 2 0 2977.211 900 2009-01-01 09:55:14 20090129 2 0 2977.750 800 2009-01-01 09:55:15 20090129 2 0 2977.019 4300 2009-01-01 09:55:16 20090129 2 0 2977.050 800 I want to get the closest available futures price for every option ... Is there any function like the excel equivalent of approximate VLOOKUP of excel using date time? 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.
[R] Installing RQuantLib on Win 7 64 Bit
Hello Group, I am trying out RQuantLib on a 64bit Win 7 machine. But running into installation errors install.packages("RQuantLib") Warning in install.packages("RQuantLib") : argument 'lib' is missing: using 'C:\Users\Tester\Documents/R/win64-library/2.11' Warning: unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/bin/windows64/contrib/2.11 Warning message: In getDependencies(pkgs, dependencies, available, lib) : package ‘RQuantLib’ is not available Any help with this installation? Thank you. S __ 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] Installing RQuantLib on Win 7 64 Bit
Sorry, not very familar with the build process ... Can anyone with a working 64 bit binary for rquantlib, pls email me a copy ... Sent from my iPhone On 26-Nov-2010, at 5:25 PM, Mike Marchywka wrote: Date: Thu, 25 Nov 2010 21:22:54 -0600 To: santosh.srini...@gmail.com From: e...@debian.org CC: r-help@r-project.org Subject: Re: [R] Installing RQuantLib on Win 7 64 Bit On 26 November 2010 at 07:05, Santosh Srinivas wrote: | Hello Group, | | I am trying out RQuantLib on a 64bit Win 7 machine. But running into | installation errors The error message is about as clear as it can get: | install.packages("RQuantLib") | | Warning in install.packages("RQuantLib") : | argument 'lib' is missing: using | 'C:\Users\Tester\Documents/R/win64-library/2.11' | Warning: unable to access index for repository | http://www.stats.ox.ac.uk/pub/RWin/bin/windows64/contrib/2.11 | Warning message: | In getDependencies(pkgs, dependencies, available, lib) : | package ‘RQuantLib’ is not available There is your answer: there simply is no binary package. I need a win64 development box (which I currently do not have) to build QuantLib as a win64 library so that CRAN and R-Forge can turn the RQuantLib source into a binary for you. How bad are things getting? LOL. Seriously though, can anyone such as OP or I download source, build, install, and contrib it back? Up until recently I had been building all the packages from source but one failed to install and now I just use install.package as was attempted here. I've been building on cygwin 1.7. __ 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] Difference between loops and vectorization
Hello R-helpers, A fundamental question ...I'm trying to understand the differences between loop and vectorization ... I understand that it should be a natural choice to use apply / adply when it is needed to perform the same function across all rows of a data frame. Any pointers on why this is so? Unable to find the right reading place on the WWW which explains the concept. Thanks for your help. S __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] using foreach (parallel processing)
Hello group, I am experimenting with parallel processing on my quad core Win 7 32 bit machine. Using these packages for the first time. I can see all my processor running at full performance when I use a smaller dataset require(snow) require(doSNOW) require(foreach) #change the 8 to however many cores\phys processors you have on your machine cl.tmp = makeCluster(rep("localhost",4), type="SOCK") registerDoSNOW(cl.tmp) optData.df <- head(pristine,10) system.time( optData.df$impliedVol <- foreach(i=1:NROW(optData.df),.packages="RQuantLib") %dopar% with(optData.df[i,], tryCatch({EuropeanOptionImpliedVolatility(type,value,underlying, strike, dividendYield, riskFreeRate, maturity, volatility)$impliedVol}, error = function (ex){0})) ) This works fine! PROBLEM: However, when I do the same but with optData.df <- pristine ... which has about 3.8 million options data ... the cores do not seem to be fully utilized (they seem to run at 25%). I noticed some slight delay before the processing starts running ... when I did with the 100k dataset ... do i need to wait longer for any allocations to be done? 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] using foreach (parallel processing)
Thanks. I guess I had to wait long enough to get the threads running and now they seem be on top gear. Hope this thing doesn't crash now! On Thu, Dec 2, 2010 at 3:36 PM, Rainer M Krug wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > On 12/02/2010 10:56 AM, Santosh Srinivas wrote: >> Hello group, > > Hi > > First of all: there is a special interest group for high performance > computing in R, which includes parallel computing, wghich would be more > appropriate to ask. But I will try anyway: > >> >> I am experimenting with parallel processing on my quad core Win 7 32 >> bit machine. Using these packages for the first time. >> >> I can see all my processor running at full performance when I use a >> smaller dataset >> >> require(snow) >> require(doSNOW) >> require(foreach) >> #change the 8 to however many cores\phys processors you have on your machine >> cl.tmp = makeCluster(rep("localhost",4), type="SOCK") >> registerDoSNOW(cl.tmp) >> >> >> optData.df <- head(pristine,10) >> >> system.time( >> optData.df$impliedVol <- >> foreach(i=1:NROW(optData.df),.packages="RQuantLib") %dopar% >> with(optData.df[i,], >> tryCatch({EuropeanOptionImpliedVolatility(type,value,underlying, >> strike, dividendYield, riskFreeRate, maturity, >> volatility)$impliedVol}, >> error = function (ex){0})) >> ) >> >> This works fine! >> >> PROBLEM: However, when I do the same but with optData.df <- pristine >> ... which has about 3.8 million options data ... the cores do not seem >> to be fully utilized (they seem to run at 25%). >> >> I noticed some slight delay before the processing starts running ... >> when I did with the 100k dataset ... do i need to wait longer for any >> allocations to be done? > > Communication to setup the threads ould definitly take some time. > So why don't you try to increase from 100.000 to 1.000.000 and see how > long it takes to initialize the threads? > > You are not mentioning how long you wait? > > Cheers, > > Rainer > >> >> 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. > > > - -- > Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation > Biology, UCT), Dipl. Phys. (Germany) > > Centre of Excellence for Invasion Biology > Natural Sciences Building > Office Suite 2039 > Stellenbosch University > Main Campus, Merriman Avenue > Stellenbosch > South Africa > > Tel: +33 - (0)9 53 10 27 44 > Cell: +27 - (0)8 39 47 90 42 > Fax (SA): +27 - (0)8 65 16 27 82 > Fax (D) : +49 - (0)3 21 21 25 22 44 > Fax (FR): +33 - (0)9 58 10 27 44 > email: rai...@krugs.de > > Skype: RMkrug > -BEGIN PGP SIGNATURE- > Version: GnuPG v1.4.10 (GNU/Linux) > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ > > iEYEARECAAYFAkz3b5YACgkQoYgNqgF2egrqtQCfQKXKZln5tz5eZDTYBmbFvruH > H/4AoIOXZJ7F3lKL6QLRkaQPHZbqBDQn > =odY/ > -END PGP SIGNATURE- > __ 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] colname refered by a variable
try this .. df[,colnames(df)==paste("A","C",sep="")] On Fri, Dec 3, 2010 at 12:05 PM, Yuan Jian wrote: > Hello, > > I tried to use a variable to refer colname, but I got error, could anyone > give me advice? > >>df=data.frame(cbind(AB=1:3,AC=3:5)) >> df$AC > [1] 3 4 5 >> df$paste("A","C",sep="") > Error: attempt to apply non-function > > thanks > Jian > > > > > [[alternative HTML version deleted]] > > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > __ R-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] Querying a data frame or data.table
Hello Group, Is there an easy way to query a data.frame or data.table (this is fast!) for multiple conditions? I don't want to use a SQL kind of statement. I am looking for something like a subset with multiple conditions. Any tips of the like the binary search methodology used for data.table would also help. Thanks in advance. S __ 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] intraday zoo
I'm trying to read intraday zoo but running into issues (again) ... what am I missing here? (the date doesn't seem to read in correctly) > head(dat) TrdDate TrdTime impliedVol 1 20090102 09:55:03 0.3610715 2 20090102 09:55:04 0.3637943 3 20090102 09:55:05 0.3752375 4 20090102 09:55:05 0.4190025 5 20090102 09:55:06 0.3696080 6 20090102 09:55:06 0.4944981 > f <- function(x) chron(x[,1],x[,2], format=c(dates="ymd", times="h:m:s")) > head(z) (741031 09:55:03) (741031 09:55:04) (741031 09:55:05) (741031 09:55:05) (741031 09:55:06) (741031 09:55:06) 0.3610715 0.3637943 0.3752375 0.4190025 0.3696080 0.4944981 Warning message: In zoo(rval[i], x.index[i]) : some methods for “zoo” objects do not work if the index entries in ‘order.by’ are not unique > __ 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.table query
Hello Group, I need a modification in the data.table example to get my intended result shown below ... is there a more simple way! dt <- data.table(A = rep(1:3, each=4), B = rep(1:4, each=3), C = rep(1:2, 6)) dt[, transform(.SD,D=mean(A)), by="B"] The result I want is below ... which is probably long winded! data.table(unique(as.data.frame(dt[, transform(.SD,D=mean(A)), by="B"][,list(B,D)]))) BD [1,] 1 1.00 [2,] 2 1.67 [3,] 3 2.33 [4,] 4 3.00 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.
[R] grep for strings
I am trying to find the function where I can search for a pattern in a text string (I thought I could use grep for this but no :(). > x [1] "abcdefghijkl" I want to find the positions (i.e. equivalent of nchar) for "cd" and in case there are multiple hits .. then the results as a array 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.
[R] foreach question
Hello Group, I am experimenting with parallel processing ... here is part of my code. require(snow) require(doSNOW) require(foreach) cl.tmp = makeCluster(rep("localhost",4), type="SOCK") registerDoSNOW(cl.tmp) foreach(i=1:NROW(sDat),.packages="gdata",.verbose=TRUE) %dopar% { do something 1 do something 2 do something 3 } I ran this individually without a parallel setup and it works perfectly Now when I do the parallel invocation the error being thrown is that the functions which I created are not being passed to the parallel instances. do something 1,2,3 above use my functions which I created in the code itself. Is there someway that I can have then pass to the parallel routines? Is this the right approach? Thanks and have a nice weekend. S __ 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] merging two vectors
unique(c(x,y)) On Sun, Dec 5, 2010 at 8:27 PM, ram basnet wrote: > Dear R users, > > It may be very simple but it is being difficult for me. > I have two vectors with some common string. And, i want to combine into a > vector in such a way that it includes string from both vectors and make a > unique. > > For example: > > x <- paste(rep("A",5),1:5,sep = ".") > x > [1] "A.1" "A.2" "A.3" "A.4" "A.5" > > y <- paste(rep("A"),3:7, sep = ".") > y > [1] "A.3" "A.4" "A.5" "A.6" "A.7" > > Now, I want to combine these two vectors in the following way: > > "A.1" "A.2" "A.3" "A.4" "A.5" "A.6" "A.7" > > I tried with merge(), but not able to get as I want. > > Is there any way to do this in R ? > > If it is, it will be great. > Thanks in advance. > > Regards, > Ram Kumar Basnet. > Wageningen, Netherland. > > > > [[alternative HTML version deleted]] > > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > __ R-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] Time out for a R Function
Hello Group, I have an R-function that works fine for most part but sometime runs into a long loop! (I'm lazy and short on time to debug right now so want to do something easy) For my purpose, it is ok to make few errors is there a way I can put a timeout on a function and the r-process needes to move on to the next step? Thank you. S __ 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] Creating binary variable depending on strings of two dataframes
your question is not clear to me .. but your solution is a variation of > data1$x.1 <- data1$x1 %in% data2$y1 you can play with your conditions to get the result you want On Tue, Dec 7, 2010 at 10:00 PM, Pete Pete wrote: > > Hi, > consider the following two dataframes: > x1=c("232","3454","3455","342","13") > x2=c("1","1","1","0","0") > data1=data.frame(x1,x2) > > y1=c("232","232","3454","3454","3455","342","13","13","13","13") > y2=c("E1","F3","F5","E1","E2","H4","F8","G3","E1","H2") > data2=data.frame(y1,y2) > > I need a new column in dataframe data1 (x3), which is either 0 or 1 > depending if the value "E1" in y2 of data2 is true while x1=y1. The result > of data1 should look like this: > x1 x2 x3 > 1 232 1 1 > 2 3454 1 1 > 3 3455 1 0 > 4 342 0 0 > 5 13 0 1 > > I think a SQL command could help me but I am too inexperienced with it to > get there. > > Thanks for your help! > > -- > View this message in context: > http://r.789695.n4.nabble.com/Creating-binary-variable-depending-on-strings-of-two-dataframes-tp3076724p3076724.html > Sent from the R help mailing list archive at Nabble.com. > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Time out for a R Function
Thank you. I tried this but not sure if I have implemented this correctly ... basically if function1 hangs .. I need the timeout to be triggered and then the process moves to the next function call. I have this: function1 <- function(x){ setTimeLimit(elapsed = 5*60, transient = FALSE) step 1 step 2 step 3 } #Code to execute about function repeatedly. It moves to a new input variable when I call it back through a parameter repeat{ function1(x) } -Original Message- From: Prof Brian Ripley [mailto:rip...@stats.ox.ac.uk] Sent: 07 December 2010 13:23 To: Santosh Srinivas Cc: r-help@r-project.org Subject: Re: [R] Time out for a R Function On Tue, 7 Dec 2010, Santosh Srinivas wrote: > Hello Group, > > I have an R-function that works fine for most part but sometime runs into a > long loop! (I'm lazy and short on time to debug right now so want to do > something easy) > For my purpose, it is ok to make few errors is there a way I can put a > timeout on a function and the r-process needes to move on to the next step? See the help on setTimeLimit(transient = FALSE) . Unlike other suggestions, that does not need you to change the code to check the time. -- 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] One question about R
Why 2.8? You should perhaps go for 2.12 ... I like 2.11 right now because most of my work has been tested on it already and it is quite stable with other packages. But, the ideally you should go for 2.12 which is the most recent release and has substantial enhancements. Then you should post the error that you are getting so that we could try to help. On Thu, Dec 9, 2010 at 7:12 AM, ZihangYin wrote: > I am a beginner with R. After I installed R 2.8.0, I tried to add a package. > R CMD INSTALL RHIPE.tar.gz > I got following error message: > cannot extract package from RHIPE.tar.gz > > Can anyone tell me what's the problem? > > -- > Best Regards, > > Zihang Yin > 919-225-1717 > Computer Science > Duke University > > __ > 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] hi have a question about merging.
Try this male.df <- subset(raceprofiling, (male==1)) female.df <- subset(raceprofiling, (male==0)) people.df <- rbind(male.df,female.df) works? -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of tanzia chaudhury Sent: 09 December 2010 09:02 To: r-help@r-project.org Subject: [R] hi have a question about merging. this is the problem: load this R data frame over the internet and save it to your hard drive. http://rss.acs.unt.edu/Rdoc/library/twang/data/racepro ling.RData please show how to save a dataset of males only (the variable male=1) to a new dataframe. Then do the same thing for females (male=0). Then show how to recombine the two datasets to belike the original one except that the female observations come rst, then the male observations. This resultingdataset should be the same size as the original. this is what i did so far: # loading the R data frame over the internet and saving it to your hard drive >rp<-url("http://rss.acs.unt.edu/Rdoc/library/twang/data/raceprofiling.RData ") >load(rp) >str(raceprofiling) #this shows that in the RData file there are 5000 obs. of 10 variables. # For the fourth dataset, please show how to save a dataset of males only (the variable male=1) #to a new #data frame. >attach(raceprofiling) >s<-male[male==1] >news<-data.frame(s) #The same thing for females (male=0). >r<-male[male==0] >newr<-data.frame(r) now to merge: I tried >merge(newr,news) but this does not give the same observation as the original file. I also tried rbind, but this gives me error. Please help [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-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] Rapache on windows
Hello all, I searched on the www but could not find installation instructution for rapache on windows. The page says that the release runs on UNIX/Linux and Mac OS X operating systems. Has anyone been able to configure it on windows? Any idea how to go about it? 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.