Thans Richard, it works well. --- Kai
On Monday, December 13, 2021, 04:00:33 AM PST, Richard O'Keefe
wrote:
You want to DELETE rows satisfying the condition P & Q.The subset() function
requires an expression saying whatyou want to RETAIN, so you need subset(PD,
!(P & Q)).
test <-
You want to DELETE rows satisfying the condition P & Q.
The subset() function requires an expression saying what
you want to RETAIN, so you need subset(PD, !(P & Q)).
test <- subset(PD, !(Class == "1st" & Survived == "No"))
By de Morgan's laws, !(P & Q) is the same as (!P) | (!Q)
so you could
Use one ampersand, not two.
And post plain text.
On December 12, 2021 8:30:11 PM PST, Kai Yang via R-help
wrote:
>Hi R team,I want to delete records from a data frame if Class = '1st' and
>Survived = 'No'. I wrote the code below, test <- subset(PD, Class != '1st' &&
>Survived != 'No')
>but
Hi R team,I want to delete records from a data frame if Class = '1st' and
Survived = 'No'. I wrote the code below, test <- subset(PD, Class != '1st' &&
Survived != 'No')
but the code return a wrong result. Can someone help me for this?
Thanks,Kai
[[alternative HTML version deleted]]
>If you want to drop levels, use droplevels() either on the factor or on
the >subset of your data frame. Example:
>droplevels(f[1]) #One element, only one level
Calling factor() on a factor, as the OP did, also drops any unused levels,
as the examples showed.
>
> You did not change df$quant - you made a new object called 'subdf'
> containing a column called 'quant' that had only one level. Changing subdf
> has
> no effect on df.
Also, subsetting a factor _intentionally_ does not change the number of levels.
Example:
f <- factor(sample(letters[1:3],
You did not change df$quant - you made a new object called 'subdf'
containing a column called 'quant' that had only one level. Changing
subdf has no effect on df.
> df <- data.frame(quant=factor(letters))
> str(df)
'data.frame': 26 obs. of 1 variable:
$ quant: Factor w/ 26 levels
Hello,
Don't use subset, use indexing.
subdf <- df[df$quant %in% "VeryFast", ]
By the way, instead of %in% you can use ==, since you're interested in
just one value of quant.
Hope this helps,
Rui Barradas
Citando ch.elahe via R-help :
> Hi all,
> I have the following
Hi all,
I have the following df and I want to know which Protocols are VeryFast, which
are FAST, which are SLOW and also which ones are VerySLOW :
$ Protocol : Factor w/ 48 levels "DP FS QTSE SAG",..: 5 5 28 5 5 5 7 7
47 5 ...
$ quant : Factor w/ 4 levels
t;V046", "V047", "V048", "V049", "V050", "V051", "V052",
"V053", "V054", "V055", "V056", "V057"), class = "factor"), linecode =
structure(c(1L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
<- c()
> x <- length(plot.id)
> for (i in (1:x)) {
> m1 <- as.numeric(strsplit(as.character(dataset$ranges2use),
> ",")[[i]])
> }
> m2
> }
>
> I am not sure where I am making a mistake.
> Thanks.
> Nilesh
>
, 2015 10:17 AM
To: DIGHE, NILESH [AG/2362]; r-help@r-project.org
Subject: Re: [R] subset data using a vector
length(strsplit(as.character(mydata$ranges2use), ","))
was that what you expected? I think not.
On 23/11/2015 16:05, DIGHE, NILESH [AG/2362] wrote:
Dear R users,
lit(as.character(dataset$ranges2use),
",")[[i]])
}
m2
}
I am not sure where I am making a mistake.
Thanks.
Nilesh
-Original Message-
From: Michael Dewey [mailto:li...@dewey.myzen.co.uk]
Sent: Monday, November 23, 2015 12:11 PM
To: DIGHE, NILESH [AG/2362]; r-help@r-p
length(strsplit(as.character(mydata$ranges2use), ","))
was that what you expected? I think not.
On 23/11/2015 16:05, DIGHE, NILESH [AG/2362] wrote:
Dear R users,
I like to split my data by a vector created by using variable "ranges".
This vector will have the current range
Dear R users,
I like to split my data by a vector created by using variable
"ranges". This vector will have the current range (ranges), preceding range
(ranges - 1), and post range (ranges + 1) for a given plotid. If the preceding
or post ranges in this vector are outside the
H [AG/2362]; r-help@r-project.org
Subject: Re: [R] subset data using a vector
length(strsplit(as.character(mydata$ranges2use), ","))
was that what you expected? I think not.
On 23/11/2015 16:05, DIGHE, NILESH [AG/2362] wrote:
> Dear R users,
> I like to split m
Hello,
I have a variable in a data frame that contains NA values. I just want to
subset so that I get the obs where that variable is missing.
In SAS I would do:
data missing;
set test;
if myvalue=' ';
run;
How can I perform this simple task in R?
Thanks in advance for your help.
--
On Nov 30, 2012, at 9:27 AM, ramoss ramine.mossad...@finra.org wrote:
Hello,
I have a variable in a data frame that contains NA values. I just want to
subset so that I get the obs where that variable is missing.
In SAS I would do:
data missing;
set test;
if myvalue=' ';
run;
How
-
project.org] On Behalf Of ramoss
Sent: Friday, November 30, 2012 4:27 PM
To: r-help@r-project.org
Subject: [R] subset data frame by variable with missing value
Hello,
I have a variable in a data frame that contains NA values. I just want
to subset so that I get the obs where that variable
Le vendredi 30 novembre 2012 à 07:27 -0800, ramoss a écrit :
Hello,
I have a variable in a data frame that contains NA values. I just want to
subset so that I get the obs where that variable is missing.
In SAS I would do:
data missing;
set test;
if myvalue=' ';
run;
How can I
I found the answer;
Its mymissing - subset(mydata,is.na(myvar))
--
View this message in context:
http://r.789695.n4.nabble.com/subset-data-frame-by-variable-with-missing-value-tp4651439p4651440.html
Sent from the R help mailing list archive at Nabble.com.
-help@r-project.org
Cc:
Sent: Friday, November 30, 2012 10:27 AM
Subject: [R] subset data frame by variable with missing value
Hello,
I have a variable in a data frame that contains NA values. I just want to
subset so that I get the obs where that variable is missing.
In SAS I would do:
data
Thanks to all
The problem is fixed. What happened is that i was using the epicalc library and
this way the program didn´t find the var edad11.
Switching off epicalc everything is all rigth.
Thanks again
Antonio Sousa
__
R-help@r-project.org mailing
Hi
Need a little help. This is easy question, but i´m new to R.
I want to subset a data frame called vef1 using a variable that is a factor
called edad11, 0 if under 11 years, 1 otherwise.
I tried:
vef1.sub-subset(vef1, edad11==0)
The code runs correctly but i get a empty dataframe.
If i use
Hmmm a trivial mockup suggests this should work:
x - factor(sample(c(0, 1), 30, TRUE)
x == 0
so perhaps you could work up a reproducible example for us: see this
site for more details on how to do so:
http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
...@sapo.pt
To: r-help@r-project.org
Cc:
Sent: Thursday, August 2, 2012 2:15 PM
Subject: [R] Subset data
Hi
Need a little help. This is easy question, but i´m new to R.
I want to subset a data frame called vef1 using a variable that is a factor
called edad11, 0 if under 11 years, 1 otherwise.
I
: antonio.bso...@sapo.pt antonio.bso...@sapo.pt
To: r-help@r-project.org
Cc:
Sent: Thursday, August 2, 2012 2:15 PM
Subject: [R] Subset data
Hi
Need a little help. This is easy question, but i´m new to R.
I want to subset a data frame called vef1 using a variable that is a
factor called edad11, 0
Hi Antonio,
It's hard to know for sure what the problem is, because we don't know
what your vef1 data.frame contains. My guess is that edad11 is not
numeric, so never equals 0 (although it might equal the character
string 0).
If you paste the results of str(vef1) in your reply we can see if my
HI David,
I realized it immediately after sending the message from email and corrected
it in Nabble as yahoo mail is down.
A.K.
__
If you reply to this email, your message will be added to the discussion below:
Dear list members,
I am trying to create a subset of a data frame based on conditions in two
columns, and after spending much time trying (and search R-help) have not had
any luck. Essentially, I have a data frame that is something like this:
Hi
Dear list members,
I am trying to create a subset of a data frame based on conditions in
two
columns, and after spending much time trying (and search R-help) have
not
had any luck. Essentially, I have a data frame that is something like
this:
date-as.POSIXct(as.character(c
, 2012 2:55 AM
Subject: [R] subset data based on values in multiple columns
Dear list members,
I am trying to create a subset of a data frame based on conditions in two
columns, and after spending much time trying (and search R-help) have not had
any luck. Essentially, I have a data frame
Hello,
One more question.. I have the data.frame pop:
xloc yloc gonad indEneW Area
123 20 516.74 1 0.02 20.21 1
223 20 1143.20 1 0.02 20.21 1
323 20 250.00 1 0.02 20.21 1
422 15 251.98 1 0.02 18.69 2
522 15 598.08 1
Try this:
subset(pop, (ave(Area, Area, FUN = length) == 1 | ave(Area, Area, FUN
= function(x)cumsum(prop.table(x))) 0.7 Area %in% 1:3))
On Fri, Mar 18, 2011 at 2:48 PM, Nicolas Gutierrez nicol...@uw.edu wrote:
Hello,
One more question.. I have the data.frame pop:
xloc yloc gonad
On Fri, Mar 18, 2011 at 10:48:44AM -0700, Nicolas Gutierrez wrote:
Hello,
One more question.. I have the data.frame pop:
xloc yloc gonad indEneW Area
123 20 516.74 1 0.02 20.21 1
223 20 1143.20 1 0.02 20.21 1
323 20 250.00 1 0.02
On Fri, Mar 18, 2011 at 10:48:44AM -0700, Nicolas Gutierrez wrote:
Hello,
One more question.. I have the data.frame pop:
xloc yloc gonad indEneW Area
123 20 516.74 1 0.02 20.21 1
223 20 1143.20 1 0.02 20.21 1
323 20 250.00 1 0.02
perfect, thanks Henrique!
Nico
On 3/18/2011 11:17 AM, Henrique Dallazuanna wrote:
Try this:
subset(pop, (ave(Area, Area, FUN = length) == 1 | ave(Area, Area, FUN
= function(x)cumsum(prop.table(x))) 0.7 Area %in% 1:3))
On Fri, Mar 18, 2011 at 2:48 PM, Nicolas Gutierreznicol...@uw.edu
@r-project.org
Betreff: [R] subset data
Dear all,
data - data.frame(id=seq(1:10),x=runif(10))
data
id x
1 1 0.3604464
2 2 0.4813987
3 3 0.0160058
4 4 0.7165909
5 5 0.6092248
6 6 0.2413049
7 7 0.7981568
8 8 0.6093960
9 9 0.2887064
10 10 0.3485780
selected.id - sample
Like this?
data-read.table(stdin(), head=T, sep=,)
id,x
1,0.3604464
2,0.4813987
3,0.0160058
4,0.7165909
5,0.6092248
6,0.2413049
7,0.7981568
8,0.6093960
9,0.2887064
10,0.3485780
selected.id - sample(data$id,3,replace=F)
selected.id
data.subset-subset(data, id %in% selected.id)
data.subset
just a small adjusts...
data[data$id %in% selected.id, ]
--- so elegant! :-)
On Wed, May 6, 2009 at 1:15 AM, milton ruser milton.ru...@gmail.com wrote:
Like this?
data-read.table(stdin(), head=T, sep=,)
id,x
1,0.3604464
2,0.4813987
3,0.0160058
4,0.7165909
5,0.6092248
6,0.2413049
Try, data[data$id%in%selected.id,]
Good day!
Kushantha
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of abdul kudus
Sent: Wednesday, May 06, 2009 10:12 AM
To: r-help@r-project.org
Subject: [R] subset data
Dear all,
data
:15 PM
To: abdul kudus; r-help@r-project.org
Subject: Re: [R] subset data
Try, data[data$id%in%selected.id,]
Good day!
Kushantha
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of abdul kudus
Sent: Wednesday, May 06, 2009 10:12 AM
Hi!
I'm doing:
etni - subset(etni, NAMECOM!=Maniquisito)
where etni is a data.frame, NAMECOM a factor and Maniquisito labels
a row that I want to delete.
The problem is that while the row is deleted, the factor level is still
there (I can see Maniquisito if I do levels(etni$NAMECOM) ).
I know
On Tuesday 01 April 2008 09:43:00 am Agustin Lobo wrote:
AL I'm doing:
AL etni - subset(etni, NAMECOM!=Maniquisito)
AL
AL where etni is a data.frame, NAMECOM a factor and Maniquisito labels
AL a row that I want to delete.
AL
AL The problem is that while the row is deleted, the factor level is
Thanks, problem solved thanks to your hints, but, within subset(),
drop=T still keeps
the unused levels (I'm using 2.6.1 on win).
Agus
Stefan Grosse escribió:
On Tuesday 01 April 2008 09:43:00 am Agustin Lobo wrote:
AL I'm doing:
AL etni - subset(etni, NAMECOM!=Maniquisito)
AL
AL where etni
Lobo
Sent: Tuesday, April 01, 2008 3:26 AM
To: Stefan Grosse
Cc: r-help@r-project.org
Subject: Re: [R] Subset: data frames and factor levels
Thanks, problem solved thanks to your hints, but, within subset(),
drop=T still keeps
the unused levels (I'm using 2.6.1 on win).
Agus
Stefan Grosse escribió
Weidong Gu wgu at uab.edu writes:
Try drop.levels in library gdata.
For what it's worth, adding a drop.levels (default FALSE)
to subset is a long-standing wish of mine -- I keep meaning
to put together a patch to do this. (This question comes
up about once a year on the R help list.) I
47 matches
Mail list logo