使用融化重塑R中的数据

时间:2015-06-13 17:22:25

标签: r reshape melt

我试图应用人们建议重塑数据的内容,但不知何故,我无法像我想要的那样重新调整数据。如果有人可以提供帮助,我将非常感激:

- (void)viewDidLoad     {
    [super viewDidLoad];
    [self setCanDisplayBannerAds:YES];
    float width = [UIScreen mainScreen].bounds.size.width;

    float height = [UIScreen mainScreen].bounds.size.height;
    static_iVar2 = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, width,height)];

    static_iVar2.delegate = self;
    NSURL *url = [NSURL URLWithString:@"http://guiasdelsur.es/category/programas/"];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [static_iVar2 loadRequest:requestObj];
    [self.view addSubview:static_iVar2];



    //second tab

    _secondTab = [[UITabBarItem alloc] initWithTitle:@"Programas" image:[UIImage imageNamed:@"iconoBota30x30.png"] tag:1];

    [[UITabBar appearance] setSelectedImageTintColor:[UIColor greenColor]];
    [self.tabBarController setSelectedIndex:1];
    self.tabBarItem = _secondTab;




    //GESTURES

    //DOWN
    UISwipeGestureRecognizer *gest1 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(hideTabBar:)];
    gest1.delegate = self;
    [gest1 setDirection:UISwipeGestureRecognizerDirectionDown];
    [self.view addGestureRecognizer:gest1];

    //UP
    UISwipeGestureRecognizer *gest2 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(showTabBar:)];
    gest2.delegate = self;
    [gest2 setDirection:UISwipeGestureRecognizerDirectionUp];
    [self.view addGestureRecognizer:gest2];



    UIToolbar *cToolBar = [[UIToolbar alloc] init];
    cToolBar.frame = CGRectMake(0, 0, self.view.frame.size.width, 44);
    NSMutableArray *items = [[NSMutableArray alloc] init];


    [cToolBar setBarStyle:UIBarStyleBlack];
    [cToolBar setTranslucent:YES ];
    [cToolBar setTintColor:[UIColor greenColor]];

    UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil ];

    UIBarButtonItem *right = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:nil action:@selector(refreshControl)];
    [right setTintColor:[UIColor greenColor]];


    [items addObject:flexibleSpace];
    [items addObject:right];




    [cToolBar setItems:items animated:NO];
    [self.view addSubview:cToolBar];

    //iAD

    ADBannerView * adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
    adView.frame = CGRectOffset(adView.frame, 0, 44);
    adView.delegate = self;
    [self.view addSubview:adView];


    //Indicator


    _indicador = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    [_indicador setCenter:self.view.center];
    [_indicador setHidesWhenStopped:YES];

    [self.view addSubview:_indicador];
    [_indicador startAnimating];

}

我想改变它,以便我可以用ggplot绘制它,需要它像这样:

My data looks like this:
      AB      LP     PD1     PD2     PY1     PY2     PY3     PY4     PY5 t
1 -50.000 -50.000 -50.000 -50.000 -50.000 -50.000 -50.000 -50.000 -50.000 1
2 -50.153 -53.316 -50.416 -50.416 -53.455 -53.467 -53.700 -53.403 -53.218 2
3 -50.288 -54.399 -50.726 -50.726 -53.603 -53.644 -54.457 -53.664 -53.776 3
4 -50.410 -53.630 -50.956 -50.956 -52.385 -52.649 -53.642 -52.575 -52.740 4
5 -50.519 -53.075 -51.127 -51.127 -52.072 -52.174 -53.132 -51.715 -52.563 5
6 -50.617 -52.616 -51.255 -51.255 -52.023 -51.947 -52.602 -51.857 -52.643 6
>

等,其中第三列是原始数据的最后一列,即时间(列t)

如果我使用AB -50.000 1 AB -50.153 2 AB -50.288 3 ,我就明白了:

v=melt(values)

几乎就在那里,但现在时间列(t)添加在底部。我如何有时间成为第三纵队?

我相信这是我需要使用ggplot2绘制多行数据的格式。

感谢您的帮助

JSS

1 个答案:

答案 0 :(得分:1)

使用reshape2,您需要执行以下操作:

v <- melt(values, id.vars = "t")