Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

How to transform a dataset in R?

$
0
0

For my job I am trying to write some code to calculate the required number of parking spaces. I have data about the number of cars arriving each hour and about the parking duration (generated via rnorm) of each car on the parking. Now i would like to calculate per minute how many parking spaces are required.

dataset

(Hour & Attraction_intensity variables)

timeonparking <- round(rnorm(14, mean = 35, sd = 10))

First I would like to generate X numbers (uniform distribution; representing minute of arrival within the given hour) for each row/hour between 0-59 where X is equal to the attraction_intensity that hour.

The new dataframe should look like this:

new dataframe

Could someone help me please? My first idea was to use a for loop. But this would not result in the table shown above, and the code contains errors which i cannot find (i am a beginner to R). I don't know how to transform the dataset.

First attempt:

for (i in nrow(df) {
    df1 <- paste(df$ï..hour[i], list(runif(df$attraction_vehicles[i], min = 0, max = 59)))
}

Many thanks!


Viewing all articles
Browse latest Browse all 201867

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>