Re: [R] multiple values in one column

2012-04-06 Thread Ashish Agarwal
How about reading lines and separating out cases having more than one major? For cases having more than one major, process the data to create duplicate rows - one for each major On Fri, Apr 6, 2012 at 8:39 PM, John D. Muccigrosso < intern...@muccigrosso.org> wrote: > I have some data files in whi

Re: [R] Trying to merge new data set to bottom of old data set. Both are zoo objects.

2012-04-04 Thread Ashish Agarwal
It is unclear what the problem is. Does following code solve your append problem? fmt = "%m/%d/%Y %H:%M" fname <- "new.txt" #records = 2904 newfile <- read.csv(fname, header = TRUE, sep = ",", skip=0, colClasses = c(rep("character",2), rep("numeric", 16)) ) newfile.comb <- cbind(newfile[2], newfil

Re: [R] Grouping and/or splitting

2012-04-03 Thread Ashish Agarwal
Thanks a ton! It was weird because according to me ordering should have by default. Anyways, your workaround along with Weidong's method are both good solutions. On Wed, Apr 4, 2012 at 12:10 PM, Berend Hasselman wrote: > > On 04-04-2012, at 07:15, Ashish Agarwal wrote: > > >

Re: [R] Compare by row and insert previous row value (Or non Time Series Lag)

2012-04-03 Thread Ashish Agarwal
Hello my old friend. Remember me from Cambridge. Here is the dirty way of getting your desired output and enjoy hassling with trips that are incomplete or missing information inpfil <- read.csv("sample_trip_od_input.csv") aa <- split(inpfil, paste(inpfil[,1],inpfil[,2],sep=',')) OrigTAZ <- inpfil

Re: [R] Grouping and/or splitting

2012-04-03 Thread Ashish Agarwal
4, 2012 at 6:29 AM, Rui Barradas wrote: > Hello, > > > Ashish Agarwal wrote > > > > I have a dataframe imported from csv file below: > > > > Houseid,Personid,Tripid,taz > > 1,1,1,4 > > 1,1,2,7 > > 2,1,1,96 > > 2,1,2,4 > > 2,

[R] Grouping and/or splitting

2012-04-03 Thread Ashish Agarwal
I have a dataframe imported from csv file below: Houseid,Personid,Tripid,taz 1,1,1,4 1,1,2,7 2,1,1,96 2,1,2,4 2,1,3,2 2,2,1,58 There are three groups identified based on the combination of first and second columns. How do I split this data frame? I tried aa <- split(inpfil, inpfil[,1:2]) but it

Re: [R] R Error : DATA to MATRIX

2012-03-26 Thread Ashish Agarwal
On similar lines, how do I assign the position of the an occurence of a value say 7 in a data vector to another data vector? > nFields [1] 6 6 6 6 6 6 7 7 6 6 6 7 6 6 6 6 I need the output data vector showing occurence of 7 as: [1] 7 8 12 I tried following but both has errors xFields7 <- NULL fo

Re: [R] Problem reading mixed CSV file

