+ Reply to Thread
Results 1 to 3 of 3

Thread: Selecting elements within 1 standard deviation from a Matrix

  1. #1
    Points: 3,609, Level: 37
    Level completed: 73%, Points required for next Level: 41

    Location
    Norman, OK 73019
    Posts
    100
    Thanks
    25
    Thanked 0 Times in 0 Posts

    Selecting elements within 1 standard deviation from a Matrix



    Hi guys,

    I have a matrix of 7 columns and each of these columns represent different variables. I want to create 7 new vectors and each will just have elements within 1 standard deviation across mean. So, each vector would be of different dimension. My idea will work but I am sure there are smarter ways to do it. I am thinking about running a for loop on each column and extracting elements which fall within 1 standard deviation across mean for respective column.

    Thanks

  2. #2
    RotParaTon
    Points: 46,248, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    Discussion EnderPosting AwardFrequent PosterCommunity AwardMaster Tagger
    Dason's Avatar
    Location
    Ames, IA
    Posts
    9,080
    Thanks
    211
    Thanked 1,608 Times in 1,378 Posts

    Re: Selecting elements within 1 standard deviation from a Matrix

    This will put those vectors into a list for you

    Code: 
    dat <- matrix(rnorm(100), ncol = 10)
    
    lapply(seq(ncol(dat)), function(i){
        x <- dat[,i]
        x[x >= mean(x)-sd(x) & x <= mean(x)+sd(x)]
    })
    "His programming is malfunctioning. It begins! Get your weapons, he's going to become a killbot!!!" - bryangoodrich

  3. The Following User Says Thank You to Dason For This Useful Post:

    sak (03-05-2013)

  4. #3
    Points: 3,609, Level: 37
    Level completed: 73%, Points required for next Level: 41

    Location
    Norman, OK 73019
    Posts
    100
    Thanks
    25
    Thanked 0 Times in 0 Posts

    Re: Selecting elements within 1 standard deviation from a Matrix


    Thanks for quick reply!!

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts








Advertise on Talk Stats