[R] Help R
arun
smartpink111 at yahoo.com
Thu Aug 29 16:12:14 CEST 2013
HI,
Your code is not clear:
for( i in 1: nrow(D))
{
for( j in 5:ncol(D))
{
D[((D[i,j]/D[i,2])>1.5)]15999)]<-1000000
## "....1.5)]15999)]"
}
^^^
}
D<- structure(list(X. = c(1108L, 1591L, 3408L, 3872L, 5823L, 8099L,
10640L, 12600L, 14680L, 14698L), media = c(22, 86.6, 807, 103.25,
73, 125.16667, 67.33333, 2417, 38, 698.16667), IE.2003 = c(32,
92, 166, 237.2, 160.6, 169, 494.8, 1958, 142.2, 505), IE.2004 = c(63,
122.8, 290, 117.8, 73.6, 206, 168.2, 1871, 46, 482), IE.2005 = c(60,
276.6, 302, 154.4, 133.6, 196, 424.8, 1960, 30, 553), IE.2006 = c(39L,
87L, 322L, 113L, 70L, 161L, 476L, 2383L, 61L, 664L), IE.2007 = c(4,
95, 621, 116, 80, 150, 670.6, 2453, 404, 847), IE.2008 = c(8L,
94L, 1071L, 90L, 74L, 94L, 74L, 2506L, 42L, 800L), IE.2009 = c(16L,
81L, 1301L, 94L, 69L, 72L, 77L, 2758L, 19L, 679L), IE.2010 = c(5,
76, 1225, 1911.2, 72, 78, 51, 2442, 243.8, 646)), .Names = c("X.",
"media", "IE.2003", "IE.2004", "IE.2005", "IE.2006", "IE.2007",
"IE.2008", "IE.2009", "IE.2010"), class = "data.frame", row.names = c("1",
"2", "3", "4", "5", "6", "7", "8", "9", "10"))
D[,-c(1:4)][D[,-c(1:4)]/D[,2]>1.5]
# [1] 60.0 276.6 133.6 196.0 424.8 39.0 476.0 61.0 670.6 404.0
#[11] 1301.0 1225.0 1911.2 243.8
A.K.
Hi to everyone,
I would like to replace some values in a data.frame (D)
> str(D)
'data.frame': 116 obs. of 10 variables:
$ X. : int 1108 1591 3408 3872 5823 8099 10640 12600 14680 14698 ...
$ media : num 22 86.6 807 103.2 73 ...
$ IE.2003: num 32 92 166 237 161 ...
$ IE.2004: num 63 122.8 290 117.8 73.6 ...
$ IE.2005: num 60 277 302 154 134 ...
$ IE.2006: num 39 87 322 113 70 ...
$ IE.2007: num 4 95 621 116 80 ...
$ IE.2008: num 8 94 1071 90 74 ...
$ IE.2009: num 16 81 1301 94 69 ...
$ IE.2010: num 5 76 1225 1911 72 ...
D
X. media IE.2003 IE.2004 IE.2005 IE.2006 IE.2007 IE.2008 IE.2009 IE.2010
1 1108 22.00000 32.0 63.0 60.0 39 4.0 8 16 5.0
2 1591 86.60000 92.0 122.8 276.6 87 95.0 94 81 76.0
3 3408 807.00000 166.0 290.0 302.0 322 621.0 1071 1301 1225.0
4 3872 103.25000 237.2 117.8 154.4 113 116.0 90 94 1911.2
5 5823 73.00000 160.6 73.6 133.6 70 80.0 74 69 72.0
6 8099 125.16667 169.0 206.0 196.0 161 150.0 94 72 78.0
7 10640 67.33333 494.8 168.2 424.8 476 670.6 74 77 51.0
8 12600 2417.00000 1958.0 1871.0 1960.0 2383 2453.0 2506 2758 2442.0
9 14680 38.00000 142.2 46.0 30.0 61 404.0 42 19 243.8
10 14698 698.16667 505.0 482.0 553.0 664 847.0 800 679 646.0
WHat I really want to do is:
for( i in 1: nrow(D))
{
for( j in 5:ncol(D))
{
D[((D[i,j]/D[i,2])>1.5)]15999)]<-1000000
}
}
More information about the R-help
mailing list