Analysis in R: Examples of commands for extracting data about vectors

This is a sample command for extracting data from vectors. This is a rudimentary introduction to the topic.

Checked with R version 4.2.2.

Example

See the command and package help for details.

###Creating Data#####
TestData <- 1:10
#Check
TestData
[1]  1  2  3  4  5  6  7  8  9 10
########

#Extraction of the fifth element
TestData[5]
[1] 5

#Replace the 5th element with 0
TestData[5] <- 0
#Check
TestData
[1]  1  2  3  4  0  6  7  8  9 10

#Extract even numbers from data
#But, 0 is excluded
TestData[TestData %% 2 == 0 & TestData != 0]
[1]  2  4  6  8 10

#Assign a name to the data
names(TestData) <- letters[1:10]
#Check
TestData
a  b  c  d  e  f  g  h  i  j 
1  2  3  4  0  6  7  8  9 10

#Extract data by name
TestData["e"]
e 
0

#Extract by range
TestData[4:9]
d e f g h i 
4 0 6 7 8 9 

I hope this makes your analysis a little easier !!

Prices and shipping availability may change. Please refer to the product page at time of purchase.
Content displayed on this site is provided by Amazon and may be updated or removed.
Amazon Associate, karada-good earns income through qualifying sales.
Copied title and URL