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 9161175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:54:33+00:00 2026-06-17T13:54:33+00:00

I have the following code: a=2 if (length(a)>1){ b<<-rowSums(c[,-(1:2)][,c(T,F)]) } else {b<<-sum(c[seq(3,length(x),2)]) } I

  • 0

I have the following code:

a=2 

if (length(a)>1){
b<<-rowSums(c[,-(1:2)][,c(T,F)]) }

else {b<<-sum(c[seq(3,length(x),2)]) }

I get the following error:

Error: unexpected 'else' in "    else"

I have no idea why I am getting this message. Any ideas?

  • 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-17T13:54:34+00:00Added an answer on June 17, 2026 at 1:54 pm

    In the R definition:

    When the if statement is not in a block the else, if present, must
    appear on the same line as the end of statement2. Otherwise the new
    line at the end of statement2 completes the if and yields a
    syntactically complete statement that is evaluated. A simple solution
    is to use a compound statement wrapped in braces, putting the else on
    the same line as the closing brace that marks the end of the
    statement.

    (R Language Definition)

    So, the ‘else’ must me in the same line as ‘}’. Either

    a=2 
    
    if (length(a)>1){
    b<<-rowSums(c[,-(1:2)][,c(T,F)]) } else {b<<-sum(c[seq(3,length(x),2)]) }
    

    or

    a=2 
    
    if (length(a)>1){
    b<<-rowSums(c[,-(1:2)][,c(T,F)]) 
    } else {b<<-sum(c[seq(3,length(x),2)]) }
    

    but is still a bad code/identation pattern. I’d try something like

    a=2 
    
    if (length(a)>1) {
        b<<-rowSums(c[,-(1:2)][,c(T,F)]) 
    } else {
        b<<-sum(c[seq(3,length(x),2)]) 
    }
    

    to avoid further mistakes, or the suggested ‘ifelse’ function.

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

Sidebar

Related Questions

I have the following code function myFunction(items) { // this prints out 11 alert(items.length);
I have the following code: for(var i = 0; i < list.length; i++){ mc_cli.get(list[i],
I have the following code: (please pardon the length of this code). I am
I have the following code: function build_all_combinations(input_array){ array = [1,2,3] limit = array.length -
I have following code using hibernate to throw a custom exception on error and
I have the following code $(document).ready(function(){ // class exists if($('.delete').length) { // add click
I have the following code if (msg.position == 0) //removed for brevity else if
I have the following code in delphi to decrypt: new_size := Length(Source) - 1;
I have the following code $.get('feed.txt', function(data) { var arr = data.split('|'); var values
I have the following code public static int unknown(String x) { if ((x.length()==1) &&

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.