Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In R language: (I know it's labeled under Phyton but this is R) I need to write a function where I ask the name of

In R language: (I know it's labeled under Phyton but this is R)

I need to write a function where I ask the name of a player and check if the name of that player already exists in the DataFile. If it doesn't exist, then we should add one point to him/her. If it exists add 1 to it's previous score.

Here there's more or less the structure to follow.

function1 <- function()

{

#You have to ask the name of the player

exist=file_exists("C://Program Files//R//exercise1.txt")

if(exists==false)

{

#here, you have to create a matrix or dataframe with the name (that you have asked) and game=1

data=matrix(c(1,2,3,4),2,2)

write.table(data, file= "C://Program Files//R//exercise1.txt")

}

else

{

print("exists")

dataFile=read.table("C://Program Files//R//exercise1.txt", header = TRUE)

#You need a loop (while or repeat) to check if the name of the player is in dataFile,

#If the name is, you have to add 1 to the game

#Else rbind to insert a row in the matrix or dataframe.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

lead country in

Answered: 1 week ago