Ah, thanks, that makes sense.
Peter
On Fri, Jul 1, 2022 at 10:01 PM Bill Dunlap wrote:
>
> This has to do with the mode of the subscript - logical subscripts are
> repeated to the length of x and integer/numeric ones are not. NA is logical,
> NA_integer_ is integer, so we get
>
> > x <- 1:10
Dear R-help members,
I'm working with the xml2 package to parse an xml document, and I don't
understand how subsetting / slicing of xml_nodesets works. I'd expect
xml_find_all to only return children of the nodes I selected with [ or
[[ but it returns all nodes found in the whole document. I d
Hello,
Maybe something like the following is what you want.
The code first creates a logical index of columns with at least one NA
or "NULL" (character string, not NULL) values. Then extracts only those
columns from the dataframe.
inx <- sapply(datos, function(x) any(x == "NULL" | is.na(x)))
Hi Paul,
Thanks for the reproducible data. You really only need to provide
enough to illustrate your question, but this works.
I suspect you have a data import problem - I doubt you really want so
many columns to be factors! Probably you need to specify that NULL
means something specific, rather
Dear friends,
Hope you are all doing well. I would like to know how to retrieve a
complete dataframe (all the columns), except for the cases when one of the
columns have either nulls or NAs.
In this case, I´d like to retrieve all the columns but only the cases
(rows) where Var5 has values differe
dear peter,
Its workingthanks a lot...
yours sincerely,
AKSHAY M KULKARNI
From: Peter Langfelder
Sent: Saturday, July 28, 2018 11:41 AM
To: akshay...@hotmail.com
Cc: r-help
Subject: Re: [R] subsetting ls() as per class...
Looking at ?rm
> objClasses <- unlist(eapply(.GlobalEnv, function(x)class(x)[1]))
> head(objClasses)
f E
"function" "environment"
df h
"tbl_df""function"
myData L
"list""list"
> names(objClasses)[objClasses=="tbl_df"]
[1]
The ll() function of R.oo returns a data.frame with various attributes that
you can subset on, e.g.
> subset(R.oo::ll(), data.class %in% c("zoo", "xts"))
member data.class dimension objectSize
2 fzzoo10 1344
4 sample.xtsxts c(180,4) 10128
5
You can extract the names into a character vector with ls and then use
grep(..., values=TRUE ) to select which ones you want to remove, and then pass
that list to rm.
However, due to the way R handles memory you are unlikely to see much savings
by doing this. I would recommend focusing on creat
Looking at ?rm, my solution would be something like
rm(list = grep("\\.NS$", ls(), value = TRUE))
But test it since I have not tested it.
Peter
On Fri, Jul 27, 2018 at 10:58 PM akshay kulkarni wrote:
>
> dear memebers,
>I am using R in AWS linux instance for my
dear memebers,
I am using R in AWS linux instance for my
research. I want to remove certain objects from the global environment to
reduce my EBS cost..for example, I want to remove all objects of class "xts",
"zoo". Is there any way to automate this, instead of re
The unlist solution is quite clever.
But I will note that none of the solutions offered so far succeed if the input
is, for example,
YH <- list(1:5, letters[1:3], 1:7)
iuhV <- c(2,2,4)
and the desire is to return a list whose elements are of the same types as the
input list. Which would
> On Jun 18, 2018, at 4:15 AM, akshay kulkarni wrote:
>
> correctionI want the method without a for loop
Here are two. The first is more readable, but the second is 5 times faster.
mapply("[", YH, iuhV)
unlist(YH, recursive = FALSE, use.names = FALSE)[cumsum( lengths(YH)) -
lengths(YH)
sapply( 1:length(YH), function(i) { YH[[i]][iuhV[i]]})
On Mon, Jun 18, 2018 at 1:55 PM, akshay kulkarni
wrote:
> dear members,
> I have list YH and index vector iuhV. I want
> to select iuhV[1] from YH[[1]], iuhv[2] from YH[[2]], iuhv[3] from
> YH[[3]]..iuhv[n] f
dear members,
I have list YH and index vector iuhV. I want to
select iuhV[1] from YH[[1]], iuhv[2] from YH[[2]], iuhv[3] from
YH[[3]]..iuhv[n] from YH[[n]]...
How to do this?
I searched SO and the internet but was bootless
Very many thanks for your time and e
Hello All,
I am facing a unique problem and am unable to find any help in R help pages
or online. I will appreciate your help for the following problem:
I have 2 data-frames, samples below and there is an expected output
R Dataframe1:
C1 C2 C3 C4.. CN
R1
Hi Neha,
This might help:
R<-read.table(text="C1 C2 C3 C4
R1 0 1 0 1
R2 1 0 1 1
R3 1 0 0 0",
header=TRUE)
U<-read.table(text="C1 C2 C3 C4
U1 1 1 0 1
U2 1 1 1 1",
header=TRUE)
# these are matrices - I think this will work for dataframes as well
for(ui in 1:dim(U)[1]) {
for(ri in 1:dim(R)[1]) {
i
> On Mar 11, 2018, at 3:32 PM, Neha Aggarwal wrote:
>
> Hello All,
> I am facing a unique problem and am unable to find any help in R help pages
> or online. I will appreciate your help for the following problem:
> I have 2 data-frames, samples below and there is an expected output
>
> R Datafr
Responses inline.
On Sun, 11 Mar 2018, Neha Aggarwal wrote:
Hello All,
I am facing a unique problem and am unable to find any help in R help pages
or online. I will appreciate your help for the following problem:
I have 2 data-frames, samples below and there is an expected output
R Dataframe1:
Hello All,
I am facing a unique problem and am unable to find any help in R help pages
or online. I will appreciate your help for the following problem:
I have 2 data-frames, samples below and there is an expected output
R Dataframe1:
C1 C2 C3 C4.. CN
R1
Thank you for the info. I did solve it using
unlist lapply strsplit functions.
On Wed, Feb 24, 2016 at 9:31 PM, Bert Gunter wrote:
> Have you gone through any R tutorials yet? I didn't entirely
> understand your question (and so cannot answer), but this sounds like
> a basic subsetting/data wr
A combination of subsetting and ?substr should get you close to a solution.
If the middle sequence you referenced isn't always the same distance from
the first character, you may have to involve regular expressions to find
"the middle".
On Wednesday, February 24, 2016, Bert Gunter wrote:
> Have
Have you gone through any R tutorials yet? I didn't entirely
understand your question (and so cannot answer), but this sounds like
a basic subsetting/data wrangling task that you should know how to do
if you have gone through a basic tutorial or two.
See also ?subset, ?"[" (basic indexing) and pos
Hi all,
One of the the columns of a data frame has a value such like
S-2001-yy
S-2004-xx
F-2007-SS
and so on
based on this column (variable) I want subset a data frame where the
middle value of this variable is between 2001 to 2004.
THE END RESULT THE DATA FRAME WILL BE THIS.
AAA
tutorials so that you
understand how R works.
-
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352
-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Sarah Goslee
Sent: Tue
It really isn't clear what you want, and posting in HTML has mangled
what you did provide.
Please use dput() to provide sample data, and give us a clear idea of
what you want, ideally an example of what the output should look like.
Adding the R code you've tried to use is also a good idea.
Sarah
I have a global matrix (e.g. table below) of species feeding. I am trying
to create specific matrix for specific sites. If for example a subset is to
have sp1, sp3 and spp only these 3 species should be appearing in the
subset (both column and rows).
I have been checking online help but I seem not
HI Jean,
Here is part of my data. As you can see, I have cross-section point and
corresponding elevation of a river. Now I want to select cross-section
points by 50m interval. But the real cross-section data might not have
exact points say 0, 50, 100,…and so on. Therefore, I need to take points
> On Nov 9, 2015, at 9:19 AM, Adams, Jean wrote:
>
> Harun,
>
> Can you give a simple example?
>
> If your cross_section looked like this
> c(144, 179, 214, 39, 284, 109, 74, 4, 249)
> and your other vector looked like this
> c(0, 50, 100, 150, 200, 250, 300, 350)
> what would you want your su
Do you want the "closest" or what range it is in? If you want the range,
then use 'cut':
> x <- c(144, 179, 214, 39, 284, 109, 74, 4, 249)
> range <- c(0, 50, 100, 150, 200, 250, 300, 350)
> result <- cut(x, breaks = range)
> cbind(x, as.character(result))
x
[1,] "144" "(100,150]"
[2,] "1
Harun,
Can you give a simple example?
If your cross_section looked like this
c(144, 179, 214, 39, 284, 109, 74, 4, 249)
and your other vector looked like this
c(0, 50, 100, 150, 200, 250, 300, 350)
what would you want your subset to look like?
Jean
On Mon, Nov 9, 2015 at 7:26 AM, Harun Rashid v
Hello,
I have a dataset with two columns 1. cross_section (range: 0~635), and
2. elevation. The dataset has more than 100 rows. Now I want to make a
subset on the condition that the 'cross_section' column will pick up the
nearest cell from another vector (say 0, 50,100,150,200,.,650).
How ca
I assume the solution is somewhat the same; you just have to define how to
determine what the "distinctive" names are to create the groupings. My
solution assumed it was the first character. If the group names end in a
unique sequence, you can use this to form the groups, or you can provide a
lis
Please learn to use dput() to post example data.
# This is your data:
data <- structure(c(1232, 0, 43, 357, 71, 919, 23, 9, , 0, 811, 0,
9871, 795, 76, 72, 743, 14), .Dim = c(3L, 6L), .Dimnames = list(
NULL, c("X1", "X2", "X3", "Y1", "Y2", "Y3")))
data
# define groups and threshold expl
sorry, for the misunderstanding. here is a more elaborate description of
what i would like to achieve.
I have a data set of counts from a RNA-Seq experiment and would like to
filter reads with low counts. I don't want to set everything to 0
automatically.
I would like to set each categorical grou
Is this what you want:
> x <- read.table(text = "X1X2X3Y1Y2Y3
+ 1232357230987172
+ 0719811795743
+ 4391907614", header = TRUE)
> x
X1 X2 X3 Y1 Y2 Y3
1 1232 357 23 0 9871 72
20 719 811 795
Hi,
I have a data frame with multiple columns, which are belong to several
groups
like that:
X1X2X3Y1Y2Y3
1232357230987172
0719811795743
4391907614
I would like to filter such rows out, where the sums in one group
Lots of ways to do this, I use %in% with bracket notation [row, column].
The empty column argument below returns all columns but you could have
conditional logic there as well.
dd[dd$rows %in% test_rows, ]
On Mon, Jun 8, 2015 at 6:44 PM, Bogdan Tanasa wrote:
> Dear all,
>
> would appreciate y
Use is.element(elements,set), or its equivalent, elements %in% set:
df <- data.frame(dd = c(1, 2, 3),
rows = c("A1", "A2", "A3"),
columns = c("B1", "B2", "B3"),
numbers = c(400, 500, 600))
test_rows <-c("A1","A3")
df[ is.element(df$rows, test_rows
Dear all,
would appreciate your suggestions on subsetting a dataframe : please let's
consider an example dataframe df:
dd<-c(1,2,3)
rows<-c("A1","A2","A3")
columns<-c("B1","B2","B3")
numbers <- c(400, 500, 600)
df <- dataframe(dd,rows,columns, numbers)
and a vector : test_rows <-c("A1","A3") ;
Assuming datums is a vector of the unique dates in Date... perhaps
datums <- sort(unique(dataset1$Date))
I usually set it up like this
for (i in 1:length(datums) ) {
crnt.date <- datums[i]
tmpdat <- subset(dataset1, Date==crnt.date)
cat(i, format(crnt.date), 'dim(tmpdat)',dim(tmpdat),'\n
Here is a self-contained example of what you might be trying to do.
You would get better answers if you supplied this yourself.
dataset1 <-
data.frame(Date=as.POSIXct(c("2015-04-01","2015-04-01","2015-04-07",
"2015-04-19")), Weight=11:14)
datums <- as.POSIXct(c("2015-04-01", "2015-04-08", "2015-04
Hi,
What about using functions like aggregate()?
Something like:
aggregate(Weight~datums, data=dataset1, FUN=mean)
If you need to do more things, you can create your own function for 'FUN'
HTH,
Ivan
--
Ivan Calandra, ATER
University of Reims Champagne-Ardenne
GEGENAA - EA 3795
CREA - 2 esplana
Dear all,
I would like to do multiple actions on a subset of my data. Therefore, I want
to create a for loop on the variable "Date" (actually a double for loop on yet
another variable, but let's omit that for a moment).
I want to run down every level of "Date" and perform multiple actions on the
I have a dataset of 20k records heavily right skewed as pareto
distribution, I'd like to pull 1k subset of it with same distribution, any
R package would do that?
Thanks.
[[alternative HTML version deleted]]
__
R-help@r-project.org mailing list
On Apr 28, 2015, at 12:20 PM, W Z wrote:
> I have a dataset of 20k records heavily right skewed as pareto
> distribution, I'd like to pull 1k subset of it with same distribution, any
> R package would do that?
Why not just:
subdat <- dat[sample( nrow(dat), 1000), ] # if "dataset" is a datafram
The elNamed(x, name) function can simplify this code a bit. The following
gives the same
result as David W's get_shas() for the sample dataset provided:
get_shas2 <- function (input) {
lapply(input, function(el) elNamed(elNamed(el, "content")[[1]],
"sha")[1])
}
Bill Dunlap
TIBCO Sof
On Feb 20, 2015, at 6:13 AM, Aron Lindberg wrote:
> Hmm…Chuck’s solution may actually be problematic because there are several
> entries which at the deepest level are called “sha”, but that should not be
> included, such as:
>
> input[[67]]$content[[1]]$commit$tree$sh
>
>
> and
>
> input[[
On Fri, 20 Feb 2015, Aron Lindberg wrote:
Hmm…Chuck’s solution may actually be problematic because there are several
entries which at the deepest level are called “sha”, but that should not be
included, such as:
input[[67]]$content[[1]]$commit$tree$sha
and
input[[67]]$content[[1]]
How can you expect a solution if you cannot specify the problem?
-- Bert
Bert Gunter
Genentech Nonclinical Biostatistics
(650) 467-7374
"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
Clifford Stoll
On Fri, Feb 20, 2015 at 6:13 AM, Aron Lindber
Hmm…Chuck’s solution may actually be problematic because there are several
entries which at the deepest level are called “sha”, but that should not be
included, such as:
input[[67]]$content[[1]]$commit$tree$sha
and
input[[67]]$content[[1]]$parents[[1]]$sha
it’s only the “sha” th
Thanks Chuck and Rolf.
While Rolf’s code also works on the dput that I actually gave you (a smaller
subset of the full dataset), it failed to work on the larger dataset, because
there are further exceptions:
input[[i]]$content[[1]] is sometimes a list, sometimes a character vector, and
Aron Lindberg case.edu> writes:
>
> Hi Everyone,
>
> I'm working on a thorny subsetting problem involving list of lists. I've put
> a
dput of the data here:
>
> https://gist.githubusercontent.com/aronlindberg/b916dee897d051ac5be5/
raw/a78cbf873a7e865c3173f943ff6309ea688c653b/dput
>
On 20/02/15 08:45, Aron Lindberg wrote:
Hi Everyone,
I'm working on a thorny subsetting problem involving list of lists.
If you think this is "thorny" you ain't seen nothin' yet!
But note that you've got a list of lists of lists ... i.e. the nesting
is at least 3 deep.
I've put a dput of
Hi Everyone,
I'm working on a thorny subsetting problem involving list of lists. I've put a
dput of the data here:
https://gist.githubusercontent.com/aronlindberg/b916dee897d051ac5be5/raw/a78cbf873a7e865c3173f943ff6309ea688c653b/dput
I can get one intense of the element I want this
hi brennan, survey design objects can be subsetted with the same subset()
syntax as data.frame objects, so following jeff's advice maybe you want
svyglm( formula , design = subset( surveydesign , variable %in% c( 'value
a' , 'value b' ) ) )
for some examples of how to construct a survey design wi
This seems like a fundamental misunderstanding on your part of how operators,
and in particular logical expressions, work in computer languages. Consider
some examples:
1+2 has a numeric answer because 1 and 2 are both numeric.
1+"a" has at the very least not a numeric answer because the values
I am aware that it is possible to specify a subset with a single
logical operator when constructing a model, such as:
svyglm(formula, design=data, subset=variable=="value").
What I can't figure out is how to specify a subset with two or more
logical operators:
svyglm(formula, design=data, subset=v
Your question is not clear to me.
> x$alpha[1:2]
[1] "a" "b"
> x$alpha[2]
[1] "b"
>
Is this what you are looking for? I hope this helps.
Chel Hee Lee
On 12/5/2014 11:12 AM, Dinesh Chowdhary wrote:
x <- list(seq = 3:7, alpha = c("a", "b", "c"))
x$alpha
[1] "a" "b" "c"
x["alpha"]
$alpha
[1
> x <- list(seq = 3:7, alpha = c("a", "b", "c"))
> x$alpha
[1] "a" "b" "c"
> x["alpha"]
$alpha
[1] "a" "b" "c"
> x[c(1,2)]
$seq
[1] 3 4 5 6 7
$alpha
[1] "a" "b" "c"
*> x[c(1, alpha[2])]*
*$*
*NULL*
*$*
*NULL*
How to access a character subset withing a list?
Thank you for your effort...
values.
hist(Out) # for a histogram of the correlation values
David C
From: Angela Boag [mailto:angela.b...@colorado.edu]
Sent: Friday, August 22, 2014 4:01 PM
To: David L Carlson
Subject: Re: [R] Subsetting data for split-sample validation, then repeating
1000x
Hi David,
Thanks for the f
m: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Angela Boag
Sent: Thursday, August 21, 2014 4:46 PM
To: r-help@r-project.org
Subject: [R] Subsetting data for split-sample validation, then repeating 1000x
Hi all,
I'm doing some within-dataset model valid
Hi all,
I'm doing some within-dataset model validation and would like to subset a
dataset 70/30 and fit a model to 70% of the data (the training data), then
validate it by predicting the remaining 30% (the testing data), and I would
like to do this split-sample validation 1000 times and average th
Hi Monaly,
According to the description of ?tri2nb
The function uses the ‘deldir’ package to convert a matrix of
two-dimensional coordinates into a neighbours list of class ‘nb’
with a list of integer vectors containing neighbour region number
ids.
So, col.tri.nb is a list of leng
Hi Arun,
Thank you for your help, I have a few questions though if you don't mind.
I'm a bit confused about the following 2 lines of code:
col.tri.nb <- tri2nb(coords, row.names=ind)
lapply(col.tri.nb,function(x) ind[x])[1:5]
## from what I understand in the first line determines the neighbourin
Hi,
Sorry, there is a mistake. XO[2,] should be:
XO[2,] <- sapply(seq_along(col.tri.nb), function(i){ind1 <-
as.character(ind[i]); ind2 <- as.character(ind[col.tri.nb[[i]]]);
mean(abs(XO[1,ind1]-XO[1,ind2]))} )
A.K.
On Friday, May 23, 2014 12:56 PM, arun wrote:
Hi Monaly,
May be this hel
eb"), class = "data.frame", row.names = c(NA,
-99L))
#Code for tessellation
library(deldir)
ao= read.table("C:/Users/Monaly/Desktop/2012_malenest.txt", header=TRUE)
a29= deldir(ao$lat_xm, ao$long_ym)
a30=tile.list(a29)
plot(a30, close=TRUE, main="2012 Male Nest"
"latitude (m)",
ylab="longitude (m)", wpoints="real", verbose=FALSE,num=TRUE, rw=c(0, 1200,
0, 2000))
text(ao$lat_xm, ao$long_ym,col=c(2,1,4),labels=round(ao$NestkastNummer, 3),
pos=2, offset=0.2, cex=0.7) #this was to identify the points
On Fri, May 23, 2
])-XO[1,c("176","140","133","163")]))
> > > XO["avg", "15"]<- mean(abs((XO[1,"15"])-XO[1,c("16","19","14")]))
> > > XO["avg", "60"]<- mean(abs((XO[1,"60&qu
uot;,"97","90","84","82","81")]))
> > XO["avg", "31"]<- mean(abs((XO[1,"31"])-XO[1,c("2","3","36","35","34")]))
> > XO["avg", "73"]<- mean
quot;64"]<- mean(abs((XO[1,"64"])-XO[1,c("113","62","128","124")]))
> XO["avg", "74"]<- mean(abs((XO[1,"74"])-XO[1,c("51","73","185")]))
> XO["avg", "95"]<
XO["avg", "36"]<-
mean(abs((XO[1,"36"])-XO[1,c("28","38","86","709","707","35","3")]))
XO["avg", "80"]<- mean(abs((XO[1,"80"])-XO[1,c("42","79&quo
Follow the link at the bottom of this message!
-- Bert
Bert Gunter
Genentech Nonclinical Biostatistics
(650) 467-7374
"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
H. Gilbert Welch
On Thu, May 22, 2014 at 8:31 AM, Monaly Mistry wrote:
> Hi,
Hi,
Sorry I'm fairly new to R and I don't really understand using dput(), when
you say reproducible example do you mean the code with the output?
Best,
Monaly.
On Thu, May 22, 2014 at 4:03 PM, arun wrote:
> Hi,
>
> It would be helpful if you provide a reproducible example using ?dput().
>
>
Hi,
I've written a code to determine the difference in score for a single
subject and its non-neighbours
o<-(ao[,c(13,5)]) ##this is the table with the relevant information
o<-na.omit(o) ##omitted data with NA
o<-o[!o$NestkastNummer %in% c(176,140,162,713),] ##removed neighbours
XO[7,1]<-abs((XO
Hello,
I have a data set with many individuals all with multiple timed
observations, and I would like to subset the data to exclude later timed
observations.
However, I would like to exclude different amounts of data for each
individual. These individuals have two types of data: DV and dose. What
t; -Original Message-
> From: r-help-boun...@r-project.org
> [mailto:r-help-boun...@r-project.org] On Behalf Of Sneha Bishnoi
> Sent: Thursday, March 27, 2014 11:06 AM
> To: Sarah Goslee
> Cc: r-help
> Subject: Re: [R] Subsetting a dataframe by dynamic column name
>
> Hi Sara
e
Cc: r-help
Subject: Re: [R] Subsetting a dataframe by dynamic column name
Hi Sarah,
Thanks! Do agree its over complicated.
However looking at the solutions I think I did not state my
problem
completely.
V provides choices for only certain set of columns in Finaldata.
So v2 may not represent al
Hi Sarah,
Thanks! Do agree its over complicated.
However looking at the solutions I think I did not state my problem
completely.
V provides choices for only certain set of columns in Finaldata.
So v2 may not represent all columns of Finaldata.
I want to retain columns not provided as a choice for
There are many ways. You're making it overly complicated
Here, in an actual reproducible example (as you were requested to submit):
V <- data.frame(v1=c(1,0,0), v2=c("Shape", "Length", "Rate"),
stringsAsFactors=FALSE)
Finaldata <- data.frame(Shape = runif(5), Length = runif(5), Rate = runif(5))
Hi all!
I am trying to drop columns from a data frame dynamically depending on user
input. The dataframe whose columns need to be dropped is called "Finaldata"
So here is what I do:
V is a dataframe with columns v1 and v2 as follows
v1 v2
1 1 Shape
2 0 Length
3 0
On 14-03-10 10:47 AM, arun wrote:
Hi,
If 'dat' is the dataset:
Try
subset(dat, Start < MapInfo & End > MapInfo)
A bit of advice I think I read in The Elements of Programming Style:
try to make complex conjunctions look like their mathematical
equivalents, and they'll be easier to read. The
Hi,
If 'dat' is the dataset:
Try
subset(dat, Start < MapInfo & End > MapInfo)
A.K.
Dear All,
I want to subset a column (MapInfo in the attached photo) in csv
file if its values be ranged between values in two other columns (Start
and End in the attached photo) using R 3.0.1. Thank you in ad
fit is initialized as a vector of integers. How can you assign an mle
fit to an element of an integer vector?
Initialize fit as a list, use lapply, or whatever. Have you read An
Intro to R (ships with R) or other R (e.g. web) tutorial? This looks
like the sort of basic misunderstanding that one wh
I have a 7-parameter model to fit using mle. I would like to generate
fits for all
pairs of parameters (with others fixed)
The following code looked like it should work:
library(stats4)
# dummy mll function for sake of example
mll = function (lnk=1.5,lnhs=-5,lnhi=-5,lnss=-5,lnsi=-5,lnws=-5,l
Thanks so much Marc and for those that responded. Mark's suggestion with
droplevels gave me the desired result.
I'm new to figuring out how to post reproducible code. I'll try using the
set.seed and rnorm functions next time and hope that does the trick.
Thanks everyone!
On Tue, Jan 14, 2014 at
s in the table being in alphabetic order and
not a semantic order of your choosing.
Bill Dunlap
TIBCO Software
wdunlap tibco.com
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
> Behalf
> Of Jeff Johnson
> Sent: Tuesday, Jan
On Jan 14, 2014, at 1:38 PM, Jeff Johnson wrote:
> I'm running the following to get what I would expect is a subset of
> countries that are not equal to "US" AND COUNTRY is not in one of my
> validcountries values.
>
> non_us <- subset(mydf, (COUNTRY %in% validcountries) & COUNTRY != "US",
> sel
Hi,
Try:
table(as.character(non_us[,"COUNTRY"]))
A.K.
On Tuesday, January 14, 2014 3:17 PM, Jeff Johnson
wrote:
I'm running the following to get what I would expect is a subset of
countries that are not equal to "US" AND COUNTRY is not in one of my
validcountries values.
non_us <- subset(myd
I'm running the following to get what I would expect is a subset of
countries that are not equal to "US" AND COUNTRY is not in one of my
validcountries values.
non_us <- subset(mydf, (COUNTRY %in% validcountries) & COUNTRY != "US",
select = COUNTRY, na.rm=TRUE)
however, when I then do table(non_u
I figured it out:
dim(results[apply(results,1,sum)&TRUE,,])
#[1] 9 3 4
A.K.
On , arun wrote:
dim(results[,,apply(results,3,sum)&TRUE])
#[1] 10 3 4
dim(results[,,abs(apply(results,3,sum))>eps])
#[1] 10 3 4
dim(results2)
#[1] 9 3 4
A.K.
On Friday, January 10, 2014 12:56 AM, Bert Gunt
Just use apply() and indexing instead!
results[,,apply(results,3,sum)&TRUE]
## will do it.
However, note that numerical error may make a hash of this. So safer
would be something like:
eps <- 1e-15 ## i.e. something small
results[,,abs(apply(results,3,sum))>eps]
Cheers,
Bert
Bert Gunter
Gen
Hi Alex,
Try:
set.seed(345)
results<- array(sample(-5:5,120,replace=TRUE),dim=c(10,3,4))
indx <- !!apply(results,1,sum)
library(plyr)
results2 <- laply(lapply(seq(dim(results)[1]),function(i)
results[i,,])[indx],identity)
attr(results2,"dimnames") <- NULL
dim(results2)
#[1] 9 3 4
A.K.
I have
Hi
On 01/02/2014 04:04 PM, arun wrote:
Hi,
Try ?match
b[match(d,a)]
#[1] "Joe" "Bob" "Dick"
Or use 'a' to put names on 'b':
> names(b) <- a
> b
A B C D E
"Tom" "Dick" "Harry" "Bob" "Joe"
Then subset by names:
> b[d]
E D B
Hi,
Try ?match
b[match(d,a)]
#[1] "Joe" "Bob" "Dick"
A.K.
I have three vectors as follows:
> a <- c('A','B','C','D','E')
> b <- c('Tom','Dick','Harry','Bob','Joe')
> d <- c('E','D','B')
Subsetting b by using d on a, with b[a %in% d], gives the names in the order
they appear in b:
> b
Here is an approach using base R tools (not tested, so I hope I don't
embarrass myself!)
dayid <- format(data$TimeStamp, '%Y-%m-%d')
day.counts <- table(dayid)
good.days <- names(day.counts)[day.counts == 48]
subset(data, dayid %in% good.days)
This could be written in a one-liner, but it's much e
3
#or
library(plyr)
df3<-df1[ddply(df1,.(as.Date(datetime)),mutate,Ldt=length(datetime)==48)$Ldt,]
identical(df3,df2)
#[1] TRUE
A.K.
- Original Message -
From: "aj...@bath.ac.uk"
To: r-help@r-project.org
Cc:
Sent: Friday, October 4, 2013 11:03 AM
Subject: [R] Subsettin
Hi,
I have a data frame, data, containing two columns: one- the TimeStamp
(formatted using data$TimeStamp <-
as.POSTIXct(as.character(data$TimeStamp), format = "%d/%m/%Y %H:%M") )
and two- the data value.
The data frame has been read from a .csv file and should contain 48
values for ea
Hi Razi,
Using dat1:
dat1[apply(dat1[,2:4],1,function(x) any(x%in% vec1)),]
# ID diag1 diag2 diag3 proc1 proc2 proc3
#2 2 k69 i80 u456 z456 z123 z456
#3 3 l91 i801 g678 u456 u123 u123
#4 4 i80 i90 h983 z123 z456 z456
#similarly, if the columns are from 18:93, change ac
Hi,
Using the same example:
str1<-paste(colnames(dat1)[grepl("diag",colnames(dat1))],"%in%","vec1",collapse="|")
subset(dat1,eval(parse(text=str1)))
# ID diag1 diag2 diag3 proc1 proc2 proc3
#2 2 k69 i80 u456 z456 z123 z456
#3 3 l91 i801 g678 u456 u123 u123
#4 4 i80 i90 h983
1 - 100 of 433 matches
Mail list logo