subset

Subsetting for a minimum number of locations for MCP in R

醉酒当歌 提交于 2019-12-12 01:37:13
问题 I'm using adehabitat to create mcps for annual and seasonal ranges. my csv is set up as a binary system for categorizing the seasons. it looks like this across the top: anid - date - easting - northing - annual - seasonA - seasonB - seasonC However, some of my animals do not have enough locations for each season. My first subset looks like this: seasonA <-locations[locations$seasonA==1] And when I make my table: t2<-table(seasonA$anid) t2 I see that some of the animals have less than 30

How to subset a matrix by column factor values?

喜夏-厌秋 提交于 2019-12-11 20:16:37
问题 I've prepared a matrix called 'grades', but I fail to select all pass cases (pass = 2). > essay exam final pass > Ann 4 20 12 2 > Ben 6 10 8 1 > Cox 8 16 12 2 > Dan 11 17 14 2 > Eos 3 13 8 1 When I tried this, it returns an error > grades[grades$pass == 2,] Error in grades$pass : $ operator is invalid for atomic vectors I understand the matrix is not a data frame, so the error occurred. I then made a data frame. > grades.df <- data.frame(grades) > is.data.frame(grades.df) [1] TRUE But still

R select all rows from a dataframe where a value is duplicated one column but has a specific value in another column

放肆的年华 提交于 2019-12-11 19:35:30
问题 I am trying to extract from my R dataframe, rows that have duplicate values in one column but which in another column have either a 0 or a 1. For example, if this is the dataframe: Data <- data.frame( + X = c(1,3,5,7,7,8,9,10,10,11,11), + Y = sample(36476545:36476555), + timepoint = c(0,1,0,0,1,1,0,1,0,1,1) + ) which looks like > Data X Y timepoint 1 1 36476549 0 2 3 36476545 1 3 5 36476552 0 4 7 36476547 0 5 7 36476546 1 6 8 36476548 1 7 9 36476551 0 8 10 36476555 1 9 10 36476553 0 10 11

C# DataGridView binding to subset of XML

大兔子大兔子 提交于 2019-12-11 19:33:11
问题 I need to populate a DataGridView conditionally. The data comes from one XML file, e.g. <?xml version="1.0" standalone="yes"?> <people> <person> <name>Bob</name> <dogs> <dog><name>Rover</name></dog> <dog><name>Rex</name></dog> </dogs> </person> <person> <name>Jim</name> <dogs> <dog><name>Duke</name></dog> <dog><name>Colin</name></dog> <dog><name>Gnasher</name></dog> </dogs> </person> </people> If I use the following code I can show all dogs in the DataGridView - but I need to restrict the

subsetting a dataset in R [duplicate]

混江龙づ霸主 提交于 2019-12-11 19:28:21
问题 This question already has answers here : Filter group of rows based on sum of values from different column in R (2 answers) Closed 7 months ago . I have a question filtering a dataset based on sum of counts My file looks like this: g1 a 2 g1 a 3 g1 a 0 g1 b 1 g2 b 3 g2 c 4 g2 d 9 g3 e 1 g3 f 3 g4 g 10 g4 h 18 g4 i 23 First column is gene names. I want to calculate from the third column, the sum associated with each gene, for g1 it's 6 for g2 it's 16 and so on. Then the condition is if the sum

Loop through unique values of a df subset, and update df with new variables

删除回忆录丶 提交于 2019-12-11 17:43:08
问题 I am struggling to append a df with new variables that are computed from a subset of this df. I have two goals: Merge many individual data sets into one. The index variable is "SID" (subject ID). Create new variables/columns in this master dataset. The attached data is an example of what the already merged dataset will look like, however contains only 2 (SIDs: 9003 and 1028). I need to loop through each unique SID and perform several relatively easy computations on some of the variables in

Maintain data frame rows after subet

女生的网名这么多〃 提交于 2019-12-11 17:34:28
问题 I am trying to calculate a % yield of some data based on a subset: # example data set set.seed(10) Measurement <- rnorm(1000, 5, 2) ID <- rep(c(1:100), each=10) Batch <- rep(c(1:10), each=100) df <- data.frame(Batch, ID, Measurement) df$ID <- factor(df$ID) df$Batch <- factor(df$Batch) # Subset data based on measurement range pass <- subset(df, Measurement > 6 & Measurement < 7) # Calculate number of rows in data frame (by Batch then ID) ac <- ddply(df, c("Batch", "ID"), nrow) colnames(ac) <-

Find max/mean/min of the a subset in R

左心房为你撑大大i 提交于 2019-12-11 17:33:02
问题 A simple question but I can't seem to figure it out. I want to find the maximum value in a subset of my data frame. To my knowledge, it would look something like: max(data.frame$vector1)[data.frame$vector2=="1",] but I get the error message of incorrect number of dimensions. This text is then supposed to be used as a logical test in another subscript 回答1: Your indexing command is wrong. Try max( dataframe[ , "vector1" ] ) ## all of vector1 for all, and max( dataframe[ dataframe[,"vector2"]==1

R Subsetting Specific Value Also Returns NA?

这一生的挚爱 提交于 2019-12-11 17:18:59
问题 I am just starting out on learning R and came across a piece of code as follows vec_1 <- c("a","b", NA, "c","d") # create a subet of all elements which equal "a" vec_1[vec_1 == "a"] The result from this is ## [1] "a" NA Im just curious, since I am subsetting vec_1 for the value "a", why does NA also show up in my results? 回答1: This is because the result of anything == NA is NA . Even NA == NA is NA . Here's the output of vec_1 == "a" - [1] TRUE FALSE NA FALSE FALSE and NA is not TRUE or FALSE

Subsetting defined group out of DNAStringSet

别说谁变了你拦得住时间么 提交于 2019-12-11 16:33:44
问题 I want to retrieve a couple of sequences from my DNAStringSet . So far I only manage to get a single sequence. For example: A DNAStringset and the list/pattern of sequences I want to isolate. Testset: aDNAStringSet <- DNAStringSet(c("GCATCCATTAC", "AATCGCCATCC", "GCATACCTTAC", "GCATACCTTAC", "GCATACCTTAC")) Names: names(aDNAStringSet) <- c("seq1", "seq2", "seq3", "seq4", "seq5") The list of sequences to isolate: patterns <- c("seq2", "seq4", "seq5") What I tested so far: selection <-