[R] pie chart

2011-09-08 Thread Mohan L
Hi All,

I have txt file like :

$ cat data.txt
US  10
UK  12
Ind 4
Germany 14
France  8

 rawdata - read.table(file='data.txt',sep='\t' , header=FALSE)

 rawdata
   V1 V2
1  US 10
2  UK 12
3 Ind  4
4 Germany 14
5  France  8

I want to draw pie chart for the above data.

How to  split rawdata into :
con - c(US,UK,Ind,Germany,France);
total - (10,12,4,14,8)


Any help will be appreciate.

Thanks  Rg
Mohan L

__
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 to add a new column filled with value 1

2010-11-09 Thread Mohan L
Dear All,

I have a data frame with  5 column and 201 row data. I want to add one
more column between column 1 and 2 with value of 1. So the new column
has to be the second column filled with 1. Any help will be
appreciated.

Thanks for your time.


Thanks  Rg
Mohan L

__
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 to merge two data frame if name matches

2010-11-09 Thread Mohan L
Dear All,

I have two data like this :

$cat main.csv

name,id,memory,storage
mohan,1,100.20,1.10
ram,1,200,100
kumar,1,400,50
xxx,1,100,40
aaa,1,800,45
mount,1,200,80

 main - read.csv(file='main.csv',sep=',' , header=TRUE)
 main
   nameidmemory storage
1 mohan   1100.2  10
2   ram  1   200.0 100
3 kumar1   400.0  50
4   xxx  1   100.0  40
5   aaa  1   800.0  45
6 mount1   200.0  80


$cat other.csv
name,ip,bsent,breceived
mohan,1,12.00,0.01  
xxx,1,00.00,1.110
kumat,1,1.00,1.00
mmm,1,10.00,8.08
own,1,20.13,12.08
per,1,1.89,0.89


 other - read.csv(file='other.csv',sep=',' , header=TRUE)
 other
   nameip   bsent   breceived
1 mohan   1   12.00 0.01
2   xxx  1   0.00  1.11
3 kumat1   1.00  1.00
4   mmm   1   10.00 8.08
5   own  1  20.13 12.08
6   per   1  1.89   0.89



I want to merge ip,bsent,breceived column to main , If the name in
the the main data frame is there in the other data frame . some
thinng like this:

nameid  memory   storage  ip   bsent breceived

mohan1100  20 1 12.00 0.01
ram1200  1000 00.000.00
kumar1400  50  1 1.00  1.00
xxx1100  40  1 00.001.110
aaa 1800  45 0 00.0000.00
mount1200  80  0 00.0000.00


If in case the name in the main data frame does not there in the
other data frame, simple I want to add zero to ip,bsent,breceived
value.


I hope this can be done with R. Any help will appricated.

Thanks for you time.

Thanks  Rg
Mohan L

__
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 variable in rmysql query

2010-11-07 Thread Mohan L
Dear All,

I am using this query it returns id :

id - dbGetQuery(con1,SELECT id FROM tenants WHERE name LIKE '%consim%')

But In my case the string consim is there in another variable(it is
coming from configuration file);

 str - consim

I am trying to replace the string some this like, but it not working:

 id - dbGetQuery(con1,SELECT id FROM tenants WHERE name LIKE '%str%')

I need help to replace the value of str . Any help will really appreciated .

Thanks for your time.

Mohan L

__
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 to sum up data frame

2010-11-07 Thread Mohan L
Dear All,

I have a data frame like this:

name  ip  Bsent Breceived
a   10.00  0.00
a   2   1.43   19.83
a   1   0.00  0.00
a  21.00  1.00
b  10.00  2.00
b  3   0.00  2.00
b  2   2.00  0.00
b 2   2.00  0.00
b 1   24.40 22.72
c 1   1.00  1.00
c 1   2.00  1.00
c 1   2.00  1.00
c 1  90.97  15.70
d 0   0.00  0.00
d 1 30.00   17.14

I want to sum up the similar name into one row, like :

name  ip  Bsent Breceived
a62.43  20.83
b9   28.40 26.72
c
d

I need help to sum up. Thanks for your time.


Thanks  Rg
Mohan L

__
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 required to remove \\N

2010-11-06 Thread Mohan L
Dear All,

I have .csv file it looks like this :
rawdata - read.csv(file='/home/Mohan/Rworks/tmp/VMList_User.txt',sep='\t'
, header=FALSE)

 head(rawdata,n=5)
  TenantDomain Owner  Current State
1\\N  ROOTadmin Running
2\\N  ROOTadmin Stopped
3\\N  ROOTadmin Running
4\\N  ROOTadmin Running
5\\N ROOTadmin Running
20  DEMO   ROOTadmin Stopped
21  DEMOROOT   admin Stopped
22  Demo ROOT   admin Stopped


The first column contain the \\n up to 19 row. I need to replace the
\\N value to  Blankspace .  Any help will  really appreciated.

Thanks for your time.

Thanks  Rg
Mohan L

__
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 current working directory to the location of the source file

2010-06-10 Thread Mohan L
On Fri, Jun 11, 2010 at 6:03 AM, Marcin Gomulka mrgo...@gmail.com wrote:

 AFAIK a script run through source() does not have any legit way to learn
 about it's own location.

 I need this to make sure that the script will find its datafiles after I
 move the whole directory. (The datafiles are in the same directory.)

 Here is a hack I invented to work around it:

 print(getwd())
 source_pathname  = get(ofile,envir = parent.frame())
 source_dirname = dirname(source_pathname )
 setwd(source_dirname)
 print(getwd())

 Question: Is there a better, cleaner way?


Hi,

I am using some thing like this to setup working directory:

##set working directory

pwd - getwd()
if (!is.null(pwd)) {
setwd(pwd)
} else {
print(Directory not found)
}

Thanks  Rg
Mohan L

