[R] Plot gamma distribution with relative frequency histogram

2014-12-04 Thread dila radi
Dear R users,

I am looking to fit a gamma curve onto a histogram of the data.

Consider dt1 as my data:
c(203.9, 91.5, 24.5, 34.5, 164, 144, 160.5, 195, 191.5, 189,
133, 110.5, 155, 80.5, 250.5, 116, 145, 118.5, 406, 183.5, 142.5,
197, 367, 134, 153.5)

I am using this code in R
x-dt1
h-hist(x,breaks=seq(0,500,25),col=rgb(0,0,1), plot=F)
h$counts - h$counts / sum(h$counts)
plot(h, freq=TRUE, ylab=Relative Frequency, xlab=Rainfall (mm),
 main = 'Histogram KBU-ML Gamma Disribution')
est - fitdistr(dt1,gamma)$estimate
curve(dgamma(x, rate=0.02220921, shape=3.63421746),from=0, to=500,
  main=Gamma distribution, add = T, col = red)

but the gamma fit is not fitted onto histogram as much as it supposed to
be. How should I overcome this?

Thank you in advanced.

Dila

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Finding the Summation of Monthly Amount

2014-10-12 Thread dila radi
Hi all,

Could someone help me on this? I have this kind of data set

structure(list(Year = c(1971L, 1971L, 1971L, 1971L, 1971L, 1971L,
1971L, 1971L, 1971L, 1971L, 1971L, 1971L, 1971L, 1971L, 1971L,
1971L, 1971L, 1971L, 1971L, 1971L, 1971L, 1971L, 1971L, 1971L,
1971L, 1971L, 1971L, 1971L, 1971L, 1971L, 1971L, 1971L, 1971L,
1971L, 1971L, 1971L, 1971L, 1971L, 1971L, 1971L, 1971L, 1971L,
1971L, 1971L, 1971L, 1971L, 1971L, 1971L, 1971L, 1971L, 1971L,
1971L, 1971L, 1971L, 1971L, 1971L, 1971L, 1971L, 1971L, 1971L,
1971L, 1971L, 1971L, 1971L, 1971L, 1971L, 1971L, 1971L, 1971L,
1971L, 1971L, 1971L, 1971L, 1971L, 1971L, 1971L, 1971L, 1971L,
1971L, 1971L, 1971L, 1971L, 1971L, 1971L, 1971L, 1971L, 1971L,
1971L, 1971L, 1971L, 1972L, 1972L, 1972L, 1972L, 1972L, 1972L,
1972L, 1972L, 1972L, 1972L, 1972L, 1972L, 1972L, 1972L, 1972L,
1972L, 1972L, 1972L, 1972L, 1972L, 1972L, 1972L, 1972L, 1972L,
1972L, 1972L, 1972L, 1972L, 1972L, 1972L, 1972L, 1972L, 1972L,
1972L, 1972L, 1972L, 1972L, 1972L, 1972L, 1972L, 1972L, 1972L,
1972L, 1972L, 1972L, 1972L, 1972L, 1972L, 1972L, 1972L, 1972L,
1972L, 1972L, 1972L, 1972L, 1972L, 1972L, 1972L, 1972L, 1972L,
1972L, 1972L, 1972L, 1972L, 1972L, 1972L, 1972L, 1972L, 1972L,
1972L, 1972L, 1972L, 1972L, 1972L, 1972L, 1972L, 1972L, 1972L,
1972L, 1972L, 1972L, 1972L, 1972L, 1972L, 1972L, 1972L, 1972L,
1972L, 1972L, 1972L, 1972L, 1973L, 1973L, 1973L, 1973L, 1973L,
1973L, 1973L, 1973L, 1973L, 1973L, 1973L, 1973L, 1973L, 1973L,
1973L, 1973L, 1973L, 1973L, 1973L, 1973L, 1973L, 1973L, 1973L,
1973L, 1973L, 1973L, 1973L, 1973L, 1973L, 1973L, 1973L, 1973L,
1973L, 1973L, 1973L, 1973L, 1973L, 1973L, 1973L, 1973L, 1973L,
1973L, 1973L, 1973L, 1973L, 1973L, 1973L, 1973L, 1973L, 1973L,
1973L, 1973L, 1973L, 1973L, 1973L, 1973L, 1973L, 1973L, 1973L,
1973L, 1973L, 1973L, 1973L, 1973L, 1973L, 1973L, 1973L, 1973L,
1973L, 1973L, 1973L, 1973L, 1973L, 1973L, 1973L, 1973L, 1973L,
1973L, 1973L, 1973L, 1973L, 1973L, 1973L, 1973L, 1973L, 1973L,
1973L, 1973L, 1973L, 1973L), Month = c(1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 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NA,
-271L))

and I want to find the sum of Rain in column 3 according to their month.
How could I achieved this so that it would appear as follow:

structure(list(Year = c(1971L, 1971L, 1971L, 1972L, 1972L, 1972L,
1973L, 1973L, 1973L), Month = c(1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L,
3L), Rain = c(176.8, 228.2, 90.9, 81, 73.1, 127.7, 242.8, 189.5,
204.2)), .Names = c(Year, Month, Rain), class = data.frame,
row.names = c(NA,
-9L))

Thank you so much

Dila

[[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] to extract extreme data for specified period

2014-06-17 Thread dila radi
Dear R users,

I used this codes to find the 1-day annual rainfall maximum

bmFort - blockmaxxer(Fort, blocks = Fort$year, which=Prec);bmFort

 and the output is given below:

structure(list(obs = c(119, 507, 994, 1398, 1583, 1917), tobs = c(119,
142, 264, 303, 123, 91), month = c(4, 5, 9, 10, 5, 4), day = c(29,
22, 21, 30, 2, 1), year = c(1900, 1901, 1902, 1903, 1904, 1905
), Prec = c(2.39, 2.32, 4.34, 0.85, 3.02, 1.74)), .Names = c(obs,
tobs, month, day, year, Prec), row.names = c(119L,
507L, 994L, 1398L, 1583L, 1917L), class = data.frame)

however, I would also like to find the 7-days annual rainfall maximum by
months within a year. I tried changing ' Fort$year' to ' Fort$day' and I
got the following:

structure(list(obs = c(28610, 1583, 14125, 18052, 18905, 32937
), tobs = c(121, 123, 246, 155, 278, 65), month = c(5, 5, 9,
6, 10, 3), day = c(1, 2, 3, 4, 5, 6), year = c(1978, 1904, 1938,
1949, 1951, 1990), Prec = c(1.85, 3.02, 3.54, 3.54, 1.67, 3.48
)), .Names = c(obs, tobs, month, day, year, Prec), row.names =
c(28610L,
1583L, 14125L, 18052L, 18905L, 32937L), class = data.frame)

what I want is the 7-days maximum within a year that is maximum value for
eg. from 1/1/1990 to 7/1/1990 then another maximum is 8/1/1990 to 14/1/1990
and so on.

this is some sample data:
structure(list(obs = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40), tobs = c(1,
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40), month = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2), day = c(1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
26, 27, 28, 29, 30, 31, 1, 2, 3, 4, 5, 6, 7, 8, 9), year = c(1900,
1900, 1900, 1900, 1900, 1900, 1900, 1900, 1900, 1900, 1900, 1900,
1900, 1900, 1900, 1900, 1900, 1900, 1900, 1900, 1900, 1900, 1900,
1900, 1900, 1900, 1900, 1900, 1900, 1900, 1900, 1900, 1900, 1900,
1900, 1900, 1900, 1900, 1900, 1900), Prec = c(0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0.1, 0.03, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0.08, 0.04, 0, 0, 0, 0, 0, 0, 0, 0, 0.02, 0, 0)), .Names =
c(obs,
tobs, month, day, year, Prec), row.names = c(NA, 40L
), class = data.frame)