2012-03-26 Thread Ashish Agarwal
Need to fix up the file having 6 and 7 columns to be read as 6 columns only. Here is the working. Can somebody please let me know how do I maintain the order in which rows were read and append the two files into one: > count.fields(textConnection("LL1532Ap,ABC# Depot-A+,,1971,8,2 LL1532Ap,ABC# Dep

Re: [R] Problem reading mixed CSV file

2012-03-25 Thread Ashish Agarwal
thanks. works very well. On Mon, Mar 26, 2012 at 12:12 PM, Berend Hasselman wrote: > > On 26-03-2012, at 08:40, Ashish Agarwal wrote: > > > comment.char = NULL does not work. > > Is there any way to make it NULL rather than having a specific character > like 

Re: [R] Problem reading mixed CSV file

2012-03-25 Thread Ashish Agarwal
comment.char = NULL does not work. Is there any way to make it NULL rather than having a specific character like '%'? On Mon, Mar 26, 2012 at 12:06 PM, Berend Hasselman wrote: > > > comment.char = "#" > > > > How do I turn it off? > ??? > > How about comment.car="%" for example? > > Berend > >

Re: [R] Problem reading mixed CSV file

2012-03-25 Thread Ashish Agarwal
OMG. I think it uses comment character # as default in the argument. comment.char = "#" How do I turn it off? On Mon, Mar 26, 2012 at 11:56 AM, Berend Hasselman wrote: > > On 26-03-2012, at 08:16, Ashish Agarwal wrote: > > > Why does the output in the

Re: [R] Problem reading mixed CSV file

2012-03-25 Thread Ashish Agarwal
Why does the output in the following say 2 and not 6? > count.fields(textConnection("LL1532Ap,ABC# Depot-A+,,1971,8,2 + LL1532Ap,ABC# Depot-A+,Bhutan,1971,6,1 + LL1532Ap,ABC# Depot-A+,China,1971,17,1 + LL1532Ap,ABC# Depot-A+,China,1971,33,1 + LL1532Ap,ABC# Depot-A+,HongKong,1971,16,2 + LL1532Ap,AB

Re: [R] Problem reading mixed CSV file

2012-03-20 Thread Ashish Agarwal
unt.fields to write out to separate files" > > x <- count.fields(...) > input <- readLines(..) > writeLines(input[x == 6], file = '6fields.csv') > writeLines(input[x==7], file = '7fields.csv') > > On Tue, Mar 20, 2012 at 11:43 AM, Ashish Agarwal &g

Re: [R] Problem reading mixed CSV file

2012-03-20 Thread Ashish Agarwal
       1967  6  8 >> > 16                       XY PopatLal                      1967  7  7 >> > 17                       XY PopatLal                      1967  9  1 >> > 18                       XY PopatLal                      1967 10  1 >> > 19                       XY Pop

Re: [R] Problem reading mixed CSV file

2012-03-18 Thread Ashish Agarwal
1 > 21                       XY PopatLal               Boston 1967  7 11 > 22                       XY PopatLal               Boston 1967  9  2 > 23                       XY PopatLal               Boston 1967 10  3 > 24                       XY PopatLal               Boston 1967  7  2 >>

Re: [R] Problem reading mixed CSV file

2012-03-16 Thread Ashish Agarwal
I have a file that is 5000 records and to edit that file is not easy. Is there any way to line 10 differently to account for changes in the third field? On Fri, Mar 16, 2012 at 11:35 PM, Peter Ehlers wrote: > On 2012-03-16 10:48, Ashish Agarwal wrote: >> >> Line 10 has City and

Re: [R] Problem reading mixed CSV file

2012-03-16 Thread Ashish Agarwal
Line 10 has City and State that too separated by comma. For line 10 how can I read differently as compared to the other lines? On Fri, Mar 16, 2012 at 10:59 PM, David Winsemius wrote: > > On Mar 16, 2012, at 1:11 PM, Ashish Agarwal wrote: > >> I want to import this CSV file into R

Re: [R] Problem reading mixed CSV file

2012-03-16 Thread Ashish Agarwal
I want to import this CSV file into R. The CSV file is ,,,1968,21,0 ,,Boston,1968,13,0 ,,Boston,1968,18,0 ,,Chicago,1967,44,0 ,,Providence,1968,17,0 ,,Providence,1969,48,0 ,,Binky,1968,24,0 ,,Chicago,1968,23,0 ,,Dally,1968,7,0 ,,Raleigh, North Carol,1968,25,0 Addy ABC-Dogs Stars-W8.1,,Providence,

[R] Problem reading mixed CSV file

2012-03-16 Thread Ashish Agarwal
I am having trouble reading this CSV file in R. There are six attributes that I need to read - CVar1, CVar2, Location, Year, Nvar3, Nvar4. Can somebody help in reading this file? On line 10 it has city and state separated by comma. I had been a user of SAS where I can use different format to read