data-management

How do I make doSMP play nicely with plyr?

不羁岁月 提交于 2019-12-10 09:31:54
问题 This code works: library(plyr) x <- data.frame(V= c("X", "Y", "X", "Y", "Z" ), Z = 1:5) ddply(x, .(V), function(df) sum(df$Z),.parallel=FALSE) While this code fails: library(doSMP) workers <- startWorkers(2) registerDoSMP(workers) x <- data.frame(V= c("X", "Y", "X", "Y", "Z" ), Z = 1:5) ddply(x, .(V), function(df) sum(df$Z),.parallel=TRUE) stopWorkers(workers) >Error in do.ply(i) : task 3 failed - "subscript out of bounds" In addition: Warning messages: 1: <anonymous>: ... may be used in an

Working with dataframes in a list: Drop variables, add new ones

≯℡__Kan透↙ 提交于 2019-12-10 06:08:22
问题 Define a list dats with two dataframes, df1 and df2 dats <- list( df1 = data.frame(a=sample(1:3), b = sample(11:13)), df2 = data.frame(a=sample(1:3), b = sample(11:13))) > dats $df1 a b 1 2 12 2 3 11 3 1 13 $df2 a b 1 3 13 2 2 11 3 1 12 I would like to drop variable a in each data frame. Next I would like to add a variable with the id of each dataframe from an external dataframe, like: ids <- data.frame(id=c("id1","id2"),df=c("df1","df2")) > ids id df 1 id1 df1 2 id2 df2 To drop unnecessary

Reading plist file. iOS Programming

你离开我真会死。 提交于 2019-12-07 06:21:29
I have this code and can't figure out what I'm doing wrong. As you can see in the code below I have a plist file called shifts.plist which is in my supporting files folder. Here is my plist structure. NSString *path = [[NSBundle mainBundle] pathForResource:@"shifts" ofType:@"plist"]; dictionary = [[NSMutableDictionary alloc]initWithContentsOfFile:path]; cell.textLabel.text = [secondTableInfo objectAtIndex:indexPath.row]; NSLog(@"%@",[[dictionary objectForKey:@"name"]objectAtIndex:0]); I would ultimately like to read the name entries and populate a UITableView with them. I used NSLog to output

How to reshape long to wide data in Stata?

让人想犯罪 __ 提交于 2019-12-06 10:09:54
I have the following data: id tests testvalue 1 A 4 1 B 5 1 C 3 1 D 3 2 A 3 2 B 3 3 C 3 3 D 4 4 A 3 4 B 5 4 A 1 4 B 3 I would like to change the above long data format into following wide data. id testA testB testC testD index 1 4 5 3 3 1 2 3 3 . . 2 3 . . 3 4 3 4 3 5 . . 4 4 1 3 . . 5 I am trying reshape wide testvalue, i(id) j(tests) It gives error because there are no unique values within tests . What would be the solution to this problem? You need to create an extra identifier to make replicates distinguishable. clear input id str1 tests testvalue 1 A 4 1 B 5 1 C 3 1 D 3 2 A 3 2 B 3 3 C 3

R reshape, restructure dataframe by chunks