Thank you very much for any help given.

Dila

[[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] Replacing NA's in the data set

2014-04-29 Thread dila radi
Hi all,

I have this data set,
 dput(Ts)

structure(list(V1 = c(3, 17, 29, 12, 4.5, 1, 0.5, 0, 0, 0, 1.2,
1.8, 1.5, 0.5, 0, 47.7, 0.3, 0, 2, 0, 5.5, 8, 27.5, 69, 29, 24.5,
57.5, 40, 1, 14.5, 0, 0, 0, 0, 0, 0, 1.5, 2, 0, 0, 0, 0, 7, 29.5,
77, 11.5, 33, 38, 36, 8, 28, 11, 11, 0, 17, 0, 51, 0.5, 5, 0,
31.5, 11, 3.5, 0, 0, 0, 0, 0, 4.5, 1, 15.5, 2.5, 0, 0, 5, 0,
0, 0, 0, 0, 5, 0, 8.5, 0, 0, 0, 0, 0, 0, 13, 37.5, 3.5, 37, 2,
32.5, 2.5, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 105.5, 0.5, 1.5,
16.5, 5.5, 0, 0, 0, 3.5, 0, 0, 10.5, 57.5, 3, 23, 0, 3, 1, 43.5,
39.5, 1, 0, 21, 2.5, 2.5, 1.5, 30, 2, 1.5, 18.5, 17, 0, 0, 13,
0, 0, 0, 0, 5.5, 0, 0, 0, 0, 22.5, 4.5, 0, 1.5, 17, 1.5, 0.5,
2, 0, 0, 25, 24.5, 7.5, 0, 3.5, 22.5, 8.5, 8.5, 0, 0, 0, 0.5,
0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21, 4.5, 0, 49, 0, 2,
12, 29, 6.5, 0, 0, 0, 0, 2.5, 0, 0, 6, 0, 8.5, 8.5, 8.5, 1, 0,
0), V2 = c(4, 12, 22.5, 10.5, 19.5, 1, 0.5, 0, 0, 0, 3, 0, 0,
3, 0, 8, 0, 0, 0, 1, 2.5, 10.5, 21, 49.5, 79.5, 16, 30, 34, 0,
13.5, 1.5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0.5, 3.5, 7, 4.5,
2.5, 2, 22.5, 8, 99.5, 10, 44, 0, 3.5, 0, 18.5, 0, 5, 11.5, 0,
18.5, 4.5, 0, 0, 0, 0.5, 0, 5.5, 3.5, 5.5, 87, 2, 2, 0, 1, 0,
0, 0, 0, 0, 0, 0, 13.5, 0, 0, 12, 8, 1, 0, 0, 3.5, 0, 1, 5, 0,
0.5, 0.5, 0, 0, 0, 0, 0, 1, 0, 0, 11, 0, 5.5, 0, 0, 2, 25.5,
0, 17.5, 0, 1, 0, 0, 3, 44.5, 0, 0, 0.3, 43.7, 0, 3.2, 13.5,
2, 0, 0, 0, 0, 5.8, 16.2, 0, 0, 7.3, 0, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 0, 0,
0, 14.9, 16.1, 0, 16.8, 2.2, 15.1, 92.7, 0, 0, 1.6, 36.2, NA,
NA, NA, NA, NA, NA, NA, NA, 1, 0, 0, 0, 17, 1, 0, 0, 3.5, 0.5,
25, 10.5, 28, 6.5, 0, 8, 1, 16, 0, 0, 0, 2.5, 0, 0, 61, 0, 0,
0, 8.5), V3 = c(11L, 21L, 41L, 22L, 0L, 0L, 12L, 0L, 0L, 3L,
4L, 7L, 0L, 3L, 5L, 19L, 0L, 0L, 0L, 0L, 23L, 36L, 57L, 34L,
123L, 31L, 56L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 0L), V4 = c(NA, NA, NA,
NA, NA, NA, NA, NA, NA, 6.5, 0, 0, 0, 3.5, 0.5, 26, 12, 0, 1.5,
2, 6.5, 34.5, 40, 61, 179, 19, 44, 48.5, 0.5, 0, 1.5, NA, NA,
NA, NA, NA, NA, NA, NA, 0, 0.5, 0, 20, 15.5, 16, 3.5, 13, 5,
5.5, 15, 6.5, 2.5, 93.5, 1.5, 9.5, 3, 9, 0, 0, 0, 0, 2, 3.5,
0, 0, 0, 3, 0, 9.5, 7.5, 3.5, 57, 2.2, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 0.5, 6, 0, 0,
0.5, 0, 0, 0, 10, 0, 0, 6, 0, 0, 0, 6, 0, 6.5, 1.5, 0, 0, 32.5,
0, 0, 0, 15, 0, 0, 0, 8.5, 0, 53, 0, 27.5, 0, 12.5, 2.3, 3.2,
0, 0, 0, 1, 2, 0.5, 3, 9.5, 20.5, 12.5, 3.5, 0, 0, 0, 0, 0, 1,
0, 0, 0, 0, 0, 0, 0, 0, 104, 2.5, 0, 0, 0, 0, 42, 0, 11.5, 41,
0, 14, 0, 18, 8, 0, 0, 14, 14.5, 0, 13.5, 0, 0, 5.5, 2, 0, 1,
0, 0, 0, 0, 3.5, 0, 0, 37.5, 0, 0, 39.2, 9.8, 0, 0, 0, 0, 0,
40.5, 0, 2, 0, 0, 2, 16, 3, 0, 1, 0, 4), V5 = c(28.5, 24, 45.5,
12.5, 0, 0, 0, 10.5, 7, 0, 0, 0, 6, 0, 38, 0, 1.5, 2, 3, 10,
32.5, 132, 20.5, 190, 19, 84, 120.5, 2, 4, 12, 0, 0, 0, 0, 0,
0, 0, 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, 0, 0, 12.5, 6, 4.5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 6.5, 5, 0, 4.5, 0, 0, 27.5, 0, 7.5, 0, 3, 38, 0, 44.5, 14,
0, 0, 0, 24.5, 0, 7, 0, 11.5, 9.5, 6, 0, 21.5, 0, 0, 0, 0, 10.5,
0, 0, 0, 39.5, 0, 0, 35.5, 6, 0, 0, 4.5, 6, 0, 0, 0, 0, 7, 0,
10.5, 56.5, 46, 14.5, 0, 5, 0), V7 = c(27, 0, 25.5, 37, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 

[R] creating multiple line graphs

2014-04-14 Thread dila radi
Hi all,

I tried to draw multiple line graphs, and this is my data:

structure(list(X = structure(c(3L, 1L, 2L), .Label = c(10%,
20%, 5%), class = factor), NRM = c(0.993112, 0.9757191,
0.9709928), AAM = c(0.9928504, 0.9764055, 0.9702813), IDW = c(0.9923301,
0.9737133, 0.9640287), CCM = c(0.9929805, 0.9768217, 0.9708724
), MI = c(0.9931722, 0.9715817, 0.9649249)), .Names = c(X,
NRM, AAM, IDW, CCM, MI), row.names = c(NA, 3L), class =
data.frame)


Im using these as my codes:
y-axis is the amount of S-index (from the data given range from 0.99 - 1.0)
x-axis is the percentage (5%, 10% and 20%)

par(mar=c(4,4,2,1.2),oma=c(0,0,0,0))
plot(dt[,2], xaxt = n,xlab=Percentage of Mising,ylab=S-index,
 main=Performance of S-Index for Different Percentage,
 ylim=c(0.99,1),type=l,col=blue,lwd=3)
lines(dt[,3],col=black,lwd=3,lty=2)
lines(dt[,4],col=red,lwd=3,type=l)
lines(dt[,5],col=green3,lwd=3,type=l)
lines(dt[,6],col=orange,lwd=3,lty=2)
axis(1,at=1:3,c(5%,10%, 20%))
legend(topright, bty=n,c(NRM,AAM,IDW,CCM,MI),
lwd=c(3,3,3,3,3), lty =c(1,2,1,4),col=
c(blue,black,green3,red,orange))

I guess there is more sophisticated way to do it. Need your help. Thank you
so much.

Regards,
Dila

[[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] Replacement Value

2014-04-07 Thread dila radi
Hi all,

I have problem on how to replace value. I have this kind of data set:

structure(list(A = c(0, 12.6, 10.1, 8.1, 14.4, 0, 0, 0, 0, 0.5,
12.9, 25.9, 49, 0, 0, 0, 0, 0, 7.8), B = c(0, 0, 9.1, 9.3, 1.5,
1, 1, 1, 1.7, 6, 0, 0, 0, 1.7, 3.8, 0, 0, 0, 1), C = c(1, 1,
9.10004, 9.2, 1.5, 1, 1, 1, 1.7, 5.9, 1,
1, 1, 1.7, 3.80001, 1, 1, 1, 1)), .Names = c(A, B, C
), row.names = c(NA, 19L), class = data.frame)

The problem is the value under variable 'C'.   It supposed to be like this:

1) When value is '0' under variable 'B', the next value under variable 'C'
also should be '0'.

2) When value is '1' under variable 'B', there is no changes for values
under variable 'C'.

How do I achieved this by fulfill these two conditions? Thank you so much.


Regards,
Dila

[[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] Deletion of rows

2014-03-14 Thread dila radi
Hi all,
 Regarding the previous post, here is part of my data.

structure(list(Year = c(1949L, 1949L, 1949L, 1949L, 1949L, 1949L,
1949L, 1949L, 1949L, 1949L, 1949L, 1949L, 1949L, 1949L, 1949L,
1949L, 1949L, 1949L, 1949L, 1949L, 1949L, 1949L, 1949L, 1949L,
1949L, 1949L, 1949L, 1949L, 1949L, 1949L, 1949L, 1950L, 1950L,
1950L, 1950L, 1950L, 1950L, 1950L, 1950L, 1950L), Day = c(1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L,
16L, 17L, 18L, 19L, 20L, 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), row.names = c(NA, 40L), class = data.frame)


But data that is left blank is the one that I want to delete so that when I
rearrange it column by column, it wont appear anymore.

Using this command, I can rearrange the data column by column

library(reshape2)
res -
transform(melt(dat,id.var=c(Year,Day)),Month=match(variable,month.abb),Amount=value)[,-c(3:4)]
res1 - res[with(res,order(Year,Month,Day)),]

So, how do I rearrange it by excluding the empty row?

Thank you for your help.

Dila


On 11 March 2014 01:42, PIKAL Petr petr.pi...@precheza.cz wrote:

 Hi

 No attachments allowed (mostly). Use ?dput and copy to email directly.

 How you can have more than 29 rows in February if each row is one day?

 I believe that merging your data with date column made by ?seq.POSIXt can
 remove any nonexistent row but it all depends on how your data are
 structured and what do you want to remove.

 Petr


  -Original Message-
  From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
  project.org] On Behalf Of dila radi
  Sent: Tuesday, March 11, 2014 6:04 AM
  To: r-help@r-project.org
  Subject: [R] Deletion of rows
 
  Hi,
 
  I would like to ask about the deletion of rows in the data.
 
  Assuming I have this kind of data set, which you can refer through the
  attachment.
 
 
  As in the attachment, I have 31 days for each month which is I want to
  delete some of the rows according to the real days per month.
 
  For example:
 
   Jan, March, May, July, Aug, Oct, Dec (these months have 31 days per
  month, so no deletion of rows needed)
 
  Feb (28 days except for leap years), Apr, June, Sept, Nov (we have 30
  days per month)
 
  so, for any month that is not 31 days, I want to delete the row
  accordingly.
 
  The question is, I have data sets from year 1970-2013, and to delete
  manually it would be time consuming, so how do I delete those rows
  according to the
 
   1) month itself
2) leap years ( year that is categorized
  as
  leap year, should
  have
  29 days in Feb)
 
  Hope you can help me. Thanks a lot.
 
  Regards,
  Dila

 
 Tento e-mail a jakékoliv k nìmu pøipojené dokumenty jsou dùvìrné a jsou
 urèeny pouze jeho adresátùm.
 Jestli¾e jste

[R] Deletion of rows

2014-03-11 Thread dila radi
Hi,

I would like to ask about the deletion of rows in the data.

Assuming I have this kind of data set, which you can refer through the
attachment.


As in the attachment, I have 31 days for each month which is I want to
delete some of the rows according to the real days per month.

For example:

 Jan, March, May, July, Aug, Oct, Dec (these months have 31 days per month,
so no deletion of rows needed)

Feb (28 days except for leap years), Apr, June, Sept, Nov (we have 30 days
per month)

so, for any month that is not 31 days, I want to delete the row accordingly.

The question is, I have data sets from year 1970-2013, and to delete
manually it would be time consuming, so how do I delete those rows
according to the

 1) month itself
  2) leap years ( year that is categorized as
leap year, should  have
29 days in Feb)

