HI R-Users
Assume that I have a data frame 'temp' with several variables (v1,v2,v3,v4,v5.).
v1 v2 v3 v4 v5
1 2 3 3 6
5 2 4 2 0
2 -9 5 4 3
6 2 1 3 4
1, I want to look at the entire row values of when v2 =-9
like
2 -9 5 4 3
I wrote
K<- list(if(temp$v2)==-9))
I wrote the like this but it gave me which is not correct.
False false false false false
2. I want assign that values as missing if v2 = -9. (ie., I want
exclude from the analysis
How do I do it in R?
Thanks in advance
look up and Missing
7 messages · Ashta, jim holtman, John Kane +3 more
Here is how to find out which rows contain -9 and then you can do with it as you please:
x
v1 v2 v3 v4 v5 1 1 2 3 3 6 2 5 2 4 2 0 3 2 -9 5 4 3 4 6 2 1 3 4
which(apply(x, 1, function(.row) any(.row == -9)))
[1] 3
On Sun, Nov 8, 2009 at 10:23 AM, Ashta <sewashm at gmail.com> wrote:
HI ?R-Users Assume that I have a data frame 'temp' with several variables (v1,v2,v3,v4,v5.). ?v1 v2 v3 ?v4 v5 ? 1 ?2 ? 3 ? 3 ? ?6 ? 5 ?2 ?4 ? ?2 ? ?0 ? 2 -9 ? 5 ? 4 ? ?3 ? 6 ?2 ? 1 ? 3 ? ?4 1, I want to look at the entire row values of when v2 =-9 ? like ? ? ? ? 2 -9 ? 5 ? 4 ? ?3 I wrote K<- list(if(temp$v2)==-9)) I wrote the like this but ?it gave me ?which is not correct. ? False false false false false 2. I want assign that values ?as missing if ? v2 = -9. ?(ie., I want exclude from the analysis How do I do it ?in R? Thanks in advance
______________________________________________ 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.
Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
On Nov 8, 2009, at 10:23 AM, Ashta wrote:
HI R-Users
Assume that I have a data frame 'temp' with several variables
(v1,v2,v3,v4,v5.).
v1 v2 v3 v4 v5
1 2 3 3 6
5 2 4 2 0
2 -9 5 4 3
6 2 1 3 4
1, I want to look at the entire row values of when v2 =-9
like
2 -9 5 4 3
I wrote K<- list(if(temp$v2)==-9))
"if" would be the wrong R function to use. It's mostly for program control. And where did the "3" come from? You were working with the column temp$v2. Oh, you wanted a row rather than the column, "v2"? So how were you going to select that row? Perhaps: K <-temp[ temp$v2 == -9, ] K
I wrote the like this but it gave me which is not correct. False false false false false
I could not get your code to produce this. I got: Error: unexpected '==' in "K<- list(if(temp$v2)=="
2. I want assign that values as missing if v2 = -9. (ie., I want exclude from the analysis How do I do it in R?
Your request is not well specified at least to my reading, because I could not tell if you wanted the re-assignment to occur in temp (and that was after I came down on the row side of the whether you wanted a row or column.) . The following assumes you wanted the row in question (created above) modified outside of "temp". > is.na(K) <- K == -9 > K v1 v2 v3 v4 v5 3 2 NA 5 4 3 If you had used ifelse you would have gotten close, but the data type would have been a list, which may not have been what you expected: > K <- ifelse(K==-9, NA, K) > K [[1]] [1] 2 [[2]] [1] NA [[3]] [1] 5 [[4]] [1] 4 [[5]] [1] 3
David Winsemius, MD Heritage Laboratories West Hartford, CT
I'm not quite sure I understood the second queston but does this work? subset(temp, xx$v2==-9) subset(temp, xx$v2!= -9)
--- On Sun, 11/8/09, Ashta <sewashm at gmail.com> wrote:
From: Ashta <sewashm at gmail.com> Subject: [R] look up and Missing To: r-help at stat.math.ethz.ch Received: Sunday, November 8, 2009, 10:23 AM HI? R-Users Assume that I have a data frame 'temp' with several variables (v1,v2,v3,v4,v5.). ? v1 v2 v3? v4 v5 ???1? 2???3???3? ? 6 ???5? 2? 4? ? 2? ? 0 ???2 -9???5???4? ? 3 ???6? 2???1???3? ? 4 1, I want to look at the entire row values of when v2 =-9 ???like ? ? ? ???2 -9???5???4? ? 3 I wrote K<- list(if(temp$v2)==-9)) I wrote the like this but? it gave me? which is not correct. ???False false false false false 2. I want assign that values? as missing if???v2 = -9.? (ie., I want exclude from the analysis How do I do it? in R? Thanks in advance
______________________________________________ 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.
__________________________________________________________________ Yahoo! Canada Toolbar: Search from anywhere on the web, and bookmark your favourite sites. Download it now http://ca.toolbar.yahoo.com.
try this: temp.new <- temp[temp$v2 != -9, ] temp.new I hope it helps. Best, Dimitris
Ashta wrote:
HI R-Users
Assume that I have a data frame 'temp' with several variables (v1,v2,v3,v4,v5.).
v1 v2 v3 v4 v5
1 2 3 3 6
5 2 4 2 0
2 -9 5 4 3
6 2 1 3 4
1, I want to look at the entire row values of when v2 =-9
like
2 -9 5 4 3
I wrote
K<- list(if(temp$v2)==-9))
I wrote the like this but it gave me which is not correct.
False false false false false
2. I want assign that values as missing if v2 = -9. (ie., I want
exclude from the analysis
How do I do it in R?
Thanks in advance
______________________________________________ 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.
Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20091108/7fde773e/attachment-0001.pl>
On Nov 8, 2009, at 11:08 AM, David Winsemius wrote:
On Nov 8, 2009, at 10:23 AM, Ashta wrote:
HI R-Users
Assume that I have a data frame 'temp' with several variables
(v1,v2,v3,v4,v5.).
v1 v2 v3 v4 v5
1 2 3 3 6
5 2 4 2 0
2 -9 5 4 3
6 2 1 3 4
1, I want to look at the entire row values of when v2 =-9
like
2 -9 5 4 3
I wrote K<- list(if(temp$v2)==-9))
A further thought, that might be more useful if you were intending to supply a portion of a dataframe to an analytical function, would be the subset function: t2 <- subset(temp, v2 != -9) E. g.: lm( v1 ~ v2 + v3, data= subset(temp, v2 != -9)
"if" would be the wrong R function to use. It's mostly for program control. And where did the "3" come from? You were working with the column temp$v2. Oh, you wanted a row rather than the column, "v2"? So how were you going to select that row? Perhaps: K <-temp[ temp$v2 == -9, ] K
I wrote the like this but it gave me which is not correct. False false false false false
I could not get your code to produce this. I got: Error: unexpected '==' in "K<- list(if(temp$v2)=="
2. I want assign that values as missing if v2 = -9. (ie., I want exclude from the analysis How do I do it in R?
Your request is not well specified at least to my reading, because I could not tell if you wanted the re-assignment to occur in temp (and that was after I came down on the row side of the whether you wanted a row or column.) . The following assumes you wanted the row in question (created above) modified outside of "temp".
is.na(K) <- K == -9 K
v1 v2 v3 v4 v5 3 2 NA 5 4 3 If you had used ifelse you would have gotten close, but the data type would have been a list, which may not have been what you expected:
K <- ifelse(K==-9, NA, K) K
[[1]] [1] 2 [[2]] [1] NA [[3]] [1] 5 [[4]] [1] 4 [[5]] [1] 3
-- David Winsemius, MD Heritage Laboratories West Hartford, CT
______________________________________________ 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.
David Winsemius, MD Heritage Laboratories West Hartford, CT