R: mean over two factors

时间:2017-08-30 20:35:52

标签: r apply

I have a classList that has 2 factors; one called kernel_type (with 3 levels: b, e, and p) and one called group_by_var (with 3 levels: tw, fif, sev). The first column of the dataset is called levels_together and contains numbers.

I have a second resetClasses() with the same structure, with different numbers in the levels_together column.

They look like this:

std::vector

I would like the mean of levels_together for tw within b; for fif within b, etc. The first three final numbers should be:

0.053 (mean of tw within b) 0.0495 (mean of fif within b) 0.0515 (mean of sev within b)

How can I accomplish this with an apply function?

1 个答案:

答案 0 :(得分:2)

You can do this with $global:Csv = Import-Csv -LiteralPath $global:ConvertedSNWReport $global:hash = @{} Import-Csv -LiteralPath $global:ConvertedSNWReport | ForEach-Object { $global:hash[$_.'Computer name'] += @($_.Application) } $global:Results = $hash.GetEnumerator() | Where-Object { $_.Value -notmatch '*Snagit*' }

import UIKit

import Parse

class Usuario: PFObject, PFSubclassing, NSCoding {

    //MARK: Propriedades
    //O NSManaged é para o PFObject
    @NSManaged var nome: String?
    @NSManaged var foto: PFFile?
    @NSManaged var dataNascimento: Date?
    @NSManaged var numeroTelefone: String?
    @NSManaged var pais: PaisCodigo?
    @NSManaged var telefoneE164: String?

    static func parseClassName() -> String {
        return "Usuario"
    }


    //Isto é para NSObject e NSCoding
    override init() {

        super.init()
    }

    required init(coder aDecoder: NSCoder) {

        super.init()

        self.nome = aDecoder.decodeObject(forKey: "nome") as? String

        let image = aDecoder.decodeObject(forKey: "foto") as? UIImage
        if let fotoImage = image {
            self.foto = PFFile(data: UIImagePNGRepresentation(fotoImage)!)
        }

        self.dataNascimento = aDecoder.decodeObject(forKey: "dataNascimento") as? Date
        self.numeroTelefone = aDecoder.decodeObject(forKey: "numeroTelefone") as? String
        self.pais = aDecoder.decodeObject(forKey: "pais") as? PaisCodigo
        self.telefoneE164 = aDecoder.decodeObject(forKey: "telefoneE164") as? String
    }

    func encode(with aCoder: NSCoder) {

        if let nomeUsuario = nome {
            aCoder.encode(nomeUsuario, forKey: "nome")
        }

        if let fotoUsuario = foto {
            do {
                let dataImage = try fotoUsuario.getData()

                let image = UIImage(data: dataImage)!

                aCoder.encode(image, forKey: "foto")
            } catch {
                //Erro
            }
        }

        if let dataNascimentoUsuario = dataNascimento {
            aCoder.encode(dataNascimentoUsuario, forKey: "dataNascimento")
        }

        if let numeroTelefoneUsuario = numeroTelefone {
            aCoder.encode(numeroTelefoneUsuario, forKey: "numeroTelefone")
        }

        if let paisUsuario = pais {
            aCoder.encode(paisUsuario, forKey: "pais")
        }

        if let telefoneE164Usuario = telefoneE164 {
            aCoder.encode(telefoneE164Usuario, forKey: "telefoneE164")
        }
    }
}