Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8109007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:17:13+00:00 2026-06-06T01:17:13+00:00

I have a function, readnorm which returns a list of related data from a

  • 0

I have a function, readnorm which returns a list of related data from a file identified by an integer:

readnorm <- function(n) {
 a <- read.csv(paste("/tmp/diff-a-", n, ".txt", sep=""), 
               col.names=c("raw"), header=FALSE)
 a <- list(n=n, raw=a$raw, median=median(a$raw), iqr=IQR(a$raw))
 a$shifted <- a$raw - a$median
 a$scaled <- a$raw / a$iqr
 a$normed <- a$shifted / a$iqr
 a$necdf <- ecdf(a$normed)
 return(a)
}

I can build a list containing data from a set of files by using lapply:

> ns = c(5,6,7,8,9,10,15,20,25,30)
> data <- lapply(ns, readnorm)
> ls(data[[1]])
[1] "iqr"     "median"  "n"       "necdf"   "normed"  "raw"     "scaled" 
[8] "shifted"

Now, what I would like to do is construct from that a set of data frames, called normed, scaled, etc, which group the entries from the components in data (the names could be the values of n if integer names are allowed in R, so normed$5 contains data[[5]]$normed, etc).

Does that make sense? This way I can plot all the raw data by using the raw data frame, for example. It’s kind-of turning the data structure I have “inside out”.

I am new to R so may be doing something very wrong. In higher-level terms, I believe that the data in the different files are from similar distributions, shifted and scaled, and I want to explore that hypothesis. The code above is my attempt to arrange things so that I can do so in a systematic manner.

So my main question is how to generate the data frames, but I am also interested in more general guidance about how to tackle this problem (how to manage the data – I know about tools like qqplot that will help with the analysis itself).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T01:17:14+00:00Added an answer on June 6, 2026 at 1:17 am

    I agree with the comment that you will be happier using lapply rather than sapply. sapply is doing some simplifying that is actually complicatifying things for you.

    More generally, if it were me, I’d do less computation in my function that reads the data, and save the processing for later, once the raw data have been placed in a single structure. For instance:

    fun <- function(x){
        read.table(paste("~/Desktop/stackoverflowExamples/raw/raw",x,".txt",sep = ""),
                    header = TRUE,sep = ",")
    }
    
    #Just read the raw data and place it all in a data frame
    dat <- do.call(cbind,lapply(1:2,fun))
    #One way to label the columns, if you want to keep track of what came from where
    colnames(dat) <- paste("X",1:2,sep = "")
    
    #Now you can shift and scale to your heart's content, much more compactly...
    dat_shifted <- scale(dat,center = apply(dat,2,median),scale = FALSE)
    dat_normed <- scale(dat,center = apply(dat,2,median),
                            scale = apply(dat,2,IQR))
    

    I’m not sure what you plan on doing with the output of ecdf, so I’ll just note that ecdf() returns a function (just in case you didn’t realize that).

    Finally, see ?make.names for a description of what’s allowed for names.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have function for export data into csv file : $products = //databse query
i have function which return list as given below. List<User> lstUsers = SearchUsers(searchText); which
i have function, which has to accept two types of data - Observable collection
i want to have function like delete file from database by using link instead
I have function getMemory() which returns VARIANT (mfc). It is said that in ulVal
I have function that returns the index of a character GetCharFromPos(Pt: TPoint): Integer; now
I have function like this: function update_List(){ LIST=[]; $.each(feed_urls,function(index,value){ $.getJSON(value, function(data) { $.each(data.feed.entry,function(i,val){ LIST.push(val.content.src);
I have function where I read from a mysql table a set of value.
I have function which performs scatter plot and I want to paste the results(Jpeg
I have function which converts a 1D list to a 3D list, but at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.