不想你离开。 提交于 2019-12-06 07:54:57
问题 I am trying to reshape a dataframe: Currently it looks like this: ID | Gender |A1 | A2 | A3 | B1 | B2 | B3 ID_1 | m | 3 | 3 | 3 | 2 | 3 | 2 ID_2 | f | 1 | 1 | 1 | 4 | 4 | 4 I want to have something like: ID | Gender | A1 | A2 | A3 ID_1 | m | 3 | 3 | 3 <- this would be columns A1 - A3 for ID 1 ID_1 | m | 2 | 2 | 2 <- this would be columns B1 - B3 for ID 1 ID_2 | f | 1 | 1 | 1 <- this would be columns A1 - A3 for ID 2 ID_2 | f | 4 | 4 | 4 <- this would be columns B1 - B3 for ID 2 (A1 and B1 /

reshaping k columns to 2 columns representing sequential pairs of the values of the k variables

点点圈 提交于 2019-12-05 19:45:08
问题 I have a data frame like this: id y1 y2 y3 y4 --+--+--+--+-- a |12|13|14| b |12|18| | c |13| | | d |13|14|15|16 I want to reshape in such a way that I end with two columns. The above example would then become: id from to --+----+--- a |12 |13 a |13 |14 a |14 | b |12 |18 b |18 | c |13 | d |13 |14 d |14 |15 d |15 |16 Each id has a 'from' and a 'to' per pair of year values. Does anybody know of an easy way to do this? I tried using reshape2 . I also looked at Combine Multiple Columns Into Tidy

How do I make doSMP play nicely with plyr?

倾然丶 夕夏残阳落幕 提交于 2019-12-05 14:33:34
This code works: library(plyr) x <- data.frame(V= c("X", "Y", "X", "Y", "Z" ), Z = 1:5) ddply(x, .(V), function(df) sum(df$Z),.parallel=FALSE) While this code fails: library(doSMP) workers <- startWorkers(2) registerDoSMP(workers) x <- data.frame(V= c("X", "Y", "X", "Y", "Z" ), Z = 1:5) ddply(x, .(V), function(df) sum(df$Z),.parallel=TRUE) stopWorkers(workers) >Error in do.ply(i) : task 3 failed - "subscript out of bounds" In addition: Warning messages: 1: <anonymous>: ... may be used in an incorrect context: ‘.fun(piece, ...)’ 2: <anonymous>: ... may be used in an incorrect context: ‘.fun

a Custom Segue that Simulates a Push Segue turns VC into Zombie

回眸只為那壹抹淺笑 提交于 2019-12-04 13:30:07
问题 [To Make things short and clear] I've written a custom segue. -(void)perform { UIView *preV = ((UIViewController *)self.sourceViewController).view; UIView *newV = ((UIViewController *)self.destinationViewController).view; [preV.window insertSubview:newV aboveSubview:preV]; newV.center = CGPointMake(preV.center.x + preV.frame.size.width, newV.center.y); [UIView animateWithDuration:0.4 animations:^{ newV.center = CGPointMake(preV.center.x, newV.center.y); preV.center = CGPointMake(0- preV

R reshape, restructure dataframe by chunks

心已入冬 提交于 2019-12-04 11:46:37
I am trying to reshape a dataframe: Currently it looks like this: ID | Gender |A1 | A2 | A3 | B1 | B2 | B3 ID_1 | m | 3 | 3 | 3 | 2 | 3 | 2 ID_2 | f | 1 | 1 | 1 | 4 | 4 | 4 I want to have something like: ID | Gender | A1 | A2 | A3 ID_1 | m | 3 | 3 | 3 <- this would be columns A1 - A3 for ID 1 ID_1 | m | 2 | 2 | 2 <- this would be columns B1 - B3 for ID 1 ID_2 | f | 1 | 1 | 1 <- this would be columns A1 - A3 for ID 2 ID_2 | f | 4 | 4 | 4 <- this would be columns B1 - B3 for ID 2 (A1 and B1 / A2 and B2 are the same variables (with regard to the content), so for example: A1 and B1 would be both

reshaping k columns to 2 columns representing sequential pairs of the values of the k variables

青春壹個敷衍的年華 提交于 2019-12-04 04:00:26
I have a data frame like this: id y1 y2 y3 y4 --+--+--+--+-- a |12|13|14| b |12|18| | c |13| | | d |13|14|15|16 I want to reshape in such a way that I end with two columns. The above example would then become: id from to --+----+--- a |12 |13 a |13 |14 a |14 | b |12 |18 b |18 | c |13 | d |13 |14 d |14 |15 d |15 |16 Each id has a 'from' and a 'to' per pair of year values. Does anybody know of an easy way to do this? I tried using reshape2 . I also looked at Combine Multiple Columns Into Tidy Data but I think my case is different. You can use lapply to loop over the pairs of columns and rbind to