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

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,851 questions

51,772 answers

573 users

How to access elements of a vector using index in R

3 Answers

0 votes
vec <- c(4, 6, 8, 1, 5)

print(vec[1])
print(vec[2]) 
print(vec[3]) 
 

 
# run:
#
# [1] 4
# [1] 6
# [1] 8
#
 

 



answered Jun 23, 2021 by avibootz
0 votes
vec <- c(4, 6, 8, 1, 9, 7)

print(vec[c(2, 4, 5)])

 

 
# run:
#
# [1] 6 1 9
#
 

 



answered Jun 23, 2021 by avibootz
0 votes
vec <- c(4, 6, 8, 1, 9, 7)

print(vec[-1])

 

 
# run:
#
# [1] 6 8 1 9 7
#

 



answered Jun 23, 2021 by avibootz

Related questions

1 answer 124 views
1 answer 136 views
1 answer 125 views
125 views asked Jul 2, 2021 by avibootz
1 answer 226 views
226 views asked Jul 7, 2021 by avibootz
1 answer 118 views
118 views asked Jul 4, 2021 by avibootz
1 answer 153 views
1 answer 140 views
140 views asked Jun 24, 2021 by avibootz
...