spilt data.frame

Hello, I'm a student and I have little information in the field of R Studio. I have 50 synoptic stations precipitation data from 1986 to 2015. I need to sort the related information for the period of years from 2007 to 2015 for each station separately. I mean there are three variables: the station's name, the specific year, and the amount of precipitation, and I need the result for each station separately.
Does anyone know how to use "split" for this purpose?
May you please write codes from the beginning "read.table"?

Hi @mariam_rs7, welcome to RStudio Community.

You can use the split() function as follows (demonstrated on the built-in iris data set).

split(iris, f = iris$Species)

Species is a factor variable that contains three levels (or categories). Passing this vector as an argument to f returns a list of 3 data frames; each containing only those observations for that Species. In your case, you'd use the station name variable instead (convert it to factor if it isn't).

The use of read.table() is quite simple. This video is a useful quick intro on how to use it.

Dear siddharthprabhu,
thank you for your reply, I know about "split()", the problem is I can't illustrate the variables correclty and write my code. Is it possible to show me some codes?

I don't understand what you are expecting. Please create a minimal reproducible example by following this guide.

I need some results like this:

> system.time(chunk(x, n)) 
   name       year   precipitation
 station (1)  2015   30.125 

but there are some "names", "years" and  "precipitation" in my file that must be deleted. I want jut information related to 2007 to 2015 for each station separately.

Then you need to filter data for the required period before splitting by station.

It would really be much easier to help if you could post a reprex.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.