RStudio - weird formatting to append new row to .csv file - r

I am trying to append a new row of data to an existing .csv file but everytime I do so, it doesn't add it to a new row. Instead, it just appends to the last row like so:
Also, the first column is supposed to show the date but I'm not sure why it shows up as hashtags. But in the column where it shows 33882020-09-24, it should end at 3388 and everything else after that should be in their respective column below.
Here is what I have for my code. I've followed multiple forums on how to append to .csv files and did exactly what was shown so I am at a loss..
Any suggestions would be greatly appreciated! Thank you in advance!!

For the data, is possible that the Rstudio don't recognise the number as a data (because you use -, and for R is a operation. Try don't use this symbol, but for example_) or try to write 24sept2020.
For add a new row a found this info:
How can a add a row to a data frame in R?

Related

Function read_excel() interprets 'Currency' data type completely wrong in one file and good in another

I have two .xls files and they both containg columns 'Salary' which has values such as $575.000,00 or $2.000.000,00 and so on.
When I use read_excel to read the first file everything is stored fine and the column data types are correct.
However when I read the second file the column 'Salary' is filled with values like 8744-10-06 and 15589-07-13.
I'm not quite sure why that is happening so if anyone has an idea it would be greatly appreciated.

RDS table opened in RStudio. How do I find field Names?

As in the header, I have opened an RDS table in R Studio, and need to know the field names within that table.
But I don't know the correct command or syntax to follow this:
UK_2001 <- readRDS("D:/Census_History/Postcodes/2001_05_MAY_AFPD.rds")
Any guidance would be gratefully received.
Thanks in advance.
You can display the structure of any R object using str which will give you the object's type (e.g. data.frame), column names and column types as well.
str(UK_2001)
If you are just after the names of the columns colnames will do.

How to delete row in for loop function?

I want to delete the second row in every sheet in an excel file. Actually, i have done this.
for (i in 1:5)
{bulan=read_excel(file, sheet=sheet[i],skip = 2)}
but it deletes the first 2 rows. How to only delete the second one? Thanx
It depends whether you would really like to delete a row in your excel sheet or read an excel sheet without a certain row.
Because what your are doing here is actually not deleting rows, but skipping the first two rows when reading the sheets. The function read_excel returns a dataframe.
If you want the dataframe without the second row, what you could do is:
for(i in 1:5){bulan <- read_excel(file, sheet=sheet[i])
bulan <- bulan[-2,]
}
However, this would not make much sense as is, since bulan gets overwritten in every step of the for loop.
If you would like to delete rows in your excel file using R, you could read the file, delete the corresponding row of the dataframe in R, and read the dataframe to an excel file again. Apparently there is am R package called "xlsx" for writing excel files.

importing txt into R

I am trying to read an ftp file from the internet ("ftp://ftp.cmegroup.com/pub/settle/stlint") into R, using the following command:
aaa<-read.table("ftp://ftp.cmegroup.vom/pub/settle/stlint", sep="\t", skip=2, header=FALSE)
the result shows the 8th, 51st, 65th, 71st, 72nd, 73rd, 74th, etc etc rows of the resulting dataset as including add-on rows appended at the end. Basically instead of returning
{row8}
{row9}
etc
{row162}
{row163}
It returns (adding in the quotes around the \n)
{row8'\n'row9'\n'etc...etc...'\n'row162}
{row163}
If it seems like i'm picking arbitrary numbers then run the code above, take a look at the actual ftp file on the internet (as of mid-day feb18) and you'll see i'm not, it really adding 155x rows onto the end of the 8th row. So what i'm looking for is simply I'm looking for a way to read it in without the random appending of rows. Thanks, and apologize in advance i'm new to R and was not able to find this fix after a while of searching.

loading data and replacement in R

Hi sorry first post here my apologies if I made a mistake.
So I'm fairly new to R and I was given an assignment where I am loading a CSV file into R. When i read.csv the whole file I get a ton of blank spots where values should be. The only info printed out is the N/A in the cells which is actually what I am trying to replace.
So I took a small sample of the file only the first couple rows and the info came up correctly in my read.csv comand. My question is is the layout of the .csv too large to display the original data in my main.csv file?
Also, How would I go about replacing all the N/A and NA's in the file to change them to blank cells or ""
Sorry if i painted my scenario poorly
first make sure that all of you data in the csv file is in GENERAL format!
there should be a title for each of the columns too
if you have an empty cell in your csv file then input a 0 into it
and make sure that around the data you CLEAR ALL the cells around them just incase there is anything funny in them
hope that helps if not then you could send me your file to sgreenaway#vmware.com and i will check it out for you :)

Resources