search for: count_ind

Displaying 5 results from an estimated 5 matches for "count_ind".

2016 Apr 20
0
Data reshaping with conditions
...351 lee A 84 351 lee A 80 351 lee A 19 351 lee A 8 351 lee A 21 351 lee A 88 351 lee B 111 351 lee B 46 351 lee B 108 351 lee B",header=TRUE) # you can also do this with other reshape functions library(prettyR) svdatstr<-stretch_df(svdat,"id",c("Count","type")) count_ind<-grep("Count",names(svdatstr)) type_ind<-grep("type",names(svdatstr)) svdatstr$maxA<-NA svdatstr$maxB<-NA svdatstr$x<-NA svdatstr$y<-NA for(row in 1:nrow(svdatstr)) { svdatstr[row,"maxA"]<- max(svdatstr[row,count_ind[as.logical(match(svdatstr[1,...
2016 Apr 21
2
Data reshaping with conditions
...gt; 8 351 lee A > 21 351 lee A > 88 351 lee B > 111 351 lee B > 46 351 lee B > 108 351 lee B",header=TRUE) > # you can also do this with other reshape functions > library(prettyR) > svdatstr<-stretch_df(svdat,"id",c("Count","type")) > count_ind<-grep("Count",names(svdatstr)) > type_ind<-grep("type",names(svdatstr)) > svdatstr$maxA<-NA > svdatstr$maxB<-NA > svdatstr$x<-NA > svdatstr$y<-NA > for(row in 1:nrow(svdatstr)) { > svdatstr[row,"maxA"]<- > > max(svdatstr...
2016 Apr 21
0
Data reshaping with conditions
...351 lee A 84 351 lee A 80 351 lee A 19 351 lee A 8 351 lee A 21 351 lee A 88 351 lee B 111 351 lee B 46 351 lee B 108 351 lee B",header=TRUE) # you can also do this with other reshape functions library(prettyR) svdatstr<-stretch_df(svdat,"id",c("Count","type")) count_ind<-grep("Count",names(svdatstr)) type_ind<-grep("type",names(svdatstr)) svdatstr$maxA<-NA svdatstr$maxB<-NA svdatstr$x<-NA svdatstr$y<-NA for(row in 1:nrow(svdatstr)) { indicesA<-count_ind[as.logical(match(svdatstr[row,type_ind],"A",0))] svdatstr[r...
2016 Apr 20
2
Data reshaping with conditions
Dear All, I am trying to reshape the data with some conditions. A small part of the data looks like below. Like this there will be more data with repeating ID. Count id name type 117 335 sally A 19 335 sally A 167 335 sally B 18 340 susan A 56 340 susan A 22 340 susan B 53 340 susan B 135 351 lee A 114 351 lee A 84 351 lee A 80 351 lee A 19 351 lee A 8 351 lee A 21 351 lee A 88 351 lee B 111 351
2016 Apr 21
0
Data reshaping with conditions
...<-svdatstr[row,indicesA][svdatstr[row,indicesA]<svdatstr[row,"maxB"]] Extraction operators may be specified sequentially or nested. Both are used in this line. However, to understand how it works, first look at the line that defines the value of "indicesA": indicesA<-count_ind[as.logical(match(svdatstr[row,type_ind],"A",0))] This defines a vector of logical (TRUE/FALSE) values for the valid "Count" values in the current row by finding the matches in the "type" values for the character string "A". The reason I have used the "m...