Displaying 20 results from an estimated 10000 matches similar to: "Analyzing subsets"
2012 Jul 11
1
sapply question
Why does this sapply code change df3 but not df1?
Thanks
df1 <- read.table(text="
cola colb colc cold cole
1 NA 5 9 NA 17
2 NA 6 NA 14 NA
3 3 NA 11 15 19
4 4 8 12 NA 20
", header=TRUE)
df2 <-df1*2
df1
df2
df3 <-sapply(names(df1),function(x) {df1[[x]]<- df2[[x]]})
df1
df3
[[alternative HTML version deleted]]
2016 Apr 24
1
assign color to subsets
'grepl' returns a logical vector; you have to use this to get your subset.
You can use:
df_tq <- subset(df, grepl("t1", Command))
df_t2 <- subset(df, grepl("t2", Command))
# if you want to also get a subset that has both, use
df_both <- subset(df, grepl("t1", Command) & grepl("t2", Command))
Jim Holtman
Data Munger Guru
What is
2016 Apr 24
0
assign color to subsets
now after this:
df_both <- subset(df, grepl("t1", Command) & grepl("t2", Command))
I use factor to apply the subset to df but then the Command level becomes 0
df_both$Command=factor(df_both$Command)
str(df_both)
$ Protocol : Factor w/ 0 levels:
Do you know what is the reason?
Thanks for replying
On Sunday, April 24, 2016 12:18 PM, jim
2016 Apr 23
4
assign color to subsets
Hi
I have the following df and I created two subsets but I don't know how to use these subsets as the colors of my plot.
data.frame': 36919 obs. of 162 variables
$TE :int 38,41,11,52,48,75,.....
$TR :int 100,210,548,546,.....
$Command :factor W/2229 levels
2012 Jul 15
4
computing a subset using a loop
Dear all,
I have a data frame with different variables and I want to build different
subsets out of this data frame using some conditions and I want to use a
loop because there will be a lot of subsets and this would be saving a lot
of time.
I try to give you an overview about my data frame. I have a data frame named
"Baumdaten" and it has one column named "transectID" with
2011 Jan 23
2
Creating subsets of a matrix
Hello,
Say I have 2 columns, bmi and gender, the first being all the values and the
second being male or female. How would I subset this into males only and
females only? I have searched these fora and read endlessly about select[]
and split() functions but to no avail. Also the table is not ordered.
bmi gender -> bmi gender + bmi gender
1 24.78 male
2010 May 17
3
Create counter variable for subsets without a loop
Hi all,
I am looking to create a rank variable based on a continuous variable
for subsets of the data. For example, for an R integrated data set
about US states this is how a loop could create what I want:
### Example with loop
data <- cbind(state.region,as.data.frame(state.x77))[,1:2] #
choosing a subset of the data
data <- data[order(data$state.region, 1/data$Population),] #
2011 Sep 12
2
regression on data subsets in datafile
I have data of the form
tC <- textConnection("
Subject Date parameter1
bob 3/2/99 10
bob 4/2/99 10
bob 5/5/99 10
bob 6/27/99 NA
bob 8/35/01 10
bob 3/2/02 10
steve 1/2/99 4
steve 2/2/00 7
steve 3/2/01 10
steve 4/2/02 NA
steve 5/2/03 16
kevin 6/5/04 24
")
data <- read.table(header=TRUE, tC)
close.connection(tC)
rm(tC)
I am trying to calculate rate of change of parameter1 in
2012 Jun 06
3
Combine subsets by factor level
I'm attempting to change a data set by compressing rows into columns.
Currently there are several rows that all have information about one
"patient," but at different cycles. I'm trying to make each patient only
have one row in the data set.
Does anyone know a good way to combine data sets by factor level? I've
separated the groups into different subsets by cycle, but not
2012 Jan 10
2
Aggregate by minimum
For each date, I would like to keep the line with the lowest speed and discard the rest. The result would have one line for each date. Can I use aggregate for this?
My table is as follows:
structure(list(speed = c(3,9,14,8,7,6), result = c(0.697, 0.011, 0.015, 0.012, 0.018, 0.019), house = c(1,
1, 1, 1, 1, 1), date = c(719, 1027, 1027, 1027, 1030, 1030),
id = c("1000",
2011 Aug 17
3
How to apply a function to subsets of a data frame *and* obtain a data frame again?
Dear all,
First, let's create some data to play around:
set.seed(1)
(df <- data.frame(Group=rep(c("Group1","Group2","Group3"), each=10),
Value=c(rexp(10, 1), rexp(10, 4), rexp(10, 10)))[sample(1:30,30),])
## Now we need the empirical distribution function:
edf <- function(x) ecdf(x)(x) # empirical distribution function evaluated at x
##
2012 Jul 13
2
which() in subset()
Why does the subset not work in the which() version below?
Thank you
v1 <- subset(t1,
version_1==as.character("100-1")
| version_1==as.character("100-2"))
a<-c("100-1", "100-2")
v1 <- subset(t1, which(a==as.character(version_1)) != 0)
[[alternative HTML version deleted]]
2011 Nov 06
1
Combining some duplicated rows & summing one of their column
Dear list,
I have this dataframe:
> names(events)
[1] "EID" "X" "Y" "trip" "tow" "catch" "effort" "depth"
[9] "season"
Where some of my unique ID "EID" appears more than once in 162 cases.
> length(events$EID)-length(unique(events$EID))
[1] 162
I would like to combined
2012 Oct 04
1
Error not found - for file retrieval with head()
Hi R-listers,
I am in plyr and using the script below and when I try to pull up the .csv
file with head() it does not show up. I am not sure where I am going wrong.
I have also checked the file box for turtlehatch.csv and it still does not
show up when I head(turtlehatch.csv). Am I missing a command?
Please advise, Jean
> devel.index <- function(values, weights=c(1, 2, 3, 4, 5, 6)) {
+
2010 Dec 02
5
Help summarizing R data frame
I am trying to aggregate data in column 2 to identifiers in col 1
eg..
take this>
identifier quantity
1 10
1 20
2 30
1 15
2 10
3 20
and make this>
identifier quantity
1 45
2 40
3 20
Thanks in
2012 Sep 26
1
Change in order of names after applying "plyr" package
Dear R helpers
I have following two data.frames viz. equity_data and param.
equity_data = data.frame(security_id = c("Air", "Air", "Air", "Air", "Air", "Air", "Air", "Air", "Air", "Air", "Air", "Air", "AB", "AB", "AB", "AB",
2012 Dec 05
4
Import multiple data frames and combine them using "cbind"
Hi group,
I imported 16 data frames using the function "list.files"
temp <- list.files(path="...........")
myfiles = lapply(temp, read.table,sep = "")
Now I have 16 data set imported in R window.
I want to combine them by row and tried some thing like (Here I am
considering only 20 columns)
for(i in 1:16){
data<- cbind(myfiles[[i]][,1:20])
}
but it
2011 Oct 24
2
How to selectively sum rows [Beginner question]
Hi, I am new to R so I would appreciate any help. I have some data that has
passenger flight data between city pairs. The way I got the data, there are
multiple rows of data for each city pair; the number of passengers needs to
be summed to get a TOTAL annual passenger count for each city pair.
So my question is: how do I create a new table (or data frame) that
selectively sums
My initial
2011 Sep 01
3
how to split a data frame by two variables
HI, Dear R community,
I want to split a data frame by using two variables: let and g
> x = data.frame(num =
c(10,11,12,43,23,14,52,52,12,23,21,23,32,31,24,45,56,56,76,45), let =
letters[1:5], g = 1:2)
> x
num let g
1 10 a 1
2 11 b 2
3 12 c 1
4 43 d 2
5 23 e 1
6 14 a 2
7 52 b 1
8 52 c 2
9 12 d 1
10 23 e 2
11 21 a 1
12 23 b 2
13 32 c 1
14
2012 Jul 20
1
conditional subset and reorder dataframe rows
Hi List
I have a dataframe (~1,200,000 rows deep) and I'd like to conditionally reorder groups of rows in this dataframe.
I would like to reorder any rows where the Chr.Strand column contains a '-' but reorder within subsets delineated by the Probe.Set.Name column.
# toy example ####
library(plyr)
negStrandGene <- data.frame(Probe.Set.Name =