Hope you can help me. Thanks a lot.

Regards,
Dila
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 Rearrangement

2014-02-27 Thread dila radi
Hi all,

I know this is easy, but I really do not have any idea to solve it.

I have this kind of data set:

dat - read.table(text=Day Year Jan Feb Mar Apr
  1  2012 0 2.5 0.5 2
  2  2012 0 6.5 0 29
  3  2012 0 9.5 0 0
  4  2012 0 0 8 0.5
  5  2012 0 5 0.5 110.5
  6  2012 0 4 3.5 22
  7  2012 11 0 12.5 3.5
  8  2012 0 5 8 36.5
  1  2013 0 2.5 0.5 2
  2  2013 0 6.5 0 29
  3  2013 0 9.5 0 0
  4  2013 0 0 8 0.5
  5  2013 0 5 0.5 110.5
  6  2013 0 4 3.5 22
  7  2013 11 0 12.5 3.5
  8  2013 0 5 8 36.5,sep=,header=TRUE)

and I want it to be in this form:

Year   Day Month Amount  2012 1 1 0  2012 2 1 0  2012 3 1 0  2012 4
1 0  2012 5 1 0  2012 6 1 0  2012 7 1 11  2012 8 1 0  2012 1 2 2.5  2012 2 2
6.5  2012 3 2 9.5  2012 4 2 0  2012 5 2 5  2012 6 2 4  2012 7 2 0  2012 8 2
5  2012 1 3 0.5  2012 2 3 0  2012 3 3 0  2012 4 3 8  2012 5 3 0.5  2012 6 3
3.5  2012 7 3 12.5  2012 8 3 8  2012 1 4 2  2012 2 4 29  2012 3 4 0  2012 4
4 0.5  2012 5 4 110.5  2012 6 4 22  2012 7 4 3.5  2012 8 4 36.5 2013 1 1
0  2013 2 1 0  2013 3 1 0  2013 4 1 0  2013 5 1 0  2013 6 1 0  2013 7 1 11
2013 8 1 0  2013 1 2 2.5  2013 2 2 6.5  2013 3 2 9.5  2013 4 2 0  2013 5 2 5
2013 6 2 4  2013 7 2 0  2013 8 2 5  2013 1 3 0.5  2013 2 3 0  2013 3 3 0
2013 4 3 8  2013 5 3 0.5  2013 6 3 3.5  2013 7 3 12.5  2013 8 3 8  2012 1 4
2  2012 2 4 29  2012 3 4 0  2012 4 4 0.5  2012 5 4 110.5  2012 6 4 22  2012
7 4 3.5  2012 8 4 36.5  2013 1 4 2  2013 2 4 29  2013 3 4 0  2013 4 4 0.5
2013 5 4 110.5  2013 6 4 22  2013 7 4 3.5  2013 8 4 36.5
I want to rearrange the data according to the YEAR (year by year)

