read.table, problem with command view

#1

hello i try to make a time serie with hydroTSM package.But i have a problem with importing data. I have a textbook that i added called "DOKIMASTIKO6". My problem is that when i call it with view command, it shows my dates and v1,v2,v3 and not the values under my dates as you can see in the picture below. I need this for running my "hydroTSM" package..thank you a lot in advance

0 Likes

#2

Hi @sgkiourtzis! Welcome!

It's hard to know quite what's going wrong here without seeing the code you used to create the DOKIMASTIKO6 data frame. It looks like the data got transposed somewhere along the way. If you look in your Environment pane you'll see that DOKIMASTIKO6 has "2 obs. of 504 variables" — in other words, 2 rows and 504 columns. It seems like it ought to have 504 rows and 2 columns, instead?

The best way to get an answer is to turn this question into a small reproducible example, so that other people can see the code and run it for themselves. Start by reading the tips here: FAQ: Tips for writing R-related questions

Making reproducible examples for data import questions can be tricky, because the code depends on an external file (the data you imported). If the data is shareable, you can post the file somewhere that people here can access, like Google Drive or GitHub. If it's not shareable, then you'll need to create an example file that shows the same problem as your real file when imported using the same code.

If you get stuck on a reproducible example, please at least try to post your import code, following all the tips in the above link! :grin:

0 Likes

#3

I imported that from an excel sheet. Indeed I want these 2 rows and 504 columns, because , the first row is dates and second is raining in mm. My problem as you can see in the results at the bottom of the image is that I have v1 v2 v3 and I dont want to have these v1 v2 v3 but only the dates and the raining in mm. I want to get rid of the imaginary row (v1,v2,v3)

0 Likes

#4

Ah, I see. "V1", "V2", etc are the column names of the data frame. A data frame has to have column names, and since your data did not contain any, the import function created default ones for you. Were you expecting that the dates would be the column names?

In R data frames and the many functions that work with them, columns are generally assumed to represent variables and rows are generally assumed to represent observations. For your data, you have two variables — date and rainfall measurement — and 504 observations. You can force R to create a data frame with one column for each observation and only one row, but this is not going to be easy to work with down the line.

Given your data, perhaps you wanted to create a time series object, not a data frame? You can read more about them here: https://www.rdocumentation.org/packages/stats/versions/3.5.1/topics/ts Typically, data import functions read data in to a data frame, which you can then convert into a ts object. ts objects are somewhat limited — if your data don't fit ts()'s assumptions, you'll probably want to look at the zoo or xts packages.

Again, for more specific advice or help, you will need to create a reproducible example or post your data import code and a sample of your data.

0 Likes