is there any mistake while plotting data? - plot

I'm trying to plot this data
data
I created a txt file and provide but I get this: Bad data on line 1 of file data.txt

Related

In R, why is my Excel Table being organized properly

I am read the csv file, UMP into R and when I enter the print command, the data goes from a basic table that is not even anymore, and this is causing my plotted graph to become a complete mess.
How can I make sure my Excel CSV file is read properly?
Your table doesn't have an header.
Try:
data <- read.csv('mytable.csv',header=F)
colnames(data) <- c('year','value')

Normal probability plot using info from a text file

I am quite new to R and I have a problem which requires the use of a text file as data and to create the Normal Probability plot of the data in the text file. I am confused on how to reference to the text file in R and use it as a parameter in the function qqnorm()
If the text file (example.txt) is a table and you want to open it as a data frame, you can open the file with the command df<-read.table("example.txt") and thereafter continue to work in R. Your data is now in df.

setwd in R - mapped drive?

Sorry I am very new to this, so am confused. I am working on a project that requires me to analyze data that is on a shared drive. I cannot make a copy of the dataset. How do I load this dataset in R? It's also a SAS file I'll need to read into R.
The file is smb://department.university.edu/lab101/me/dataset/file.xpt Setwd(smb://department.university.edu/lab101/me/dataset) doesn't work, but am not sure what would here.
First, Your setwd receives a character string as file path:
setwd("smb:\\department.university.edu\lab101\me\dataset")
Then you can read the file like mentioned here:
# save SAS dataset in trasport format
libname out xport 'c:/mydata.xpt';
data out.mydata;
set sasuser.mydata;
run;
# in R
library(Hmisc)
mydata <- sasxport.get("file.xpt")
# character variables are converted to R factors
Reference: http://www.statmethods.net/input/importingdata.html

Vcorpus Rstudio combining .txt files

I have a directory of .txt files and need to combine then into one file. each file would be a separate line. I tried:
new_corpus <-VCorpus(DirSource("Downloads/data/"))
The data is in the file but I get an error
Error in DirSource(directory = "Downloads/data/") :
empty directory
This is a bit basic but I was only given this information on how to create the corpus. What I need to do is take this file and create one factor that is the .txt and another with an ID, in the form of:
ID .txt
ID .txt
.......
EDIT To clarify on emilliman5 comment:
I need both a data frame and a corpus. The example I am working from used a csv file with the data already tagged for a Naive Bayes problem. I can work through that example and all the steps. The data I have is in a different format. It is 2 directories (/ham and /spam) of short .txt files. I was able to create a corpus, when I changed my command to:
new_corpus <-VCorpus(DirSource("~/Downloads/data/"))
I have cleaned the raw data and can make DTM but at the end I will need to create a crossTable with the labels spam and ham. I do not understand how I insert that information into the corpus.

Using a CSV file to create a stem plot

I'm new to R (and anything programming related) so am getting my head around what is actually happening.
I created a CSV file in Excel with one column consisting of names and the other column consisting of pretend exam scores for each name. I saved it from Excel as a CSV file.
So to import it into R I used the following command:
data1<- read.csv(file.choose(),header=F)
When I created the CSV file I didn't create any headers so the column for names is given the header V1 and the column for the exam scores is given the header V2.
So to create my stem plot I then use the command:
class_stem <- stem(data1$V2)
Is this the most efficient way to do this?
My real confusion starts when I import the data as a table. Should I be even importing it as a table or just leaving it as I had done? My purpose at this stage was just to create a stem and leaf plot

Resources