Thank you.

Regards,
Dila

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

2014-02-24 Thread dila radi
Hi all,

I have a data set in this form:

Year: 2012
 Day Jan Feb Mar Apr  1 0 2.5 0.5 2  2 0 6.5 0 29  3 0 9.5 0 0  4 0 0 8 0.5
5 0 5 0.5 110.5  6 0 4 3.5 22  7 11 0 12.5 3.5  8 0 5 8 36.5
I want to rearrange the data in this form:

DateAmount
1/1/2012  0
2/1/2012  0
3/1/2012  0
4/1/2012  0
...   ...
...   ...

How can I achieve this?

Thank you in advanced!

Regards,
Dila

[[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] Replace NA's with value in the next row

2013-11-13 Thread dila radi
Hi all,

I have a data set which treat missing value as NA and now I need to replace
all these NA's by using number in the same row but different column.

Here is the part of my data:
 V1 V2 V3 V4 V5 V6 V7  0 0 0 1.2 0 0 0.259  0 0 12.8 0 23.7 0 8.495  6 0
81.7 0.2 0 20 19.937  0 1.5 60.9 0 0 15.5 13.900  1 13 56.8 17.5 32.8 6.4
27.654  4 3 66.4 2 0.3 NA 17.145


I want to replace (V6, 6) with (V7, 6). I have about 1000 NA's in V6 which
I want to replace  with the same row in V7. The other values in V6, I want
to keep remain the same.

How to achieve this? Assuming my data is called Targetstation,  I have
tried this:

Targetstation - within(Targetstation, v6 - replace(v6, is.na(v6), v7[is.na
(v6)]))

But R gives me this:

Warning messages:

1: In is.na(v6) : is.na() applied to non-(list or vector) of type 'NULL'

2: In is.na(v6) : is.na() applied to non-(list or vector) of type 'NULL'


How to solve this?

Thank you in advance.

Regards,

Dila.

[[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] How to replace NA's data with some value

2013-11-12 Thread dila radi
Hi all,

I have a data set with missing value. I would like to estimate those
missing value by using normal ratio method.
Below is part of my data:

  AS   BL Serdang  Jhr   Phg  Target station
   00.012.8  0.0  23.7  0.0
   60.081.7  0.2  0.0   NA
   01.560.9  0.0  0.0   15.5
   1   13.056.8 17.5 32.8  6.4
   4 3.066.4  2.0  0.3   NA

Now I want to replace those NA's,  with the estimation values by using this
formula:
weight$v6
-(weight1*AS)+(weight2*BL)+(weight3*Serdang)+(weight4*Jhr)+(weight5*Phg);
Targetstation

but I still could not replace the NA's. My problem is, how do I replace
those NA's with another value?

Thank you so much for your help and attention.

Regards,
Dila

[[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] how to introduce missing data for complete data

2013-11-10 Thread dila radi
Hi,

Im new R users. In my research I use rainfall data and Im interested in
estimating missing data. I would like to use Normal Ratio Method to
estimate missing data. My problem is, how do I introduce missing data
randomly within my complete set of data?


Stn ID  Year  Mth   Day   Amount
48603 71 1 1 1
48603 71 1 2 0.5
48603 71 1 3 1.3
48603 71 1 4 0.8
48603 71 1 5 0
48603 71 1 6 0
48603 71 1 7 0
...

Thank you so much for your attention and help.

Regards,
Dila

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