Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Semrush - keyword research tool

Linux Foundation Training and Certification

Teach Your Child To Read

Disclosure: My content contains affiliate links.

32,304 questions

42,479 answers

573 users

How to create data frame from matrix with numbers and NA values in R

1 Answer

0 votes
m = matrix(sample(c(NA, 1:10), 100, replace = TRUE), 10)
 
df <- as.data.frame(m)

print(df)
 

 
 
       
       
# run:
#
#    V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
# 1   5  3  5  5  1  6 NA NA  9   4
# 2   2  4  8  9  9  6  7 10  2   9
# 3   6  9  2 NA  3 NA  5  3 10   9
# 4   1  9  4  9  6  5 10 10  9  NA
# 5   4 10  3  1  4  9  6  2  3   4
# 6  NA  2  1  2  1  9  3 NA  2   7
# 7   1  3  6  2  8 10 NA NA  6   1
# 8   4 10  3  3 NA  4  1  1  7  NA
# 9   1  1  7 10  9  7  5  9  7   3
# 10  2 10  1  9  9  4 10  6 10   3
#

 



Learn & Practice Python
with the most comprehensive set of 13 hands-on online Python courses
Start now


answered Jul 9, 2021 by avibootz

Related questions

1 answer 102 views
1 answer 115 views
1 answer 115 views
1 answer 106 views
1 answer 98 views
...