Importing XML files in R
To import XML files here we are going to use XML Package in R Programming language.
XML file for demonstration:
XML
< RECORDS > < STUDENT > < ID >1</ ID > < NAME >Alia</ NAME > < MARKS >620</ MARKS > < BRANCH >IT</ BRANCH > </ STUDENT > < STUDENT > < ID >2</ ID > < NAME >Brijesh</ NAME > < MARKS >440</ MARKS > < BRANCH >Commerce</ BRANCH > </ STUDENT > < STUDENT > < ID >3</ ID > < NAME >Yash</ NAME > < MARKS >600</ MARKS > < BRANCH >Humanities</ BRANCH > </ STUDENT > < STUDENT > < ID >4</ ID > < NAME >Mallika</ NAME > < MARKS >660</ MARKS > < BRANCH >IT</ BRANCH > </ STUDENT > < STUDENT > < ID >5</ ID > < NAME >Zayn</ NAME > < MARKS >560</ MARKS > < BRANCH >IT</ BRANCH > </ STUDENT > </ RECORDS > |
Reading XML file:
It can be read after installing the package and then parsing it with xmlparse() function.
R
# loading the library and other important packages library ( "XML" ) library ( "methods" ) # the contents of sample.xml are parsed data <- xmlParse (file = "sample.xml" ) print (data) |
Output:
1
Alia
620
IT
2
Brijesh
440
Commerce
3
Yash
600
Humanities
4
Mallika
660
IT
5
Zayn
560
IT
How To Import Data from a File in R Programming
The collection of facts is known as data. Data can be in different forms. To analyze data using R programming Language, data should be first imported in R which can be in different formats like txt, CSV, or any other delimiter-separated files. After importing data then manipulate, analyze, and report it.
Contact Us