[[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] Re :help to aggregate data

2010-06-09 Thread Mohan L
Dear All,

I have the data some thing like this, I am showing here three days data
only:

 dummy.data - read.table(file='dummy.txt',sep='', header=TRUE)
 dummy.data
 StDate Domaindesc Logins
1  05/01/10xxx 10
2  05/01/10xxx 45
3  05/01/10xxx  2
4  05/01/10yyy 45
5  05/01/10yyy 20
6  05/01/10yyy 22
7  05/01/10zzz 34
8  05/01/10zzz 54
9  05/01/10zzz  1
10 05/01/10zzz  0
11 05/02/10yyy 32
12 05/02/10xxx 40
13 05/02/10zzz 23
14 05/02/10yyy  5
15 05/02/10zzz 12
16 05/02/10xxx 19
17 05/02/10xxx 23
18 05/02/10xxx 11
19 05/02/10yyy  9
20 05/02/10zzz  0
21 05/03/10xxx  2
22 05/03/10xxx 21
23 05/03/10xxx  6
24 05/03/10yyy 45
25 05/03/10yyy 43
26 05/03/10yyy 34
27 05/03/10yyy 41
28 05/03/10zzz 31
29 05/03/10zzz 19
30 05/03/10zzz 27

I trying to aggregate(sum) the Logins based on  Domaindesc,StDate. I need
like this :

Domaindesc05/01/10 05/02/10 05/03/10
xxx 5793 29
yyy 8746 122
zzz

Any help will be greatly appreciated.

Thanks for your time.
Mohan L

[[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] Re : help to replace variable value

2010-05-28 Thread Mohan L
Dear All,

I have a data frame data  with Jan , Feb as column. I using  like this
data$Jan to take Jan column. I have the Jan in another variable

var1 - Jan

data$var1

I need to replace the variable value there . Any help will be greatly
appreciated.

Thanks  Rg
Mohan L

[[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] Factor to Numeric

2010-05-26 Thread Mohan L
Dear All,

I have a data frame with State and 12 Months as column. I want to convert
all the 12 month column from factor to numeric.
any help will be greatly appreciated.
 str(data)
'data.frame':33 obs. of  9 variables:
 $ State: Factor w/ 33 levels Andaman and Nicobar Islands,..: 1 2 3 4
5 6 7 8 9 10 ...
 $ April: Factor w/ 21 levels 0,1,10,116,..: 2 16 1 1 9 20 1 1 2
21 ...
 $ August   : Factor w/ 18 levels 0,1,10,125,..: 1 14 1 1 9 3 1 1 2
5 ...
 $ February : Factor w/ 19 levels 0,1,103,..: 1 15 1 1 2 6 2 1 2 14
...
 $ January  : Factor w/ 19 levels 0,1,10,114,..: 1 15 1 1 11 12 2 1
1 4 ...
 $ July : Factor w/ 16 levels 0,1,122,..: 1 13 1 1 1 12 8 2 1 4
...
 $ June : Factor w/ 18 levels 0,1,10,119,..: 1 14 1 1 9 10 9 2 1
4 ...
 $ May  : Factor w/ 20 levels 0,1,10,111,..: 2 19 1 1 10 15 1 1
1 5 ...
 $ September: Factor w/ 19 levels 0,1,11,122,..: 1 18 1 1 14 3 2 1 2
9 ...

Thanks  Rg
Mohan L

[[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] Factor to Numeric

2010-05-26 Thread Mohan L
On Wed, May 26, 2010 at 1:13 PM, Ivan Calandra ivan.calan...@uni-hamburg.de
 wrote:

 Hi,

 What about:
 as.numeric(as.character(data$State))
 ?


What I what is, I want to convert all the column excluding State to factor
to numeric in the data frame. So that  I will send  this data frame to
another function to total .

Any help.

Thanks  Rg
Mohan L

[[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 required to melt a data frame

2010-05-25 Thread Mohan L
I have the raw data with 9 column and 197977 row:

 dummy
   State Months Bedroom
1xxxJan   1
2xxxJan   2
3xxxJan   1
4yyyJan   1
5yyyJan   2
6yyyJan   1
7zzzJan   3
8zzzJan   1
9zzzJan   2
10   xxxFeb   3
11   xxxFeb   4
12   xxxFeb   2
13   yyyFeb   1
14   yyyFeb   2
15   yyyFeb   1
16   zzzFeb   2
17   zzzFeb   3
18   zzzFeb   3

 dim(rawdata)
[1] 197977  9

I want to do some calculation on the State Months Bedroom. So I am
picking only three column using subset.

 subsets.dummy - subset(dummy, select=c(State,Months,Bedroom))
 subsets.dummy
   State Months Bedroom
1xxxJan   1
2xxxJan   2
3xxxJan   1
4yyyJan   1
5yyyJan   2
6yyyJan   1
7zzzJan   3
8zzzJan   1
9zzzJan   2
10   xxxFeb   3
11   xxxFeb   4
12   xxxFeb   2
13   yyyFeb   1
14   yyyFeb   2
15   yyyFeb   1
16   zzzFeb   0
17   zzzFeb   3
18   zzzFeb   3

From the above data. I want below table for 1,2,3,4 Bedroom.
Ex : for 1 Bedroom, I need how may(count of 1 Bedroom) 1 Bedroom is there in
a particular state for month wise.

State  Jan Feb
 xxx   20
 yyy   22
 zzz   10

for 2 Bedroom :
State  Jan Feb
 xxx   11
 yyy   11
 zzz   10

I want to melt subsets.dummy data for the above requirement. To achive
this I am doing like this:

melt.data.frame(subsets.dummy,id.vars=c(State,Bedroom),measure.vars=Months)
   State Bedroom variable value
1xxx   1   Months   Jan
2xxx   2   Months   Jan
3xxx   1   Months   Jan
4yyy   1   Months   Jan
5yyy   2   Months   Jan
6yyy   1   Months   Jan
7zzz   3   Months   Jan
8zzz   1   Months   Jan
9zzz   2   Months   Jan
10   xxx   3   Months   Feb
11   xxx   4   Months   Feb
12   xxx   2   Months   Feb
13   yyy   1   Months   Feb
14   yyy   2   Months   Feb
15   yyy   1   Months   Feb
16   zzz   2   Months   Feb
17   zzz   3   Months   Feb
18   zzz   3   Months   Feb

I trying to get a new data frame for 1 bedroom using cast. But I am not able
to get the below data for 1 Bedroom using cost.

State  Jan Feb
 xxx   20
 yyy   22
 zzz   10

I not able to understand how to cost it.  any help will be greatly
appreciated.

Thanks  Rg
Mohan L

[[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] help required to melt a data frame

2010-05-25 Thread Mohan L
On Tue, May 25, 2010 at 6:59 PM, Hadley Wickham had...@rice.edu wrote:

  I trying to get a new data frame for 1 bedroom using cast. But I am not
 able
  to get the below data for 1 Bedroom using cost.
 
  State  Jan Feb
   xxx   20
   yyy   22
   zzz   10

 What do those numbers represent?

 Hadley


The raw data is  real estate  property portal data. the numbers represent
how many 1 Bedroom house has registered in xxx state on particular months.
Then we will normalize the data and plot the graph for trend analysis.

Thanks  Rg
Mohan L

[[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] help required to melt a data frame

2010-05-25 Thread Mohan L

 In that case, you probably want:

 subsets.melt - melt(subsets.dummy,id.vars=c(State,Bedroom, Months))
 cast(subsets.melt, State ~ Months, fill = 0, fun = length)

 Hadley


Dear Hadley,

 subsets.melt - melt(subsets.dummy,id.vars=c(State,Bedroom, Months))
 subsets.melt
   State Bedroom Months
1xxx   1Jan
2xxx   2Jan
3xxx   1Jan
4yyy   1Jan
5yyy   2Jan
6yyy   1Jan
7zzz   3Jan
8zzz   1Jan
9zzz   2Jan
10   xxx   3Feb
11   xxx   4Feb
12   xxx   2Feb
13   yyy   1Feb
14   yyy   2Feb
15   yyy   1Feb
16   zzz   2Feb
17   zzz   3Feb
18   zzz   3Feb
 cast(subsets.melt, State ~ Months, fill = 0, fun = length)

It show some thing like this :

Using Months as value column.  Use the value argument to cast to override
this choice
Error in `[.data.frame`(data, , variables, drop = FALSE) :
  undefined columns selected

Thanks
Mohan L

[[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] help required to melt a data frame

2010-05-25 Thread Mohan L
On Tue, May 25, 2010 at 9:35 PM, Wu Gong gho...@gmail.com wrote:


 Do you mean count frequency of One Bedroom?

 table(dummy[dummy$Bedroom==1,][,1:2])


Dear learner,

Thanks for you time.

Yes, that is what I am trying to archive using  melt and cost.  any way it
works for me . Thanks for your help.


Thanks  Rg
Mohan L

[[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 required state wise count

2010-05-24 Thread Mohan L
I have the data like this:

 dummy
   State Months No
1xxxJan  1
2xxxJan  2
3xxxJan  1
4yyyJan  1
5yyyJan  2
6yyyJan  1
7zzzJan  3
8zzzJan  1
9zzzJan  2
10   xxxFeb  3
11   xxxFeb  4
12   xxxFeb  2
13   yyyFeb  1
14   yyyFeb  2
15   yyyFeb  1
16   zzzFeb  2
17   zzzFeb  3
18   zzzFeb  3

I want for a month Jan how many count(row) is there for xxx and yyy.some
thing like this:

State Jan  Feb  Mar
xxx   3 3
yyy   3 3
zzz   3 3

Any clue will be greatly appreciated

Thanks  Rg
Mohan L

[[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] help required state wise count

2010-05-24 Thread Mohan L

  Hi Mohan,
 Try this:

 table(dummy$State,dummy$Months)

 Jim

 Thanks for your time.
table(dummy$State,dummy$Months)

in this case the state column becomes the row index. I want the state name
as the first column. There may be a way to do it.

Thanks  Rg
Mohan L

[[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] rounding up to nearest integer

2010-05-24 Thread Mohan L
Dear All,

I have a data frame data  and the below is the str of data :

$ Feb   : int  1 1195 0 11 28 152 24 2 1 1470 ...
 $ Mar   : int  0 1212 0 17 27 184 15 1 1 1311 ...
 $ Apr   : int  2 1244 1 15 23 135 11 0 1 991 ...
 $ May   : int  2 1158 2 10 23 111 16 1 1 1237 ...
 $ Jun   : int  0 845 1 9 16 86 16 2 1 1129 ...
 $ Jul   : int  0 832 0 7 16 68 9 1 0 994 ...
 $ Aug   : int  0 1107 1 4 25 144 7 0 3 1260 ...
 $ Sep   : int  2 1278 1 8 53 212 14 0 3 1375 ...
 $ Oct   : int  3 1329 0 8 39 201 13 0 0 1340 ...
 $ Nov   : int  1 1179 0 5 7 135 2 0 0 1153 ...
 $ Dec   : int  0 1271 0 7 34 168 5 1 2 1792 ...
 $ Jan.10: int  0 1405 1 10 55 245 26 2 4 2806 ...
 $ Feb.10: int  0 1330 1 9 29 360 27 3 6 3492 ...
 $ Mar.10: int  0 1727 0 8 7 341 8 2 4 4578 ...
 $ Apr.10: int  0 1530 1 8 12 144 7 2 2 5453 ...

I am doing some this like this :

 x - (data[,-(1:2)] - data[,2]) * prop.table(data[,2]) + data[,2]
 x
   Feb  Mar  Apr  May  Jun
Jul
1 1.000.5971.4031.4030.597
0.597
2  1292.610851 1293.5003225 1295.1746211 1290.6749436 1274.2982103
1273.6180264

Now the str of x is :

 str(x)
'data.frame':32 obs. of  15 variables:
 $ Feb   : num  1 1293 0 5 18 ...
 $ Mar   : num  1 1294 0 5 18 ...
 $ Apr   : num  1 1295 0 5 18 ...
 $ May   : num  1 1291 0 5 18 ...
 $ Jun   : num  1 1274 0 5 18 ...
 $ Jul   : num  1 1274 0 5 18 ...
 $ Aug   : num  1 1288 0 5 18 ...
 $ Sep   : num  1 1297 0 5 18 ...
 $ Oct   : num  1 1300 0 5 18 ...
 $ Nov   : num  1 1292 0 5 18 ...
 $ Dec   : num  1 1297 0 5 18 ...
 $ Jan.10: num  1 1303.6 0 5 18 ...
 $ Feb.10: num  1 1300 0 5 18 ...
 $ Mar.10: num  1 1320 0 5 18 ...
 $ Apr.10: num  1 1310 0 5 18 ...

I need to round up the data frame some thing like this :

  Feb  Mar  Apr  May  Jun  Jul
1 1  11   1 1
1
2  1293 1294   1295  1291   1274   1274

there may be a way to round up the nearest integer. any help will be greatly
appropriated.

Thanks  Rg
Mohan L

[[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] Re : Indexing array to 1000

2010-05-22 Thread Mohan L
Dear All,

I have an array some thing like this:

 avglog
  January  February March April   May  June  July
August September
60102 83397 56774 48785 49010 40572 38175
47037 51402

The class of avglog array.
 class(avglog)
[1] array

 str(avglog)
 num [1:9(1d)] 60102 83397 56774 48785 49010 ...
 - attr(*, dimnames)=List of 1
  ..$ : chr [1:9] January February March April ...

I have to normalize this avglog array to 1000. I mean, I need to devide
1000/avglog[1] and have to multiply this to all the elements in the array
and need to plot graph Month Vs Index. To achive this I am doing the below
code. I am feeling there may be a simple way to do this.

 value - matrix (avglog)

 value
   [,1]
 [1,] 60102
 [2,] 83397
 [3,] 56774
 [4,] 48785
 [5,] 49010
 [6,] 40572
 [7,] 38175
 [8,] 47037
 [9,] 51402

 day1Avg - value[1]
 day1Avg
[1] 60102
 ID - (1000/day1Avg)
 ID
[1] 0.01663838
 index - value*ID
 index
   [,1]
 [1,] 1000.
 [2,] 1387.5911
 [3,]  944.6275
 [4,]  811.7034
 [5,]  815.4471
 [6,]  675.0524
 [7,]  635.1702
 [8,]  782.6195
 [9,]  855.2461

 monthcount - length(avglog)

 Month -  c(1:monthcount)

 trend - cbind(Month,c(index))

 colnames(trend) - c(Month,Index)

 trend
   Month  Index
 [1,]1 1000.
 [2,]2 1387.5911
 [3,]3  944.6275
 [4,]4  811.7034
 [5,]5  815.4471
 [6,]6  675.0524
 [7,]7  635.1702
 [8,]8  782.6195
 [9,]9  855.2461

any help will be greatly appreciated.

Thanks  Rg
Mohan L

[[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] help to indexing data frame

2010-05-21 Thread Mohan L
On Fri, May 21, 2010 at 11:27 AM, Mohan L l.mohan...@gmail.com wrote:


 Dear All,

 I have data some thing like this:

  sample
 StateJan   Feb Mar
 A  1   1 1
 B1298   12931294
 C00 0
 D55 5
 E   18  18   18

 I need to  multiply  Jan  column *1000 and divided by the same number,
 like this :

  data[,-(1:2)] * ((data[,2] *1000)/data[ ,2])


 data[,-(1:2)] * 1000/data[ ,2]

It will work as I expected. I have 0 in the C row. After the calculation
it gives  NaN zero place. But I need there zero instead of NaN.

There may be some solution for this.

Thanks  Rg
Mohan L

[[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] Re : Manipulating Data Frames

2010-05-20 Thread Mohan L
Dear All,

I have data some thisng like this :

 data - read.csv(file='ipsample.csv',sep=',' , header=TRUE)

 data
  State  Jan  Feb  Mar  Apr  May Jun
1   AAA11022   0
2   BBB 1298 1195 1212 1244 1158 845
3  CCC 00012   1
4   DDD5   11   17   15   10   9
5   EEE   18   28   27   23   23  16
6   FFF   68  152  184  135  111  86

from this data frame, I took Jan as base and calculating weightage like
this :

 basemonth.sum - sum(data[[2]])

 basemonth.sum
[1] 1390

 basemonth.data - data[[2]]

  basemonth.data
[1]1 129805   18   68

 weightage - basemonth.data / basemonth.sum

 weightage
[1] 0.0007194245 0.9338129496 0.00 0.0035971223 0.0129496403
[6] 0.0489208633


The above is the weightage for base month Jan.  Now I need to calculate
weighted states data. What I need to do is :
(((Feb[i]-Jan[1])*weightage)+Jan[1]) for all column. The Jan column is
fixed. I need to do the calculation in all the column Feb, Mar etc...


 StateJan   Feb
Mar
1   AAA1(((Feb[1]-Jan[1])*weightage[1])+Jan[1])
(((Mar[1]-Jan[1])*weightage[1])+Jan[1])
2   BBB 1298 (((Feb[2]-Jan[2])*weightage[2])+Jan[2])
(((Mar[2]-Jan[1])*weightage[2])+Ja[1])
3   CCC 0
4   DDD5
5   EEE   18
6   FFF   68

I am struggling with this . I have framed a logic using for loop. But it
seems me very bad logic.  Any help will be greatly appreciated.

Thanks  Rg
Mohan L

[[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 to indexing data frame

2010-05-20 Thread Mohan L
Dear All,

I have data some thing like this:

 sample
StateJan   Feb Mar
A  1   1 1
B1298   12931294
C00 0
D55 5
E   18  18   18

I need to  multiply  Jan  column *1000 and divided by the same number,
like this :

 data[,-(1:2)] * ((data[,2] *1000)/data[ ,2])

I doing some thing wrong with the above to get below result.

What I actually need is :


StateJan  FebMar
A  1*1000/1   1*1000/1  1*1000/1
B1298*1000/1298 1293*1000/1298   1294
C00 0
D55 5
E   18   18   18

Here Jan base for me .  Any help will be greatly appreciated.

Thanks  Rg
Mohan L

[[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] Re : Adding column sum to new row in data frame

2010-05-19 Thread Mohan L
Dear All,

I have data some thing like this:

State Jan Feb Mar Apr May Jun  AAA 1 1 0 2 2 0  BBB 1298 1195 1212 1244
1158 845  CCC 0 0 0 1 2 1  DDD 5 11 17 15 10 9  EEE 18 28 27 23 23 16  FFF
68 152 184 135 111 86


I want to sum all the column(Jan, Feb, Mar ...) and have to merge the total
at last row. like this:

StateJanFebMarAprMayJunAAA110220BBB12981195121212441158845CCC 000121DDD51117
15109EEE182827232316FFF6815218413511186Total1390 1387 1440 1420 1306
957


I am doing some thing like this, but I don't know how to merge Total to
data  Or I don't know there may be a alternative way.

 data - read.csv(file='ipsample.csv',sep=',' , header=TRUE)
 data
  State  Jan  Feb  Mar  Apr  May Jun
1   AAA11022   0
2   BBB 1298 1195 1212 1244 1158 845
3  CCC 00012   1
4   DDD5   11   17   15   10   9
5   EEE   18   28   27   23   23  16
6   FFF   68  152  184  135  111  86

 attributes(data)
$names
[1] State Jan   Feb   Mar   Apr   May   Jun

$class
[1] data.frame

$row.names
[1] 1 2 3 4 5 6


 x - data[,2:ncol(data)]

 x

   Jan  Feb  Mar  Apr  May Jun
111022   0
2 1298 1195 1212 1244 1158 845
300012   1
45   11   17   15   10   9
5   18   28   27   23   23  16
6   68  152  184  135  111  86

 Total - sapply(x,sum,na.rm=T)

 Total
 Jan  Feb  Mar  Apr  May  Jun
1390 1387 1440 1420 1306  957

I hope there may be alternative way.  Any help will be appreciated.

Thanks  Rg
Mohan L

[[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] Re : Adding column sum to new row in data frame

2010-05-19 Thread Mohan L
Hi Joshua,



 rbind(data, c(Total,apply(data[,-1], 2, sum, na.rm=TRUE)))


Yes. This what exactly I want. Thanks for your time.



 If your State column is a factor, it will return a warning that NAs
 were introduced (but the totals will still be at the bottom).


Yes.

 is.factor(data$State)
[1] TRUE

 State column is a factor, it will return warning message like this .
Warning message:
In `[-.factor`(`*tmp*`, ri, value = Total) :
  invalid factor level, NAs generated

I know that this is common factor vs character problem in R. I think there
may be a safe way to handle this:

 data - read.csv(file='ipsample.csv',sep=',' , header=TRUE)

 a - rbind(data, c(Total,apply(data[,-1], 2, sum, na.rm=TRUE)))
Warning message:
In `[-.factor`(`*tmp*`, ri, value = Total) :
  invalid factor level, NAs generated

 a
  State  Jan  Feb  Mar  Apr  May Jun
1   AAA11022   0
2   BBB 1298 1195 1212 1244 1158 845
3  CCC 00012   1
4   DDD5   11   17   15   10   9
5   EEE   18   28   27   23   23  16
6   FFF   68  152  184  135  111  86
7  NA 1390 1387 1440 1420 1306 957

How to safely avoid this warning massage?
Now I have NA instead of Total in last row State column. How to I
replace it as Total?

Thanks  Rg
Mohan L

[[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] Re : Adding column sum to new row in data frame

2010-05-19 Thread Mohan L


 How to safely avoid this warning massage?
 Now I have NA instead of Total in last row State column. How to I
 replace it as Total?

 Dear All,

The below link provides a very good explanation of  Creating factor
variables and way to avoid the warning message
http://www.ats.ucla.edu/stat/R/modules/factor_variables.htm

Now it works for me without warning message ( invalid factor level, NAs
generated ) according to the document above , I did  below to avoid the
warning:

 data - read.csv(file='ipsample.csv',sep=',' , header=TRUE)
 data
  State  Jan  Feb  Mar  Apr  May Jun
1   AAA11022   0
2   BBB 1298 1195 1212 1244 1158 845
3  CCC 00012   1
4   DDD5   11   17   15   10   9
5   EEE   18   28   27   23   23  16
6   FFF   68  152  184  135  111  86


 a - rbind(data, c(Total,apply(data[,-1], 2, sum, na.rm=TRUE)))
Warning message:
In `[-.factor`(`*tmp*`, ri, value = Total) :
  invalid factor level, NAs generated

 a
  State  Jan  Feb  Mar  Apr  May Jun
1   AAA11022   0
2   BBB 1298 1195 1212 1244 1158 845
3  CCC 00012   1
4   DDD5   11   17   15   10   9
5   EEE   18   28   27   23   23  16
6   FFF   68  152  184  135  111  86
7  NA 1390 1387 1440 1420 1306 957

We can see that instead of Total, the label was NA. To do this
correctly, I have added the new level, Total, to the factor column
data$State using the factor function with the levels argument. Then I can
finally add an element to the factor variable from the new level. here is
the steps

 levels(data$State)
[1] AAA  BBB  CCC  DDD  EEE  FFF

 data$State - factor(data$State,levels=c(levels(data$State),Total))

 data$State
[1] AAA  BBB  CCC  DDD  EEE  FFF
Levels: AAA BBB CCC  DDD EEE FFF Total

 levels(data$State)
[1] AAA   BBB   CCC   DDD   EEE   FFF   Total

 x - rbind(data, c(Total,apply(data[,-1], 2, sum, na.rm=TRUE)))

Now the above works without warning.

 x
  State  Jan  Feb  Mar  Apr  May Jun
1   AAA11022   0
2   BBB 1298 1195 1212 1244 1158 845
3  CCC 00012   1
4   DDD5   11   17   15   10   9
5   EEE   18   28   27   23   23  16
6   FFF   68  152  184  135  111  86
7 Total 1390 1387 1440 1420 1306 957

I think I am doing right. If  I miss understood anything. Please guide me  I
am beginer to R.

Thanks  Rg
Mohan L

[[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] Re : Adding column sum to new row in data frame

2010-05-19 Thread Mohan L
On Thu, May 20, 2010 at 10:31 AM, Joshua Wiley jwiley.ps...@gmail.comwrote:

 Dear Mohan,

 First, I would like to modify my code slightly to:

 data - rbind(data,data.frame(State=Total,t(apply(data[,-1], 2, sum,
 na.rm=TRUE

 This actually will add a 7th level to your factor automatically.  The
 reason I wanted to change from using c() to data.frame() is that if
 one uses c(), all the columns are converted to character (this has to
 do with different methods for rbind, see ?rbind particularly the
 Details and Value section which describe the different methods for
 rbind and what its behavior will be if it is using the default
 method).  This may not be an issue, but it would hamper any subsequent
 calculations you may wish to perform on your data.


Thanks for your great help.


Mohan L

[[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] Re : append new line in existing graph

2010-05-17 Thread Mohan L
Dear All,

I am executing my R script from PHP using the shell_exec.

$return = shell_exec(/usr/bin/R --slave --args .$Domain.,.$Gender. 
/var/www/html/trends/newTrend.R);

In newTrend.R, I am plotting graph and save in pdf file using the below
code. It will create a pdf file with two line.

pdf(file=/var/www/html/trends/bmtrend.pdf, height=7.5, width=10.5)

g_range - range(0,index , ReqDataindex)

plot(index, type=o, col=blue, ylim=g_range,axes=FALSE, ann=FALSE)

axis(1, at=1:7, lab=c(1:daycount))

axis(2, las=1, at=25*0:g_range[2])

box()

lines(ReqDataindex, type=o, pch=22, lty=2, col=red)

Now what I want do is: I want to execute shell_exec() second time with
different argument  and I want to add one more line to existing
(bmtrend.pdf) file. I mean if the  bmtrend.pdf file does not exist, my
script has to create the file. If the bmtrend.pdf file is already exist, I
want to append new line in existing file.

any help would be greatly appreciated.

Thanks for you time.
Mohan L

[[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 required data from already read data

2010-05-06 Thread Mohan L
Hi all,

I have data like this:

sample - read.csv(file=sample.csv,sep=,,header=TRUE)
 sample

   stdate   Domainsex age Login
1  01/11/09xxx FeMale  25 2
2  01/11/09xxx FeMale  35 4
3  01/11/09xxx   Male  1830
4  01/11/09xxx   Male  31 3
5  02/11/09xxx   Male  3211
6  02/11/09xxx   Male  31 1
7  02/11/09xxx FeMale  29 1
8  02/11/09xxx FeMale  23 5
9  03/11/09xxx FeMale  25 9
10 03/11/09xxx FeMale  35 6
11 03/11/09xxx   Male  18 3
12 03/11/09xxx   Male  31 0
13 04/11/09xxx   Male  3225
14 04/11/09xxx   Male  31 1
15 04/11/09xxx FeMale  29 0
16 01/11/09yyy FeMale  25 2
17 01/11/09yyy FeMale  35 4
18 01/11/09yyy   Male  1830
19 01/11/09yyy   Male  31 3
20 02/11/09yyy   Male  3211
21 02/11/09yyy   Male  31 1
22 02/11/09yyy FeMale  29 1
23 02/11/09yyy FeMale  23 5
24 03/11/09yyy FeMale  25 9
25 03/11/09yyy FeMale  35 6


I have done the graph for all the data. Now I want to get data from
particular Domain and Sex from above data, then I need to do the calculation
, eg :

# if both are true
if(Domain == xxx  sex==FeMale)

I need the data in another variable, like this

1  01/11/09xxx FeMale  25 2
2  01/11/09xxx FeMale  35 4
3  02/11/09xxx FeMale  29 1

I have failed to achieve it .  any help would greatly appreciated.

Thanks  Rg
Mohan L

[[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] extract required data from already read data

2010-05-06 Thread Mohan L
On Fri, May 7, 2010 at 10:51 AM, Joshua Wiley jwiley.ps...@gmail.comwrote:

 Try something like:

 sample[which(sample$Domain==xxx  sample$sex==FeMale), ]

 Hope that helps,


Hi Josh,

It works. Thanks for your time.

I am using source() to run program, like

 source (sample.R)

I want to know how to pass the argument to my sample.R, some this like

 source(sample.R, xxx,FeMale)

 Is it possible? any link will greatly appreciated.

Thanks  Rg
Mohan L

[[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] make a column from the row names

2010-05-04 Thread Mohan L
Dear All,

 avglog
01/11/09 02/11/09 03/11/09 04/11/09
9.75 4.50 4.50 8.67
 avglog1 - data.frame(avglog)
 avglog1
   avglog
01/11/09 9.75
02/11/09 4.50
03/11/09 4.50
04/11/09 8.67

The first column isnt a column, It's the row names. I makeing a column from
the row names by using the following

 value1$Day - rownames(value1)
 value1
avglog  Day
01/11/09 9.75 01/11/09
02/11/09 4.50 02/11/09
03/11/09 4.50 03/11/09
04/11/09 8.67 04/11/09

But I want like this :

Dayavglog Index
119.759.75*100
224.504.50*100
334.504.50*100
448.678.67*100


How to achieve it? Any help will be appreciated.

Thanks  Rg
Mohan L

[[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] Re :argument is not numeric or logical

2010-05-02 Thread Mohan L
Hi all,

I have data size of :

 dim(sample)
[1] 3594317

The first column is stdate  - is date  ( 01/11/2009 00:00:00,02/11/2009
00:00:00,02/11/2009 00:00:00 etc... )
Login is 13th column - is numbers (12,0,1 erc...)

The below operation return the following error.

 sample1 - read.csv(file=sample1.csv,sep=,,header=TRUE)
 avglog - with(sample1, tapply(Login, stdate, mean))

Warning messages:
1: In mean.default(X[[1L]], ...) :
  argument is not numeric or logical: returning NA
2: In mean.default(X[[2L]], ...) :
  argument is not numeric or logical: returning NA
3: In mean.default(X[[3L]], ...) :
  argument is not numeric or logical: returning NA
4: In mean.default(X[[4L]], ...) :
  argument is not numeric or logical: returning NA
5: In mean.default(X[[5L]], ...) :
  argument is not numeric or logical: returning NA
6: In mean.default(X[[6L]], ...) :
  argument is not numeric or logical: returning NA
7: In mean.default(X[[7L]], ...) :
  argument is not numeric or logical: returning NA


 avglog
01/11/09 00:00 02/11/09 00:00 03/11/09 00:00 04/11/09 00:00 05/11/09 00:00
NA NA NA NA NA

How to fix this issue?

Thanks  Rg
Mohan L

[[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] Re :argument is not numeric or logical

2010-05-02 Thread Mohan L

 Your code has a different name for the sample object. And it would be more
 informative if you offered str on sample1.


This is the result of str on sample1.
 str(sample1)
'data.frame':35943 obs. of  17 variables:
 $ stdate : Factor w/ 7 levels 01/11/09 00:00,..: 1 1 1 1 1 1 1 1 1 1
...
 $ domain : Factor w/ 15 levels Assamese,Bengali,..: 1 1 1 1 1 1 1 1
1 1 ...
 $ gender : Factor w/ 2 levels FeMale,Male: 1 1 1 1 1 1 1 1 2 2 ...
 $ postedby   : Factor w/ 10 levels Brother,Daughter,..: 2 6 6 7 7 7 7 9
1 5 ...
 $ caste  : Factor w/ 424 levels ,Caste no bar,..: 1 171 189 130 182
214 394 32 394 373 ...
 $ age: Factor w/ 15 levels 20,20,21,..: 7 15 8 9 11 12 4 9 9
10 ...
 $ occupation : Factor w/ 54 levels ,Accounts/Finance Professional,..:
43 43 3 2 43 33 43 53 36 14 ...
 $ religion   : Factor w/ 17 levels ,Buddhist,..: 11 7 7 7 7 7 13 7 14
10 ...
 $ city   : Factor w/ 561 levels ,24 Parganas,..: 365 202 116 365
135 143 202 339 404 1 ...
 $ country: Factor w/ 115 levels Afghanistan,..: 47 47 47 47 47 47 47
47 47 11 ...
 $ education  : Factor w/ 12 levels ,Bachelors - Arts/ Science/ Commerce/
Others,..: 2 5 8 2 2 8 2 2 9 9 ...
 $ profiletype: Factor w/ 1 level Free: 1 1 1 1 1 1 1 1 1 1 ...
 $ Login  : Factor w/ 419 levels .00,1.00,10.00,..: 114 283 217
216 14 1 2 2 407 327 ...
 $ EISent : Factor w/ 250 levels .00,1.00,10.00,..: 1 132 23 132 2
1 1 1 1 2 ...
 $ EIReceived : num  12 5 43 0 8 2 11 12 4 0 ...
 $ PMSent : Factor w/ 298 levels .00,1.00,10.00,..: 1 1 1 1 1 1 1
1 1 1 ...
 $ PMReceived : num  8 4 61 1 12 8 0 9 1 0 ...


What I am trying is:  I have 7 days data in .csv format. I need to the
average Login for first day(1/11/2009) , from this average I have to
calculate index divisor(ID). Then I have to calculate the average Login for
all 7 days and need to multiple each day Login average with   index
divisor(ID), like this

stdate LoginAverage   Index
1/11/2009  29.50 LoginAverage*ID

This what I am trying? Any help will be appreciated

Thanks for your time.

Thanks  Rg
Mohan L

[[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] Re :argument is not numeric or logical

2010-05-02 Thread Mohan L
 Your code has a different name for the sample object. And it would be more
 informative if you offered str on sample1.

 This is the result of str on sample1.
  str(sample1)
 'data.frame':35943 obs. of  17 variables:
  $ stdate : Factor w/ 7 levels 01/11/09 00:00,..: 1 1 1 1 1 1 1 1 1
 1 ...


 So stdate is not a date variable but that is probably not your problem
 since it looks like the time portion of your not-dates are all 00:00.
 tapply can work with this information


  snipped


   $ Login  : Factor w/ 419 levels .00,1.00,10.00,..: 114 283 217
 216 14 1 2 2 407 327 ...


 So Login is not a numeric class variable. Read the FAQ about the proper
 way to convert that variable to numeric without loosing information.


The Login column contain all numeric values . I don't understand why I need
to convert that variable to numeric?

login column contain data like this :

 sample$Login

[35881] .00  1.00 .00  1.00 .00  .00  1.00
2.00
[35889] 1.00 3.00 .00  .00  .00  1.00 .00
32.00
[35897] 2.00 4.00 .00  17.003.00 1.00 12.00
.00
[35905] 8.00 .00  3.00 7.00 .00  17.00.00
4.00
[35913] 16.004.00 20.007.00 .00  22.0018.00
1.00
[35921] 3.00 3.00 .00  .00  37.003.00 12.00
3.00
[35929] 2.00 11.00.00  5.00 77.001.00 4.00
1.00
[35937] 9.00 18.003.00 3.00 4.00 14.002.00

The mode of Login is numeric only :

 mode(sample$Login)
[1] numeric


 And I am also using as.numeric(as.character(sample$Login), still it has
some warning and NA . I don't understand why this is happening.  could you
explain?

 avglog - with(sample1, tapply(as.numeric(as.character(sample$Login)),
stdate, mean))
Warning message:
In tapply(as.numeric(as.character(sample$Login)), stdate, mean) :
  NAs introduced by coercion
 avglog
01/11/09 00:00 02/11/09 00:00 03/11/09 00:00 04/11/09 00:00 05/11/09 00:00
  22.04866   16.65358 NA   15.84970   16.58600
06/11/09 00:00 07/11/09 00:00
  16.20743   18.52379

Thanks  Rg
Mohan L

[[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] Re :argument is not numeric or logical

2010-05-02 Thread Mohan L

 I have no way to determining  _why_ it is not numeric, but it simply is ...
 not. Your input method turned it into a factor. Perhaps there was one
 missing delimiter, or there was a stray character in one of the entries in
 the file. Who knows. Why waste time arguing? Follow the directions for
 fixing the problem.


Hi David,

Thanks for your time.

I thinks it works  now.

 str(assame$Login)
 Factor w/ 419 levels .00,1.00,10.00,..: 114 283 217 216 14 1 2 2 407
327 ...

 is.numeric(assame$Login)
[1] FALSE

as.numeric(assame$Login)  //convert to numerics

 str(as.numeric(assame$Login))
 num [1:35943] 114 283 217 216 14 1 2 2 407 327 ...

the I did some thing like this :

 avglog - with(assame, tapply(as.numeric(Login), stdate, mean) )

 avglog
01/11/09 00:00 02/11/09 00:00 03/11/09 00:00 04/11/09 00:00 05/11/09 00:00
  145.0176   135.5207   133.0390   131.1457   132.3732
06/11/09 00:00 07/11/09 00:00
  129.6357   133.4521

Am I right ?



Thanks  Rg
Mohan L

[[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] Re :argument is not numeric or logical

2010-05-02 Thread Mohan L

 as.numeric(assame$Login)  //convert to numerics



 Nooo. You did not do what what I suggested earlier. Do not reach
 for your keyboard in the R console until you have read the FAQ section
 regarding converting factors to numeric. If you don't want to read the FAQ


Hi David,
Now I understand the trick :

as.numeric(as.character(Login))


 avglog -
with(assame,tapply(as.numeric(as.character(Login)),stdate,mean))  avglog
01/11/09 00:00 02/11/09 00:00 04/11/09 00:00 05/11/09 00:00 06/11/09 00:00
  22.04866   16.65358   15.84970   16.58600   16.20743
07/11/09 00:00
  18.52379

But still it will not work :

 avglog -
with(assame,tapply(as.numeric(levels(Login)[as.integer(Login)]),stdate,mean))
Error in tapply(as.numeric(levels(Login)[as.integer(Login)]), stdate,  :
  arguments must have same length


Thanks  Rg
Mohan L

[[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] Re :reading large file

2010-05-01 Thread Mohan L
On Sat, May 1, 2010 at 11:55 AM, Tal Galili tal.gal...@gmail.com wrote:

 Hi Mohan,
 Check:

 dim(bmtrend)

 If the output is like the dimension of your data, then it would appear you
 succeeded in reading in the data :)


Yes . You are right. It reads all the data.

 Thanks you.

Mohan L

[[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] Average Login based on date

2010-05-01 Thread Mohan L
Hi All,

I have the data like this :

sample - read.csv(file=sample.csv,sep=,,header=TRUE)
 sample

 stdate Domainsex age Login
1  01/11/09xxx FeMale  25 2
2  01/11/09xxx FeMale  35 4
3  01/11/09xxx   Male  1830
4  01/11/09xxx   Male  31 3
5  02/11/09xxx   Male  3211
6  02/11/09xxx   Male  31 1
7  02/11/09xxx FeMale  29 1
8  02/11/09xxx FeMale  23 5
9  03/11/09xxx FeMale  25 9
10 03/11/09xxx FeMale  35 6
11 03/11/09xxx   Male  18 3
12 03/11/09xxx   Male  31 0
13 04/11/09xxx   Male  3225
14 04/11/09xxx   Male  31 1
15 04/11/09xxx FeMale  29 0
16 01/11/09yyy FeMale  25 2
17 01/11/09yyy FeMale  35 4
18 01/11/09yyy   Male  1830
19 01/11/09yyy   Male  31 3
20 02/11/09yyy   Male  3211
21 02/11/09yyy   Male  31 1
22 02/11/09yyy FeMale  29 1
23 02/11/09yyy FeMale  23 5
24 03/11/09yyy FeMale  25 9
25 03/11/09yyy FeMale  35 6
26 03/11/09yyy   Male  18 3
27 03/11/09yyy   Male  31 0
28 04/11/09yyy   Male  3225
29 04/11/09yyy   Male  31 1
30 04/11/09yyy FeMale  29 0

I need to fine the average login on 01/11/09 and 02/11/09 etc... like below

stdate  AverageLogin
01/11/09  9.75
02/11/09   .
03/11/09  ...

How do I find the average Login based on date?

Thanks for your time.
Mohan L

[[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] Re :reading large file

2010-04-30 Thread Mohan L
On Sat, May 1, 2010 at 11:02 AM, Mohan L l.mohan...@gmail.com wrote:

 Hi All,

 I am new to R and the mailing list.

 I have a data file (.xls) format with little bit large (16 column,35000
 rows ) data file. I am trying to read this file for calculation.  I have
 converted the file into .csv format and read like that :

  bmtrend - read.csv(file=simple.csv,head=TRUE,sep=,)

  bmtrend

 will display something in the middle of display

 [ reached get Option(max.print) -- omitted 30061 rows ]]

 It will not show the full list of data.

 please suggest me best way to read large file?



 Thanks  Rg
 Mohan L


I send the mail without subject, I apologies for  inconvenience.

[[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] Re :

2010-04-30 Thread Mohan L
Hi All,

I am new to R and the mailing list.

I have a data file (.xls) format with little bit large (16 column,35000 rows
) data file. I am trying to read this file for calculation.  I have
converted the file into .csv format and read like that :

 bmtrend - read.csv(file=simple.csv,head=TRUE,sep=,)

 bmtrend

will display something in the middle of display

[ reached get Option(max.print) -- omitted 30061 rows ]]

It will not show the full list of data.

please suggest me best way to read large file?



Thanks  Rg
Mohan L

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