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

  • Home
  • SEARCH
  • 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 8537165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:50:00+00:00 2026-06-11T10:50:00+00:00

I have this script: dat <- read.csv(file=Task_vs_Files_Whirr2.csv, header=T, sep=,, row.names=1) (sapply(1:nrow(dat), function(x) { if

  • 0

I have this script:

dat <- read.csv(file="Task_vs_Files_Whirr2.csv", header=T, sep=",",
                row.names=1) 
(sapply(1:nrow(dat), function(x) {
    if (dat[x,2]==1) { 
         write.csv(dat[ (dat[[2]]==1 ) & (1:nrow(dat) >= x) , ] , 
                   file = paste("fil_", x, ".csv") )
    } else {
         NULL
 }))

but the script return NULL value, as below:

[[1]]
NULL

[[2]]
NULL

[[3]]
NULL

[[4]]
NULL

[[5]]
NULL

[[6]]
NULL

[[7]]
NULL

Here are other details:

> str(dat) 
'data.frame':   7 obs. of  7 variables:
 $ pom.xml.         : int  1 1 0 0 0 1 1
 $ ZooKeeper.java   : int  0 0 0 0 0 1 0
 $ HBase.java       : int  1 1 1 0 1 1 0
 $ Hadoop.java.     : int  0 0 0 0 0 0 1
 $ BasicServer.java.: int  1 0 0 0 0 0 0
 $ Abstract.java.   : int  1 1 0 1 0 1 1
 $ HBaseRegion.java : int  1 0 0 0 0 1 1

> dput(dat)
structure(list(pom.xml. = c(1L, 1L, 0L, 0L, 0L, 1L, 1L), ZooKeeper.java = c(0L, 
0L, 0L, 0L, 0L, 1L, 0L), HBase.java = c(1L, 1L, 1L, 0L, 1L, 1L, 
0L), Hadoop.java. = c(0L, 0L, 0L, 0L, 0L, 0L, 1L), BasicServer.java. = c(1L, 
0L, 0L, 0L, 0L, 0L, 0L), Abstract.java. = c(1L, 1L, 0L, 1L, 0L, 
1L, 1L), HBaseRegion.java = c(1L, 0L, 0L, 0L, 0L, 1L, 1L)), .Names = c("pom.xml.", 
"ZooKeeper.java", "HBase.java", "Hadoop.java.", "BasicServer.java.", 
"Abstract.java.", "HBaseRegion.java"), class = "data.frame", row.names = c("WHIRR-25", 
"WHIRR-28", "WHIRR-55", "WHIRR-61", "WHIRR-76", "WHIRR-87", "WHIRR-92"
))

> sessionInfo()
R version 2.13.1 (2011-07-08)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252    LC_MONETARY=English_Australia.1252 LC_NUMERIC=C                      
[5] LC_TIME=English_Australia.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     
  • 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-11T10:50:01+00:00Added an answer on June 11, 2026 at 10:50 am

    Trying to salvage something…. (see my comment above as to why NULL is being returned)

    If you are only interested in those data where dat[,2]==1, you might as well use which to find those rows

    interested <- which(dat[,2]==1)
    

    now, do you really want separate files containing the same data, repeated without the header row each time? That is what your code is doing now.

    writing a for loop because it is far simpler to understand

    row_index <- seq.int(nrow(dat))
    for(.row in interested){
    
      write.csv(dat[(dat[[2]] == 1) & (row_index >=.row),], 
                file = sprintf('fil_%s.csv',.row))
    }
    

    With your current data this will create a file fil_6.csv containing the 6th row of your data frame (which is the only row where x[,2]==1.

    Whether this script will scale to a bigger data set is unclear, because it is unclear what you want to do.

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

Sidebar

Related Questions

I have this file: CLUSTERS=SP1,SP2,SP3 FNAME_SP1=REWARDS_BTS_SP1_<GTS>.dat FNAME_SP2=DUMP_LOG_SP2_<GTS>.dat FNAME_SP3=TEST_CASE_TABLE_SP3_<GTS>.dat What I want to get from
I have the following dat file, named ls.dat : # Gnuplot script file for
I have this script that run to fix my menu bar to the browser
I have this script and need to be able to call the $play variable
I have this script set up that echoes all relevant users in a database
I have this script in the head of my index.html. I want different scripts
I have this script: #!/var/home/cherry/opt/perl use Test::More; use DBI; use Test::mysqld; use Data::Dumper; my
I have this script $('head').append('<link rel=stylesheet href=css/file1.css type=text/css />'); $('head').append('<link rel=stylesheet href=css/jquery.jscrollpane.css type=text/css />');
I have this script http://jsfiddle.net/gphp/ZMmRv/4/ I have two events: 1 - the div is
I have this script where I want to add an object to an array

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.