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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:52:02+00:00 2026-06-11T21:52:02+00:00

is it possible to have a matrix with 1 row only in R? Here

  • 0

is it possible to have a matrix with 1 row only in R?

Here is my code:

   nas <- which(!is.na(y))   
   x <- x[nas,]
   y <- y[nas]

   ...
   data.frame(y,x)

the idea is that i have a vector y and matrix x. Y can contain some NA values, which i want to find and remove the index of those values from both vector and the matrix.

Later i want to frame y with x. The problem is, however, when there is only one value that is not NA in y. It means i have to remove all but 1 element from y and all but 1 row from x, this having matrix with only 1 row, which seems to be converted to numeric, which seems to break the data.frame operation. I expected it to return frame containing 1 row: y x1 x2 .., instead i get:

   y    x
1  0 12.0
2  0 14.8
3  0 14.2
4  0 14.8
5  0  2.0
6  0  4.0
7  0  1.0
8  0  2.0
9  0 26.0
10 0  4.0
11 0  6.0
12 0  2.0
13 0 16.0
  • 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-11T21:52:03+00:00Added an answer on June 11, 2026 at 9:52 pm

    You need to specify drop = FALSE to stop R coercing a matrix or array to the lowest possible number of dimensions. See ?`[` for more details.

    x <- matrix(1:4,ncol=2)
    x[1,]
    ## [1] 1 2
    x[1,,drop=F]
    ##      [,1] [,2]
    ## [1,]    1    3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: correlation matrix in r I have an excel sheet which has 700
Suppose I have a data frame, df, that looks like: f t1 t2 t3
Possible Duplicates: How to subtract a vector from each row of a matrix? How
I have a 1000x1000 matrix, with some data in each entry. Is it possible
Is it possible have two projects with the same name in flex builder? Here
Is it possible to have a free iPhone app that has say an initial
Is it possible to have unobtrusive validation to make a field required but only
There was a post on here recently which posed the following question: You have
I have 2 matrix structs means equal data but have different form like these:
I have an wrapping object array -in fact a matrix- which includes a checkbox,

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.