help to display a csv output

hello
As you can see, i add a new column calculation in my csv file

library('dplyr')
read.csv("C:\\Users\\xx\\Documents\\INFORMATIQUE\\DATA SCIENCE\\dataset\\mtcars.csv", header=TRUE) 
filter(mtcars, gear %in% '4' & carb %in% '1') 
mtcars$toto <- (mtcars$gear * mtcars$carb)

when I execute the script, i would like to display only the output result (actually I have the csv file and the output both displayed - see screenshot)

I have also another question: instead using the entire path like below i would like to use a relative path
how to do please?

read.csv("C:\\Users\\xx\\Documents\\INFORMATIQUE\\DATA SCIENCE\\dataset\\mtcars.csv", header=TRUE) 

Does this help?

dd <- mtcars  %>%  filter(gear %in% '4' & carb %in% '1')  %>%  
      mutate(toto = gear * carb)
dd

I am not a Windows user so I am not sure about the best way to do a relative path in that OS.

Unfortunately, not
I try something like this but the histogram is not based on the filter output but on the entire output

library('dplyr') library('ggplot2') data = read.csv("C:\\Users\\xx\\Documents\\INFORMATIQUE\\DATA SCIENCE\\dataset\\mtcars.csv", header=TRUE) filter(data, gear %in% '4') hist( x = data$gear, main = "Gear")

To use a relative path, first run

Sys.getenv("HOME")

That will return something like

"C:/Users/fjcc/Documents"

You can then refer to that part of the file path with ~. So if you get "C:/Users/xx/Documents, you can use

data = read.csv("~/INFORMATIQUE/DATA SCIENCE/dataset/mtcars.csv", header=TRUE) 

To get the histogram to work, try

library('dplyr') 
library('ggplot2') 
data = read.csv("C:\\Users\\xx\\Documents\\INFORMATIQUE\\DATA SCIENCE\\dataset\\mtcars.csv", header=TRUE) 

data = filter(data, gear %in% '4') 
hist( x = data$gear, main = "Gear")

A somewhat similar approach to that of @FJCC

library(tidyverse)
dat1 <- mtcars
dat2 <- dat1  %>%  filter(gear == 4)
hist(dat2$gear)
![hist_gear|404x388](upload://tvbQ9XHnUixaD5IQzyGsd1csGv2.png)

However I am not sure it is going to give you anything useful. All you will get is

hist_gear

Perpaps you could tell us in substantive terms what you wish to do?

1 Like

This topic was automatically closed 7 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.