[R] Converting string to data frame

2016-07-28 Thread Steven Kang
Hi R users, I would like to convert a string into a data frame by creating a separator (ie pipe) between each potential fields (then using *read.table* function). ie. Here is the dummy input data for illustration (4 x 5) Date Type Description

[R] PDF extraction with tm package

2016-07-21 Thread Steven Kang
Hi R users, I’m having some issues trying to extract texts from PDF file using tm package. Here are the steps that were carried out: 1. Downloaded and installed the following programs: - Xpdf (Copied the ‘bin32’, ‘bin64’, ‘doc’ folders into ‘C:\Program Files\Xpdf’ directory; also added C:\Progr

Re: [R] String split and concatenation

2010-09-29 Thread Steven Kang
ighly appreciate for any advice. On Wed, Sep 29, 2010 at 3:33 PM, wrote: > dump("x", file = "x.R") > file.show("x.R") > > will get you most of the way. > > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@

[R] String split and concatenation

2010-09-28 Thread Steven Kang
Hi R users, I desire to transform the following vector consisting of repeated characters x <- rep(letters, 3) into this exact format (i.e a single string containing each characters in quotation mark separated by comma between each; al ). ("a", "b", "c", "d", "a", "b", "c", "d",

[R] Regular Expression

2010-08-08 Thread Steven Kang
Hi all, >From a list of strings, I desire to filter out the followings: 1. Digits at the beginning of the strings 2. Character "SPE" following the digits (if it exists) 3. Any characters followed by hyphen The following produces the desired result, but would like to know whether this can be done

Re: [R] apply family functions

2010-08-06 Thread Steven Kang
ini <- as.Date("2010/1/1", "%Y/%m/%d") # Generate arbitrary data frame consisting of date values oc <- data.frame(Open = seq(ini, ini + 6, 1), Close = seq(ini + 365, ini + 365 + 6, 1), Open1 = seq(ini + 365*2, ini + 365*2 + 6, 1), Close1 = seq(ini + 365*3, ini + 365*3 + 6, 1), Open2 = seq(ini + 365

[R] apply family functions

2010-08-05 Thread Steven Kang
Hi all, I would like to flag each record in the data according to certain conditions as specified below. For example, If "Close_date" in *dat* is between ("Open" & "Close") or ("Open1" & "Close1") or ("Open2" & "Close2") in *oc, *flag the records as "Valid", otherwise "Invalid" I would like to

[R] Date conversion

2010-08-04 Thread Steven Kang
Hi all, I am trying to convert all the dates (all days that are not Friday) in data frame into dates to next Friday. The following works but the result is returned as vector rather than the original class. It would be greatly apprecited if you could provide any solution to this problem. Many th

[R] Carriage return character issue

2010-08-03 Thread Steven Kang
Hi all, I imported a file (in CSV format) into R for processing, then imported the result into MySQL. However, there are *carriage return* characters (hexadecimal: *0D*) that are appended to the characters in the last field of the table. i.e *\r* appended to the character values (as shown below)

[R] Storing processed results back into original objects

2010-07-15 Thread Steven Kang
Hi all, There are matrices with same column names but arranged in different orders and I desire columns of these matrices to have same order. For example, below are 2 arbitrary data sets with columns arranged in different order. I require columns of these to have same order as specified in "colum

[R] "Write.table" problem

2010-06-15 Thread Steven Kang
Hi all, I have imported csv file for processing and exported as txt file (using * "write.table"* with sep = "\t", row.names = FALSE options) However, when I import this txt file in R (*"read.delim"* with header = TRUE, sep = "\t" options) the dimension (i.e number of rows) is inconsistent with th

[R] Generating records from data frame

2010-03-09 Thread Steven Kang
Hi all, I wish to generate additional records according to one of the field values in a data frame. For example, unique record from the input data is required to be generated number of times as specified in the 'Number' field in the following code. > x <- data.frame(Name = c("a", "b", "c", "d"),

[R] Help on loading "xlsx" package

2010-02-11 Thread Steven Kang
Dear R users, Im trying to load *"xlsx"* package which depends on *"xlsxjars"* and * "rJava"* packages. All the 3 packages (zipped files) are installed successfully in windows. I have added "C:\Program Files\Java\jre1.6.0_03\bin\client" to the PATH variable to get rJava working. However, the f

[R] Creating missing children element in XML file

2010-02-02 Thread Steven Kang
Dear R users, The following are 2 root elements contained in XML file (of 1 root elements). child element (as highlighted in 2nd root element) is missing in the 1st root element. Consequently, when imported into R (via "xmlToDataFrame" function), the columns ("Section", "ProductionDate" &

[R] Installling source package

2010-01-31 Thread Steven Kang
Hi R users, Im trying to install XML source package (in window platform) using the following command. *install.packages(pkgs = "C:\\Documents and Settings\\skang\\Desktop\\Softwares\\R\\Library\\XML_2.6-0.tar.gz", repos = NULL, type = "source")* and get the following result. gzip: stdin: unexpec

[R] Problem associated with importing xlsx data file (Excel 2007)

2010-01-27 Thread Steven Kang
Hi all, I have imported xlsx file (Excel 2007) into R using the following scripts. *library(RODBC) * *setwd("...") * *query <- odbcConnectExcel2007(xls.file = "GI 2010.xlsx", readOnly = TRUE) dat <- sqlQuery(query, "select * from [sheet1$]", as.is = TRUE, na.strings = "exp")* *dat* cont

[R] Replacing ' (apostrophe) with "(two apostrophe)

2010-01-26 Thread Steven Kang
Hi all, I am trying to replace a string containing ' (apostrophe) with "(two apostrophes not inverted commas). i.e *asdf'qwer* replaced to *asdf"qwer* Is this feasible? Thanks . -- Steven [[alternative HTML version deleted]] __ R-help@

Re: [R] Creating directories & folders

2010-01-24 Thread Steven Kang
On Mon, Jan 25, 2010 at 10:22 AM, Cedrick W. Johnson < cedr...@cedrickjohnson.com> wrote: > Try: > > > for (i in 1:length(folders)) { > dir.create(paste(parent.dir,folders[i], sep="/")) > } > > The above creates FUND1, FUND2 & MARINE folders whereas the desired folders to be created are "FD1 Q4 2

[R] Creating directories & folders

2010-01-24 Thread Steven Kang
Dear R users, I would like to create the following 3 folders (FUND1, FUND2, MARINE) within the 'parent.dir' as defined below. FUND1 <- "FD1 Q4 2009" FUND2 <- "FD2 Q4 2009" MARINE <- "MARINE Q4 2009" parent.dir <- "D:/." folders <- c("FUND1", "FUND2", "MARINE") for (i in 1:

[R] Dynamic arguments in "rbind" function

2010-01-04 Thread Steven Kang
Hi, all Basically, I have unknown number of data that need to be imported and collapsed row-wisely. The code below works fine, however the "rbind" function may require 50 arguments if there are 50 data files... Thus, I would like to explore whether there are any methods in using dynamic objects

[R] Eliminating 'Unprintable ASCII' characters

2009-11-24 Thread Steven Kang
Hi all, I have a csv file containing words with *UNPRINTABLE ASCII* characters (described in the following table). Are there any viable method in eliminating these characters? I realise that *EXTENDED ASCII* characters (i.e , ¡, ¢, £, ¤ etc) can be removed or replaced via *"gsub"* or *"gregexpr"

[R] Removing "+" and "?" signs

2009-11-22 Thread Steven Kang
Hi all, I get an error message when trying to replace *+* or *?* signs (with empty space) from a string. x <- "asdf+,jkl?" gsub("?", " ", x) Error message: Error in gsub("?", " ", x) : invalid regular expression '?' In addition: Warning message: In gsub("?", " ", x) : regcomp error: 'In

[R] Finding & replacing non-ASCII characters

2009-11-19 Thread Steven Kang
Hi guys, Are there any feasible methods in searching & finding non-ASCII characters in R? For example, from the following object, x <- mia. SzaÌmitaÌó The desired output is, x.out <- mia. SzaImitaIA Your help in resolving this would be greatly appreciated. [[alternative

Re: [R] how can I convert .csv format to matrix???

2009-11-02 Thread Steven Kang
can try matrix.x <- as.matrix(x) On Mon, Nov 2, 2009 at 8:38 PM, bbslover wrote: > > In my disk C:/ have a a.csv file, I want to read it to R, importantly, > when > I use x=read.csv("C:/a.csv") ,the x format is data.frame, I want to it > to > become matrix format, how can I do it ? > > t

[R] Using processed objects as arguments of a function

2009-11-01 Thread Steven Kang
Dear R users, I wish to utilise processed and saved objects as arguments of a function. Specifically, I have created objects using *"assign"* & *"paste"* functions with an incremental index i, the names of the objects are: fund1, fund2, fund3,., fund80,. (where the numerical value in

Re: [R] Removing & generating data by category

2009-10-29 Thread Steven Kang
> > Color me puzzled. Can you express the run more clearly in Boolean logic? > > Its a bit tedious to explain in Boolean logic.. Suppose the data is subsetted according to two distinct 'clm' variables (i.e 1 set consisting of only "General" & other only of "Life") * General.dat* * * id loc

Re: [R] Removing & generating data by category

2009-10-29 Thread Steven Kang
;),6),rep("Life",4))) > > a$uid <- paste(a$id, ".", a$loc, sep="") > > out <- tapply( a$clm, a$uid, paste ) # can also add collapse="," > $A1.B1 > [1] "General" > > $A2.B2 > [1] "General" "Life"

[R] Removing & generating data by category

2009-10-28 Thread Steven Kang
Dear R users, Basically, from the following arbitrary data set: a <- data.frame(id=c(c("A1","A2","A3","A4","A5"),c("A3","A2","A3","A4","A5")),loc=c("B1","B2","B3","B4","B5"),clm=c(rep(("General"),6),rep("Life",4))) > a id loc clm 1 A1 B1 General 2 A2 B2 General 3 A3 B3 General 4 A

[R] Loading same libraries (old version & newest version) in r

2009-10-11 Thread Steven Kang
Hi all, I require 2 RMySQL libraries in order to query from a database. 'RMySQL_0.7-4' (newest version) results in an error when more than 1 field is queried. ''RMySQL_0.5-11' (old version) resolves this issue where more than 1 field can be queried without any errors. However, other queries resu

[R] 'dbSendQuery' or 'dbGetQuery' error from library 'RMySQL'

2009-10-06 Thread Steven Kang
Dear R users, Basically, I desire to extract more than 1 column from a table in MySQL database. However, I get a pop-up error reading *"R for Windows GUI front-end has encountered a problem and needs to close. We are sorry for the incovenience."* when there are more than 1 field following "SELEC

Re: [R] Suppressing script commands in R console when executing long program

2009-09-19 Thread Steven Kang
Thanks all for your help! On Sat, Sep 19, 2009 at 2:05 AM, Ishwor wrote: > Hi Duncan > > >> You can try putting this in your Rprofile > >> options("keep.source=F") > >> > >> This will work in the R cmd but it will not work in the RGui > >> > > > > The syntax is wrong there: that should be optio

[R] Suppressing script commands in R console when executing long program

2009-09-17 Thread Steven Kang
Hi R users, I have a script composing of more than 1000 lines and would like suppress the R codes from the console when executing the script (to reduce the physical processing time) I have tried options(echo=T) but no luck.. *Q1. Are there any way of suppressing the commands in the R console?*

[R] Header names when importing csv/excel data sets

2009-09-14 Thread Steven Kang
Dear R users, Suppose the csv file contains header names such as *"Nike, dunk"*, *"Converse, All stars"* etc When imported to R (with header = T option), the column names are given by: *"Nike..dunk"* *"Converse..All.stars"* I have tried the following command to convert these c

[R] Accumulating results from "for" loop in a list/array

2009-09-10 Thread Steven Kang
Dear R users, I would like to accumulate objects generated from 'for' loop to a list or array. To illustrate the problem, arbitrary data set and script is shown below, x <- data.frame(a = c(rep("n",3),rep("y",2),rep("n",3),rep("y",2)), b = c(rep("y",2),rep("n",4),rep("y",3),"n"), c = c(rep("n"

Re: [R] "Read.csv" in R with dynamic file (1st) argument

2009-09-10 Thread Steven Kang
r build the name however you like > fpath <- 'macintoshhd/users/me/myfolder/ # or whatever you need > > read.csv(eval(paste(fpath,fnam,sep="")) #worked for me > > > Carl > > > > --- > > Try this: > > read.csv(sprintf("D://R//Da

[R] "Read.csv" in R with dynamic file (1st) argument

2009-09-09 Thread Steven Kang
Dear R users, I have numerous data sets (csv files) saved in the folder which has the same name as individual data. (i.e data x1 saved in x1 folder, data x2 in x2 folder etc) I would like to read in the desired data set name using 'scan' function and assign this inputted value to an object so th

[R] Character manipulation using "strsplit" & vectorization

2009-09-07 Thread Steven Kang
<- "The university of North Carolina" } Note: above shows only partial (if/else if) conditions. Q1: The above "for" loop works fine (but very slow on large data set..), thus I would like to explore whether there is an alternative VECTORIZATION metho

[R] User defined function's argument as Subset function's input

2009-09-03 Thread Steven Kang
Dear R users, I have a data where I desire to subset according to certain conditions. However, the script is very messy as there are about 30 distinct conditions. (i.e. same script but with different conditions) I would like to make a user defined function so that I can input the desired conditi

Re: [R] Help on efficiency/vectorization

2009-08-27 Thread Steven Kang
> > fortune("parse") > > If the answer is parse() you should usually rethink the question. > -- Thomas Lumley > R-help (February 2005) > > > So please use one of the other answers given in the thread... > > >MO> --- On Thu, 27/8/09

[R] Help on efficiency/vectorization

2009-08-26 Thread Steven Kang
Dear R users, I am trying to extract the rownames of a data set for which each columns meet a certain criteria. (condition - elements of each column to be equal 1) I have the correct result, however I am seeking for more efficient (desire vectorization) way in implementing such problem as it can

[R] Removing objects from workspace

2009-08-24 Thread Steven Kang
Hi all, I am currently woking with hundreds of objects in workspace and whenever I invoke ls() to observe the names of the objects, there are too much of unnecessary variables. For example, if I only require say 3 or 4 objects from hundreds of objects in workspace, are there any methods that may

[R] Filling in empty arrays/lists from using "paste" function

2009-08-24 Thread Steven Kang
Dear R users, I am trying to fill in arrays (5 different according to distinct "id") from objects produced from arbitrary data set below. a <- data.frame(id=rep(c("idA1","idA2","idA3","idA4","idA5"),2),pro=c("bb","uu","ee","tt","uu","gg","tt","bb","gg","ee"),sal=rpois(10,2)) idpro sa

Re: [R] Assigning value of subset argument in "subset" function

2009-08-23 Thread Steven Kang
criteria where xx == 9 sub.a.10 <- sum(sub.a$xxx) to get sum of xxx (=28) satisfying the criteria where xx == 10 etc Please enlighten my problem. thanks On Mon, Aug 24, 2009 at 12:19 PM, David Winsemius wrote: > > On Aug 23, 2009, at 10:12 PM, David Winsemius wrote: > > &

[R] Assigning value of subset argument in "subset" function

2009-08-23 Thread Steven Kang
Dear R users, I am using "subset" function to filter out specific conditions and would like to use the value of subsetted argument as a name of an object. Specifically, from the following statement: a <- subset(dat, dat$x == "A" & dat$xx == 1 & dat$xxx == "AB" & dat$y == "B" & dat$yy == 2)

[R] Appending elements according to criteria to an empty array

2009-08-20 Thread Steven Kang
Hi all R users, I am trying to extract elements from an array (x as shown below) where the difference between the consecutive elements does not equal 1. The desired output is: j = 6,17,27,38,58,69,79,90 However, the code below only returns: j = 1,69,79,90 I am a