[R] Help R
Jose Iparraguirre
Jose.Iparraguirre at ageuk.org.uk
Thu Aug 29 16:27:49 CEST 2013
As said by arun, the code is not clear.
Ma Teresa, what is it that you actually want to do?
Regards,
José
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of arun
Sent: 29 August 2013 15:12
To: R help
Subject: Re: [R] Help R
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
}
}
______________________________________________
R-help at 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.
The Wireless from Age UK | Radio for grown-ups.
www.ageuk.org.uk/thewireless
If you’re looking for a radio station that offers real variety, tune in to The Wireless from Age UK.
Whether you choose to listen through the website at www.ageuk.org.uk/thewireless, on digital radio (currently available in London and Yorkshire) or through our TuneIn Radio app, you can look forward to an inspiring mix of music, conversation and useful information 24 hours a day.
-------------------------------
Age UK is a registered charity and company limited by guarantee, (registered charity number 1128267, registered company number 6825798).
Registered office: Tavis House, 1-6 Tavistock Square, London WC1H 9NA.
For the purposes of promoting Age UK Insurance, Age UK is an Appointed Representative of Age UK Enterprises Limited, Age UK is an Introducer
Appointed Representative of JLT Benefit Solutions Limited and Simplyhealth Access for the purposes of introducing potential annuity and health
cash plans customers respectively. Age UK Enterprises Limited, JLT Benefit Solutions Limited and Simplyhealth Access are all authorised and
regulated by the Financial Services Authority.
------------------------------
This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are
addressed. If you receive a message in error, please advise the sender and delete immediately.
Except where this email is sent in the usual course of our business, any opinions expressed in this email are those of the author and do not
necessarily reflect the opinions of Age UK or its subsidiaries and associated companies. Age UK monitors all e-mail transmissions passing
through its network and may block or modify mails which are deemed to be unsuitable.
Age Concern England (charity number 261794) and Help the Aged (charity number 272786) and their trading and other associated companies merged
on 1st April 2009. Together they have formed the Age UK Group, dedicated to improving the lives of people in later life. The three national
Age Concerns in Scotland, Northern Ireland and Wales have also merged with Help the Aged in these nations to form three registered charities:
Age Scotland, Age NI, Age Cymru.
More information about the R-help
mailing list