pdmotta
1
Something like
> meus_dados <- read.csv("C:\\R_Estudos\\baseballdatabank-master\\baseballdatabank-master\\core\\People_.csv", header = TRUE)
> head(meus_dados)
playerID weight height
1 aardsda01 215 75
2 aaronha01 180 72
3 aaronto01 190 75
4 aasedo01 190 75
5 abadan01 184 73
6 abadfe01 235 74
> meus_dados <- sample(round(0.03*20322))
> head(meus_dados)
[1] 37 213 334 5 307 359
How can I use sample() and keepd the Header ?
Thanks
That has nothing to do with your dataset. It is just creating 609 (0.03*20322) random numbers.
What are you looking to do?
a01 215 75
2 aaronha01 180 72
3 aaronto01 190 75
4 aasedo01 190 75
5 abadan01 184 73
6 abadfe01 235 74
By the way, we can't read your csv file. Create a reprex instead, or even a sample dataset e.g.
data.frame(player_id = letters[1:6],
height = runif(6, 170, 220),
weight = runif(6, 70, 80))
pdmotta
3
Ok , thanks but how can I extract a sample from a dstaset ?
Something like 3% of a csv ?
Use dplyr::slice_sample()
library(dplyr)
meus_datos <- data.frame(player_id = letters[1:6],
height = runif(6, 170, 220),
weight = runif(6, 70, 80))
meus_datos %>%
slice_sample(prop = 0.5)
meus_datos %>%
slice_sample(n = 3)
startz
5
Or alternatively,
> library(tidyverse)
> z <- data.frame(a=2:10)
> colnames(z) <- "hello"
> z
hello
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
> sample_frac(z,0.5)
hello
1 10
2 5
3 8
4 2
1 Like
pdmotta
6
Thanks , I agree with the the csv but it´s not the deal anyway.
system
Closed
7
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.